1 | <?php
|
---|
2 | include_once('/a/www/centrala/global.php');
|
---|
3 |
|
---|
4 | $Serial = date('Ymds', time());
|
---|
5 | $ExternalServerName = 'gw-hajda.inext.cz';
|
---|
6 | $MinimumTime = 7200;
|
---|
7 | $RetryTime = 7200;
|
---|
8 | $ExpireTime = 2419200;
|
---|
9 | $RefreshTime = 28800;
|
---|
10 | $BaseDir = '/var/named/chroot/var/named/';
|
---|
11 | // === Local network DNS server ===
|
---|
12 |
|
---|
13 | // Generate DNS records
|
---|
14 | $File = fopen($BaseDir.'internal/zdechov.net.zone', 'w');
|
---|
15 | fputs($File,'$ORIGIN zdechov.net.'."\n".
|
---|
16 | '$TTL 86400'."\n".
|
---|
17 | "zdechov.net.\tIN\tSOA\tcentrala.zdechov.net.\troot.centrala.zdechov.net. (\n".
|
---|
18 | "\t\t\t".$Serial."\t; serial\n".
|
---|
19 | "\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
20 | "\t\t\t".$RetryTime."\t; retry\n".
|
---|
21 | "\t\t\t".$ExpireTime."\t; expire\n".
|
---|
22 | "\t\t\t86400\t; ttl\n".
|
---|
23 | "\t\t\t)\n".
|
---|
24 | "\t\t\tTXT\t".'"community network ZdechovNET"'."\n".
|
---|
25 | "\t\t\tNS\tcentrala.zdechov.net.\n".
|
---|
26 | // "\t\tIN\tA\t192.168.0.1\n".
|
---|
27 | "\t\t\tMX\t10 mail.zdechov.net.\n");
|
---|
28 |
|
---|
29 | $DbResult = $Database->select('hosts','*',' block < 2 AND IP <> ""');
|
---|
30 | while($Row = $DbResult->fetch_array())
|
---|
31 | {
|
---|
32 | $Data = strtolower($Row['name']);
|
---|
33 | if(strlen($Data)<8) $Data .= "\t";
|
---|
34 | fputs($File, $Data."\tIN\tA\t".$Row['IP']."\n");
|
---|
35 | }
|
---|
36 |
|
---|
37 | // External records in internal server
|
---|
38 | $DbResult = $Database->select('hosts','*','external_ip<>""');
|
---|
39 | while($Row = $DbResult->fetch_array())
|
---|
40 | {
|
---|
41 | $Data = strtolower($Row['name']).'-ext';
|
---|
42 | if(strlen($Data)<8) $Data .= "\t";
|
---|
43 | fputs($File,$Data."\tIN\tA\t".$Row['external_ip']."\n");
|
---|
44 | }
|
---|
45 |
|
---|
46 | $DbResult = $Database->select('network_dns_alias', '*');
|
---|
47 | while($Alias = $DbResult->fetch_array())
|
---|
48 | {
|
---|
49 | $Data = strtolower($Alias['name']);
|
---|
50 | if(strlen($Data)<8) $Data .= "\t";
|
---|
51 | fputs($File, $Data."\tIN\tCNAME\t".$Alias['target']."\n");
|
---|
52 | }
|
---|
53 |
|
---|
54 | fclose($File);
|
---|
55 |
|
---|
56 | // Generate reverse DNS records
|
---|
57 | $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');
|
---|
58 | foreach($Networks as $Network)
|
---|
59 | {
|
---|
60 | $Parts = explode('.', $Network);
|
---|
61 | $File = fopen($BaseDir.'internal/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
|
---|
62 | fputs($File,
|
---|
63 | '$TTL 86400'."\n".
|
---|
64 | "@\tIN\tSOA\tcentrala.zdechov.net.\troot.centrala.zdechov.net. (\n".
|
---|
65 | "\t\t\t\t".$Serial."\t; serial\n".
|
---|
66 | "\t\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
67 | "\t\t\t\t".$RetryTime."\t; retry\n".
|
---|
68 | "\t\t\t\t".$ExpireTime."\t; expire\n".
|
---|
69 | "\t\t\t\t86400 ; ttl\n".
|
---|
70 | "\t\t\t\t)\n".
|
---|
71 | "@\tIN\tNS\tcentrala.zdechov.net.\n\n");
|
---|
72 | $DbResult = $Database->select('hosts','*','IP LIKE "'.$Network.'%"');
|
---|
73 | while($Row = $DbResult->fetch_array())
|
---|
74 | {
|
---|
75 | $IP = explode('.',$Row['IP']);
|
---|
76 | fputs($File,$IP[3]."\tIN\tPTR\t".strtolower($Row['name']).".zdechov.net.\n");
|
---|
77 | }
|
---|
78 | fclose($File);
|
---|
79 | }
|
---|
80 |
|
---|
81 | // Generate reverse DNS records
|
---|
82 | $Networks = array('85.92.50');
|
---|
83 | foreach($Networks as $Network)
|
---|
84 | {
|
---|
85 | $Parts = explode('.', $Network);
|
---|
86 | $File = fopen($BaseDir.'internal/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
|
---|
87 | fputs($File,
|
---|
88 | '$TTL 86400'."\n".
|
---|
89 | "@\tIN\tSOA\tcentrala.zdechov.net.\troot.centrala.zdechov.net. (\n".
|
---|
90 | "\t\t\t\t".$Serial."\t; serial\n".
|
---|
91 | "\t\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
92 | "\t\t\t\t".$RetryTime."\t; retry\n".
|
---|
93 | "\t\t\t\t".$ExpireTime."\t; expire\n".
|
---|
94 | "\t\t\t\t86400 ; ttl\n".
|
---|
95 | "\t\t\t\t)\n".
|
---|
96 | "@\tIN\tNS\tcentrala.zdechov.net.\n\n");
|
---|
97 | $DbResult = $Database->select('hosts','*','external_ip LIKE "'.$Network.'.%"');
|
---|
98 | while($Row = $DbResult->fetch_array())
|
---|
99 | {
|
---|
100 | $IP = explode('.',$Row['external_ip']);
|
---|
101 | fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Row['name'])."-ext.zdechov.net.\n");
|
---|
102 | }
|
---|
103 | fclose($File);
|
---|
104 | }
|
---|
105 |
|
---|
106 | // === External network DNS server ===
|
---|
107 |
|
---|
108 | // Generate DNS records
|
---|
109 | $File = fopen($BaseDir.'external/zdechov.net.zone', 'w');
|
---|
110 | $Header = '$ORIGIN zdechov.net.'."\n".
|
---|
111 | '$TTL 86400'."\n".
|
---|
112 | "zdechov.net.\tIN\tSOA\t".$ExternalServerName.".\troot.centrala.zdechov.net. (\t\n".
|
---|
113 | "\t\t\t".$Serial."\t; serial\n".
|
---|
114 | "\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
115 | "\t\t\t".$RetryTime."\t; retry\n".
|
---|
116 | "\t\t\t".$ExpireTime."\t; expire\n".
|
---|
117 | "\t\t\t86400\t; ttl\n".
|
---|
118 | "\t\t\t)\n".
|
---|
119 | "\t\t\tTXT\t".'"community network ZdechovNET"'."\n".
|
---|
120 | "\t\t\tNS\t".$ExternalServerName.".\n".
|
---|
121 | "\t\t\tNS\tplandsfeld.avonet.cz.\n".
|
---|
122 | "\t\tIN\tA\t81.2.194.142\n".
|
---|
123 | "\t\t\tMX\t10 mail.zdechov.net.\n";
|
---|
124 |
|
---|
125 | fputs($File, $Header);
|
---|
126 |
|
---|
127 | $DbResult = $Database->select('hosts','*','external_ip<>""');
|
---|
128 | while($Row = $DbResult->fetch_array())
|
---|
129 | {
|
---|
130 | $Data = strtolower($Row['name']);
|
---|
131 | if(strlen($Data)<8) $Data .= "\t";
|
---|
132 | fputs($File,$Data."\tIN\tA\t".$Row['external_ip']."\n");
|
---|
133 | }
|
---|
134 |
|
---|
135 | $DbResult = $Database->query("SELECT network_dns_alias.* FROM `network_dns_alias` JOIN `hosts` ON network_dns_alias.target LIKE hosts.name AND hosts.external_ip != ''");
|
---|
136 | while($Alias = $DbResult->fetch_array())
|
---|
137 | {
|
---|
138 | $Data = strtolower($Alias['name']);
|
---|
139 | if(strlen($Data) < 8) $Data .= "\t";
|
---|
140 | fputs($File, $Data."\tIN\tCNAME\t".$Alias['target']."\n");
|
---|
141 | }
|
---|
142 |
|
---|
143 | fclose($File);
|
---|
144 |
|
---|
145 | // Generate reverse DNS records
|
---|
146 | $Networks = array('85.92.50', '81.2.194', '193.86.238', '212.111.4');
|
---|
147 | foreach($Networks as $Network)
|
---|
148 | {
|
---|
149 | $Parts = explode('.', $Network);
|
---|
150 | $File = fopen($BaseDir.'external/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
|
---|
151 | fputs($File,
|
---|
152 | '$TTL 86400'."\n".
|
---|
153 | "@\tIN\tSOA\t".$ExternalServerName.".\troot.centrala.zdechov.net. (\n".
|
---|
154 | "\t\t\t\t".$Serial."\t; serial\n".
|
---|
155 | "\t\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
156 | "\t\t\t\t".$RetryTime."\t; retry\n".
|
---|
157 | "\t\t\t\t".$ExpireTime."\t; expire\n".
|
---|
158 | "\t\t\t\t86400 ; ttl\n".
|
---|
159 | "\t\t\t\t)\n".
|
---|
160 | "@\tIN\tNS\t".$ExternalServerName.".\n\n".
|
---|
161 | "\t\t\tNS\tplandsfeld.avonet.cz.\n");
|
---|
162 |
|
---|
163 | $DbResult = $Database->select('hosts','*','external_ip LIKE "'.$Network.'.%"');
|
---|
164 | while($Row = $DbResult->fetch_array())
|
---|
165 | {
|
---|
166 | $IP = explode('.',$Row['external_ip']);
|
---|
167 | fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Row['name']).".zdechov.net.\n");
|
---|
168 | }
|
---|
169 | fclose($File);
|
---|
170 | }
|
---|
171 |
|
---|
172 | // === CZFree network DNS server ===
|
---|
173 | $Domain = 'zdechov.zlin.czf';
|
---|
174 | $Nameserver = 'centrala';
|
---|
175 |
|
---|
176 | // Generate DNS records
|
---|
177 | $File = fopen($BaseDir.'czfree/zdechov.zlin.czf.zone', 'w');
|
---|
178 | $File2 = fopen($BaseDir.'internal/zdechov.zlin.czf.zone', 'w');
|
---|
179 |
|
---|
180 | $Header = '$ORIGIN zdechov.zlin.czf.'."\n".
|
---|
181 | '$TTL 86400'."\n".
|
---|
182 | $Domain.".\tIN\tSOA\t".$Nameserver.".".$Domain.".\troot.".$Nameserver.".".$Domain." (\n".
|
---|
183 | "\t\t\t".$Serial."\t; serial\n".
|
---|
184 | "\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
185 | "\t\t\t".$RetryTime."\t; retry\n".
|
---|
186 | "\t\t\t".$ExpireTime."\t; expire\n".
|
---|
187 | "\t\t\t86400\t; ttl\n".
|
---|
188 | "\t\t\t)\n".
|
---|
189 | "\t\t\tTXT\t".'"Community network ZdechovNET"'."\n".
|
---|
190 | "\t\t\tNS\t".$Nameserver.".".$Domain.".\n".
|
---|
191 | "\t\t\tNS\tserver.zlin.czf.\n";
|
---|
192 | "\t\t\tMX\t10 mail.".$Domain.".\n";
|
---|
193 |
|
---|
194 | fputs($File, $Header);
|
---|
195 |
|
---|
196 | $Header = '$ORIGIN zdechov.zlin.czf.'."\n".
|
---|
197 | '$TTL 86400'."\n".
|
---|
198 | $Domain.".\tIN\tSOA\t".$Nameserver.".".$Domain.".\troot.".$Nameserver.".".$Domain." (\n".
|
---|
199 | "\t\t\t".$Serial."\t; serial\n".
|
---|
200 | "\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
201 | "\t\t\t".$RetryTime."\t; retry\n".
|
---|
202 | "\t\t\t".$ExpireTime."\t; expire\n".
|
---|
203 | "\t\t\t)\n".
|
---|
204 | "\t\t\tTXT\t".'"Community network ZdechovNET"'."\n".
|
---|
205 | "\t\t\tNS\t".$Nameserver.".".$Domain.".\n".
|
---|
206 | "\t\t\tNS\tserver.zlin.czf.\n";
|
---|
207 | "\t\t\tMX\t10 mail.".$Domain.".\n";
|
---|
208 | fputs($File2, $Header);
|
---|
209 |
|
---|
210 | $DbResult = $Database->select('hosts','*','czfree_ip<>""');
|
---|
211 | while($Row = $DbResult->fetch_array())
|
---|
212 | {
|
---|
213 | $Data = strtolower($Row['name']);
|
---|
214 | if(strlen($Data) < 8) $Data .= "\t";
|
---|
215 | fputs($File,$Data."\tIN\tA\t".$Row['czfree_ip']."\n");
|
---|
216 | fputs($File2,$Data."\tIN\tA\t".$Row['IP']."\n");
|
---|
217 | $Data = strtolower($Row['name'].'-ext');
|
---|
218 | if(strlen($Data) < 8) $Data .= "\t";
|
---|
219 | fputs($File2, $Data."\tIN\tA\t".$Row['czfree_ip']."\n");
|
---|
220 | }
|
---|
221 |
|
---|
222 | $DbResult = $Database->query("SELECT network_dns_alias.* FROM `network_dns_alias` JOIN `hosts` ON network_dns_alias.target LIKE hosts.name AND hosts.czfree_ip != ''");
|
---|
223 | while($Alias = $DbResult->fetch_array())
|
---|
224 | {
|
---|
225 | $Data = $Alias['name'];
|
---|
226 | if(strlen($Data)<8) $Data .= "\t";
|
---|
227 | fputs($File, $Data."\tIN\tCNAME\t".$Alias['target']."\n");
|
---|
228 | fputs($File2, $Data."\tIN\tCNAME\t".$Alias['target']."\n");
|
---|
229 | }
|
---|
230 | fclose($File);
|
---|
231 | fclose($File2);
|
---|
232 |
|
---|
233 | // Generate reverse DNS records
|
---|
234 | $Nameserver = 'centrala';
|
---|
235 | $Networks = array('10.144.200');
|
---|
236 | foreach($Networks as $Network)
|
---|
237 | {
|
---|
238 | $Parts = explode('.', $Network);
|
---|
239 | $File = fopen($BaseDir.'czfree/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
|
---|
240 | $File2 = fopen($BaseDir.'internal/'.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa.zone', 'w+');
|
---|
241 | $Nameserver = 'centrala';
|
---|
242 | $Header = '$TTL 86400'."\n".
|
---|
243 | "@\tIN\tSOA\t".$Nameserver.".".$Domain.".\troot.".$Nameserver.".".$Domain.". (\n".
|
---|
244 | "\t\t\t\t".$Serial."\t; serial\n".
|
---|
245 | "\t\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
246 | "\t\t\t\t".$RetryTime."\t; retry\n".
|
---|
247 | "\t\t\t\t".$ExpireTime."\t; expire\n".
|
---|
248 | "\t\t\t\t86400 ; ttl\n".
|
---|
249 | "\t\t\t\t)\n".
|
---|
250 | "@\tIN\tNS\t".$Nameserver.".".$Domain.".\n".
|
---|
251 | "\tIN\tNS\tserver.zlin.czf.\n\n";
|
---|
252 | fputs($File, $Header);
|
---|
253 |
|
---|
254 | $Nameserver = 'centrala-ext';
|
---|
255 | $Header = '$TTL 86400'."\n".
|
---|
256 | "@\tIN\tSOA\t".$Nameserver.".".$Domain.".\troot.".$Nameserver.".".$Domain.". (\n".
|
---|
257 | "\t\t\t\t".$Serial."\t; serial\n".
|
---|
258 | "\t\t\t\t".$RefreshTime."\t; refresh\n".
|
---|
259 | "\t\t\t\t".$RetryTime."\t; retry\n".
|
---|
260 | "\t\t\t\t".$ExpireTime."\t; expire\n".
|
---|
261 | "\t\t\t\t86400 ; ttl\n".
|
---|
262 | "\t\t\t\t)\n".
|
---|
263 | "@\tIN\tNS\t".$Nameserver.".".$Domain.".\n";
|
---|
264 | "\tIN\tNS\tserver.zlin.czf.\n\n";
|
---|
265 |
|
---|
266 | fputs($File2, $Header);
|
---|
267 |
|
---|
268 | $DbResult = $Database->select('hosts','*','czfree_ip <> ""');
|
---|
269 | while($Row = $DbResult->fetch_array())
|
---|
270 | {
|
---|
271 | $IP = explode('.',$Row['czfree_ip']);
|
---|
272 | fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Row['name']).".".$Domain.".\n");
|
---|
273 | fputs($File2, $IP[3]."\tIN\tPTR\t".strtolower($Row['name']).'-ext'.".".$Domain.".\n");
|
---|
274 | }
|
---|
275 | fclose($File);
|
---|
276 | fclose($File2);
|
---|
277 | }
|
---|
278 | ?>
|
---|