Ignore:
Timestamp:
Mar 9, 2016, 9:16:11 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Network interface state notification made registrated as callback instead of fixed method in Notify class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Network/Network.php

    r795 r813  
    107107    $this->License = 'GNU/GPLv3';
    108108    $this->Description = 'Networking related tools';
    109     $this->Dependencies = array();
     109    $this->Dependencies = array('Notify');
    110110  }
    111111
     
    120120  function DoStart()
    121121  {
     122    $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkReachability', array($this, 'ReachabilityCheck'));
     123   
    122124    $this->System->RegisterPage('network', 'PageNetwork');
    123125    $this->System->RegisterPage(array('network', 'administration'), 'PageNetworkAdministration');
     
    593595  {
    594596  }
     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  }
    595656}
Note: See TracChangeset for help on using the changeset viewer.