Debian Codegraph @

webadmin/index.php

raw
1 <?
2 // $Id: index.php,v 1.11 2002/08/13 12:20:22 tis Exp $
3
4 include("config.inc");
5 include("common.inc");
6 error_reporting(E_ERROR|E_WARNING|E_PARSE);
7
8 if (isset($HTTP_GET_VARS[call])) {
9 main($HTTP_GET_VARS[call]);
10 } elseif (isset($HTTP_POST_VARS[call])) {
11 main($HTTP_POST_VARS[call]);
12 } else {
13 include("framesets.inc");
14 }
15
16 function main($call)
17 {
18 global $ZONEEDIT, $HTTP_GET_VARS, $HTTP_POST_VARS;
19 switch ($call) {
20 case "dnslist":
21 connect_ldap();
22 include("menuheader.inc");
23 if (ereg("[am]", check_constraint())) {
24 full_dns_list();
25 } else {
26 individual_dns_list();
27 }
28 include("footer.inc");
29 break;
30 case "search":
31 connect_ldap();
32 include("mainheader.inc");
33 if (isset($HTTP_GET_VARS[zonename])) {
34 $zonedn = search_zone($HTTP_GET_VARS[zonename]);
35 if (strlen($zonedn)>0) {
36 zone_edit_plus($zonedn);
37 } else {
38 new_zone($HTTP_GET_VARS[zonename]);
39 }
40 }
41 include("footer.inc");
42 break;
43 case "editzone":
44 connect_ldap();
45 include("mainheader.inc");
46 if (isset($HTTP_POST_VARS[modifysoa])) {
47 modify_zone_soa($HTTP_POST_VARS[zonedn]);
48 log_action("modify_zone_soa: $HTTP_POST_VARS[zonedn]");
49 } elseif (isset($HTTP_POST_VARS[addrrset])) {
50 add_rrset($HTTP_POST_VARS[zonedn]);
51 log_action("add_rrset: $HTTP_POST_VARS[zonedn]");
52 } elseif (isset($HTTP_POST_VARS[modifyrrset])) {
53 if (isset($HTTP_POST_VARS[deleterrset])) {
54 delete_rrset($HTTP_POST_VARS[zonedn], $HTTP_POST_VARS[setdn]);
55 log_action("delete_rrset: $HTTP_POST_VARS[setdn]");
56 } else {
57 modify_rrset($HTTP_POST_VARS[zonedn], $HTTP_POST_VARS[setdn]);
58 log_action("modify_rrset: ".$HTTP_POST_VARS[setdn]);
59 }
60 }
61 if (isset($HTTP_GET_VARS[zonedn]))
62 zone_edit_plus($HTTP_GET_VARS[zonedn]);
63 elseif (isset($HTTP_POST_VARS[zonedn]))
64 edit_zone_attrs($HTTP_POST_VARS[zonedn]);
65 include("footer.inc");
66 break;
67 case "newzone":
68 connect_ldap();
69 include("mainheader.inc");
70 new_zone();
71 include("footer.inc");
72 break;
73 case "addzone":
74 connect_ldap();
75 include("mainheader.inc");
76 zone_edit_plus(add_zone());
77 include("footer.inc");
78 break;
79 case "removezone":
80 connect_ldap();
81 if (isset($HTTP_GET_VARS[zonedn]) && remove_zone($HTTP_GET_VARS[zonedn])) {
82 include("xearthheader.inc");
83 include("footer.inc");
84 }
85 break;
86 }
87 }
88
89
90 function full_dns_list()
91 {
92 global $ldap, $BASEDN, $ZONEEDIT, $HTTP_GET_VARS;
93 $letters = array( "0-9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q-R","S","T","U","V","W","X-Z" );
94 if (isset($HTTP_GET_VARS[wait])) sleep($HTTP_GET_VARS[wait]);
95 if (isset($HTTP_GET_VARS[selet])) $selet = $HTTP_GET_VARS[selet];
96 ?>
97 <form method="GET" action="<? echo $ZONEEDIT ?>" target="main" enctype="multipart/form-data">
98 <input type="hidden" name="call" value="search"><input type="hidden" name="selet" value="<? echo $selet ?>">
99 &nbsp;Find&nbsp;<input type="text" name="zonename" size="20" maxlength="64">
100 &nbsp;<input type="submit" name="Go" value="Go">
101 </form>
102 <a href="<? echo "$ZONEEDIT?call=newzone&selet=$selet" ?>" TARGET="main">
103 <img src="icons/zone_new.gif" width="16" height="16" align="texttop" border="0">&nbsp;&nbsp;Add new Zone</a><br>
104 <?
105 foreach ($letters as $let) {
106 $tree1 = ($let==$letters[count($letters)-1] ? "end" : "cont");
107 if (ereg("(.*)[$let]-[$let](.*)", $selet, $regs)
108 || ereg("(.*)[$let](.*)", $selet, $regs)) {
109 $newselet = $regs[1].$regs[2];
110 ereg_replace("[$let]+", "", $newselet);
111 print "<a href='$ZONEEDIT?call=dnslist&selet=$newselet'>".
112 "<img src='icons/minus-$tree1.gif' width='19' height='16' align='texttop' border='0'>".
113 "<img src='icons/folder-open.gif' width='16' height='16' align='texttop' border='0'>...$let</a><br>\n";
114 } else {
115 $newselet = $selet.$let;
116 print "<a href='$ZONEEDIT?call=dnslist&selet=$newselet'>".
117 "<img src='icons/plus-$tree1.gif' width='19' height='16' align='texttop' border='0'>".
118 "<img src='icons/folder-closed.gif' width='16' height='16' align='texttop' border='0'>...$let</a><br>\n";
119 continue;
120 }
121 $filter = "(&(objectclass=dnszone)";
122 if (ereg("([0-9A-Z])-([0-9A-Z])", $let, $regs)) {
123 $filter .= "(|";
124 for ($i = ord($regs[1]); $i<=ord($regs[2]); $i++) {
125 $filter .= "(cn=".chr($i)."*)";
126 }
127 $filter .= "))";
128 } else {
129 $filter .= "(cn=$let*))";
130 }
131 $query = ldap_search($ldap, $BASEDN, $filter);
132 //ldap_sort($ldap, $query, "cn");
133 $entries = ldap_get_entries($ldap, $query);
134 ldap_free_result($query);
135 for ($i = 0; $i<$entries[count]; $i++) {
136 $zonedn = $entries[$i]["dn"];
137 $zonename = $entries[$i]["dnszonename"][0];
138 $tree2 = ($i==$entries[count]-1 ? "end" : "cont");
139 print "<a href='$ZONEEDIT?call=editzone&zonedn=$zonedn&selet=$selet' TARGET='main'>".
140 "<img src='".($tree1=="cont" ? "icons/img-vert-line.gif" : "icons/img-blank.gif" )."'".
141 " width='19' height='16' align='texttop' border='0'>".
142 "<img src='icons/branch-$tree2.gif' width='19' height='16' align='texttop' border='0'><img src='";
143 if (ereg("[d]", $selet)) {
144 $auth = authorized($zonename);
145 if ($auth==1) {
146 print "icons/zone_val.gif";
147 } elseif ($auth==-1) {
148 print "icons/zone_forb.gif";
149 } else {
150 print "icons/zone_unre.gif";
151 }
152 } else {
153 print "icons/zone_unkn.gif";
154 }
155 print "' width='16' height='16' align='texttop' border='0'>&nbsp;$zonename</a><br>\n";
156 }
157 print "\n";
158 }
159 #print "<tr align=center><th><a href='$ZONEEDIT?call=dnslist'";
160 if (ereg("[d]", $selet)) {
161 ereg_replace("[d]", "", $selet);
162 print "<a href='$ZONEEDIT?call=dnslist&selet=$selet' TARGET='menu'>Without DNS-lookup</a><br>\n";
163 } else {
164 print "<a href='$ZONEEDIT?call=dnslist&selet=$selet"."d' TARGET='menu'>With DNS-lookup</a><br>\n";
165 }
166 }
167
168 function individual_dns_list()
169 {
170 global $ldap, $binddn, $BASEDN, $ZONEEDIT, $HTTP_GET_VARS;
171 $query = ldap_search($ldap, $BASEDN, "(&(objectclass=DNSzone)(owner=$binddn))");
172 $entries = ldap_get_entries($ldap, $query);
173 for ($i = 0; $i<$entries[count]; $i++) {
174 $zonedn = $entries[$i][dn];
175 $zonename = $entries[$i][dnszonename][0];
176 $tree = ($i==$entries[count]-1 ? "end" : "cont");
177 print "<a href='$ZONEEDIT?call=editzone&zonedn=$zonedn' TARGET='main'>".
178 "<img src='icons/branch-$tree.gif' width='19' height='16' align='texttop' border='0'>".
179 "<img src='icons/zone_unkn.gif' width='16' height='16' align='texttop' border='0'>&nbsp;$zonename</a><br>\n";
180 }
181 }
182
183 function search_zone($zonename)
184 {
185 global $ldap, $BASEDN;
186 $filter = "(&(objectclass=dnszone)(dnszonename=$zonename))";
187 $query = ldap_search($ldap, $BASEDN, $filter);
188 $entries = ldap_get_entries($ldap, $query);
189 if ($entries[count]>1) {
190 $mesg = "Ambigous zonenames $zonename in<br>";
191 for ($i = 0; $i<$entries[count]; $i++) {
192 $mesg .= "dn: <a href='$ZONEEDIT?call=editzone&zonedn=".$entries[$i]["dn"]."' target='main'>".
193 $entries[$i]["dn"]."</a><br>";
194 }
195 print "<br><h3 align='center'><font color='orange'>Warning: $mesg</font></h3>";
196 exit;
197 }
198 if ($entries[count]==1) {
199 return $entries[0][dn];
200 } else switch (authorized($zonename)) {
201 case -2:
202 error_confirm("The zone does not belong to a valid top level domain");
203 exit;
204 case -1:
205 error_confirm("The zone is owned by someone else");
206 print_whois($zonename);
207 exit;
208 default:
209 return;
210 }
211 }
212
213 function print_zone_soa($zonedata, $constr)
214 {
215 print "<tr><td align='right'>Serial: </td>";
216 if (ereg("[amo]", $constr)) {
217 print "<td><input type='text' name='dnsserial' size='16' maxlength='24' value='$zonedata[dnsserial]'></td>";
218 } else {
219 print "<td><b> ".$zonedata["dnsserial"]." </b></td>";
220 }
221 print "<td align='right'>Refresh: </td><td>";
222 if (ereg("[amo]", $constr)) {
223 print "<input type='text' name='dnsrefresh' size='16' maxlength='24' value='$zonedata[dnsrefresh]'>";
224 } else {
225 print " <b> ".$zonedata["dnsrefresh"]." </b>";
226 }
227 print "</td></tr>\n<tr><td align='right'>Retry: </td><td>";
228 if (ereg("[amo]", $constr)) {
229 print "<input type='text' name='dnsretry' size='16' maxlength='24' value='$zonedata[dnsretry]'>";
230 } else {
231 print " <b> ".$zonedata["dnsretry"]." </b>";
232 }
233 print "</td>\n<td align='right'>Expire: </td><td>";
234 if (ereg("[amo]", $constr)) {
235 print "<input type='text' name='dnsexpire' size='16' maxlength='24' value='$zonedata[dnsexpire]'>";
236 } else {
237 print " <b> ".$zonedata["dnsexpire"]." </b>";
238 }
239 print "</td></tr>\n<tr><td align='right'>Minimum: </td><td>";
240 if (ereg("[amo]", $constr)) {
241 print "<input type='text' name='dnsminimum' size='16' maxlength='24' value='$zonedata[dnsminimum]'>";
242 } else {
243 print " <b> ".$zonedata["dnsminimum"]." </b>";
244 }
245 print "</td>\n<td align='right'>Adminmailbox: </td><td>";
246 if (ereg("[amo]", $constr)) {
247 print "<input type='text' name='dnsadminmailbox' size='16' maxlength='24' value='$zonedata[dnsadminmailbox]'>";
248 } else {
249 print " <b> ".$zonedata["dnsadminmailbox"]." </b>";
250 }
251 print "</td></tr>\n<tr><td align='right'>Zonemaster: </td><td>";
252 if (ereg("[amo]", $constr)) {
253 print "<input type='text' name='dnszonemaster' size='16' maxlength='24' value='$zonedata[dnszonemaster]'>";
254 } else {
255 print " <b> ".$zonedata["dnszonemaster"]." </b>";
256 }
257 print "</td>\n<td align='right'>Time to live: </td><td>";
258 if (ereg("[amo]", $constr)) {
259 print "<input type='text' name='dnsttl' size='16' maxlength='24' value='$zonedata[dnsttl]'>";
260 } else {
261 print " <b> ".$zonedata["dnsttl"]." </b>";
262 }
263 print "</td></tr>\n";
264 }
265
266 function get_zone_name($zonedn)
267 {
268 global $ldap;
269 $query = ldap_read($ldap, $zonedn, "(objectclass=dnszone)", array("dnszonename"));
270 $entries = ldap_get_entries($ldap, $query);
271 $zonename = $entries[0][dnszonename][0];
272 ldap_free_result($query);
273 return $zonename;
274 }
275
276 function modify_zone_soa($zonedn)
277 {
278 global $ldap, $ZONE_INFO, $HTTP_POST_VARS;
279 $zonename = get_zone_name($zonedn);
280 $entry = array();
281 foreach ($ZONE_INFO as $za) {
282 if (strlen($HTTP_POST_VARS["$za"])>0)
283 $entry["$za"] = $HTTP_POST_VARS["$za"];
284 }
285 if (ereg("[a]", check_constraint($zonedn))) {
286 $entry[dnszonename] = array("$zonename");
287 for ($i = 0; isset($HTTP_POST_VARS["dnszonename$i"]); $i++) {
288 if (strlen($HTTP_POST_VARS["dnszonename$i"])>3)
289 array_push($entry[dnszonename], $HTTP_POST_VARS["dnszonename$i"]);
290 }
291 }
292 ldap_modify($ldap, $zonedn, $entry) or die("ldap_modify failed to update SOA for $zonedn");
293 }
294
295 function authorized($zonename)
296 {
297 return 1;
298 }
299
300 function zone_edit_plus($zonedn)
301 {
302 $zonename = get_zone_name($zonedn);
303 $auth = authorized($zonename);
304 if ($auth==1) {
305 print "<center><br><h3><font color='green'>The nameserver is active and authorized to handle this zone</font></h3>\n";
306 edit_zone_attrs($zonedn);
307 print_whois($zonename);
308 } elseif ($auth==0) {
309 print "<center><br><h3><font color='orange'>The nameserver is not active for this zone</font></h3>\n";
310 edit_zone_attrs($zonedn);
311 print_whois($zonename);
312 } elseif ($auth==-1) {
313 print "<center><br><h3><font color='red'>The nameserver is not authorized to handle this zone</font></h3>\n";
314 edit_zone_attrs($zonedn);
315 print_whois($zonename);
316 } else {
317 print "<br><H2 align='center'><font color='red'>Zone <I>$zonename</I> does not not belong to a valid TLD</font></H2>\n";
318 delete_zone();
319 }
320 }
321
322 function edit_zone_attrs($zonedn)
323 {
324 global $ldap, $ZONE_INFO, $ZONEEDIT, $HTTP_GET_VARS, $HTTP_POST_VARS;
325 if (isset($HTTP_GET_VARS[selet])) $selet = $HTTP_GET_VARS[selet]; elseif (isset($HTTP_POST_VARS[selet])) $selet = $HTTP_POST_VARS[selet];
326 $query = ldap_read($ldap, $zonedn, "(objectclass=dnszone)");
327 $entries = ldap_get_entries($ldap, $query);
328 $zonename = $entries[0][dnszonename][0];
329 ldap_free_result($query);
330 $zonedn = $entries[0][dn];
331 $zonename0 = $entries[0][dnszonename][0];
332 $zonenames = array();
333 for ($i = 1; $i<$entries[0][dnszonename][count]; $i++) {
334 array_push($zonenames, $entries[0][dnszonename][$i]);
335 }
336 $zonedata = array();
337 foreach ($ZONE_INFO as $za) {
338 $zonedata[$za] = $entries[0][$za][0];
339 }
340
341 print "<center><h2>Edit DNS zone <I>$zonename0</I></h2>";
342 $zoneconstr = check_constraint($zonedn);
343 if (ereg("[a]", $zoneconstr)) {
344 # Print modifiable table for SOA
345 if (ereg("[f]", $selet)) {
346 print "<form method='POST' action='$ZONEEDIT' target='main' enctype='multipart/form-data'>".
347 "<input type='hidden' name='call' value='editzone'>".
348 "<input type='hidden' name='zonedn' value='$zonedn'>";
349 } else {
350 print "<form method='POST' action='$ZONEEDIT' enctype='multipart/form-data'>".
351 "<input type='hidden' name='call' value='editzone'>".
352 "<input type='hidden' name='zonedn' value='$zonedn'>".
353 "<input type='hidden' name='selet' value='$selet'>";
354 }
355 print "<table border='1' width='85%' COLS='4' CELLSPACING='1' CELLPADDING='0'>\n";
356 $zc = 0;
357 foreach ($zonenames as $zn) {
358 print "<tr><td align='right' colspan='2'> Aliasing Zonename: </td><td colspan='2'>";
359 if (ereg("[a]", $zoneconstr))
360 print "<input type='text' name='dnszonename$zc' value='$zn' size='40' maxlength='64'>";
361 else
362 print "<b>$zn</b>";
363 print "</td></tr>\n";
364 $zc++;
365 }
366 if (ereg("[a]", $zoneconstr)) {
367 print "<tr><td align='right' colspan='2'> Add aliasing Zonename: </td><td colspan='2'>".
368 "<input type='text' name='dnszonename$zc' size='40' maxlength='64'></td></tr>\n";
369 }
370 print_zone_soa($zonedata, $zoneconstr);
371 print "<tr><td colspan='4' align='center'><input type='submit' name='modifysoa' value=' Modify SOA for zone: \"$zonename0\" '>".
372 "</td></tr></table><P></form>";
373 } else {
374 # Print non-modifiable table for SOA
375 print "<table border='1' width='85%' COLS='4' CELLSPACING='1' CELLPADDING='0'>\n";
376 foreach ($zonenames as $zn) {
377 print "<tr><td align='right' colspan='2'> Aliasing Zonename: </td><td colspan='2'> <b>$zn</b></td></tr>\n";
378 }
379 print_zone_soa($zonedata, $zoneconstr);
380 print "</table><P>\n";
381 }
382
383 # Tables for RRsets
384 $query = ldap_list($ldap, $zonedn, "(objectclass=dnsrrset)");
385 $rrsets = ldap_get_entries($ldap, $query);
386 ldap_free_result($query);
387 print "<table border='1' width='98%' COLS='5' CELLSPACING='1' CELLPADDING='0'>\n".
388 "<tr><th width='1%'>DNS Name</th><th width='1%'>Type</th><th width='250'>Mapping</th>".
389 "<th width='1%'>TTL/Pref</th><th width='1%'>&nbsp;</th></tr>\n";
390 for ($i = 0; $i<$rrsets[count]; $i++) {
391 $setdn = $rrsets[$i][dn];
392 $setconstr = $zoneconstr.check_constraint($setdn);
393 $domainname = $rrsets[$i][dnsdomainname][0];
394 $ipaddr = $rrsets[$i][dnsipaddr];
395 $cipaddr = $rrsets[$i][dnscipaddr][0];
396 $cname = $rrsets[$i][dnscname][0];
397 $type = $rrsets[$i][dnstype][0];
398 $ttl = $rrsets[$i][dnsttl][0];
399 $preference = $rrsets[$i][dnspreference][0];
400 if (ereg("[amo]", $setconstr)) {
401 if (ereg("[f]", $selet)) {
402 print "<form method='POST' action='$ZONEEDIT' target='main' enctype='multipart/form-data'>".
403 "<input type='hidden' name='call' value='editzone'>".
404 "<input type='hidden' name='selet' value='$selet'>".
405 "<input type='hidden' name='zonedn' value='$zonedn'>".
406 "<input type='hidden' name='setdn' value='$setdn'>";
407 } else {
408 print "<form method='POST' action='$ZONEEDIT' enctype='multipart/form-data'>".
409 "<input type='hidden' name='call' value='editzone'>".
410 "<input type='hidden' name='zonedn' value='$zonedn'>".
411 "<input type='hidden' name='setdn' value='$setdn'>";
412 }
413 }
414 if (ereg("[amo]", $setconstr)) {
415 print "<br><input type='checkbox' name='deleterrset' value=' Delete '>Delete";
416 }
417 print "</td><td><b>$type</b></td><td><table border='0'>";
418 if ($type=="CNAME" || $type=="MX" || $type=="NS") {
419 print "<tr><td align='right'>CName:</td>";
420 if (ereg("[amo]", $setconstr))
421 print "<td><input type='text' name='dnscname' value='$cname' size='20' maxlength='64'></td></tr>\n";
422 else
423 print "<td><b>$cname</b></td></tr>\n";
424 }
425 if ($type=="A" || $type=="MX" || $type=="NS") {
426 if (ereg("[a]", $setconstr)) {
427 print "<tr><td align='right'>Canonical IP:</td>".
428 "<td><input type='text' name='dnscipaddr' value='$cipaddr' size='20' maxlength='15'></td></tr>\n";
429 } else if (isset($cipaddr)) {
430 print "<tr><td align='right'>Canonical IP:</td><td><b>$cipaddr</b></td></tr>\n";
431 }
432 for ($k = 0; $k<$rrsets[$i][dnsipaddr][count]; $k++) {
433 print "<tr><td align='right'>Modify IP:</td>";
434 $ipaddr = $rrsets[$i][dnsipaddr][$k];
435 if (ereg("[amo]", $setconstr))
436 print "<td><input type='text' name='dnsipaddr$k' value='$ipaddr' size='20' maxlength='15'></td></tr>\n";
437 else
438 print "<td><b>$ipaddr</b></td></tr>\n";
439 }
440 if (ereg("[amo]", $setconstr)) {
441 print "<tr><td align='right'>Add IP: </td><td><input type='text' name='dnsipaddr$k' value='' size='20' maxlength='15'></td></tr>\n";
442 }
443 }
444 print "</table></td>";
445 if (ereg("[amo]", $setconstr)) {
446 print "</td><td>TTL: <input type='text' name='dnsttl' value='$ttl' size='6' maxlength='6'>";
447 if ($type=="MX")
448 print "<br>Pref: <input type='text' name='dnspreference' value='$preference' size='6' maxlength='6'>";
449 print "</td><td><input type='submit' name='modifyrrset' value=' Modify '></td></tr></form>\n";
450 } else {
451 print "</td><td>TTL: <b>$ttl</b>";
452 if ($type=="MX")
453 print "<br>Pref: <b>$preference</b>";
454 print "</td></tr>\n";
455 }
456 }
457 if (ereg("[amo]", $setconstr)) {
458 if (ereg("[f]", $selet)) {
459 print "\n<form method='POST' action='$ZONEEDIT' target='main' enctype='multipart/form-data'>".
460 "<input type='hidden' name='call' value='editzone'>".
461 "<input type='hidden' name='selet' value='$selet'>".
462 "<input type='hidden' name='zonedn' value='$zonedn'";
463 } else {
464 print "\n<form method='POST' action='$ZONEEDIT' enctype='multipart/form-data'>".
465 "<input type='hidden' name='call' value='editzone'>".
466 "<input type='hidden' name='zonedn' value='$zonedn'";
467 }
468 print "<tr><td align='center'><input type='text' name='dnsdomainname' size='12' maxlength='32' override='1'></td>".
469 "<td align='center'><select name='dnstype'><option value='CNAME'>CNAME</option><option value='A'>A</option>".
470 "<option value='MX'>MX</option><option value='NS'>NS</option><option value='PTR'>PTR</option>".
471 "<option value='TXT'>TXT</option></select></td>".
472 "<td>&nbsp;</td><td colspan='2' align='center'><input type='submit' name='addrrset' value=' Add new record '></td></tr>".
473 "</form>";
474 }
475 print "</table><P>\n";
476
477 print "<table border='1' COLS='2' width='66%'><tr>";
478 // 'Delete' form
479 $onclick = "if(confirm('Do you really want to remove zone: $zonename0 and all its resource records?'))";
480 if (ereg("[f]", $selet)) {
481 $onclick .= "{ parent.frames.menu.location='$ZONEEDIT?call=dnslist&selet=$selet&wait=1';".
482 "parent.frames.main.location='$ZONEEDIT?call=removezone&zonedn=$zonedn&selet=$selet'; }";
483 } else {
484 $onclick .= "{ parent.window.location='$ZONEEDIT?call=removezone&zonedn=$zonedn'; }";
485 }
486 if (ereg("[am]", $setconstr)) {
487 print "<form><td align='center'><INPUT TYPE='BUTTON' VALUE=' Delete Zone \"$zonename0\" ' ONCLICK=\"$onclick\"></td></form>\n";
488 }
489
490 // form for reset/refresh button
491 if (ereg("[f]", $selet)) {
492 print "<form method='POST' action='$ZONEEDIT' target='main' enctype='multipart/form-data'>".
493 "<input type='hidden' name='call' value='editzone'>".
494 "<input type='hidden' name='zonedn' value='$zonedn'>".
495 "<input type='hidden' name='selet' value='$selet'>";
496 } else {
497 print "<form method='POST' action='$ZONEEDIT' enctype='multipart/form-data'>".
498 "<input type='hidden' name='call' value='editzone'>".
499 "<input type='hidden' name='zonedn' value='$zonedn'>";
500 }
501 print "<td align='center'><input type='submit' name='resetform' value=' Reset and Refresh '></td></form>".
502 "</tr></table>\n";
503 }
504
505 function new_zone($new_zonename = "")
506 {
507 global $HTTP_GET_VARS, $ZONE_SOA, $ZONEEDIT, $BASEDN;
508 if (isset($HTTP_GET_VARS[selet])) $selet = $HTTP_GET_VARS[selet];
509 $zonedata = $ZONE_SOA;
510 $zonedata[dnsserial] = new_serial();
511 $onsubmit = "{ parent.frames.menu.location='$ZONEEDIT?call=dnslist&selet=$selet&wait=1'; }";
512 print "<center><h2>Add new DNS zone</h2>";
513 print "<form action='$ZONEEDIT' method='POST' target='main' enctype='multipart/form-data' onsubmit=\"$onsubmit\">".
514 "<input type='hidden' name='call' value='addzone'>".
515 "<input type='hidden' name='selet value='$selet'>".
516 "<table border='1' width='85%' COLS='4'>\n".
517 "<tr><td align='right' colspan='2'> New Zonename: </td><td colspan='2'>".
518 "<input type='text' name='dnszonename' size='40' maxlength='64' value='".(strlen($new_zonename)>3 ? $new_zonename : "")."'>".
519 "</td></tr>\n";
520 print_zone_soa($zonedata, check_constraint());
521 print "</td></tr><tr><td colspan='2' align='center'>".
522 "<input type='submit'>".
523 "</td><td colspan='2' align='center'>".
524 "<input type='reset'>".
525 "</td></tr></table>\n".
526 "</form>";
527 }
528
529 function add_zone()
530 {
531 global $ldap, $HTTP_POST_VARS, $BASEDN, $ZONE_SOA, $ZONE_ENTRY, $ZONE_INFO;
532 $zonedata = array();
533 foreach ($ZONE_INFO as $za) {
534 if (strlen($HTTP_POST_VARS[$za])>0) {
535 $zonedata[$za] = $HTTP_POST_VARS[$za];
536 }
537 }
538 $zonedata["cn"] = $zonedata["dnszonename"];
539 $zonedata["objectclass"] = "dnszone";
540 $zonedn = "cn=$zonedata[cn],$BASEDN";
541 ldap_add($ldap, $zonedn, $zonedata) or die("Failed to add zonedn: $zonedn");
542
543 foreach ($ZONE_ENTRY as $ze) {
544 $dnch = "cn=$ze[cn],$zonedn";
545 ldap_add($ldap, $dnch, $ze) or die("Failed to add rrset dn: $dnch");
546 }
547 return $zonedn;
548 }
549
550 function remove_zone($zonedn)
551 {
552 global $ldap;
553 $query = ldap_list($ldap, $zonedn, "(objectclass=DNSrrset)");
554 $entries = ldap_get_entries($ldap, $query);
555 ldap_free_result($query);
556 for ($i = 0; $i<$entries[count]; $i++) {
557 ldap_delete($ldap, $entries[$i][dn]) or die("Failed to delete dn: $entries[$i][dn]");
558 }
559 ldap_delete($ldap, $zonedn) or die("Failed to delete dn: $zonedn");
560 return 1;
561 }
562
563 function new_serial($zonedn = 0)
564 {
565 global $ldap;
566 $newserial = date("Ymd")."00";
567 if ($zonedn) {
568 $query = ldap_read($ldap, $zonedn, "(objectclass=DNSzone)");
569 $entries = ldap_get_entries($ldap, $query);
570 $oldserial = $entries[0][dnsserial][0];
571 }
572 return ($newserial>$oldserial) ? $newserial : $oldserial+1;
573 }
574
575 function add_rrset($zonedn)
576 {
577 global $ldap, $binddn, $HTTP_POST_VARS, $DEFAULT_TTL, $DEFAULT_PREFERENCE;
578 if (!isset($HTTP_POST_VARS[dnsdomainname])) die("No domainname specified");
579 if (strlen($HTTP_POST_VARS[dnsdomainname])>0)
580 $entry[dnsdomainname] = $HTTP_POST_VARS[dnsdomainname];
581 if (!isset($HTTP_POST_VARS[dnstype])) die("No type specified");
582 $entry[dnstype] = $HTTP_POST_VARS[dnstype];
583 $entry[dnsclass] = "IN"; // INternet is hardcoded
584 $entry[dnsttl] = $DEFAULT_TTL;
585 // $entry[owner] = $binddn;
586 if ($entry[dnstype]=="MX" || $entry[dnstype]=="NS") {
587 for ($i = 1;; $i++) {
588 $setcn = "$entry[dnstype]$i:$entry[dnsdomainname]";
589 $query = ldap_list($ldap, $zonedn, "(&(objectclass=dnsrrset)(cn=$setcn))");
590 $rrset = ldap_get_entries($ldap, $query);
591 ldap_free_result($query);
592 if ($rrset[count]==0)
593 break;
594 }
595 if ($entry[dnstype]=="MX")
596 $entry[dnspreference] = $DEFAULT_PREFERENCE;
597 } else {
598 $setcn = "$entry[dnstype]:$entry[dnsdomainname]";
599 $query = ldap_list($ldap, $zonedn, "(&(objectclass=dnsrrset)(cn=$setcn))");
600 $rrset = ldap_get_entries($ldap, $query);
601 ldap_free_result($query);
602 if ($rrset[count]>0) {
603 error_confirm("$entry[dnsdomainname] has already been added to this zone");
604 return;
605 }
606 }
607 $entry[objectclass] = "dnsrrset";
608 $entry[cn] = $setcn;
609 $setdn = "cn=$setcn,$zonedn";
610 ldap_add($ldap, $setdn, $entry) or die("Faild to add DNSrrset $setdn to DNSzone $zonedn");
611 }
612
613 function modify_rrset($zonedn, $setdn)
614 {
615 global $ldap, $HTTP_POST_VARS;
616 $zonename = get_zone_name($zonedn);
617 $entry = array();
618 if (isset($HTTP_POST_VARS[dnscname])) {
619 if ($HTTP_POST_VARS[dnscname]=="") {
620 $entry[dnscname] = array();
621 } elseif (ereg("\.$", $HTTP_POST_VARS[dnscname])) {
622 if (checkdnsrr($HTTP_POST_VARS[dnscname], "A")) {
623 $entry[dnscname] = $HTTP_POST_VARS[dnscname];
624 } else {
625 error_confirm("Error: $HTTP_POST_VARS[dnscname] does not resolve to a valid IP-address");
626 return;
627 }
628 } elseif (isset($HTTP_POST_VARS[dnsipaddr0]) || isset($HTTP_POST_VARS[dnscipaddr])) {
629 // records with their own address settings are not checked against DNS
630 $entry[dnscname] = $HTTP_POST_VARS[dnscname];
631 } else {
632 if (!checkdnsrr("$HTTP_POST_VARS[dnscname].$zonename", "A")) {
633 print "<br><h2 align='center'><font color='orange'>Warning: $HTTP_POST_VARS[dnscname].$zonename".
634 " does not resolve to a valid IP-address</font></h2>\n";
635 }
636 $entry[dnscname] = $HTTP_POST_VARS[dnscname];
637 }
638 }
639 if (isset($HTTP_POST_VARS[dnscipaddr])) {
640 if (ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $HTTP_POST_VARS[dnscipaddr], $reg)) {
641 $regip = "$reg[1].$reg[2].$reg[3].$reg[4]";
642 if (check_unique_cipaddr($setdn, $regip))
643 $entry[dnscipaddr] = $regip;
644 else
645 return;
646 } elseif ($HTTP_POST_VARS[dnscipaddr]=="") {
647 $entry[dnscipaddr] = array();
648 } else {
649 error_confirm("$HTTP_POST_VARS[dnscipaddr] is not a valid IP-address");
650 return;
651 }
652 }
653 if (isset($HTTP_POST_VARS[dnsttl])) {
654 if (ereg("([0-9]+)", $HTTP_POST_VARS[dnsttl], $reg)) {
655 $entry[dnsttl] = $reg[1];
656 } else {
657 error_confirm("$HTTP_POST_VARS[dnsttl] is not a valid Time To Live");
658 return;
659 }
660 }
661 if (isset($HTTP_POST_VARS[dnspreference])) {
662 if (ereg("([0-9]+)", $HTTP_POST_VARS[dnspreference], $reg)) {
663 $entry[dnspreference] = $reg[1];
664 } else {
665 error_confirm("$HTTP_POST_VARS[dnspreference] is not a valid MX-prefrence");
666 return;
667 }
668 }
669 $entry[dnsipaddr] = array();
670 for ($i = 0; isset($HTTP_POST_VARS["dnsipaddr$i"]); $i++) {
671 $ipaddr = $HTTP_POST_VARS["dnsipaddr$i"];
672 if (ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $ipaddr, $reg)) {
673 array_push($entry[dnsipaddr], "$reg[1].$reg[2].$reg[3].$reg[4]");
674 } elseif ($ipaddr!="") {
675 error_confirm("$ipaddr is not a valid IP-address");
676 return;
677 }
678 }
679 ldap_modify($ldap, $setdn, $entry) or die("Faild to modify DNSrrest $setdn in DNSzone $zonedn");
680 ldap_mod_replace($ldap, $zonedn, array("dnsserial"=>new_serial($zonedn)));
681 }
682
683 function delete_rrset($zonedn, $setdn)
684 {
685 global $ldap;
686 ldap_delete($ldap, $setdn) or die("Failed to delete $setdn from LDAP");;
687 ldap_mod_replace($ldap, $zonedn, array("dnsserial"=>new_serial($zonedn)));
688 }
689
690 function check_unique_cipaddr($setdn, $cipaddr)
691 {
692 global $ldap, $BASEDN;
693 $query = ldap_search($ldap, $BASEDN, "(&(objectclass=dnsrrset)(dnscipaddr=$cipaddr))");
694 $entries = ldap_get_entries($ldap, $query);
695 ldap_free_result($query);
696 for ($i = 0; $i<$entries[count]; $i++) {
697 $dn = $entries[$i][dn];
698 if ($dn!=$setdn) {
699 error_confirm("Canonical IP-address $cipaddr is already used by $dn");
700 return 0;
701 }
702 }
703 return 1;
704 }
705
706 function print_whois($zonename)
707 {
708 global $WHOISSERVERS;
709 return; // weil unser FW-Gschaftler den Port 43 von innen nach aussen zugedreht hat
710
711 if (ereg("\.([a-zA-Z]+)$", $zonename, $regex)) {
712 $whoissrv = $WHOISSERVERS["$regex[1]"];
713 if (isset($whoissrv)) {
714 $whoisrecord = system("whois -h $whoissrv $zonename");
715 print "<h3 align='center'>Whois-record for zone <I>$zonename</I></h3><P>\n".
716 "as serverd by $whoissrv<br>\n".
717 "<table border='1' width='85%' CELLSPACING='1' CELLPADDING='0'><tr align='LEFT'>".
718 "<td><PRE>$whoisrecord</PRE></td></tr></table>\n";
719 } else {
720 print "<h3 align=center><font color=red>No WHOIS-Server found for \"$regex[1]\"</font></h3>\n";
721 }
722 }
723 }
724
725 ?>