Changeset 814


Ignore:
Timestamp:
Mar 9, 2016, 10:07:18 PM (9 years ago)
Author:
chronos
Message:
  • Added: Notify callback for checking state of network ports. Network ports can be defined as subtable under network interface.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r808 r814  
    19461946        "VALUES (NULL , 'Kontrola pokladen', ".$DbRow['Id'].", '".$ActionId."', '1');");
    19471947  }
    1948 
     1948}
     1949
     1950function UpdateTo814($Manager)
     1951{
     1952  $Manager->Execute('CREATE TABLE IF NOT EXISTS `NetworkPort` (
     1953    `Id` int(11) NOT NULL AUTO_INCREMENT,
     1954    `Name` varchar(255) NOT NULL,
     1955    `Interface` int(11) NOT NULL,
     1956    `Number` int(11) NOT NULL,
     1957    `Enabled` int(11) NOT NULL,
     1958    `Online` int(11) NOT NULL,
     1959    `LastOnline` datetime NULL,
     1960    `OnlineNotify` int(11) NOT NULL,
     1961    PRIMARY KEY (`Id`),
     1962    KEY `Interface` (`Interface`)
     1963    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
     1964
     1965  $Manager->Execute('ALTER TABLE `NetworkPort`
     1966  ADD CONSTRAINT `NetworkPort_ibfk_1` FOREIGN KEY (`Interface`) REFERENCES `NetworkInterface` (`Id`);');
     1967  $Manager->Execute('ALTER TABLE `NetworkInterface` ADD `Enabled` INT NOT NULL DEFAULT "1" AFTER `OnlineNotify`;');
     1968  $Manager->Execute('ALTER TABLE `NetworkInterface` CHANGE `LastOnline` `LastOnline` DATETIME NULL;');
     1969  $Manager->Execute('UPDATE `NetworkInterface` SET `LastOnline` = NULL WHERE `LastOnline` = "0000-00-00 00:00:00"');
     1970  $Manager->Execute('ALTER TABLE `NetworkDevice` CHANGE `LastOnline` `LastOnline` DATETIME NULL;');
     1971  $Manager->Execute('UPDATE `NetworkDevice` SET `LastOnline` = NULL WHERE `LastOnline` = "0000-00-00 00:00:00"');
    19491972}
    19501973
     
    20372060      803 => array('Revision' => 807, 'Function' => 'UpdateTo807'),
    20382061      807 => array('Revision' => 808, 'Function' => 'UpdateTo808'),
     2062      808 => array('Revision' => 814, 'Function' => 'UpdateTo814'),
    20392063    ));
    20402064  }
  • trunk/Application/Version.php

    r813 r814  
    11<?php
    22
    3 $Revision = 813; // Subversion revision
    4 $DatabaseRevision = 808; // SQL structure revision
     3$Revision = 814; // Subversion revision
     4$DatabaseRevision = 814; // SQL structure revision
    55$ReleaseTime = strtotime('2016-03-09');
  • trunk/Modules/Network/Network.php

    r813 r814  
    120120  function DoStart()
    121121  {
    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   
    123127   
    124128    $this->System->RegisterPage('network', 'PageNetwork');
     
    188192        'ExternalIP' => array('Type' => 'IPv4Address', 'Caption' => 'Veřejná IPv4', 'Default' => '', 'Null' => true),
    189193        'Device' => array('Type' => 'TNetworkDevice', 'Caption' => 'Zařízení', 'Default' => ''),
     194        'Enabled' => array('Type' => 'Boolean', 'Caption' => 'Povoleno', 'Default' => '1'),
    190195        'Online' => array('Type' => 'TOnlineState', 'Caption' => 'Běží', 'Default' => '0', 'ReadOnly' => true),
    191196        'LastOnline' => array('Type' => 'DateTime', 'Caption' => 'Naposledy běželo', 'Default' => '', 'ReadOnly' => true),
     
    194199        'Signal' => array('Type' => 'TNetworkSignalListInterface', 'Caption' => 'Signál', 'Default' => ''),
    195200        'Wireless' => array('Type' => 'TNetworkInterfaceWirelessListInterface', 'Caption' => 'Bezdrátové spoje', 'Default' => ''),
     201        'Ports' => array('Type' => 'TDevicePortListInterface', 'Caption' => 'Síťové porty', 'Default' => ''),
    196202      ),
    197203    ));
     
    225231        'AddressRangeIPv6' => array('Type' => 'String', 'Caption' => 'Rozsah adres IPv6', 'Default' => ''),
    226232        '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),
    227245      ),
    228246    ));
     
    510528      'Filter' => '1',
    511529    ));
     530    $this->System->FormManager->RegisterFormType('TDevicePortListInterface', array(
     531      'Type' => 'ManyToOne',
     532      'Table' => 'NetworkPort',
     533      'Id' => 'Id',
     534      'Ref' => 'Interface',
     535      'Filter' => '1',
     536    ));
    512537    $this->System->FormManager->RegisterFormType('TNetworkLinkType', array(
    513538      'Type' => 'Reference',
     
    654679    }
    655680  }
     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  }
    656729}
  • trunk/Modules/NetworkConfigAirOS/Generators/Signal.php

    r781 r814  
    1111    // Load netwatch status from all DHCP routers
    1212    $DbResult3 = $this->Database->query('SELECT `Id`, `LoginName`, `LoginPassword`, '.
    13         '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '.
    14         'FROM `NetworkDevice` WHERE (`API` = 2) AND (`Used` = 1)');
     13      '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '.
     14      'FROM `NetworkDevice` WHERE (`API` = 2) AND (`Used` = 1)');
    1515    while($Device = $DbResult3->fetch_assoc())
    1616    {
     
    3434        $RateTx = $Properties['tx'];
    3535        $this->Database->insert('NetworkSignal', array('MAC' => $Properties['mac'],
    36             'Value' => $Strength, 'RateRx' => $RateRx, 'RateTx' => $RateTx,
    37             'Time' => TimeToMysqlDateTime($Time), 'Interface' => $Interface, 'Device' => $Device['Id']));
     36          'Value' => $Strength, 'RateRx' => $RateRx, 'RateTx' => $RateTx,
     37          'Time' => TimeToMysqlDateTime($Time), 'Interface' => $Interface, 'Device' => $Device['Id']));
    3838      }
    3939    }
Note: See TracChangeset for help on using the changeset viewer.