Changeset 818


Ignore:
Timestamp:
Mar 16, 2016, 10:01:02 PM (9 years ago)
Author:
chronos
Message:
  • Added: UpDown history for network ports.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r817 r818  
    19881988  $Manager->Execute('UPDATE `NetworkConfiguration` SET `SysName`="RouterosDNS" WHERE `Id`=13');
    19891989  $Manager->Execute('ALTER TABLE `NetworkConfiguration` DROP `Execute`;');
     1990}
     1991
     1992function UpdateTo818($Manager)
     1993{
     1994  $Manager->Execute('ALTER TABLE `NetworkPort` ADD `Protocol` INT NOT NULL AFTER `Enabled`;');
     1995  $Manager->Execute('CREATE TABLE IF NOT EXISTS `NetworkPortUpDown` (
     1996    `Id` int(11) NOT NULL AUTO_INCREMENT,
     1997    `Time` datetime NOT NULL,
     1998    `Port` int(11) NOT NULL,
     1999    `State` int(11) NOT NULL,
     2000    `Duration` int(11) DEFAULT NULL,
     2001    PRIMARY KEY (`Id`),
     2002    KEY `Port` (`Port`),
     2003    KEY `Time` (`Time`)
     2004    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;');
     2005   $Manager->Execute('ALTER TABLE `NetworkPortUpDown`
     2006     ADD CONSTRAINT `NetworkPortUpDown_ibfk_1` FOREIGN KEY (`Port`) REFERENCES `NetworkPort` (`Id`);');
    19902007}
    19912008
     
    20802097      808 => array('Revision' => 814, 'Function' => 'UpdateTo814'),
    20812098      814 => array('Revision' => 817, 'Function' => 'UpdateTo817'),
     2099      817 => array('Revision' => 818, 'Function' => 'UpdateTo818'),
    20822100    ));
    20832101  }
  • trunk/Application/Version.php

    r817 r818  
    11<?php
    22
    3 $Revision = 817; // Subversion revision
    4 $DatabaseRevision = 817; // SQL structure revision
     3$Revision = 818; // Subversion revision
     4$DatabaseRevision = 818; // SQL structure revision
    55$ReleaseTime = strtotime('2016-03-16');
  • trunk/Modules/Network/Network.php

    r817 r818  
    244244      'Items' => array(
    245245        'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
     246        'Protocol' => array('Type' => 'TNetworkProtocol', 'Caption' => 'Protokol', 'Default' => '0'),
    246247        'Number' => array('Type' => 'Integer', 'Caption' => 'Číslo', 'Default' => ''),
    247248        'Interface' => array('Type' => 'TNetworkInterface', 'Caption' => 'Rozhraní', 'Default' => ''),
     
    249250        'Online' => array('Type' => 'TOnlineState', 'Caption' => 'Běží', 'Default' => '0', 'ReadOnly' => true),
    250251        'LastOnline' => array('Type' => 'DateTime', 'Caption' => 'Naposledy běželo', 'Default' => '', 'ReadOnly' => true),
     252        'UpDown' => array('Type' => 'TNetworkPortUpDown', 'Caption' => 'Změny stavu', 'Default' => ''),
    251253      ),
    252254    ));
     
    490492      ),
    491493    ));
     494    $this->System->FormManager->RegisterClass('NetworkInterfaceUpDown', array(
     495      'Title' => 'Změny stavu rozhraní',
     496      'Table' => 'NetworkInterfaceUpDown',
     497      'DefaultSortColumn' => 'Time',
     498      'DefaultSortOrder' => 1,
     499      'Items' => array(
     500        'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => '', 'ReadOnly' => true),
     501        'Interface' => array('Type' => 'TNetworkInterface', 'Caption' => 'Rozhraní', 'Default' => '', 'ReadOnly' => true),
     502        'State' => array('Type' => 'TOnlineState', 'Caption' => 'Stav', 'Default' => '', 'ReadOnly' => true),
     503        'Duration' => array('Type' => 'TimeDiff', 'Caption' => 'Trvání', 'Default' => '', 'ReadOnly' => true),
     504      ),
     505    ));
     506    $this->System->FormManager->RegisterClass('NetworkPortUpDown', array(
     507      'Title' => 'Změny stavu portů',
     508      'Table' => 'NetworkPortUpDown',
     509      'DefaultSortColumn' => 'Time',
     510      'DefaultSortOrder' => 1,
     511      'Items' => array(
     512        'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => '', 'ReadOnly' => true),
     513        'Port' => array('Type' => 'TNetworkPort', 'Caption' => 'Port', 'Default' => '', 'ReadOnly' => true),
     514        'State' => array('Type' => 'TOnlineState', 'Caption' => 'Stav', 'Default' => '', 'ReadOnly' => true),
     515        'Duration' => array('Type' => 'TimeDiff', 'Caption' => 'Trvání', 'Default' => '', 'ReadOnly' => true),
     516      ),
     517    ));
     518    $this->System->FormManager->RegisterFormType('TNetworkProtocol', array(
     519      'Type' => 'Enumeration',
     520      'States' => array('TCP', 'UDP'),
     521    ));
    492522    $this->System->FormManager->RegisterFormType('TNetworkDevice', array(
    493523      'Type' => 'Reference',
     
    513543      'Filter' => '1',
    514544    ));
     545    $this->System->FormManager->RegisterFormType('TNetworkPort', array(
     546      'Type' => 'Reference',
     547      'Table' => 'NetworkPort',
     548      'View' => '(SELECT `NetworkPort`.*, CONCAT(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")), ":", `NetworkPort`.`Number`) AS `PortName` FROM `NetworkPort` '.
     549      'LEFT JOIN `NetworkInterface` ON `NetworkInterface`.`Id` = `NetworkPort`.`Interface` '.
     550      'LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device`) AS `T`',
     551      'Id' => 'Id',
     552      'Name' => 'PortName',
     553      'Filter' => '1',
     554    ));
    515555    $this->System->FormManager->RegisterFormType('TNetworkInterfaceType', array(
    516556      'Type' => 'Reference',
     
    597637      'Filter' => '1',
    598638    ));
    599 
     639    $this->System->FormManager->RegisterFormType('TNetworkPortUpDown', array(
     640      'Type' => 'ManyToOne',
     641      'Table' => 'NetworkPortUpDown',
     642      'Id' => 'Id',
     643      'Ref' => 'Port',
     644      'Filter' => '1',
     645    ));
     646   
    600647    $this->System->ModuleManager->Modules['IS']->RegisterDashboardItem('Network',
    601648      array('ModuleNetwork', 'ShowDashboardItem'));
  • trunk/Modules/NetworkConfigLinux/Generators/CheckPorts.php

    r815 r818  
    33class ConfigCheckPorts extends NetworkConfigItem
    44{
    5   function CheckPortStatus($IP, $Port)
     5  function CheckPortStatus($IP, $Port, $Protocol = 'tcp')
    66  {
    77    $Timeout = 1;
    88    $State = 0;
    9     if($Socket = @fsockopen($IP, $Port, $ErrorNumber, $ErrorString, $Timeout))
     9    if($Protocol = 'tcp') $Prefix = '';
     10      else if($Protocol = 'udp') $Prefix = 'udp://';
     11      else throw new Exception('Unsupported protocol "'.$Protocol.'"');
     12    if($Socket = @fsockopen($Prefix.$IP, $Port, $ErrorNumber, $ErrorString, $Timeout))
    1013    {
    1114      fclose($Socket);
     
    2124    // Load all ports to memory
    2225    $Ports = array();
    23     $DbResult = $this->Database->query('SELECT `NetworkPort`.`Id`, `NetworkPort`.`Number`, '.
     26    $DbResult = $this->Database->query('SELECT `NetworkPort`.`Id`, `NetworkPort`.`Number`, `NetworkPort`.`Protocol`, '.
    2427      '`NetworkPort`.`Online`, 0 AS `NewOnline`, `NetworkInterface`.`LocalIP` AS `LocalIP` '.
    2528      'FROM `NetworkPort` '.
     
    3134    foreach($Ports as $Index => $Port)
    3235    {
    33       $Port['NewOnline'] = $this->CheckPortStatus($Port['LocalIP'], $Port['Number']);
     36      if($Port['Protocol'] == 0) $Port['Protocol'] = 'tcp';
     37      if($Port['Protocol'] == 1) $Port['Protocol'] = 'udp';
     38      $Port['NewOnline'] = $this->CheckPortStatus($Port['LocalIP'], $Port['Number'], $Port['Protocol']);
    3439
    3540      // Update last online time if still online
     
    3742      {
    3843        $DbResult = $this->Database->update('NetworkPort', '`Id` = "'.$Port['Id'].'"',
    39         array('LastOnline' => TimeToMysqlDateTime($StartTime)));
     44          array('Online' => 1, 'LastOnline' => TimeToMysqlDateTime($StartTime)));
     45      }
     46
     47      // Update UpDown table
     48      if($Port['Online'] != $Port['NewOnline'])
     49      {
     50        // Online state changed
     51        $DbResult = $this->Database->query('INSERT INTO `NetworkPortUpDown` (`Port`,
     52         `State`, `Time`, `Duration`) VALUES ('.$Port['Id'].', '.$Port['NewOnline'].', "'.
     53          TimeToMysqlDateTime($StartTime).'", NULL)');
     54        // Update previous record duration in UpDown table
     55        $this->Database->query('UPDATE `NetworkPortUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '.
     56          '`TM`.`Time`, (SELECT `Time` FROM (SELECT * FROM `NetworkPortUpDown`) AS `TA` WHERE (`TA`.`Time` > `TM`.`Time`) '.
     57          'AND (`TA`.`Port`=`TM`.`Port`) ORDER BY `TA`.`Time` ASC LIMIT 1)) '.
     58          'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Port['Id'].')');
    4059      }
    4160    }
    42  
     61    $DbResult = $this->Database->update('NetworkDevice', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0));
     62
    4363    // Set offline all ports which were not updated as online
    4464    $DbResult = $this->Database->select('NetworkPort', '*', '(`Online` = 1) AND '.
  • trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php

    r793 r818  
    4949              array('LastOnline' => TimeToMysqlDateTime($StartTime)));
    5050
    51           if($Interface['Online'] != $Interface['NewOnline'])
    52           {
    53             // Online state changed
    54             $DbResult = $this->Database->query('INSERT INTO `NetworkInterfaceUpDown` (`Interface`,
    55         `State`, `Time`, `Duration`) VALUES ('.$Interface['Id'].', '.$Interface['NewOnline'].', "'.
    56                 TimeToMysqlDateTime($StartTime).'", NULL)');
    57             // Update previous record duration in UpDown table
    58             $this->Database->query('UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '.
    59                 '`TM`.`Time`, (SELECT `Time` FROM (SELECT * FROM `NetworkInterfaceUpDown`) AS `TA` WHERE (`TA`.`Time` > `TM`.`Time`) '.
    60                 'AND (`TA`.`Interface`=`TM`.`Interface`) ORDER BY `TA`.`Time` ASC LIMIT 1)) '.
    61                 'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Interface['Id'].')');
    62             $this->Database->update('NetworkInterface', '`Id` = "'.$Interface['Id'].'"',
    63                 array('Online' => $Interface['NewOnline']));
    64           }
     51        if($Interface['Online'] != $Interface['NewOnline'])
     52        {
     53          // Online state changed
     54          $DbResult = $this->Database->query('INSERT INTO `NetworkInterfaceUpDown` (`Interface`,
     55           `State`, `Time`, `Duration`) VALUES ('.$Interface['Id'].', '.$Interface['NewOnline'].', "'.
     56            TimeToMysqlDateTime($StartTime).'", NULL)');
     57          // Update previous record duration in UpDown table
     58          $this->Database->query('UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '.
     59            '`TM`.`Time`, (SELECT `Time` FROM (SELECT * FROM `NetworkInterfaceUpDown`) AS `TA` WHERE (`TA`.`Time` > `TM`.`Time`) '.
     60            'AND (`TA`.`Interface`=`TM`.`Interface`) ORDER BY `TA`.`Time` ASC LIMIT 1)) '.
     61            'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Interface['Id'].')');
     62          $this->Database->update('NetworkInterface', '`Id` = "'.$Interface['Id'].'"',
     63            array('Online' => $Interface['NewOnline']));
     64        }
    6565      }
    6666
  • trunk/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php

    r781 r818  
    4040  {
    4141    $this->System->Pages['zdarma'] = 'PageFreeAccess';
    42     $this->System->FormManager->RegisterClass('NetworkInterfaceUpDown', array(
    43       'Title' => 'Změny stavu rozhraní',
    44       'Table' => 'NetworkInterfaceUpDown',
    45       'DefaultSortColumn' => 'Time',
    46       'DefaultSortOrder' => 1,
    47       'Items' => array(
    48         'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => '', 'ReadOnly' => true),
    49         'Interface' => array('Type' => 'TNetworkInterface', 'Caption' => 'Rozhraní', 'Default' => '', 'ReadOnly' => true),
    50         'State' => array('Type' => 'TOnlineState', 'Caption' => 'Stav', 'Default' => '', 'ReadOnly' => true),
    51         'Duration' => array('Type' => 'TimeDiff', 'Caption' => 'Trvání', 'Default' => '', 'ReadOnly' => true),
    52       ),
    53     ));
    54 
    5542    $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-dns', 'ConfigRouterOSDNS');
    5643    $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-dhcp', 'ConfigRouterOSDHCP');
Note: See TracChangeset for help on using the changeset viewer.