Ignore:
Timestamp:
Jan 8, 2016, 11:00:11 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Network configure actions now can be executed through cmd.php interface using "php cmd.php config <action>".
File:
1 edited

Legend:

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

    r738 r781  
    11<?php
    22
    3 if(isset($_SERVER['REMOTE_ADDR'])) die();
    4 include_once(dirname(__FILE__).'/../../../Application/System.php');
    5 $System = new System();
    6 $System->ShowPage = false;
    7 $System->Run();
    8 $Path = array('tool', 'netwatch');
     3class ConfigRouterOSNetwatch extends NetworkConfigItem
     4{
     5  function Run()
     6  {
     7    $Path = array('tool', 'netwatch');
    98
    10 $Routerboard = new Routerboard();
    11 $Routerboard->UserName = $Config['MainRouter']['UserName'];
    12 $Routerboard->Timeout = $Config['MainRouter']['ConnectTimeout'];
    13 $Routerboard->Debug = true;
     9    $Routerboard = new Routerboard();
     10    $Routerboard->UserName = $this->System->Config['MainRouter']['UserName'];
     11    $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout'];
     12    $Routerboard->Debug = true;
    1413
    15 $DbResult3 = $System->Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Configure` = 1'); // WHERE `Member` = 0');
    16 while($Router = $DbResult3->fetch_assoc())
    17 {
    18   echo($Router['DHCP']."\n");
    19   $Routerboard->HostName = $Router['DHCP'];
    20   $Items = array();
    21   $DbResult = $System->Database->query('SELECT * FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`DHCP`="'.$Router['DHCP'].'")');
    22   while($Subnet = $DbResult->fetch_assoc())
    23   {
    24     $I = explode('.', $Subnet['AddressRange']);
    25     $I = $I[2];
    26     $DbResult2 = $System->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface`'.
    27     ' LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].')'.
    28     ' AND (`NetworkDevice`.`Used` = 1) ORDER BY `NetworkInterface`.`LocalIP`');
    29     while($Interface = $DbResult2->fetch_assoc())
     14    $DbResult3 = $this->Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Configure` = 1'); // WHERE `Member` = 0');
     15    while($Router = $DbResult3->fetch_assoc())
    3016    {
    31       $Name = $Interface['DeviceName'];
    32       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    33       echo($Name.', ');
    34       $Items[] = array('host' => $Interface['LocalIP'], 'interval' => '00:01:00', 'comment' => $Name);
     17      echo($Router['DHCP']."\n");
     18      $Routerboard->HostName = $Router['DHCP'];
     19      $Items = array();
     20      $DbResult = $this->Database->query('SELECT * FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`DHCP`="'.$Router['DHCP'].'")');
     21      while($Subnet = $DbResult->fetch_assoc())
     22      {
     23        $I = explode('.', $Subnet['AddressRange']);
     24        $I = $I[2];
     25        $DbResult2 = $this->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface`'.
     26            ' LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].')'.
     27            ' AND (`NetworkDevice`.`Used` = 1) ORDER BY `NetworkInterface`.`LocalIP`');
     28        while($Interface = $DbResult2->fetch_assoc())
     29        {
     30          $Name = $Interface['DeviceName'];
     31          if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     32          echo($Name.', ');
     33          $Items[] = array('host' => $Interface['LocalIP'], 'interval' => '00:01:00', 'comment' => $Name);
     34        }
     35      }
     36      $Routerboard->ListUpdate($Path, array('host', 'interval', 'comment'), $Items);
     37      echo("\n");
    3538    }
    3639  }
    37   $Routerboard->ListUpdate($Path, array('host', 'interval', 'comment'), $Items);
    38   echo("\n");
    3940}
Note: See TracChangeset for help on using the changeset viewer.