Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php

    r863 r873  
    1010    $Interfaces = array();
    1111    $DbResult = $this->Database->select('NetworkInterface', '`Id`, `LocalIP` AS `IP`, `Online`, 0 AS `NewOnline`');
    12     while($DbRow = $DbResult->fetch_assoc())
     12    while ($DbRow = $DbResult->fetch_assoc())
    1313      $Interfaces[$DbRow['IP']] = $DbRow;
    1414
     
    1616    $DbResult3 = $this->Database->query('SELECT `DHCP` FROM `NetworkSubnet` '.
    1717      'WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY `DHCP`');
    18     while($Subnet = $DbResult3->fetch_assoc())
     18    while ($Subnet = $DbResult3->fetch_assoc())
    1919    {
    2020      echo('router '.$Subnet['DHCP']."\n");
     
    2222      $Routerboard->Connect($Subnet['DHCP'], $this->System->Config['API']['UserName'],
    2323        $this->System->Config['API']['Password']);
    24       if(!$Routerboard->Connected) continue;
     24      if (!$Routerboard->Connected) continue;
    2525      $Routerboard->Write('/tool/netwatch/getall', false);
    2626      $Routerboard->Write('=.proplist=host,status');
    2727      $Read = $Routerboard->Read(false);
    2828      $List = $Routerboard->ParseResponse($Read);
    29       foreach($List as $Properties)
     29      foreach ($List as $Properties)
    3030      {
    3131        $IP = $Properties['host'];
    32         if($Properties['status'] == 'up') $Online = 1;
     32        if ($Properties['status'] == 'up') $Online = 1;
    3333          else $Online = 0;
    3434
    35         if($Online)
     35        if ($Online)
    3636        {
    37           if(array_key_exists($IP, $Interfaces))
     37          if (array_key_exists($IP, $Interfaces))
    3838            $Interfaces[$IP]['NewOnline'] = 1;
    3939            else echo('IP '.$IP.' not found.'."\n");
     
    4444    $Queries = array();
    4545    $QueriesInsert = array();
    46     foreach($Interfaces as $Index => $Interface)
     46    foreach ($Interfaces as $Index => $Interface)
    4747    {
    4848      // Update last online time if still online
    49       if($Interface['NewOnline'])
     49      if ($Interface['NewOnline'])
    5050        $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = '.$Interface['Id'],
    5151          array('LastOnline' => TimeToMysqlDateTime($StartTime)));
    5252
    53       if($Interface['Online'] != $Interface['NewOnline'])
     53      if ($Interface['Online'] != $Interface['NewOnline'])
    5454      {
    5555        // Online state changed
     
    7878    $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 1) AND '.
    7979      '(`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'")');
    80     while($DbRow = $DbResult->fetch_assoc())
     80    while ($DbRow = $DbResult->fetch_assoc())
    8181    {
    8282      echo('IP '.$DbRow['LocalIP'].' online but time not updated.'."\n");
     
    8484    $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 0) AND '.
    8585      '(`LastOnline` >= "'.TimeToMysqlDateTime($StartTime).'")');
    86     while($DbRow = $DbResult->fetch_assoc())
     86    while ($DbRow = $DbResult->fetch_assoc())
    8787    {
    8888      echo('IP '.$DbRow['LocalIP'].' not online but time updated.'."\n");
     
    9292    // Update device online state
    9393    $DbResult = $this->Database->select('NetworkInterface', '`Device`, SUM(`Online`) AS `SumOnline`', '`Online` = 1 GROUP BY `Device`');
    94     while($Device = $DbResult->fetch_assoc())
     94    while ($Device = $DbResult->fetch_assoc())
    9595    {
    96       if($Device['SumOnline'] > 0)
     96      if ($Device['SumOnline'] > 0)
    9797        $Queries[] = $this->Database->GetUpdate('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1));
    9898    }
Note: See TracChangeset for help on using the changeset viewer.