Changeset 211 for trunk/system/generators/dns.php
- Timestamp:
- May 10, 2009, 11:35:41 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 php_script_error.log 3 3 statistic 4 4 webis
-
- Property svn:ignore
-
trunk/system/generators/dns.php
r201 r211 1 1 <?php 2 2 3 if(isset($_SERVER['REMOTE_ADDR'])) die(); 3 4 include_once('../../global.php'); 4 5 6 $BaseDomain = 'zdechov.net'; 5 7 $Serial = date('Ymds', time()); 6 8 $MinimumTime = 7200; … … 16 18 17 19 // 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'); 21 fputs($File,'$ORIGIN '.$BaseDomain.'.'."\n". 20 22 '$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". 22 24 "\t\t\t".$Serial."\t; serial\n". 23 25 "\t\t\t".$RefreshTime."\t; refresh\n". … … 26 28 "\t\t\t".$MinimumTime."\t; minimum\n". 27 29 "\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". 30 32 "\t\t\tTXT\t".'"community network ZdechovNET"'."\n". 31 33 // "\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 <> ""'); 37 while($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"); 40 44 } 41 45 42 46 // 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 <> ""'); 48 while($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"); 49 55 } 50 56 51 57 $DbResult = $Database->select('NetworkDomainAlias', '*'); 52 while($Alias = $DbResult->fetch_a rray())58 while($Alias = $DbResult->fetch_assoc()) 53 59 { 54 60 $Data = strtolower($Alias['Name']); … … 67 73 fputs($File, 68 74 '$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()) 80 86 { 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"); 83 92 } 84 93 fclose($File); … … 93 102 fputs($File, 94 103 '$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()) 106 115 { 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"); 109 121 } 110 122 fclose($File); … … 114 126 115 127 // 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". 118 130 '$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". 120 132 "\t\t\t".$Serial."\t; serial\n". 121 133 "\t\t\t".$RefreshTime."\t; refresh\n". … … 125 137 "\t\t\t)\n". 126 138 "\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". 129 141 "\t\tIN\tNS\tplandsfeld.avonet.cz.\n"; 130 142 // "\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". 132 144 "; SPF\n". 133 145 "zdechov.net.\tIN\tTXT\t\"v=spf1 mx -all\"\n". … … 139 151 fputs($File, $Header); 140 152 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 != ""'); 154 while($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 != ""'); 165 while($Alias = $DbResult->fetch_assoc()) 151 166 { 152 167 $Data = strtolower($Alias['Name']); … … 165 180 fputs($File, 166 181 '$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". 175 190 "\t\t\tNS\tplandsfeld.avonet.cz.\n". 176 "\t\t\tNS\t".$NameServers[1].". zdechov.net.\n");177 178 $DbResult = $Database-> select('hosts','*','external_ipLIKE "'.$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()) 180 195 { 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"); 183 202 } 203 184 204 fclose($File); 185 205 } … … 225 245 fputs($File2, $Header); 226 246 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 != ""'); 248 while($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"); 237 258 } 238 259 239 260 $DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias` JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""'); 240 while($Alias = $DbResult->fetch_a rray())261 while($Alias = $DbResult->fetch_assoc()) 241 262 { 242 263 $Data = $Alias['Name']; … … 282 303 fputs($File2, $Header); 283 304 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()) 286 307 { 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"); 290 315 } 316 291 317 fclose($File); 292 318 fclose($File2);
Note:
See TracChangeset
for help on using the changeset viewer.