Ignore:
Timestamp:
May 23, 2015, 12:07:08 AM (9 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

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

    r738 r739  
    1313$Routerboard->Debug = true;
    1414
    15 // Devices, Interfaces
    16 $Items = array();
    17 $DbResult = $System->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '.
    18   'JOIN `NetworkDevice` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
    19   'WHERE `NetworkDevice`.`Used`=1');
    20 while($Interface = $DbResult->fetch_assoc())
     15$DbResult = $System->Database->query('SELECT * FROM `NetworkDomain`');
     16while($Domain = $DbResult->fetch_assoc())
    2117{
    22   $Name = $Interface['DeviceName'];
    23   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    24   $Name .= '.zdechov.net';
    25   $Items[] = array('name' => $Name, 'address' => $Interface['LocalIP'], 'ttl' => '1d');
     18  $DomainName = $Domain['Name'];
     19
     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  }
     28
     29  // Devices, Interfaces
     30  $Items = array();
     31  $DbResult2 = $System->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    $Name .= '.'.$DomainName;
     39    $Items[] = array('name' => $Name, 'address' => $Interface['LocalIP'], 'ttl' => '1d');
     40  }
     41
     42  // Domain aliases
     43  $DbResult2 = $System->Database->query('SELECT `NetworkDomainAlias`.*, `NetworkInterface`.`LocalIP` AS `LocalIP` FROM `NetworkDomainAlias` '.
     44    'JOIN `NetworkDevice` ON `NetworkDomainAlias`.`Target`=`NetworkDevice`.`Name` '.
     45    'JOIN `NetworkInterface` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
     46    'WHERE `NetworkDevice`.`Used`=1');
     47  while($Alias = $DbResult2->fetch_assoc())
     48  {
     49    $Name = $Alias['Name'];
     50    $Name .= '.'.$DomainName;
     51    $Items[] = array('name' => $Name, 'address' => $Alias['LocalIP'], 'ttl' => $Domain['TTL']);
     52  }
     53
     54  $DbResult2 = $System->Database->query('SELECT * FROM `NetworkDomainServer` WHERE `Domain`='.$Domain['Id']);
     55  if($DbResult2->num_rows > 0)
     56  {
     57    $Server = $DbResult2->fetch_assoc();
     58    $Routerboard->HostName = $Server['Address'];
     59    $Routerboard->ListUpdate($Path, array('name', 'address', 'ttl'), $Items);
     60  }
    2661}
    27 
    28 // Domain aliases
    29 $DbResult = $System->Database->query('SELECT `NetworkDomainAlias`.*, `NetworkInterface`.`LocalIP` AS `LocalIP` FROM `NetworkDomainAlias` '.
    30   'JOIN `NetworkDevice` ON `NetworkDomainAlias`.`Target`=`NetworkDevice`.`Name` '.
    31   'JOIN `NetworkInterface` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
    32   'WHERE `NetworkDevice`.`Used`=1');
    33 while($Alias = $DbResult->fetch_assoc())
    34 {
    35   $Name = $Alias['Name'];
    36   $Name .= '.zdechov.net';
    37   $Items[] = array('name' => $Name, 'address' => $Alias['LocalIP'], 'ttl' => '1d');
    38 }
    39 
    40 $Routerboard->HostName = '192.168.10.1';
    41 $Routerboard->ListUpdate($Path, array('name', 'address', 'ttl'), $Items);
Note: See TracChangeset for help on using the changeset viewer.