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/DNS.php

    r777 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('ip', 'dns', 'static');
     3class ConfigRouterOSDNS extends NetworkConfigItem
     4{
     5  function Run()
     6  {
     7    $Path = array('ip', 'dns', 'static');
    98
    10 $Routerboard = new Routerboard($Config['MainRouter']['HostName']);
    11 $Routerboard->UserName = $Config['MainRouter']['UserName'];
    12 $Routerboard->Timeout = $Config['MainRouter']['ConnectTimeout'];
    13 $Routerboard->Debug = true;
     9    $Routerboard = new Routerboard($this->System->Config['MainRouter']['HostName']);
     10    $Routerboard->UserName = $this->System->Config['MainRouter']['UserName'];
     11    $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout'];
     12    $Routerboard->Debug = true;
    1413
    15 $DbResult = $System->Database->query('SELECT * FROM `NetworkDomain`');
    16 while($Domain = $DbResult->fetch_assoc())
    17 {
    18   $DomainName = $Domain['Name'];
     14    $DbResult = $this->Database->query('SELECT * FROM `NetworkDomain`');
     15    while($Domain = $DbResult->fetch_assoc())
     16    {
     17      $DomainName = $Domain['Name'];
    1918
    20   // Get full domain name from parent items
    21   $CurrentDomain = $Domain;
    22   while($CurrentDomain['Parent'] > 0)
    23   {
    24     $DbResult2 = $System->Database->query('SELECT * FROM `NetworkDomain` WHERE `Id`='.$CurrentDomain['Parent']);
    25     $CurrentDomain = $DbResult2->fetch_assoc();
    26     $DomainName .= '.'.$CurrentDomain['Name'];
    27   }
     19      // Get full domain name from parent items
     20      $CurrentDomain = $Domain;
     21      while($CurrentDomain['Parent'] > 0)
     22      {
     23        $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomain` WHERE `Id`='.$CurrentDomain['Parent']);
     24        $CurrentDomain = $DbResult2->fetch_assoc();
     25        $DomainName .= '.'.$CurrentDomain['Name'];
     26      }
    2827
    29   $Items = array();
     28      $Items = array();
    3029
    31   // Devices, Interfaces
    32   $DbResult2 = $System->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '.
    33     'JOIN `NetworkDevice` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
    34     'WHERE (`NetworkDevice`.`Used`=1)');
    35   while($Interface = $DbResult2->fetch_assoc())
    36   {
    37     $Name = $Interface['DeviceName'];
    38     if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    39     $NameFull = $Name.'.'.$DomainName;
    40     $NameExtFull = $Name.'-ext.'.$DomainName;
    41     if($Interface['LocalIP'] != '')
    42       $Items[] = array('name' => $NameFull, 'address' => $Interface['LocalIP']);
    43     if($Interface['IPv6'] != '')
    44       $Items[] = array('name' => $NameFull, 'address' => $Interface['IPv6']);
    45     if($Interface['ExternalIP'] != '')
    46       $Items[] = array('name' => $NameExtFull, 'address' => $Interface['ExternalIP']);
    47   }
     30      // Devices, Interfaces
     31      $DbResult2 = $this->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '.
     32          'JOIN `NetworkDevice` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
     33          'WHERE (`NetworkDevice`.`Used`=1)');
     34      while($Interface = $DbResult2->fetch_assoc())
     35      {
     36        $Name = $Interface['DeviceName'];
     37        if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     38        $NameFull = $Name.'.'.$DomainName;
     39        $NameExtFull = $Name.'-ext.'.$DomainName;
     40        if($Interface['LocalIP'] != '')
     41          $Items[] = array('name' => $NameFull, 'address' => $Interface['LocalIP']);
     42        if($Interface['IPv6'] != '')
     43          $Items[] = array('name' => $NameFull, 'address' => $Interface['IPv6']);
     44        if($Interface['ExternalIP'] != '')
     45          $Items[] = array('name' => $NameExtFull, 'address' => $Interface['ExternalIP']);
     46      }
    4847
    49   // Domain aliases
    50   $DbResult2 = $System->Database->query('SELECT `NetworkDomainAlias`.*, `NetworkInterface`.`LocalIP` AS `LocalIP`, '.
    51     '`NetworkInterface`.`IPv6` AS `IPv6`, `NetworkInterface`.`ExternalIP` AS `ExternalIP` FROM `NetworkDomainAlias` '.
    52     'JOIN `NetworkDevice` ON SUBSTR(`NetworkDomainAlias`.`Target`, 1, LENGTH(`NetworkDevice`.`Name` ))=`NetworkDevice`.`Name` '.
    53     'JOIN `NetworkInterface` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
    54     'WHERE (`NetworkDevice`.`Used`=1) AND '.
    55     '(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) = `NetworkDomainAlias`.`Target`)');
    56   while($Alias = $DbResult2->fetch_assoc())
    57   {
    58     $Name = $Alias['Name'];
    59     $NameFull = $Name.'.'.$DomainName;
    60     $NameExtFull = $Name.'-ext.'.$DomainName;
    61     if($Alias['LocalIP'] != '')
    62       $Items[] = array('name' => $NameFull, 'address' => $Alias['LocalIP']);
    63     if($Alias['IPv6'] != '')
    64       $Items[] = array('name' => $NameFull, 'address' => $Alias['IPv6']);
    65     if($Alias['ExternalIP'] != '')
    66       $Items[] = array('name' => $NameExtFull, 'address' => $Alias['ExternalIP']);
    67   }
     48      // Domain aliases
     49      $DbResult2 = $this->Database->query('SELECT `NetworkDomainAlias`.*, `NetworkInterface`.`LocalIP` AS `LocalIP`, '.
     50          '`NetworkInterface`.`IPv6` AS `IPv6`, `NetworkInterface`.`ExternalIP` AS `ExternalIP` FROM `NetworkDomainAlias` '.
     51          'JOIN `NetworkDevice` ON SUBSTR(`NetworkDomainAlias`.`Target`, 1, LENGTH(`NetworkDevice`.`Name` ))=`NetworkDevice`.`Name` '.
     52          'JOIN `NetworkInterface` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
     53          'WHERE (`NetworkDevice`.`Used`=1) AND '.
     54          '(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) = `NetworkDomainAlias`.`Target`)');
     55      while($Alias = $DbResult2->fetch_assoc())
     56      {
     57        $Name = $Alias['Name'];
     58        $NameFull = $Name.'.'.$DomainName;
     59        $NameExtFull = $Name.'-ext.'.$DomainName;
     60        if($Alias['LocalIP'] != '')
     61          $Items[] = array('name' => $NameFull, 'address' => $Alias['LocalIP']);
     62        if($Alias['IPv6'] != '')
     63          $Items[] = array('name' => $NameFull, 'address' => $Alias['IPv6']);
     64        if($Alias['ExternalIP'] != '')
     65          $Items[] = array('name' => $NameExtFull, 'address' => $Alias['ExternalIP']);
     66      }
    6867
    69   $DbResult2 = $System->Database->query('SELECT * FROM `NetworkDomainServer` WHERE `Domain`='.$Domain['Id']);
    70   while($Server = $DbResult2->fetch_assoc())
    71   {
    72     $Routerboard->HostName = $Server['Address'];
    73     $Routerboard->ListUpdate($Path, array('name', 'address'), $Items);
     68      $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomainServer` WHERE `Domain`='.$Domain['Id']);
     69      while($Server = $DbResult2->fetch_assoc())
     70      {
     71        $Routerboard->HostName = $Server['Address'];
     72        $Routerboard->ListUpdate($Path, array('name', 'address'), $Items);
     73      }
     74    }
    7475  }
    7576}
Note: See TracChangeset for help on using the changeset viewer.