Changeset 814 for trunk/Modules/Network/Network.php
- Timestamp:
- Mar 9, 2016, 10:07:18 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Network/Network.php
r813 r814 120 120 function DoStart() 121 121 { 122 $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkReachability', array($this, 'ReachabilityCheck')); 122 $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkReachability', 123 array($this, 'ReachabilityCheck')); 124 $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkPort', 125 array($this, 'PortCheck')); 126 123 127 124 128 $this->System->RegisterPage('network', 'PageNetwork'); … … 188 192 'ExternalIP' => array('Type' => 'IPv4Address', 'Caption' => 'Veřejná IPv4', 'Default' => '', 'Null' => true), 189 193 'Device' => array('Type' => 'TNetworkDevice', 'Caption' => 'Zařízení', 'Default' => ''), 194 'Enabled' => array('Type' => 'Boolean', 'Caption' => 'Povoleno', 'Default' => '1'), 190 195 'Online' => array('Type' => 'TOnlineState', 'Caption' => 'Běží', 'Default' => '0', 'ReadOnly' => true), 191 196 'LastOnline' => array('Type' => 'DateTime', 'Caption' => 'Naposledy běželo', 'Default' => '', 'ReadOnly' => true), … … 194 199 'Signal' => array('Type' => 'TNetworkSignalListInterface', 'Caption' => 'Signál', 'Default' => ''), 195 200 'Wireless' => array('Type' => 'TNetworkInterfaceWirelessListInterface', 'Caption' => 'Bezdrátové spoje', 'Default' => ''), 201 'Ports' => array('Type' => 'TDevicePortListInterface', 'Caption' => 'Síťové porty', 'Default' => ''), 196 202 ), 197 203 )); … … 225 231 'AddressRangeIPv6' => array('Type' => 'String', 'Caption' => 'Rozsah adres IPv6', 'Default' => ''), 226 232 'Configure' => array('Type' => 'Boolean', 'Caption' => 'Nastavovat', 'Default' => ''), 233 ), 234 )); 235 $this->System->FormManager->RegisterClass('NetworkPort', array( 236 'Title' => 'Síťový port', 237 'Table' => 'NetworkPort', 238 'Items' => array( 239 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''), 240 'Number' => array('Type' => 'Integer', 'Caption' => 'Číslo', 'Default' => ''), 241 'Interface' => array('Type' => 'TNetworkInterface', 'Caption' => 'Rozhraní', 'Default' => ''), 242 'Enabled' => array('Type' => 'Boolean', 'Caption' => 'Povoleno', 'Default' => '1'), 243 'Online' => array('Type' => 'TOnlineState', 'Caption' => 'Běží', 'Default' => '0', 'ReadOnly' => true), 244 'LastOnline' => array('Type' => 'DateTime', 'Caption' => 'Naposledy běželo', 'Default' => '', 'ReadOnly' => true), 227 245 ), 228 246 )); … … 510 528 'Filter' => '1', 511 529 )); 530 $this->System->FormManager->RegisterFormType('TDevicePortListInterface', array( 531 'Type' => 'ManyToOne', 532 'Table' => 'NetworkPort', 533 'Id' => 'Id', 534 'Ref' => 'Interface', 535 'Filter' => '1', 536 )); 512 537 $this->System->FormManager->RegisterFormType('TNetworkLinkType', array( 513 538 'Type' => 'Reference', … … 654 679 } 655 680 } 681 682 function PortCheckList($Title, $OnlineNow, $OnlinePrevious, $MinDuration) 683 { 684 $Time = time(); 685 $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>'); 686 $Output = ''; 687 $Condition = 'WHERE (`NetworkPort`.`Online` = '.$OnlineNow.') AND (`NetworkPort`.`OnlineNotify` = '.$OnlinePrevious.') '. 688 'AND (`NetworkPort`.`LastOnline` <= "'.TimeToMysqlDateTime($Time - $MinDuration).'")'; 689 $DbResult3 = $this->Database->query('SELECT CONCAT(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")), ":", `NetworkPort`.`Number`) AS `Name`, '. 690 '`NetworkPort`.`Online`, `NetworkPort`.`LastOnline` FROM `NetworkPort` '. 691 'LEFT JOIN `NetworkInterface` ON `NetworkInterface`.`Id` = `NetworkPort`.`Interface` '. 692 'LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '. 693 $Condition.' AND (`NetworkDevice`.`PermanentOnline`=1) AND (`NetworkDevice`.`Used`=1) AND '. 694 '(`NetworkInterface`.`LocalIP` != "") AND (`NetworkPort`.`Enabled` = 1)'. 695 'ORDER BY `Name` ASC'); 696 echo($this->Database->LastQuery); 697 if($DbResult3->num_rows > 0) 698 { 699 $Output .= $Title.'<br/>'; 700 $Output .= '<table>'. 701 '<tr><th align="center">Jméno</th><th align="center">Stav</th><th align="center">Čas</th><th align="center">Trvání</th></tr>'."\n"; 702 while($Item = $DbResult3->fetch_assoc()) 703 { 704 $Duration = $Time - MysqlDateTimeToTime($Item['LastOnline']); 705 $DurationText = sprintf('%02d', floor($Duration / 3600 % 24)).':'. 706 sprintf('%02d', floor($Duration / 60 % 60)).':'. 707 sprintf('%02d', floor($Duration % 60)); 708 $Days = floor($Duration / (60 * 60 * 24)); 709 if($Days > 0) $DurationText = $Days.' dnů '.$DurationText; 710 711 $Output .= '<tr><td>'.$Item['Name'].'</td><td>'.$OnlineText[$Item['Online']]. 712 '</td><td>'.$Item['LastOnline'].'</td><td>'.$DurationText.'</td></tr>'."\n"; 713 } 714 $Output .= '</table><br/>'."\n"; 715 } 716 $this->Database->query('UPDATE `NetworkPort` SET `OnlineNotify` = `Online` '. 717 $Condition); 718 return $Output; 719 } 720 721 function PortCheck() 722 { 723 $Output = ''; 724 $Output = $this->PortCheckList('Nově online', 1, 0, 0); 725 $Output .= $this->PortCheckList('Nově offline', 0, 1, 5 * 60); 726 if($Output != '') $Output .= $this->PortCheckList('Stále offline', 0, 0, 0); 727 return($Output); 728 } 656 729 }
Note:
See TracChangeset
for help on using the changeset viewer.