Changeset 658


Ignore:
Timestamp:
May 26, 2014, 1:00:20 AM (11 years ago)
Author:
chronos
Message:
  • Přidáno: V tabulce změn stavu síťových rozhraní zobrazovat také dobu trvání.
  • Opraveno: Neprováděly se skripty využívající třídu Routerboard.
  • Opraveno: Načítání stavu rozhraní z RouterOS.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r657 r658  
    11<?php
    22
    3 $Revision = 657; // Subversion revision
     3$Revision = 658; // Subversion revision
    44$DatabaseRevision = 657; // SQL structure revision
    55$ReleaseTime = strtotime('2014-05-25');
  • trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php

    r657 r658  
    1414  $StartTime = time();
    1515
    16   // Load netwatch status from all DHCP routers 
     16  // Load netwatch status from all DHCP routers
    1717  $DbResult3 = $System->Database->query('SELECT `DHCP`, `AddressRange`, `Mask` FROM `NetworkSubnet` '.
    1818                'WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY DHCP');
     
    2929      if($Properties['status'] == 'up') $Online = 1;
    3030        else $Online = 0;
    31        
    32       $DbResult = $System->Database->select('NetworkInterface', 'Online', '`LocalIP` = "'.$Properties['host'].'";');
     31
     32      $DbResult = $System->Database->select('NetworkInterface', '`Id`,`Online`', '`LocalIP` = "'.$Properties['host'].'";');
    3333      while($DbRow = $DbResult->fetch_assoc())
    3434      {
    3535        $LastOnline = $DbRow['Online'];
    36         $Interface = $DbRow['NetworkInterface'];
    37        
     36        $Interface = $DbRow['Id'];
     37
    3838        // Record state changes
    3939        if($Online != $LastOnline)
    40         {     
     40        {
    4141          $System->Database->insert('NetworkInterfaceUpDown', array(
    4242                  'Interface' => $Interface, 'State' => $Online, 'Time' => TimeToMysqlDateTime($StartTime)));
    4343        }
    44       };
    45        
     44      }
     45
    4646      if($Online)
    4747      {
    48         $DbResult = $System->Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"', 
     48        $DbResult = $System->Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"',
    4949          array('Online' => 1, 'LastOnline' => TimeToMysqlDateTime($StartTime)));
    50       } 
     50      }
    5151    }
    52   } 
     52  }
    5353  $DbResult = $System->Database->update('NetworkInterface', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0));
    5454
     
    6767  {
    6868    $DbResult2 = $System->Database->select('NetworkInterfaceStat', '*', '(`NetworkInterface`="'.$Interface['Id'].'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    69     if($DbResult2->num_rows == 0) $System->Database->query('REPLACE INTO `NetworkInterfaceStat` (`NetworkInterface`, `Time`, `PingCount`) VALUES ("'.$Interface['Id'].'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"), 1)');         
     69    if($DbResult2->num_rows == 0) $System->Database->query('REPLACE INTO `NetworkInterfaceStat` (`NetworkInterface`, `Time`, `PingCount`) VALUES ("'.$Interface['Id'].'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"), 1)');
    7070      else $System->Database->query('UPDATE `NetworkInterfaceStat` SET `PingCount` = `PingCount` + 1 WHERE (`NetworkInterface`="'.$Interface['Id'].'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    7171  }
  • trunk/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php

    r657 r658  
    1616    $this->Dependencies = array('NetworkConfig');
    1717  }
    18  
     18
    1919  function DoInstall()
    2020  {
    2121  }
    22  
     22
    2323  function DoUnInstall()
    2424  {
     
    3434        'Interface' => array('Type' => 'TNetworkInterface', 'Caption' => 'Rozhraní', 'Default' => '', 'ReadOnly' => true),
    3535        'State' => array('Type' => 'Boolean', 'Caption' => 'Stav', 'Default' => '', 'ReadOnly' => true),
     36        'Duration' => array('Type' => 'Time', 'Caption' => 'Trvání', 'Default' => '', 'ReadOnly' => true,
     37          'SQL' => 'TIMEDIFF(`Time`,'.
     38            '(SELECT `Time` FROM `NetworkInterfaceUpDown` AS `TA` WHERE (`TA`.`Time` > `TX`.`Time`) '.
     39                        'AND (`TA`.`Interface`=`TX`.`Interface`) ORDER BY `TA`.`Time` LIMIT 1))'),
    3640      ),
    3741    ));
  • trunk/Modules/NetworkConfigRouterOS/Routerboard.php

    r656 r658  
    3939      if(count($Batch) > 0)
    4040       $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch)));
    41     } else 
     41    } else
    4242      $Output = array_merge($Output, $this->ExecuteBatch($Commands));
    4343    return($Output);
    4444  }
    45  
     45
    4646  function ExecuteBatch($Commands)
    47   {   
     47  {
    4848    $Commands = trim($Commands);
    4949    if($Commands != '')
     
    5151      $Commands = addslashes($Commands);
    5252      $Commands = str_replace('$', '\$', $Commands);
    53       //$Commands = str_replace(' ', '\ ', $Commands); 
     53      //$Commands = str_replace(' ', '\ ', $Commands);
    5454      $Command = $this->SSHPath.' -o ConnectTimeout='.$this->Timeout.' -l '.$this->UserName.' -i '.$this->PrivateKey.' '.$this->HostName.' "'.$Commands.'"';
    5555      if($this->Debug) echo($Command);
    5656      $Output = array();
    57       //exec($Command, $Output);
     57      exec($Command, $Output);
    5858    } else $Output = '';
    5959    if($this->Debug) print_r($Output);
     
    121121    $ConditionList = substr($ConditionList, 0, -1);
    122122    if(trim($ConditionList) != '')
    123       $ConditionList = ' where '.$ConditionList;   
     123      $ConditionList = ' where '.$ConditionList;
    124124
    125125    $Result = $this->Execute(implode(' ', $Path).' print terse'.$ConditionList);
     
    134134        if(in_array($Value[0], $Properties))
    135135        {
    136           if(count($Value) > 1) 
     136          if(count($Value) > 1)
    137137          {
    138             if($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1);           
     138            if($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1);
    139139            //if(strlen($Value[1]) > 0)
    140140            $ListItem[$Value[0]] = $Value[1];
     
    151151    $this->Execute(implode(' ', $Path).' { remove [find] }');
    152152  }
    153  
     153
    154154  function ListUpdate($Path, $Properties, $Values, $Condition = array(), $UsePrint = false)
    155155  {
    156156    // Get current list from routerboard
    157     if($UsePrint == 0) 
     157    if($UsePrint == 0)
    158158    {
    159159      $List = $this->ListGet($Path, $Properties, $Condition);
     
    167167        }
    168168      }
    169     } else 
    170     {
    171       $List = $this->ListGetPrint($Path, $Properties, $Condition);     
     169    } else
     170    {
     171      $List = $this->ListGetPrint($Path, $Properties, $Condition);
    172172    }
    173173    $Commands = array();
    174    
     174
    175175    // Add empty properties to values
    176176    foreach($Values as $Index => $Item)
     
    181181           $Item[$Property] = '';
    182182      }
    183       $Values[$Index] = $Item;     
     183      $Values[$Index] = $Item;
    184184    }
    185185    foreach($List as $Index => $Item)
     
    190190           $Item[$Property] = '';
    191191      }
    192       $List[$Index] = $Item;     
    193     }
    194    
     192      $List[$Index] = $Item;
     193    }
     194
    195195    // Sort properties
    196196    foreach($Values as $Index => $Item)
     
    204204    if($this->Debug) print_r($List);
    205205    if($this->Debug) print_r($Values);
    206        
     206
    207207    // Erase all items not existed in $Values
    208208    foreach($List as $Index => $ListItem)
     
    213213        foreach($ListItem as $Index => $Property)
    214214        {
    215           if($Property != '') 
     215          if($Property != '')
    216216          {
    217217            if(($Property == 'yes') or ($Property == 'no')) $Prop .= $Index.'='.$Property.' ';
     
    224224      }
    225225    }
    226    
     226
    227227    // Add new items
    228228    foreach($Values as $ListItem)
     
    240240    }
    241241    if($this->Debug) print_r($Commands);
    242     return($this->Execute($Commands));   
     242    return($this->Execute($Commands));
    243243  }
    244244}
Note: See TracChangeset for help on using the changeset viewer.