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

    r740 r781  
    55 */
    66
    7 if(isset($_SERVER['REMOTE_ADDR'])) die();
    8 include_once(dirname(__FILE__).'/../../../Application/System.php');
    9 $System = new System();
    10 $System->ShowPage = false;
    11 $System->Run();
    12 
    13 $BaseDomain = 'zdechov.net';
    14 $Now = getdate();
    15 $I = floor(($Now['hours'] * 60 * 60 + $Now['minutes'] * 60 + $Now['seconds']) / (24 * 60 * 60) * 100);
    16 $Serial = date('Ymd', time()).$I;
    17 $MinimumTime = 7200;
    18 $RetryTime = 7200;
    19 $ExpireTime = 2419200;
    20 $RefreshTime = 28800;
    21 $MinimumTime = 10800;
    22 $TTL = 86400;
    23 $BaseDir = '/var/named';
    24 //$BaseDir = '/home/chronos/Projekty/centrala/trunk/var/named';
    25 if(!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.');
    26 $MailServer = 'centrala';
    27 
    28 function GenerateDNS($DNS)
     7class ConfigDNS extends NetworkConfigItem
    298{
    30   $Output = '$ORIGIN '.$DNS['Domain'].'.'."\n".
    31   '$TTL '.$DNS['TTL']."\n".
    32   $DNS['Domain'].".\tIN\tSOA\t".$DNS['NameServer'][0].".\troot.".$DNS['Domain'].".  (\n".
    33   "\t\t\t".$DNS['Serial']."\t; serial\n".
    34   "\t\t\t".$DNS['Refresh']."\t; refresh\n".
    35   "\t\t\t".$DNS['Retry']."\t; retry\n".
    36   "\t\t\t".$DNS['Expire']."\t; expire\n".
    37   "\t\t\t".$DNS['Minimum']."\t; minimum\n".
    38   "\t\t\t)\n";
    39   foreach($DNS['NameServer'] as $NameServer)
     9  function GenerateDNS($DNS)
    4010  {
    41     $Output .= "\t\tIN\tNS\t".strtolower($NameServer).".\n";
    42   }
    43   $Output .= "\t\t\tTXT\t".'"'.$DNS['Description'].'"'."\n";
    44 
    45   // Mail server records
    46   $Priority = 10;
    47   foreach($DNS['MailServer'] as $MailServer)
    48   {
    49     $Output .="\t\t\tMX\t".$Priority." ".strtolower($MailServer).".\n";
    50     $Priority += 10;
    51   }
    52   $Output .= "; SPF\n".
    53     $DNS['Domain'].".\tIN\tTXT\t\"v=spf1 mx -all\"\n".
    54     $DNS['Domain'].".\tIN\tSPF\t\"v=spf1 mx -all\"\n";
    55   foreach($DNS['MailServer'] as $MailServer)
    56   {
    57     $Output .= $MailServer.".\tIN\tTXT\t\"v=spf1 a -all\"\n".
    58     $MailServer.".\tIN\tSPF\t\"v=spf1 a -all\"\n";
    59   }
    60 
    61   // IPv4 host list
    62   foreach($DNS['Host'] as $Host)
    63   {
    64     if(strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
    65     $Output .= strtolower($Host['Name'])."\tIN\tA\t".$Host['Address']."\n";
    66   }
    67 
    68   // IPv6 host list
    69   foreach($DNS['Host'] as $Host)
    70   {
    71     if(strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
    72     if(array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
    73       $Output .= strtolower($Host['Name'])."\tIN\tAAAA\t".$Host['IPv6']."\n";
    74   }
    75 
    76   // Alias list
    77   foreach($DNS['Alias'] as $Alias)
    78   {
    79     if(strlen($Alias['Name']) < 8) $Alias['Name'] .= "\t";
    80     $Output .= strtolower($Alias['Name'])."\tIN\tCNAME\t".strtolower($Alias['Target'])."\n";
    81   }
    82 
    83   $File = fopen($DNS['BaseDir'].$DNS['Domain'].'.zone', 'w');
    84   fputs($File, $Output);
    85   fclose($File);
    86 
    87   // Generate reverse DNS records
    88   foreach($DNS['Network'] as $Network)
    89   {
    90     $Parts = explode('.', $Network);
    91     $Output = // '$ORIGIN '.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa'."\n".
    92     '$TTL '.$DNS['TTL']."\n".
    93     "@\tIN\tSOA\t".$DNS['NameServer'][0].".\troot.".$DNS['Domain'].".  (\n".
    94     "\t\t\t\t".$DNS['Serial']."\t; serial\n".
    95     "\t\t\t\t".$DNS['Refresh']."\t; refresh\n".
    96     "\t\t\t\t".$DNS['Retry']."\t; retry\n".
    97     "\t\t\t\t".$DNS['Expire']."\t; expire\n".
    98     "\t\t\t\t".$DNS['Minimum']."\t; minimum\n".
    99     "\t\t\t\t)\n";
    100     foreach($DNS['ReverseNameServer'] as $NameServer)
    101     {
    102       if(substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
    103         $Output .= "@\tIN\tNS\t".$NameServer.".\n";
    104       else $Output .= "\tIN\tNS\t".$NameServer.".\n";
    105     }
     11    $Output = '$ORIGIN '.$DNS['Domain'].'.'."\n".
     12        '$TTL '.$DNS['TTL']."\n".
     13        $DNS['Domain'].".\tIN\tSOA\t".$DNS['NameServer'][0].".\troot.".$DNS['Domain'].".  (\n".
     14        "\t\t\t".$DNS['Serial']."\t; serial\n".
     15        "\t\t\t".$DNS['Refresh']."\t; refresh\n".
     16        "\t\t\t".$DNS['Retry']."\t; retry\n".
     17        "\t\t\t".$DNS['Expire']."\t; expire\n".
     18        "\t\t\t".$DNS['Minimum']."\t; minimum\n".
     19        "\t\t\t)\n";
     20    foreach($DNS['NameServer'] as $NameServer)
     21    {
     22      $Output .= "\t\tIN\tNS\t".strtolower($NameServer).".\n";
     23    }
     24    $Output .= "\t\t\tTXT\t".'"'.$DNS['Description'].'"'."\n";
     25
     26    // Mail server records
     27    $Priority = 10;
     28    foreach($DNS['MailServer'] as $MailServer)
     29    {
     30      $Output .="\t\t\tMX\t".$Priority." ".strtolower($MailServer).".\n";
     31      $Priority += 10;
     32    }
     33    $Output .= "; SPF\n".
     34        $DNS['Domain'].".\tIN\tTXT\t\"v=spf1 mx -all\"\n".
     35        $DNS['Domain'].".\tIN\tSPF\t\"v=spf1 mx -all\"\n";
     36    foreach($DNS['MailServer'] as $MailServer)
     37    {
     38      $Output .= $MailServer.".\tIN\tTXT\t\"v=spf1 a -all\"\n".
     39          $MailServer.".\tIN\tSPF\t\"v=spf1 a -all\"\n";
     40    }
     41
     42    // IPv4 host list
    10643    foreach($DNS['Host'] as $Host)
    107     if(substr($Host['Address'], 0, strlen($Network)) == $Network)
    108     {
    109       $AddressParts = explode('.', $Host['Address']);
    110       $Host['Name'] = strtolower($Host['Name']);
    111       $Output .= $AddressParts[3]."\tIN\tPTR\t".$Host['Name'].".".$DNS['Domain'].".\n";
    112     }
    113     $File = fopen($DNS['BaseDir'].$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
    114     fputs($File, $Output);
    115     //echo($Output);
    116     fclose($File);
    117   }
    118 
    119   // Generate reverse DNS IPv6 records
    120   foreach($DNS['IPv6Network'] as $Network)
    121   {
    122     $Parts = explode('/', $Network);
    123     $NetworkAddress = $Parts[0];
    124     $Prefix = $Parts[1];
    125     $Output = // '$ORIGIN '.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa'."\n".
    126     '$TTL '.$DNS['TTL']."\n".
    127     "@\tIN\tSOA\t".$DNS['NameServer'][0].".\troot.".$DNS['Domain'].".  (\n".
    128     "\t\t\t\t".$DNS['Serial']."\t; serial\n".
    129     "\t\t\t\t".$DNS['Refresh']."\t; refresh\n".
    130     "\t\t\t\t".$DNS['Retry']."\t; retry\n".
    131     "\t\t\t\t".$DNS['Expire']."\t; expire\n".
    132     "\t\t\t\t".$DNS['Minimum']."\t; minimum\n".
    133     "\t\t\t\t)\n";
    134     foreach($DNS['ReverseNameServer'] as $NameServer)
    135     {
    136       if(substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
    137         $Output .= "@\tIN\tNS\t".$NameServer.".\n";
    138       else $Output .= "\tIN\tNS\t".$NameServer.".\n";
    139     }
     44    {
     45      if(strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
     46      $Output .= strtolower($Host['Name'])."\tIN\tA\t".$Host['Address']."\n";
     47    }
     48
     49    // IPv6 host list
    14050    foreach($DNS['Host'] as $Host)
    141     if(array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
    142     {
    143       $Addr = new NetworkAddressIPv6();
    144       $Addr->AddressFromString($Host['IPv6']);
    145       $Octets = $Addr->GetOctets();
    146       $Octets = array_slice($Octets, 0, (128 - $Prefix) / 4);
    147       $Octets = implode('.', $Octets);
    148 
    149       $Host['Name'] = strtolower($Host['Name']);
    150       $Output .= $Octets."\tIN\tPTR\t".$Host['Name'].".".$DNS['Domain'].".\n";
    151     }
    152 
    153     $NetAddr = new NetworkAddressIPv6();
    154     $NetAddr->AddressFromString($NetworkAddress);
    155     $Octets = array_reverse($NetAddr->GetOctets());
    156     $Octets = array_reverse(array_slice($Octets, 0, $Prefix / 4));
    157     $FileName = implode('.', $Octets).'.ip6.arpa.zone';
    158     $File = fopen($DNS['BaseDir'].$FileName, 'w+');
     51    {
     52      if(strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
     53      if(array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
     54        $Output .= strtolower($Host['Name'])."\tIN\tAAAA\t".$Host['IPv6']."\n";
     55    }
     56
     57    // Alias list
     58    foreach($DNS['Alias'] as $Alias)
     59    {
     60      if(strlen($Alias['Name']) < 8) $Alias['Name'] .= "\t";
     61      $Output .= strtolower($Alias['Name'])."\tIN\tCNAME\t".strtolower($Alias['Target'])."\n";
     62    }
     63
     64    $File = fopen($DNS['BaseDir'].$DNS['Domain'].'.zone', 'w');
    15965    fputs($File, $Output);
    16066    fclose($File);
     67
     68    // Generate reverse DNS records
     69    foreach($DNS['Network'] as $Network)
     70    {
     71      $Parts = explode('.', $Network);
     72      $Output = // '$ORIGIN '.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa'."\n".
     73      '$TTL '.$DNS['TTL']."\n".
     74      "@\tIN\tSOA\t".$DNS['NameServer'][0].".\troot.".$DNS['Domain'].".  (\n".
     75      "\t\t\t\t".$DNS['Serial']."\t; serial\n".
     76      "\t\t\t\t".$DNS['Refresh']."\t; refresh\n".
     77      "\t\t\t\t".$DNS['Retry']."\t; retry\n".
     78      "\t\t\t\t".$DNS['Expire']."\t; expire\n".
     79      "\t\t\t\t".$DNS['Minimum']."\t; minimum\n".
     80      "\t\t\t\t)\n";
     81      foreach($DNS['ReverseNameServer'] as $NameServer)
     82      {
     83        if(substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
     84          $Output .= "@\tIN\tNS\t".$NameServer.".\n";
     85        else $Output .= "\tIN\tNS\t".$NameServer.".\n";
     86      }
     87      foreach($DNS['Host'] as $Host)
     88        if(substr($Host['Address'], 0, strlen($Network)) == $Network)
     89        {
     90          $AddressParts = explode('.', $Host['Address']);
     91          $Host['Name'] = strtolower($Host['Name']);
     92          $Output .= $AddressParts[3]."\tIN\tPTR\t".$Host['Name'].".".$DNS['Domain'].".\n";
     93        }
     94      $File = fopen($DNS['BaseDir'].$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
     95      fputs($File, $Output);
     96      //echo($Output);
     97      fclose($File);
     98    }
     99
     100    // Generate reverse DNS IPv6 records
     101    foreach($DNS['IPv6Network'] as $Network)
     102    {
     103      $Parts = explode('/', $Network);
     104      $NetworkAddress = $Parts[0];
     105      $Prefix = $Parts[1];
     106      $Output = // '$ORIGIN '.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa'."\n".
     107      '$TTL '.$DNS['TTL']."\n".
     108      "@\tIN\tSOA\t".$DNS['NameServer'][0].".\troot.".$DNS['Domain'].".  (\n".
     109      "\t\t\t\t".$DNS['Serial']."\t; serial\n".
     110      "\t\t\t\t".$DNS['Refresh']."\t; refresh\n".
     111      "\t\t\t\t".$DNS['Retry']."\t; retry\n".
     112      "\t\t\t\t".$DNS['Expire']."\t; expire\n".
     113      "\t\t\t\t".$DNS['Minimum']."\t; minimum\n".
     114      "\t\t\t\t)\n";
     115      foreach($DNS['ReverseNameServer'] as $NameServer)
     116      {
     117        if(substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
     118          $Output .= "@\tIN\tNS\t".$NameServer.".\n";
     119        else $Output .= "\tIN\tNS\t".$NameServer.".\n";
     120      }
     121      foreach($DNS['Host'] as $Host)
     122        if(array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
     123        {
     124          $Addr = new NetworkAddressIPv6();
     125          $Addr->AddressFromString($Host['IPv6']);
     126          $Octets = $Addr->GetOctets();
     127          $Octets = array_slice($Octets, 0, (128 - $Prefix) / 4);
     128          $Octets = implode('.', $Octets);
     129
     130          $Host['Name'] = strtolower($Host['Name']);
     131          $Output .= $Octets."\tIN\tPTR\t".$Host['Name'].".".$DNS['Domain'].".\n";
     132        }
     133
     134      $NetAddr = new NetworkAddressIPv6();
     135      $NetAddr->AddressFromString($NetworkAddress);
     136      $Octets = array_reverse($NetAddr->GetOctets());
     137      $Octets = array_reverse(array_slice($Octets, 0, $Prefix / 4));
     138      $FileName = implode('.', $Octets).'.ip6.arpa.zone';
     139      $File = fopen($DNS['BaseDir'].$FileName, 'w+');
     140      fputs($File, $Output);
     141      fclose($File);
     142    }
     143  }
     144
     145  function Run()
     146  {
     147    $BaseDomain = 'zdechov.net';
     148    $Now = getdate();
     149    $I = floor(($Now['hours'] * 60 * 60 + $Now['minutes'] * 60 + $Now['seconds']) / (24 * 60 * 60) * 100);
     150    $Serial = date('Ymd', time()).$I;
     151    $MinimumTime = 7200;
     152    $RetryTime = 7200;
     153    $ExpireTime = 2419200;
     154    $RefreshTime = 28800;
     155    $MinimumTime = 10800;
     156    $TTL = 86400;
     157    //$BaseDir = '/var/named';
     158    $BaseDir = '/home/chronos/Projekty/centrala/trunk/var/named';
     159    if(!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.');
     160    $MailServer = 'centrala';
     161
     162
     163    $BaseDomain = 'zdechov.net';
     164    $LocalDNS = array(
     165        'Domain' => $BaseDomain,
     166        'Serial' => $Serial,
     167        'Refresh' => $RefreshTime,
     168        'Expire' => $ExpireTime,
     169        'Retry' => $RetryTime,
     170        'Minimum' => $MinimumTime,
     171        'TTL' => $TTL,
     172        'Description' => 'ZdechovNET community network',
     173        'BaseDir' => $BaseDir.'/internal/',
     174        'MailServer' => array('centrala.'.$BaseDomain),
     175        'NameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
     176        'ReverseNameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
     177        'Host' => array(),
     178        'Alias' => array(),
     179        'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67', '10.145.68',
     180            '10.145.69', '10.145.70', '10.145.71', '77.92.221', '172.16.0', '172.16.1'),
     181        'IPv6Network' => array('2a00:e580:244::/48'),
     182    );
     183
     184    // Local records
     185    $DbResult = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
     186        'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP <> ""');
     187    while($Interface = $DbResult->fetch_assoc())
     188    {
     189      $Name = $Interface['DeviceName'];
     190      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     191      $LocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP'],
     192          'IPv6' => $Interface['IPv6']);
     193    }
     194
     195    // External IPv4 records in internal server
     196    $DbResult = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
     197        'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP <> ""');
     198    while($Interface = $DbResult->fetch_assoc())
     199    {
     200      $Name = $Interface['DeviceName'];
     201      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     202      $LocalDNS['Host'][] = array('Name' => $Name.'-ext', 'Address' => $Interface['ExternalIP']);
     203    }
     204
     205    // CZFree records in internal server
     206    /*
     207     $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
     208     'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP <> ""');
     209     while($Interface = $DbResult->fetch_assoc())
     210     {
     211     $Name = $Interface['DeviceName'];
     212     if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     213     $LocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['CZFreeIP']);
     214     }
     215     */
     216
     217    // Domain aliases
     218    $DbResult = $this->Database->select('NetworkDomainAlias', '*');
     219    while($Alias = $DbResult->fetch_assoc())
     220    {
     221      $LocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     222    }
     223
     224
     225    // === External network DNS server ===
     226    $ExternalDNS = array(
     227        'Domain' => $BaseDomain,
     228        'Serial' => $Serial,
     229        'Refresh' => $RefreshTime,
     230        'Expire' => $ExpireTime,
     231        'Retry' => $RetryTime,
     232        'Minimum' => $MinimumTime,
     233        'TTL' => $TTL,
     234        'Description' => 'ZdechovNET community network',
     235        'BaseDir' => $BaseDir.'/external/',
     236        'MailServer' => array('centrala.'.$BaseDomain),
     237        'NameServer' => array('gw-hajda.inext.cz', 'ns0.xname.org', 'ns2.afraid.org'),
     238        'ReverseNameServer' => array('gw-hajda.inext.cz', 'inext.inext.cz'),
     239        'Host' => array(),
     240        'Alias' => array(),
     241        'Network' => array('81.2.194', '193.86.238', '212.111.4', '77.92.221'),
     242        'IPv6Network' => array('2a00:e580:244::/48'),
     243    );
     244
     245    $DbResult = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
     246        'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP != ""');
     247    while($Interface = $DbResult->fetch_assoc())
     248    {
     249      $Name = $Interface['DeviceName'];
     250      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     251      $ExternalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['ExternalIP'],
     252          'IPv6' => $Interface['IPv6']);
     253    }
     254
     255    // Domain alias
     256    $DbResult = $this->Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
     257    // JOIN `NetworkDevice` ON NetworkDomainAlias.Target LIKE NetworkDevice.Name AND NetworkInterface.ExternalIP != ""');
     258    while($Alias = $DbResult->fetch_assoc())
     259    {
     260      $ExternalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     261    }
     262
     263
     264    // === CZFree network DNS server ===
     265    $BaseDomain = 'zdechovnet.czf';
     266    $CZFreeDNS = array(
     267        'Domain' => $BaseDomain,
     268        'Serial' => date('Ymds', time()),
     269        'Refresh' => 28800,
     270        'Expire' => 2419200,
     271        'Retry' => 7200,
     272        'Minimum' => 10800,
     273        'TTL' => 86400,
     274        'Description' => 'ZdechovNET community network',
     275        'BaseDir' => $BaseDir.'/czfree/',
     276        'MailServer' => array('centrala.'.$BaseDomain),
     277        'NameServer' => array('centrala.'.$BaseDomain, 'mozek'.$BaseDomain),
     278        'ReverseNameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
     279        'Host' => array(),
     280        'Alias' => array(),
     281        'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67',
     282            '10.145.68', '10.145.69', '10.145.70', '10.145.71'),
     283        'IPv6Network' => array(),
     284    );
     285
     286    // Hosts
     287    $DbResult = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
     288        'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP != ""');
     289    while($Interface = $DbResult->fetch_assoc())
     290    {
     291      $Name = $Interface['DeviceName'];
     292      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     293      $CZFreeDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
     294    }
     295
     296    // Domain alias
     297    $DbResult = $this->Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
     298    // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
     299    while($Alias = $DbResult->fetch_assoc())
     300    {
     301      $CZFreeDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     302    }
     303
     304    // === CZFree network local address ===
     305    $BaseDomain = 'zdechovnet.czf';
     306    $CZFreeLocalDNS = array(
     307        'Domain' => $BaseDomain,
     308        'Serial' => date('Ymds', time()),
     309        'Refresh' => 28800,
     310        'Expire' => 2419200,
     311        'Retry' => 7200,
     312        'Minimum' => 10800,
     313        'TTL' => 86400,
     314        'Description' => 'ZdechovNET community network',
     315        'BaseDir' => $BaseDir.'/internal/',
     316        'MailServer' => array('centrala.'.$BaseDomain),
     317        'NameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
     318        'ReverseNameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
     319        'Host' => array(),
     320        'Alias' => array(),
     321        'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67',
     322            '10.145.68', '10.145.69', '10.145.70', '10.145.71'),
     323        'IPv6Network' => array(),
     324    );
     325
     326    // Hosts
     327    $DbResult = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
     328        'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP != ""');
     329    while($Interface = $DbResult->fetch_assoc())
     330    {
     331      $Name = $Interface['DeviceName'];
     332      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     333      //  $CZFreeLocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['LocalIP']);
     334      $CZFreeLocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
     335    }
     336
     337    // Domain alias
     338    $DbResult = $this->Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
     339    // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
     340    while($Alias = $DbResult->fetch_assoc())
     341    {
     342      $CZFreeLocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     343    }
     344
     345    $this->GenerateDNS($CZFreeDNS);
     346    $this->GenerateDNS($CZFreeLocalDNS);
     347
     348    $this->GenerateDNS($LocalDNS);
     349    $this->GenerateDNS($ExternalDNS);
    161350  }
    162351}
    163 
    164 $BaseDomain = 'zdechov.net';
    165 $LocalDNS = array(
    166   'Domain' => $BaseDomain,
    167   'Serial' => $Serial,
    168   'Refresh' => $RefreshTime,
    169   'Expire' => $ExpireTime,
    170   'Retry' => $RetryTime,
    171   'Minimum' => $MinimumTime,
    172   'TTL' => $TTL,
    173   'Description' => 'ZdechovNET community network',
    174   'BaseDir' => $BaseDir.'/internal/',
    175   'MailServer' => array('centrala.'.$BaseDomain),
    176   'NameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
    177   'ReverseNameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
    178   'Host' => array(),
    179   'Alias' => array(),
    180   'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67', '10.145.68',
    181     '10.145.69', '10.145.70', '10.145.71', '77.92.221', '172.16.0', '172.16.1'),
    182   'IPv6Network' => array('2a00:e580:244::/48'),
    183 );
    184 
    185 // Local records
    186 $DbResult = $System->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
    187   'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP <> ""');
    188 while($Interface = $DbResult->fetch_assoc())
    189 {
    190   $Name = $Interface['DeviceName'];
    191   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    192   $LocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP'],
    193     'IPv6' => $Interface['IPv6']);
    194 }
    195 
    196 // External IPv4 records in internal server
    197 $DbResult = $System->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
    198   'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP <> ""');
    199 while($Interface = $DbResult->fetch_assoc())
    200 {
    201   $Name = $Interface['DeviceName'];
    202   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    203   $LocalDNS['Host'][] = array('Name' => $Name.'-ext', 'Address' => $Interface['ExternalIP']);
    204 }
    205 
    206 // CZFree records in internal server
    207 /*
    208 $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
    209   'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP <> ""');
    210 while($Interface = $DbResult->fetch_assoc())
    211 {
    212   $Name = $Interface['DeviceName'];
    213   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    214   $LocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['CZFreeIP']);
    215 }
    216 */
    217 
    218 // Domain aliases
    219 $DbResult = $System->Database->select('NetworkDomainAlias', '*');
    220 while($Alias = $DbResult->fetch_assoc())
    221 {
    222   $LocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
    223 }
    224 
    225 
    226 // === External network DNS server ===
    227 $ExternalDNS = array(
    228   'Domain' => $BaseDomain,
    229   'Serial' => $Serial,
    230   'Refresh' => $RefreshTime,
    231   'Expire' => $ExpireTime,
    232   'Retry' => $RetryTime,
    233   'Minimum' => $MinimumTime,
    234   'TTL' => $TTL,
    235   'Description' => 'ZdechovNET community network',
    236   'BaseDir' => $BaseDir.'/external/',
    237   'MailServer' => array('centrala.'.$BaseDomain),
    238   'NameServer' => array('gw-hajda.inext.cz', 'ns0.xname.org', 'ns2.afraid.org'),
    239   'ReverseNameServer' => array('gw-hajda.inext.cz', 'inext.inext.cz'),
    240   'Host' => array(),
    241   'Alias' => array(),
    242   'Network' => array('81.2.194', '193.86.238', '212.111.4', '77.92.221'),
    243   'IPv6Network' => array('2a00:e580:244::/48'),
    244 );
    245 
    246 $DbResult = $System->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
    247   'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP != ""');
    248 while($Interface = $DbResult->fetch_assoc())
    249 {
    250   $Name = $Interface['DeviceName'];
    251   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    252   $ExternalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['ExternalIP'],
    253     'IPv6' => $Interface['IPv6']);
    254 }
    255 
    256 // Domain alias
    257 $DbResult = $System->Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
    258 // JOIN `NetworkDevice` ON NetworkDomainAlias.Target LIKE NetworkDevice.Name AND NetworkInterface.ExternalIP != ""');
    259 while($Alias = $DbResult->fetch_assoc())
    260 {
    261   $ExternalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
    262 }
    263 
    264 
    265 // === CZFree network DNS server ===
    266 $BaseDomain = 'zdechovnet.czf';
    267 $CZFreeDNS = array(
    268   'Domain' => $BaseDomain,
    269   'Serial' => date('Ymds', time()),
    270   'Refresh' => 28800,
    271   'Expire' => 2419200,
    272   'Retry' => 7200,
    273   'Minimum' => 10800,
    274   'TTL' => 86400,
    275   'Description' => 'ZdechovNET community network',
    276   'BaseDir' => $BaseDir.'/czfree/',
    277   'MailServer' => array('centrala.'.$BaseDomain),
    278   'NameServer' => array('centrala.'.$BaseDomain, 'mozek'.$BaseDomain),
    279   'ReverseNameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
    280   'Host' => array(),
    281   'Alias' => array(),
    282   'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67',
    283     '10.145.68', '10.145.69', '10.145.70', '10.145.71'),
    284   'IPv6Network' => array(),
    285 );
    286 
    287 // Hosts
    288 $DbResult = $System->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
    289   'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP != ""');
    290 while($Interface = $DbResult->fetch_assoc())
    291 {
    292   $Name = $Interface['DeviceName'];
    293   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    294   $CZFreeDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
    295 }
    296 
    297 // Domain alias
    298 $DbResult = $System->Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
    299 // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
    300 while($Alias = $DbResult->fetch_assoc())
    301 {
    302   $CZFreeDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
    303 }
    304 
    305 // === CZFree network local address ===
    306 $BaseDomain = 'zdechovnet.czf';
    307 $CZFreeLocalDNS = array(
    308   'Domain' => $BaseDomain,
    309   'Serial' => date('Ymds', time()),
    310   'Refresh' => 28800,
    311   'Expire' => 2419200,
    312   'Retry' => 7200,
    313   'Minimum' => 10800,
    314   'TTL' => 86400,
    315   'Description' => 'ZdechovNET community network',
    316   'BaseDir' => $BaseDir.'/internal/',
    317   'MailServer' => array('centrala.'.$BaseDomain),
    318   'NameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
    319   'ReverseNameServer' => array('centrala.'.$BaseDomain, 'mozek.'.$BaseDomain),
    320   'Host' => array(),
    321   'Alias' => array(),
    322   'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67',
    323     '10.145.68', '10.145.69', '10.145.70', '10.145.71'),
    324   'IPv6Network' => array(),
    325 );
    326 
    327 // Hosts
    328 $DbResult = $System->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
    329   'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP != ""');
    330 while($Interface = $DbResult->fetch_assoc())
    331 {
    332   $Name = $Interface['DeviceName'];
    333   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    334 //  $CZFreeLocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['LocalIP']);
    335   $CZFreeLocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
    336 }
    337 
    338 // Domain alias
    339 $DbResult = $System->Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
    340 // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
    341 while($Alias = $DbResult->fetch_assoc())
    342 {
    343   $CZFreeLocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
    344 }
    345 
    346 GenerateDNS($CZFreeDNS);
    347 GenerateDNS($CZFreeLocalDNS);
    348 
    349 
    350 GenerateDNS($LocalDNS);
    351 GenerateDNS($ExternalDNS);
Note: See TracChangeset for help on using the changeset viewer.