Ignore:
Timestamp:
Jan 2, 2016, 3:45:31 PM (9 years ago)
Author:
chronos
Message:
  • Fixed: Now DNS server items are correctly configured to RouterOS DNS server.
File:
1 edited

Legend:

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

    r739 r777  
    2727  }
    2828
     29  $Items = array();
     30
    2931  // Devices, Interfaces
    30   $Items = array();
    3132  $DbResult2 = $System->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '.
    3233    'JOIN `NetworkDevice` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
    33     'WHERE `NetworkDevice`.`Used`=1');
     34    'WHERE (`NetworkDevice`.`Used`=1)');
    3435  while($Interface = $DbResult2->fetch_assoc())
    3536  {
    3637    $Name = $Interface['DeviceName'];
    3738    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    38     $Name .= '.'.$DomainName;
    39     $Items[] = array('name' => $Name, 'address' => $Interface['LocalIP'], 'ttl' => '1d');
     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']);
    4047  }
    4148
    4249  // Domain aliases
    43   $DbResult2 = $System->Database->query('SELECT `NetworkDomainAlias`.*, `NetworkInterface`.`LocalIP` AS `LocalIP` FROM `NetworkDomainAlias` '.
    44     'JOIN `NetworkDevice` ON `NetworkDomainAlias`.`Target`=`NetworkDevice`.`Name` '.
     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` '.
    4553    'JOIN `NetworkInterface` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
    46     'WHERE `NetworkDevice`.`Used`=1');
     54    'WHERE (`NetworkDevice`.`Used`=1) AND '.
     55    '(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) = `NetworkDomainAlias`.`Target`)');
    4756  while($Alias = $DbResult2->fetch_assoc())
    4857  {
    4958    $Name = $Alias['Name'];
    50     $Name .= '.'.$DomainName;
    51     $Items[] = array('name' => $Name, 'address' => $Alias['LocalIP'], 'ttl' => $Domain['TTL']);
     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']);
    5267  }
    5368
    5469  $DbResult2 = $System->Database->query('SELECT * FROM `NetworkDomainServer` WHERE `Domain`='.$Domain['Id']);
    55   if($DbResult2->num_rows > 0)
     70  while($Server = $DbResult2->fetch_assoc())
    5671  {
    57     $Server = $DbResult2->fetch_assoc();
    5872    $Routerboard->HostName = $Server['Address'];
    59     $Routerboard->ListUpdate($Path, array('name', 'address', 'ttl'), $Items);
     73    $Routerboard->ListUpdate($Path, array('name', 'address'), $Items);
    6074  }
    6175}
Note: See TracChangeset for help on using the changeset viewer.