Changeset 235 for trunk


Ignore:
Timestamp:
Jul 25, 2009, 7:31:03 PM (15 years ago)
Author:
george
Message:
  • Opraveno: Přečíslování veřejného rozsahu adres. * Upraveno: Generování DNS záznamů bylo sjednoceno do jedné parametrické funkce.
Location:
trunk/system/generators
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/system/generators/dns.php

    r232 r235  
    1111$RefreshTime = 28800;
    1212$MinimumTime = 10800;
    13 $BaseDir = '/var/named/chroot/var/named/';
     13$TTL = 86400;
     14$BaseDir = '/var/named/';
    1415$MailServer = 'centrala';
    15 $NameServers = array('centrala', 'tv');
    16 
    17 // === Local network DNS server ===
    18 
    19 // Generate DNS records
    20 $File = fopen($BaseDir.'internal/'.$BaseDomain.'.zone', 'w');
    21 fputs($File,'$ORIGIN '.$BaseDomain.'.'."\n".
    22 '$TTL 86400'."\n".
    23 $BaseDomain.".\tIN\tSOA\t".$NameServers[0].".".$BaseDomain.".\troot.".$BaseDomain.".  (\n".
    24 "\t\t\t".$Serial."\t; serial\n".
    25 "\t\t\t".$RefreshTime."\t; refresh\n".
    26 "\t\t\t".$RetryTime."\t; retry\n".
    27 "\t\t\t".$ExpireTime."\t; expire\n".
    28 "\t\t\t".$MinimumTime."\t; minimum\n".
    29 "\t\t\t)\n".
    30 "\t\tIN\tNS\t".$NameServers[0].".".$BaseDomain.".\n".
    31 "\t\tIN\tNS\t".$NameServers[1].".".$BaseDomain.".\n".
    32 "\t\t\tTXT\t".'"community network ZdechovNET"'."\n".
    33 // "\t\tIN\tA\t192.168.0.1\n".
    34 "\t\t\tMX\t10 ".$MailServer.".".$BaseDomain.".\n");
    35 
     16
     17function GenerateDNS($DNS)
     18{
     19  $Output = '$ORIGIN '.$DNS['Domain'].'.'."\n".
     20  '$TTL '.$DNS['TTL']."\n".
     21  $DNS['Domain'].".\tIN\tSOA\t".$DNS['NameServer'][0].".\troot.".$DNS['Domain'].".  (\n".
     22  "\t\t\t".$DNS['Serial']."\t; serial\n".
     23  "\t\t\t".$DNS['Refresh']."\t; refresh\n".
     24  "\t\t\t".$DNS['Retry']."\t; retry\n".
     25  "\t\t\t".$DNS['Expire']."\t; expire\n".
     26  "\t\t\t".$DNS['Minimum']."\t; minimum\n".
     27  "\t\t\t)\n";
     28  foreach($DNS['NameServer'] as $NameServer)
     29  {
     30    $Output .= "\t\tIN\tNS\t".strtolower($NameServer).".\n";
     31  }
     32  $Output .= "\t\t\tTXT\t".'"'.$DNS['Description'].'"'."\n";
     33
     34  // Mail server records
     35  $Priority = 10;
     36  foreach($DNS['MailServer'] as $MailServer)
     37  {
     38    $Output .="\t\t\tMX\t".$Priority." ".strtolower($MailServer).".\n";
     39    $Priority += 10;
     40  }
     41  $Output .= "; SPF\n".
     42    $DNS['Domain'].".\tIN\tTXT\t\"v=spf1 mx -all\"\n".
     43    $DNS['Domain'].".\tIN\tSPF\t\"v=spf1 mx -all\"\n";
     44  foreach($DNS['MailServer'] as $MailServer)
     45  {
     46    $Output .= $MailServer.".\tIN\tTXT\t\"v=spf1 a -all\"\n".
     47    $MailServer.".\tIN\tSPF\t\"v=spf1 a -all\"\n";
     48  }
     49
     50  // Host list
     51  foreach($DNS['Host'] as $Host)
     52  {
     53    if(strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
     54    $Output .= strtolower($Host['Name'])."\tIN\tA\t".$Host['Address']."\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');
     65  fputs($File, $Output);
     66  fclose($File);
     67
     68  // Generate reverse DNS records
     69  foreach($DNS['Network'] as $Network)
     70  {
     71    $Parts = explode('.', $Network);
     72    $Output = '$ORIGINS '.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa'.
     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['NameServer'] 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    fclose($File);
     97  }
     98}
     99
     100$BaseDomain = 'zdechov.net';
     101$LocalDNS = array(
     102  'Domain' => $BaseDomain,
     103  'Serial' => $Serial,
     104  'Refresh' => $RefreshTime,
     105  'Expire' => $ExpireTime,
     106  'Retry' => $RetryTime,
     107  'Minimum' => $MinimumTime,
     108  'TTL' => $TTL,
     109  'Description' => 'ZdechovNET community network',
     110  'BaseDir' => '/var/named/internal/',
     111  'MailServer' => array('centrala.'.$BaseDomain),
     112  'NameServer' => array('centrala.'.$BaseDomain, 'tv.'.$BaseDomain),
     113  'Host' => array(),
     114  'Alias' => array(),
     115  'Network' => array('192.168.0', '192.168.1', '192.168.2', '192.168.3', '192.168.4', '192.168.5', '192.168.6', '192.168.7', '77.92.221'),
     116);
     117
     118// Local records
    36119$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP <> ""');
    37120while($Interface = $DbResult->fetch_assoc())
     
    39122  $Name = $Interface['DeviceName'];
    40123  if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    41   $Name = strtolower($Name);
    42   if(strlen($Name) < 8) $Name .= "\t";
    43   fputs($File, $Name."\tIN\tA\t".$Interface['LocalIP']."\n");
     124  $LocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
    44125}
    45126
     
    50131  $Name = $Interface['DeviceName'];
    51132  if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    52   $Name = strtolower($Name.'-ext');
    53   if(strlen($Name) < 8) $Name .= "\t";
    54   fputs($File, $Name."\tIN\tA\t".$Interface['ExternalIP']."\n");
    55 }
    56 
     133  $LocalDNS['Host'][] = array('Name' => $Name.'-ext', 'Address' => $Interface['ExternalIP']);
     134}
     135
     136// CZFree records in internal server
     137$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP <> ""');
     138while($Interface = $DbResult->fetch_assoc())
     139{
     140  $Name = $Interface['DeviceName'];
     141  if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     142  $LocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['CZFreeIP']);
     143}
     144
     145// Domain aliases
    57146$DbResult = $Database->select('NetworkDomainAlias', '*');
    58147while($Alias = $DbResult->fetch_assoc())
    59148{
    60   $Data = strtolower($Alias['Name']);
    61   if(strlen($Data) < 8) $Data .= "\t";
    62   fputs($File, $Data."\tIN\tCNAME\t".$Alias['Target']."\n");
    63 }
    64 
    65 fclose($File);
    66 
    67 // Generate reverse DNS records
    68 $Networks = array('192.168.0', '192.168.1', '192.168.2', '192.168.3', '192.168.4', '192.168.5', '192.168.6', '192.168.7');
    69 foreach($Networks as $Network)
    70 {
    71   $Parts = explode('.', $Network);
    72   $File = fopen($BaseDir.'internal/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
    73   fputs($File,
    74   '$TTL 86400'."\n".
    75   "@\tIN\tSOA\t".$NameServers[0].".".$BaseDomain.".\troot.".$BaseDomain.".  (\n".
    76   "\t\t\t\t".$Serial."\t; serial\n".
    77   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    78   "\t\t\t\t".$RetryTime."\t; retry\n".
    79   "\t\t\t\t".$ExpireTime."\t; expire\n".
    80   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    81   "\t\t\t\t)\n".
    82   "@\tIN\tNS\t".$NameServers[0].".".$BaseDomain.".\n".
    83   "\tIN\tNS\t".$NameServers[1].".".$BaseDomain.".\n\n");
    84   $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP LIKE "'.$Network.'%"');
    85   while($Interface = $DbResult->fetch_assoc())
    86   {
    87     $Name = $Interface['DeviceName'];
    88     if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    89     $Name = strtolower($Name);
    90     $IP = explode('.', $Interface['LocalIP']);
    91     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name).".zdechov.net.\n");
    92   }
    93   fclose($File);
    94 }
    95 
    96 // Generate reverse DNS records
    97 $Networks = array('85.92.50');
    98 foreach($Networks as $Network)
    99 {
    100   $Parts = explode('.', $Network);
    101   $File = fopen($BaseDir.'internal/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
    102   fputs($File,
    103   '$TTL 86400'."\n".
    104   "@\tIN\tSOA\t".$NameServers[0].".".$BaseDomain.".\troot.".$BaseDomain.".  (\n".
    105   "\t\t\t\t".$Serial."\t; serial\n".
    106   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    107   "\t\t\t\t".$RetryTime."\t; retry\n".
    108   "\t\t\t\t".$ExpireTime."\t; expire\n".
    109   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    110   "\t\t\t\t)\n".
    111   "@\tIN\tNS\t".$NameServers[0].".".$BaseDomain.".\n".
    112   "\tIN\tNS\t".$NameServers[1].".".$BaseDomain.".\n\n");
    113   $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP LIKE "'.$Network.'%"');
    114   while($Interface = $DbResult->fetch_assoc())
    115   {
    116     $Name = $Interface['DeviceName'];
    117     if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    118     $Name = strtolower($Name.'-ext');
    119     $IP = explode('.',$Interface['ExternalIP']);
    120     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name).'.'.$BaseDomain.".\n");
    121   }
    122   fclose($File);
    123 }
     149  $LocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     150}
     151
    124152
    125153// === External network DNS server ===
    126 
    127 // Generate DNS records
    128 $File = fopen($BaseDir.'external/'.$BaseDomain.'.zone', 'w');
    129 $Header = '$ORIGIN '.$BaseDomain.'.'."\n".
    130 '$TTL 86400'."\n".
    131 $BaseDomain.".\tIN\tSOA\t".$NameServers[0].".".$BaseDomain.".\troot.".$BaseDomain.".  (\t\n".
    132 "\t\t\t".$Serial."\t; serial\n".
    133 "\t\t\t".$RefreshTime."\t; refresh\n".
    134 "\t\t\t".$RetryTime."\t; retry\n".
    135 "\t\t\t".$ExpireTime."\t; expire\n".
    136 "\t\t\t".$MinimumTime."\t; minimum\n".
    137 "\t\t\t)\n".
    138 "\t\t\tTXT\t".'"community network ZdechovNET"'."\n".
    139 "\t\tIN\tNS\t".$NameServers[0].".".$BaseDomain.".\n".
    140 "\t\tIN\tNS\t".$NameServers[1].".".$BaseDomain.".\n".
    141 "\t\tIN\tNS\tplandsfeld.avonet.cz.\n";
    142 // "\t\tIN\tA\t81.2.194.142\n".
    143 $Header .= "\t\t\tMX\t10 ".$MailServer.".".$BaseDomain.".\n".
    144 "; SPF\n".
    145 "zdechov.net.\tIN\tTXT\t\"v=spf1 mx -all\"\n".
    146 "zdechov.net.\tIN\tSPF\t\"v=spf1 mx -all\"\n".
    147 "centrala\tIN\tTXT\t\"v=spf1 a -all\"\n".
    148 "centrala\tIN\tSPF\t\"v=spf1 a -all\"\n".
    149 "; Host list\n";
    150 
    151 fputs($File, $Header);
     154$ExternalDNS = array(
     155  'Domain' => $BaseDomain,
     156  'Serial' => date('Ymds', time()),
     157  'Refresh' => 28800,
     158  'Expire' => 2419200,
     159  'Retry' => 7200,
     160  'Minimum' => 10800,
     161  'TTL' => 86400,
     162  'Description' => 'ZdechovNET community network',
     163  'BaseDir' => '/var/named/external/',
     164  'MailServer' => array('centrala.'.$BaseDomain),
     165  'NameServer' => array('gw-hajda.inext.cz', 'ns3.eu.editdns.net', 'ns1.twisted4life.com'),
     166  'Host' => array(),
     167  'Alias' => array(),
     168  'Network' => array('81.2.194', '193.86.238', '212.111.4', '77.92.221'),
     169);
    152170
    153171$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP != ""');
     
    156174  $Name = $Interface['DeviceName'];
    157175  if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    158   $Name = strtolower($Name);
    159   if(strlen($Name) < 8) $Name .= "\t";
    160   fputs($File, $Name."\tIN\tA\t".$Interface['ExternalIP']."\n");
    161 }
    162 
     176  $ExternalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['ExternalIP']);
     177}
     178
     179// Domain alias
    163180$DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
    164181// JOIN `NetworkDevice` ON NetworkDomainAlias.Target LIKE NetworkDevice.Name AND NetworkInterface.ExternalIP != ""');
    165182while($Alias = $DbResult->fetch_assoc())
    166183{
    167   $Data = strtolower($Alias['Name']);
    168   if(strlen($Data) < 8) $Data .= "\t";
    169   fputs($File, $Data."\tIN\tCNAME\t".$Alias['Target']."\n");
    170 }
    171 
    172 fclose($File);
    173 
    174 // Generate reverse DNS records
    175 $Networks = array('85.92.50', '81.2.194', '193.86.238', '212.111.4');
    176 foreach($Networks as $Network)
    177 {
    178   $Parts = explode('.', $Network);
    179   $File = fopen($BaseDir.'external/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
    180   fputs($File,
    181   '$TTL 86400'."\n".
    182   "@\tIN\tSOA\t".$NameServers[0].".".$BaseDomain.".\troot.".$BaseDomain.".  (\n".
    183   "\t\t\t\t".$Serial."\t; serial\n".
    184   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    185   "\t\t\t\t".$RetryTime."\t; retry\n".
    186   "\t\t\t\t".$ExpireTime."\t; expire\n".
    187   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    188   "\t\t\t\t)\n".
    189   "@\tIN\tNS\t".$NameServers[0].".".$BaseDomain.".\n\n".
    190   "\t\t\tNS\tplandsfeld.avonet.cz.\n".
    191   "\t\t\tNS\t".$NameServers[1].".".$BaseDomain.".\n");
    192 
    193   $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP LIKE "'.$Network.'.%"');
    194   while($Interface = $DbResult->fetch_assoc())
    195   {
    196     $Name = $Interface['DeviceName'];
    197     if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    198     $Name = strtolower($Name);
    199     //if(strlen($Name) < 8) $Name .= "\t";
    200     $IP = explode('.', $Interface['ExternalIP']);
    201     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name).".".$BaseDomain.".\n");
    202   }
    203 
    204   fclose($File);
    205 }
     184  $ExternalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     185}
     186
    206187
    207188// === CZFree network DNS server ===
    208 $Domain = 'zdechov.zlin.czf';
    209 
    210 // Generate DNS records
    211 $File = fopen($BaseDir.'czfree/zdechov.zlin.czf.zone', 'w');
    212 $File2 = fopen($BaseDir.'internal/zdechov.zlin.czf.zone', 'w');
    213 
    214 $Header = '$ORIGIN zdechov.zlin.czf.'."\n".
    215 '$TTL 86400'."\n".
    216 $Domain.".\tIN\tSOA\t".$NameServers[0].".".$Domain.".\troot.".$Domain." (\n".
    217 "\t\t\t".$Serial."\t; serial\n".
    218 "\t\t\t".$RefreshTime."\t; refresh\n".
    219 "\t\t\t".$RetryTime."\t; retry\n".
    220 "\t\t\t".$ExpireTime."\t; expire\n".
    221 "\t\t\t".$MinimumTime."\t; minimum\n".
    222 "\t\t\t)\n".
    223 "\t\t\tTXT\t".'"Community network ZdechovNET"'."\n".
    224 "\t\t\tNS\t".$NameServers[0].".".$Domain.".\n".
    225 "\t\t\tNS\t".$NameServers[1].".".$Domain.".\n".
    226 "\t\t\tNS\tserver.zlin.czf.\n";
    227 "\t\t\tMX\t10 ".$MailServer.".".$Domain.".\n";
    228 
    229 fputs($File, $Header);
    230 
    231 $Header = '$ORIGIN zdechov.zlin.czf.'."\n".
    232 '$TTL 86400'."\n".
    233 $Domain.".\tIN\tSOA\t".$NameServers[0].".".$Domain.".\troot.".$Domain." (\n".
    234 "\t\t\t".$Serial."\t; serial\n".
    235 "\t\t\t".$RefreshTime."\t; refresh\n".
    236 "\t\t\t".$RetryTime."\t; retry\n".
    237 "\t\t\t".$ExpireTime."\t; expire\n".
    238 "\t\t\t".$MinimumTime."\t; minimum\n".
    239 "\t\t\t)\n".
    240 "\t\t\tTXT\t".'"Community network ZdechovNET"'."\n".
    241 "\t\t\tNS\t".$NameServers[0].".".$Domain.".\n".
    242 "\t\t\tNS\t".$NameServers[1].".".$Domain.".\n".
    243 "\t\t\tNS\tserver.zlin.czf.\n";
    244 "\t\t\tMX\t10 ".$MailServer.".".$Domain.".\n";
    245 fputs($File2, $Header);
    246 
     189$BaseDomain = 'zdechov.zlin.czf';
     190$CZFreeDNS = array(
     191  'Domain' => $BaseDomain,
     192  'Serial' => date('Ymds', time()),
     193  'Refresh' => 28800,
     194  'Expire' => 2419200,
     195  'Retry' => 7200,
     196  'Minimum' => 10800,
     197  'TTL' => 86400,
     198  'Description' => 'ZdechovNET community network',
     199  'BaseDir' => '/var/named/czfree/',
     200  'MailServer' => array('centrala.'.$BaseDomain),
     201  'NameServer' => array('centrala.'.$BaseDomain, 'server.zlin.czf'),
     202  'Host' => array(),
     203  'Alias' => array(),
     204  'Network' => array('10.144.200'),
     205);
     206
     207// Hosts
    247208$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP != ""');
    248209while($Interface = $DbResult->fetch_assoc())
     
    250211  $Name = $Interface['DeviceName'];
    251212  if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    252   $Name = strtolower($Name);
    253   if(strlen($Name) < 8) $Name .= "\t";
    254   fputs($File, $Name."\tIN\tA\t".$Interface['CZFreeIP']."\n");
    255   fputs($File2, $Name."\tIN\tA\t".$Interface['LocalIP']."\n");
    256   $Name = $Interface['DeviceName'];
    257   if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    258   $Name = strtolower($Name);
    259   $Name .= '-czfree';
    260   fputs($File2, $Name."\tIN\tA\t".$Interface['CZFreeIP']."\n");
    261 }
    262 
     213  $CZFreeDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['CZFreeIP']);
     214}
     215
     216// Domain alias
    263217$DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
    264 // JOIN `hosts`  ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
    265 while($Alias = $DbResult->fetch_assoc())
    266 {
    267   $Data = $Alias['Name'];
    268   if(strlen($Data) < 8) $Data .= "\t";
    269   fputs($File, $Data."\tIN\tCNAME\t".$Alias['Target']."\n");
    270   fputs($File2, $Data."\tIN\tCNAME\t".$Alias['Target']."\n");
    271 }
    272 fclose($File);
    273 fclose($File2);
    274 
    275 // Generate reverse DNS records
    276 $Networks = array('10.144.200');
    277 foreach($Networks as $Network)
    278 {
    279   $Parts = explode('.', $Network);
    280   $File = fopen($BaseDir.'czfree/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
    281   $File2 = fopen($BaseDir.'internal/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
    282   $Header = '$TTL 86400'."\n".
    283   "@\tIN\tSOA\t".$NameServers[0].".".$Domain.".\troot.".$Domain.".  (\n".
    284   "\t\t\t\t".$Serial."\t; serial\n".
    285   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    286   "\t\t\t\t".$RetryTime."\t; retry\n".
    287   "\t\t\t\t".$ExpireTime."\t; expire\n".
    288   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    289   "\t\t\t\t)\n".
    290   "@\tIN\tNS\t".$NameServers[0].".".$Domain.".\n".
    291   "@\tIN\tNS\t".$NameServers[1].".".$Domain.".\n".
    292   "\tIN\tNS\tserver.zlin.czf.\n\n";
    293   fputs($File, $Header);
    294 
    295   $Header = '$TTL 86400'."\n".
    296   "@\tIN\tSOA\t".$NameServers[0]."-ext.".$Domain.".\troot.".$Domain.".  (\n".
    297   "\t\t\t\t".$Serial."\t; serial\n".
    298   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    299   "\t\t\t\t".$RetryTime."\t; retry\n".
    300   "\t\t\t\t".$ExpireTime."\t; expire\n".
    301   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    302   "\t\t\t\t)\n".
    303   "@\tIN\tNS\t".$NameServers[0]."-ext.".$Domain.".\n";
    304   "@\tIN\tNS\t".$NameServers[1]."-ext.".$Domain.".\n";
    305   "\tIN\tNS\tserver.zlin.czf.\n\n";
    306 
    307   fputs($File2, $Header);
    308 
    309   $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP LIKE "'.$Network.'.%"');
    310   while($Interface = $DbResult->fetch_assoc())
    311   {
    312     $Name = $Interface['DeviceName'];
    313     if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    314     $Name = strtolower($Name);
    315     $Name2 = $Name;
    316     if(strlen($Name) < 8) $Name .= "\t";
    317     $IP = explode('.', $Interface['CZFreeIP']);
    318     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name2).".".$Domain.".\n");
    319     fputs($File2, $IP[3]."\tIN\tPTR\t".strtolower($Name2.'-czfree').".".$Domain.".\n");
    320   }
    321 
    322   fclose($File);
    323   fclose($File2);
    324 }
     218// JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
     219while($Alias = $DbResult->fetch_assoc())
     220{
     221  $CZFreeDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     222}
     223
     224// === CZFree network local address ===
     225$BaseDomain = 'zdechov.zlin.czf';
     226$CZFreeLocalDNS = array(
     227  'Domain' => $BaseDomain,
     228  'Serial' => date('Ymds', time()),
     229  'Refresh' => 28800,
     230  'Expire' => 2419200,
     231  'Retry' => 7200,
     232  'Minimum' => 10800,
     233  'TTL' => 86400,
     234  'Description' => 'ZdechovNET community network',
     235  'BaseDir' => '/var/named/internal/',
     236  'MailServer' => array('centrala.'.$BaseDomain),
     237  'NameServer' => array('centrala.'.$BaseDomain, 'server.zlin.czf'),
     238  'Host' => array(),
     239  'Alias' => array(),
     240  'Network' => array('10.144.200'),
     241);
     242
     243// Hosts
     244$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP != ""');
     245while($Interface = $DbResult->fetch_assoc())
     246{
     247  $Name = $Interface['DeviceName'];
     248  if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     249  $CZFreeLocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['CZFreeIP']);
     250  $CZFreeLocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
     251}
     252
     253// Domain alias
     254$DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
     255// JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
     256while($Alias = $DbResult->fetch_assoc())
     257{
     258  $CZFreeLocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     259}
     260
     261GenerateDNS($LocalDNS);
     262GenerateDNS($ExternalDNS);
     263GenerateDNS($CZFreeDNS);
     264GenerateDNS($CZFreeLocalDNS);
    325265
    326266?>
  • trunk/system/generators/nat_routerboard.php

    r213 r235  
    2222    echo($Name.'('.$Interface['LocalIP'].'), ');
    2323    $Commands[] = ' /ip firewall nat add chain=srcnat src-address='.$Interface['LocalIP'].' out-interface='.$InetInterface.' action=src-nat to-addresses='.$Interface['ExternalIP'].' comment="'.$Name.'"';
     24    $Commands[] = ' /ip firewall nat add chain=dstnat dst-address='.$Interface['ExternalIP'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Interface['LocalIP'].' comment="'.$Name.'"';
     25
     26    // Temporary old incoming public subnet range
     27    $ExternalIPParts = explode('.', $Interface['ExternalIP']);
     28    $ExternalIPParts[0] = 85;
     29    $ExternalIPParts[1] = 92;
     30    $ExternalIPParts[2] = 50;
     31    $Interface['ExternalIP'] = implode('.', $ExternalIPParts);
    2432    $Commands[] = ' /ip firewall nat add chain=dstnat dst-address='.$Interface['ExternalIP'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Interface['LocalIP'].' comment="'.$Name.'"';
    2533  }
  • trunk/system/generators/netwatch.php

    r215 r235  
    2121      $Name = $Interface['DeviceName'];
    2222      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     23      echo($Name.', ');
    2324      $Commands[] = '/tool netwatch add host='.$Interface['LocalIP'].' interval=1m comment='.$Name;
    2425    }
Note: See TracChangeset for help on using the changeset viewer.