Ignore:
Timestamp:
May 10, 2009, 11:35:41 AM (16 years ago)
Author:
george
Message:
  • Upraveno: Dynamická velikost mapy.
  • Upraveno: Volba zobrazení prvků mapy.
  • Opraveno: Skript pro generování DNS záznamů opraven pro podporu struktury nových tabulek.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22php_script_error.log
        33statistic
        4 
         4webis
  • trunk/system/generators/dns.php

    r201 r211  
    11<?php
     2
    23if(isset($_SERVER['REMOTE_ADDR'])) die();
    34include_once('../../global.php');
    45
     6$BaseDomain = 'zdechov.net';
    57$Serial = date('Ymds', time());
    68$MinimumTime = 7200;
     
    1618
    1719// Generate DNS records
    18 $File = fopen($BaseDir.'internal/zdechov.net.zone', 'w');
    19 fputs($File,'$ORIGIN zdechov.net.'."\n".
     20$File = fopen($BaseDir.'internal/'.$BaseDomain.'.zone', 'w');
     21fputs($File,'$ORIGIN '.$BaseDomain.'.'."\n".
    2022'$TTL 86400'."\n".
    21 "zdechov.net.\tIN\tSOA\t".$NameServers[0].".zdechov.net.\troot.zdechov.net.     (\n".
     23$BaseDomain.".\tIN\tSOA\t".$NameServers[0].".".$BaseDomain.".\troot.".$BaseDomain.".    (\n".
    2224"\t\t\t".$Serial."\t; serial\n".
    2325"\t\t\t".$RefreshTime."\t; refresh\n".
     
    2628"\t\t\t".$MinimumTime."\t; minimum\n".
    2729"\t\t\t)\n".
    28 "\t\tIN\tNS\t".$NameServers[0].".zdechov.net.\n".
    29 "\t\tIN\tNS\t".$NameServers[1].".zdechov.net.\n".
     30"\t\tIN\tNS\t".$NameServers[0].".".$BaseDomain.".\n".
     31"\t\tIN\tNS\t".$NameServers[1].".".$BaseDomain.".\n".
    3032"\t\t\tTXT\t".'"community network ZdechovNET"'."\n".
    3133// "\t\tIN\tA\t192.168.0.1\n".
    32 "\t\t\tMX\t10 ".$MailServer.".zdechov.net.\n");
    33 
    34 $DbResult = $Database->select('hosts','*',' block < 2 AND IP <> ""');
    35 while($Row = $DbResult->fetch_array())
    36 {
    37   $Data = strtolower($Row['name']);
    38   if(strlen($Data) < 8) $Data .= "\t";
    39   fputs($File, $Data."\tIN\tA\t".$Row['IP']."\n");
     34"\t\t\tMX\t10 ".$MailServer.".".$BaseDomain.".\n");
     35
     36$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetwordInterface.Device WHERE NetworkInterface.LocalIP <> ""');
     37while($Interface = $DbResult->fetch_assoc())
     38{
     39  $Name = $Interface['DeviceName'];
     40  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");
    4044}
    4145
    4246// External records in internal server
    43 $DbResult = $Database->select('hosts','*','external_ip<>""');
    44 while($Row = $DbResult->fetch_array())
    45 {
    46   $Data = strtolower($Row['name']).'-ext';
    47   if(strlen($Data) < 8) $Data .= "\t";
    48   fputs($File,$Data."\tIN\tA\t".$Row['external_ip']."\n");
     47$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetwordInterface.Device WHERE NetworkInterface.ExternalIP <> ""');
     48while($Interface = $DbResult->fetch_assoc())
     49{
     50  $Name = $Interface['DeviceName'];
     51  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");
    4955}
    5056
    5157$DbResult = $Database->select('NetworkDomainAlias', '*');
    52 while($Alias = $DbResult->fetch_array())
     58while($Alias = $DbResult->fetch_assoc())
    5359{
    5460  $Data = strtolower($Alias['Name']);
     
    6773  fputs($File,
    6874  '$TTL 86400'."\n".
    69   "@\tIN\tSOA\t".$NameServers[0].".zdechov.net.\troot.zdechov.net.      (\n".
    70   "\t\t\t\t".$Serial."\t; serial\n".
    71   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    72   "\t\t\t\t".$RetryTime."\t; retry\n".
    73   "\t\t\t\t".$ExpireTime."\t; expire\n".
    74   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    75   "\t\t\t\t)\n".
    76   "@\tIN\tNS\t".$NameServers[0].".zdechov.net.\n".
    77   "\tIN\tNS\t".$NameServers[1].".zdechov.net.\n\n");
    78   $DbResult = $Database->select('hosts','*','IP LIKE "'.$Network.'%"');
    79   while($Row = $DbResult->fetch_array())
     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())
    8086  {
    81     $IP = explode('.',$Row['IP']);
    82     fputs($File,$IP[3]."\tIN\tPTR\t".strtolower($Row['name']).".zdechov.net.\n");
     87    $Name = $Interface['DeviceName'];
     88    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     89    $Name = strtolower($Name.'-ext');
     90    $IP = explode('.', $Interface['LocalIP']);
     91    fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name).".zdechov.net.\n");
    8392  }
    8493  fclose($File);
     
    93102  fputs($File,
    94103  '$TTL 86400'."\n".
    95   "@\tIN\tSOA\t".$NameServers[0].".zdechov.net.\troot.zdechov.net.      (\n".
    96   "\t\t\t\t".$Serial."\t; serial\n".
    97   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    98   "\t\t\t\t".$RetryTime."\t; retry\n".
    99   "\t\t\t\t".$ExpireTime."\t; expire\n".
    100   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    101   "\t\t\t\t)\n".
    102   "@\tIN\tNS\t".$NameServers[0].".zdechov.net.\n".
    103   "\tIN\tNS\t".$NameServers[1].".zdechov.net.\n\n");
    104   $DbResult = $Database->select('hosts','*','external_ip LIKE "'.$Network.'.%"');
    105   while($Row = $DbResult->fetch_array())
     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())
    106115  {
    107     $IP = explode('.',$Row['external_ip']);
    108     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Row['name'])."-ext.zdechov.net.\n");
     116    $Name = $Interface['DeviceName'];
     117    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     118    $Name = strtolower($Name.'-ext');
     119    $IP = explode('.',$Interafce['ExternalIP']);
     120    fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name])."-ext.".$BaseDomain.".\n");
    109121  }
    110122  fclose($File);
     
    114126
    115127// Generate DNS records
    116 $File = fopen($BaseDir.'external/zdechov.net.zone', 'w');
    117 $Header = '$ORIGIN zdechov.net.'."\n".
     128$File = fopen($BaseDir.'external/'.$BaseDomain.'.zone', 'w');
     129$Header = '$ORIGIN '.$BaseDomain.'.'."\n".
    118130'$TTL 86400'."\n".
    119 "zdechov.net.\tIN\tSOA\t".$NameServers[0].".zdechov.net.\troot.zdechov.net.     (\t\n".
     131$BaseDomain.".\tIN\tSOA\t".$NameServers[0].".".$BaseDomain.".\troot.".$BaseDomain.".    (\t\n".
    120132"\t\t\t".$Serial."\t; serial\n".
    121133"\t\t\t".$RefreshTime."\t; refresh\n".
     
    125137"\t\t\t)\n".
    126138"\t\t\tTXT\t".'"community network ZdechovNET"'."\n".
    127 "\t\tIN\tNS\t".$NameServers[0].".zdechov.net.\n".
    128 "\t\tIN\tNS\t".$NameServers[1].".zdechov.net.\n".
     139"\t\tIN\tNS\t".$NameServers[0].".".$BaseDomain.".\n".
     140"\t\tIN\tNS\t".$NameServers[1].".".$BaseDomain.".\n".
    129141"\t\tIN\tNS\tplandsfeld.avonet.cz.\n";
    130142// "\t\tIN\tA\t81.2.194.142\n".
    131 $Header .= "\t\t\tMX\t10 ".$MailServer.".zdechov.net.\n".
     143$Header .= "\t\t\tMX\t10 ".$MailServer.".".$BaseDomain.".\n".
    132144"; SPF\n".
    133145"zdechov.net.\tIN\tTXT\t\"v=spf1 mx -all\"\n".
     
    139151fputs($File, $Header);
    140152
    141 $DbResult = $Database->select('hosts','*','external_ip<>""');
    142 while($Row = $DbResult->fetch_array())
    143 {
    144   $Data = strtolower($Row['name']);
    145   if(strlen($Data) < 8) $Data .= "\t";
    146   fputs($File,$Data."\tIN\tA\t".$Row['external_ip']."\n");
    147 }
    148 
    149 $DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM  `NetworkDomainAlias` JOIN  `hosts`  ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.external_ip != ""');
    150 while($Alias = $DbResult->fetch_array())
     153$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP != ""');
     154while($Interface = $DbResult->fetch_assoc())
     155{
     156  $Name = $Interface['DeviceName'];
     157  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
     163$DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
     164// JOIN `NetworkDevice` ON NetworkDomainAlias.Target LIKE NetworkDevice.Name AND NetworkInterface.ExternalIP != ""');
     165while($Alias = $DbResult->fetch_assoc())
    151166{
    152167  $Data = strtolower($Alias['Name']);
     
    165180  fputs($File,
    166181  '$TTL 86400'."\n".
    167   "@\tIN\tSOA\t".$NameServers[0].".zdechov.net.\troot.zdechov.net.      (\n".
    168   "\t\t\t\t".$Serial."\t; serial\n".
    169   "\t\t\t\t".$RefreshTime."\t; refresh\n".
    170   "\t\t\t\t".$RetryTime."\t; retry\n".
    171   "\t\t\t\t".$ExpireTime."\t; expire\n".
    172   "\t\t\t\t".$MinimumTime."\t; minimum\n".
    173   "\t\t\t\t)\n".
    174   "@\tIN\tNS\t".$NameServers[0].".zdechov.net.\n\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".
    175190  "\t\t\tNS\tplandsfeld.avonet.cz.\n".
    176   "\t\t\tNS\t".$NameServers[1].".zdechov.net.\n");
    177 
    178   $DbResult = $Database->select('hosts','*','external_ip LIKE "'.$Network.'.%"');
    179   while($Row = $DbResult->fetch_array())
     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 = NetwordInterface.Device WHERE NetworkInterface.ExternalIP LIKE "'.$Network.'.%"');
     194  while($Interface = $DbResult->fetch_assoc())
    180195  {
    181     $IP = explode('.',$Row['external_ip']);
    182     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Row['name']).".zdechov.net.\n");
     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($Interface['Name']).".".$BaseDomain.".\n");
    183202  }
     203
    184204  fclose($File);
    185205}
     
    225245fputs($File2, $Header);
    226246
    227 $DbResult = $Database->select('hosts','*','czfree_ip<>""');
    228 while($Row = $DbResult->fetch_array())
    229 {
    230   $Data = strtolower($Row['name']);
    231   if(strlen($Data) < 8) $Data .= "\t";
    232   fputs($File,$Data."\tIN\tA\t".$Row['czfree_ip']."\n");
    233   fputs($File2,$Data."\tIN\tA\t".$Row['IP']."\n");
    234   $Data = strtolower($Row['name'].'-ext');
    235   if(strlen($Data) < 8) $Data .= "\t";
    236   fputs($File2, $Data."\tIN\tA\t".$Row['czfree_ip']."\n");
     247$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP != ""');
     248while($Interface = $DbResult->fetch_assoc())
     249{
     250  $Name = $Interface['DeviceName'];
     251  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 .= '-czfree';
     257  fputs($File2, $Name."\tIN\tA\t".$Interface['CZFreeIP']."\n");
    237258}
    238259
    239260$DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias` JOIN `hosts`  ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
    240 while($Alias = $DbResult->fetch_array())
     261while($Alias = $DbResult->fetch_assoc())
    241262{
    242263  $Data = $Alias['Name'];
     
    282303  fputs($File2, $Header);
    283304
    284   $DbResult = $Database->select('hosts','*','czfree_ip <> ""');
    285   while($Row = $DbResult->fetch_array())
     305  $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetwordInterface.Device WHERE NetworkInterface.CZFreeIP LIKE "'.$Network.'.%"');
     306  while($Interface = $DbResult->fetch_assoc())
    286307  {
    287     $IP = explode('.',$Row['czfree_ip']);
    288     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Row['name']).".".$Domain.".\n");
    289     fputs($File2, $IP[3]."\tIN\tPTR\t".strtolower($Row['name']).'-ext'.".".$Domain.".\n");
     308    $Name = $Interface['DeviceName'];
     309    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     310    $Name = strtolower($Name);
     311    if(strlen($Name) < 8) $Name .= "\t";
     312    $IP = explode('.', $Interface['CZFreeIP']);
     313    fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Interface['Name']).".".$Domain.".\n");
     314    fputs($File2, $IP[3]."\tIN\tPTR\t".strtolower($Interface['Name'].'-czfree').".".$Domain.".\n");
    290315  }
     316
    291317  fclose($File);
    292318  fclose($File2);
Note: See TracChangeset for help on using the changeset viewer.