Changeset 813
- Timestamp:
- Mar 9, 2016, 9:16:11 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Version.php
r810 r813 1 1 <?php 2 2 3 $Revision = 81 0; // Subversion revision3 $Revision = 813; // Subversion revision 4 4 $DatabaseRevision = 808; // SQL structure revision 5 $ReleaseTime = strtotime('2016-03-0 6');5 $ReleaseTime = strtotime('2016-03-09'); -
trunk/Modules/Network/Network.php
r795 r813 107 107 $this->License = 'GNU/GPLv3'; 108 108 $this->Description = 'Networking related tools'; 109 $this->Dependencies = array( );109 $this->Dependencies = array('Notify'); 110 110 } 111 111 … … 120 120 function DoStart() 121 121 { 122 $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkReachability', array($this, 'ReachabilityCheck')); 123 122 124 $this->System->RegisterPage('network', 'PageNetwork'); 123 125 $this->System->RegisterPage(array('network', 'administration'), 'PageNetworkAdministration'); … … 593 595 { 594 596 } 597 598 function OnlineList($Title, $OnlineNow, $OnlinePrevious, $MinDuration) 599 { 600 $Time = time(); 601 $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>'); 602 $Output = ''; 603 $Condition = 'WHERE (`NetworkInterface`.`Online` = '.$OnlineNow.') AND (`NetworkInterface`.`OnlineNotify` = '.$OnlinePrevious.') '. 604 'AND (`NetworkInterface`.`LastOnline` <= "'.TimeToMysqlDateTime($Time - $MinDuration).'")'; 605 $DbResult3 = $this->Database->query('SELECT CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) AS `Name`, '. 606 '`NetworkInterface`.`Online`, `NetworkInterface`.`LastOnline` FROM `NetworkInterface` '. 607 'LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '. 608 $Condition.' AND (`NetworkDevice`.`PermanentOnline`=1) AND (`NetworkDevice`.`Used`=1) AND '. 609 '(`NetworkInterface`.`LocalIP` != "") '. 610 'ORDER BY `Name` ASC'); 611 if($DbResult3->num_rows > 0) 612 { 613 $Output .= $Title.'<br/>'; 614 $Output .= '<table>'. 615 '<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"; 616 while($Item = $DbResult3->fetch_assoc()) 617 { 618 $Duration = $Time - MysqlDateTimeToTime($Item['LastOnline']); 619 $DurationText = sprintf('%02d', floor($Duration / 3600 % 24)).':'. 620 sprintf('%02d', floor($Duration / 60 % 60)).':'. 621 sprintf('%02d', floor($Duration % 60)); 622 $Days = floor($Duration / (60 * 60 * 24)); 623 if($Days > 0) $DurationText = $Days.' dnů '.$DurationText; 624 625 $Output .= '<tr><td>'.$Item['Name'].'</td><td>'.$OnlineText[$Item['Online']]. 626 '</td><td>'.$Item['LastOnline'].'</td><td>'.$DurationText.'</td></tr>'."\n"; 627 } 628 $Output .= '</table><br/>'."\n"; 629 } 630 $this->Database->query('UPDATE `NetworkInterface` SET `OnlineNotify` = `Online` '. 631 $Condition); 632 return $Output; 633 } 634 635 function ReachabilityCheck() 636 { 637 $Output = ''; 638 $Output = $this->OnlineList('Nově online', 1, 0, 0); 639 $Output .= $this->OnlineList('Nově offline', 0, 1, 5 * 60); 640 if($Output != '') $Output .= $this->OnlineList('Stále offline', 0, 0, 0); 641 return($Output); 642 } 643 644 function CheckPortStatus($Ip, $Port) 645 { 646 $Timeout = 1; 647 if($Socket = @fsockopen($Ip, $Port, $ErrorNumber, $ErrorString, $Timeout)) 648 { 649 fclose($Socket); 650 return(1); 651 } else 652 { 653 return(0); 654 } 655 } 595 656 } -
trunk/Modules/Notify/Notify.php
r772 r813 1 1 <?php 2 3 define('CONTACT_CATEGORY_EMAIL', 4); 2 4 3 5 class ModuleNotify extends AppModule 4 6 { 7 var $Checks; 8 5 9 function __construct($System) 6 10 { … … 11 15 $this->License = 'GNU/GPL'; 12 16 $this->Description = 'Send notification messages to selected users'; 13 $this->Dependencies = array('User', 'Subject'); 17 $this->Dependencies = array('User'); 18 $this->Checks = array(); 14 19 } 15 20 … … 34 39 )); 35 40 } 36 37 function OnlineList($Title, $OnlineNow, $OnlinePrevious, $MinDuration)41 42 function RegisterCheck($Name, $Callback) 38 43 { 39 $Time = time(); 40 $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>'); 41 $Output = ''; 42 $Condition = 'WHERE (`NetworkInterface`.`Online` = '.$OnlineNow.') AND (`NetworkInterface`.`OnlineNotify` = '.$OnlinePrevious.') '. 43 'AND (`NetworkInterface`.`LastOnline` <= "'.TimeToMysqlDateTime($Time - $MinDuration).'")'; 44 $DbResult3 = $this->Database->query('SELECT CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) AS `Name`, '. 45 '`NetworkInterface`.`Online`, `NetworkInterface`.`LastOnline` FROM `NetworkInterface` '. 46 'LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '. 47 $Condition.' AND (`NetworkDevice`.`PermanentOnline`=1) AND (`NetworkDevice`.`Used`=1) AND '. 48 '(`NetworkInterface`.`LocalIP` != "") '. 49 'ORDER BY `Name` ASC'); 50 if($DbResult3->num_rows > 0) { 51 $Output .= $Title.'<br/>'; 52 $Output .= '<table>'. 53 '<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"; 54 while($Item = $DbResult3->fetch_assoc()) 55 { 56 $Duration = $Time - MysqlDateTimeToTime($Item['LastOnline']); 57 $DurationText = sprintf('%02d', floor($Duration / 3600 % 24)).':'. 58 sprintf('%02d', floor($Duration / 60 % 60)).':'. 59 sprintf('%02d', floor($Duration % 60)); 60 $Days = floor($Duration / (60 * 60 * 24)); 61 if($Days > 0) $DurationText = $Days.' dnů '.$DurationText; 62 63 $Output .= '<tr><td>'.$Item['Name'].'</td><td>'.$OnlineText[$Item['Online']]. 64 '</td><td>'.$Item['LastOnline'].'</td><td>'.$DurationText.'</td></tr>'."\n"; 65 } 66 $Output .= '</table><br/>'."\n"; 67 } 68 $this->Database->query('UPDATE `NetworkInterface` SET `OnlineNotify` = `Online` '. 69 $Condition); 70 return $Output; 44 if(array_key_exists($Name, $this->Checks)) 45 throw new Exception('Check function "'.$Name.'" already registered.'); 46 $this->Checks[$Name] = array('Callback' => $Callback); 47 } 48 49 function UnregisterCheck($Name) 50 { 51 if(!array_key_exists($Name, $this->Checks)) 52 throw new Exception('Check function "'.$Name.'" not registered.'); 53 unset($this->Checks[$Name]); 71 54 } 72 55 … … 74 57 { 75 58 $Output = ''; 59 $Content = ''; 60 61 // Get output from checks 62 $DbResult2 = $this->Database->query('SELECT `Id`, `Name`, `SysName` FROM `NotifyCategory`'); 63 while($Category = $DbResult2->fetch_assoc()) 64 { 65 if(array_key_exists($Category['SysName'], $this->Checks)) 66 { 67 $List = call_user_func($this->Checks[$Category['SysName']]['Callback']); 68 if($List != '') { 69 $Output .= 'Kategorie: '.$Category['Name'].":\n"; 70 $Content .= 'Kategorie: '.$Category['Name']."<br>\n"; 71 $Content .= $List; 72 } 73 } 74 } 75 76 // Send content to users 76 77 $DbResult = $this->Database->query('SELECT `NotifyUser`.`Id`, `NotifyUser`.`LastTime`, `User`.`Name`, `Contact`.`Value`, `Contact`.`Category` FROM `NotifyUser` '. 77 78 'LEFT JOIN `User` ON `User`.`Id` = `NotifyUser`.`User` '. … … 80 81 { 81 82 $Time = time(); 82 $Content = '';83 83 $Output .= 'User '.$User['Name'].'<br/>'; 84 $DbResult2 = $this->Database->query('SELECT `Id`, `Name`, `SysName` FROM `NotifyCategory`'); 85 while($Category = $DbResult2->fetch_assoc()) 86 { 87 if($Category['SysName'] == 'NetworkReachability') { 88 $List = $this->OnlineList('Nově online', 1, 0, 0); 89 $List .= $this->OnlineList('Nově offline', 0, 1, 5 * 60); 90 if($List != '') $List .= $this->OnlineList('Stále offline', 0, 0, 0); 91 if($List != '') { 92 $Output .= 'Kategorie: '.$Category['Name'].":\n"; 93 $Content .= 'Kategorie: '.$Category['Name']."<br>\n"; 94 $Content .= $List; 95 } 96 } 97 } 84 98 85 $this->Database->update('NotifyUser', '`Id`='.$User['Id'], array('LastTime' => TimeToMysqlDateTime($Time))); 99 86 100 if(($User['Category'] == 4) and ($Content !='')) {87 if(($User['Category'] == CONTACT_CATEGORY_EMAIL) and ($Content !='')) { 101 88 $Mail = new Mail(); 102 89 $Mail->Subject = 'Notification'; 103 90 $Mail->AddTo($User['Value'], $User['Name']); 104 $Mail->AddBody(strip_tags($Content), 'text/plain');91 //$Mail->AddBody(strip_tags($Content), 'text/plain'); 105 92 $Mail->AddBody('<style> 106 93 table { border-collapse: collapse; } … … 110 97 $Mail->Send(); 111 98 $Output .= 'Sent email to '.$User['Value'].' ('.$User['Name'].')<br/>'; 112 $Output .= $Content;99 $Output .= strip_tags(str_replace("</", " </", str_replace('<br/>', "\n", $Content))); 113 100 } 114 101 … … 147 134 ADD CONSTRAINT `NotifyUser_ibfk_1` FOREIGN KEY (`User`) REFERENCES `User` (`Id`), 148 135 ADD CONSTRAINT `NotifyUser_ibfk_2` FOREIGN KEY (`Contact`) REFERENCES `Contact` (`Id`);'); 149 150 136 } 151 137
Note:
See TracChangeset
for help on using the changeset viewer.