1
|
1 |
<? |
|
2 |
|
|
3 |
// +--------------------------------------------------------------------+ |
|
4 |
// | PowerAdmin | |
|
5 |
// +--------------------------------------------------------------------+ |
|
6 |
// | Copyright (c) 1997-2002 The PowerAdmin Team | |
|
7 |
// +--------------------------------------------------------------------+ |
|
8 |
// | This source file is subject to the license carried by the overal | |
|
9 |
// | program PowerAdmin as found on http://poweradmin.sf.net | |
|
10 |
// | The PowerAdmin program falls under the QPL License: | |
|
11 |
// | http://www.trolltech.com/developer/licensing/qpl.html | |
|
12 |
// +--------------------------------------------------------------------+ |
|
13 |
// | Authors: Roeland Nieuwenhuis <trancer <AT> trancer <DOT> nl> | |
|
14 |
// | Sjeemz <sjeemz <AT> sjeemz <DOT> nl> | |
|
15 |
// +--------------------------------------------------------------------+ |
|
16 |
|
|
17 |
// Filename: record.inc.php |
|
18 |
// Startdate: 26-10-2002 |
|
19 |
// This file is ought to edit the records in the database. |
|
20 |
// Records are domains aswell, they also belong here. |
|
21 |
// All database functions are associative. |
|
22 |
// use nextID first to get a new id. Then insert it into the database. |
|
23 |
// do not rely on auto_increment (see above). |
|
24 |
// use dns.inc.php for validation functions. |
|
25 |
// |
|
26 |
// $Id: record.inc.php,v 1.21 2003/05/10 20:21:01 azurazu Exp $ |
|
27 |
// |
|
28 |
|
|
29 |
|
|
30 |
function update_soa_serial($domain_id) |
|
31 |
{ |
|
32 |
global $db; |
|
33 |
/* |
|
34 |
* THIS CODE ISNT TESTED THROUGH MUCH YET! |
|
35 |
* !!!!!!! BETACODE !!!!!!!!!! |
|
36 |
* Code committed by DeViCeD, Thanks a lot! |
|
37 |
* Heavily hax0red by Trancer/azurazu |
|
38 |
* |
|
39 |
* First we have to check, wheather current searial number |
|
40 |
* was already updated on the other nameservers. |
|
41 |
* If field 'notified_serial' is NULL, then I guess domain is |
|
42 |
* NATIVE and we don't have any secondary nameservers for this domain. |
|
43 |
* NOTICE: Serial number *will* be RFC1912 compilant after update |
|
44 |
* NOTICE: This function will allow only 100 DNS zone transfers ;-) |
|
45 |
* YYYYMMDDnn |
|
46 |
*/ |
|
47 |
|
|
48 |
$sqlq = "SELECT `notified_serial` FROM `domains` WHERE `id` = '".$domain_id."'"; |
8
|
49 |
$notified_serial = $db->queryOne($sqlq); |
1
|
50 |
|
|
51 |
$sqlq = "SELECT `content` FROM `records` WHERE `type` = 'SOA' AND `domain_id` = '".$domain_id."'"; |
8
|
52 |
$content = $db->queryOne($sqlq); |
1
|
53 |
$need_to_update = false; |
|
54 |
|
|
55 |
// Getting the serial field. |
|
56 |
$soa = explode(" ", $content); |
|
57 |
|
|
58 |
if(empty($notified_serial)) |
|
59 |
{ |
|
60 |
// Ok native replication, so we have to update. |
|
61 |
$need_to_update = true; |
|
62 |
} |
|
63 |
elseif($notified_serial >= $soa[2]) |
|
64 |
{ |
|
65 |
$need_to_update = true; |
|
66 |
} |
|
67 |
elseif(strlen($soa[2]) != 10) |
|
68 |
{ |
|
69 |
$need_to_update = true; |
|
70 |
} |
|
71 |
else |
|
72 |
{ |
|
73 |
$need_to_update = false; |
|
74 |
} |
|
75 |
if($need_to_update) |
|
76 |
{ |
|
77 |
// Ok so we have to update it seems. |
|
78 |
$current_serial = $soa[2]; |
|
79 |
|
|
80 |
/* |
|
81 |
* What we need here (for RFC1912) is YEAR, MONTH and DAY |
|
82 |
* so let's get it ... |
|
83 |
*/ |
|
84 |
$new_serial = date('Ymd'); // we will add revision number later |
|
85 |
|
|
86 |
if(strncmp($new_serial, $current_serial, 8) === 0) |
|
87 |
{ |
|
88 |
/* |
|
89 |
* Ok, so we already made updates tonight |
|
90 |
* let's just increase the revision number |
|
91 |
*/ |
|
92 |
$revision_number = (int) substr($current_serial, -2); |
|
93 |
if ($revision_number == 99) return false; // ok, we cannot update anymore tonight |
|
94 |
++$revision_number; |
|
95 |
// here it is ... same date, new revision |
|
96 |
$new_serial .= str_pad($revision_number, 2, "0", STR_PAD_LEFT); |
|
97 |
} |
|
98 |
else |
|
99 |
{ |
|
100 |
/* |
|
101 |
* Current serial is not RFC1912 compilant, so let's make a new one |
|
102 |
*/ |
|
103 |
$new_serial .= '00'; |
|
104 |
} |
|
105 |
$soa[2] = $new_serial; // change serial in SOA array |
|
106 |
$new_soa = ""; |
|
107 |
// build new soa and update SQL after that |
|
108 |
for ($i = 0; $i < count($soa); $i++) |
|
109 |
{ |
|
110 |
$new_soa .= $soa[$i] . " "; |
|
111 |
} |
|
112 |
$sqlq = "UPDATE `records` SET `content` = '".$new_soa."' WHERE `domain_id` = '".$domain_id."' AND `type` = 'SOA' LIMIT 1"; |
|
113 |
$db->Query($sqlq); |
|
114 |
return true; |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/* |
|
119 |
* Edit a record. |
|
120 |
* This function validates it if correct it inserts it into the database. |
|
121 |
* return values: true if succesful. |
|
122 |
*/ |
|
123 |
function edit_record($recordid, $zoneid, $name, $type, $content, $ttl, $prio) |
|
124 |
{ |
|
125 |
global $db; |
|
126 |
if($content == "") |
|
127 |
{ |
|
128 |
error(ERR_RECORD_EMPTY_CONTENT); |
|
129 |
} |
|
130 |
// Edits the given record (validates specific stuff first) |
|
131 |
if (!xs(recid_to_domid($recordid))) |
|
132 |
{ |
|
133 |
error(ERR_RECORD_ACCESS_DENIED); |
|
134 |
} |
|
135 |
if (is_numeric($zoneid)) |
|
136 |
{ |
|
137 |
validate_input($recordid, $zoneid, $type, $content, $name, $prio, $ttl); |
|
138 |
$change = time(); |
|
139 |
$db->query("UPDATE records set name='$name', type='$type', content='$content', ttl='$ttl', prio='$prio', change_date='$change' WHERE id=$recordid"); |
|
140 |
|
|
141 |
/* |
|
142 |
* Added by DeViCeD - Update SOA Serial number |
|
143 |
* There should be more checks |
|
144 |
*/ |
|
145 |
if ($type != 'SOA') |
|
146 |
{ |
|
147 |
update_soa_serial($zoneid); |
|
148 |
} |
|
149 |
return true; |
|
150 |
} |
|
151 |
else |
|
152 |
{ |
|
153 |
error(sprintf(ERR_INV_ARGC, "edit_record", "no zoneid given")); |
|
154 |
} |
|
155 |
|
|
156 |
} |
|
157 |
|
|
158 |
|
|
159 |
/* |
|
160 |
* Adds a record. |
|
161 |
* This function validates it if correct it inserts it into the database. |
|
162 |
* return values: true if succesful. |
|
163 |
*/ |
|
164 |
function add_record($zoneid, $name, $type, $content, $ttl, $prio) |
|
165 |
{ |
|
166 |
|
|
167 |
global $db; |
|
168 |
if (!xs($zoneid)) |
|
169 |
{ |
|
170 |
error(ERR_RECORD_ACCESS_DENIED); |
|
171 |
} |
|
172 |
if (is_numeric($zoneid)) |
|
173 |
{ |
8
|
174 |
// Check the user input. |
|
175 |
validate_input($zoneid, $type, $content, $name, $prio, $ttl); |
1
|
176 |
|
8
|
177 |
// Generate new timestamp for the daemon |
1
|
178 |
$change = time(); |
8
|
179 |
|
1
|
180 |
// Execute query. |
8
|
181 |
$db->query("INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES ($zoneid, '$name', '$type', '$content', $ttl, '$prio', $change)"); |
1
|
182 |
if ($type != 'SOA') |
|
183 |
{ |
|
184 |
update_soa_serial($zoneid); |
|
185 |
} |
|
186 |
return true; |
|
187 |
} |
|
188 |
else |
|
189 |
{ |
|
190 |
error(sprintf(ERR_INV_ARG, "add_record")); |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
|
13
|
195 |
function add_supermaster($master_ip, $ns_name, $account) |
|
196 |
{ |
|
197 |
global $db; |
|
198 |
if (!is_valid_ip($master_ip) && !is_valid_ip6($master_ip)) |
|
199 |
{ |
|
200 |
error(sprintf(ERR_INV_ARGC, "add_supermaster", "No or no valid ipv4 or ipv6 address given.")); |
|
201 |
} |
|
202 |
if (!is_valid_hostname($ns_name)) |
|
203 |
{ |
|
204 |
error(ERR_DNS_HOSTNAME); |
|
205 |
} |
|
206 |
if (!validate_account($account)) |
|
207 |
{ |
|
208 |
error(sprintf(ERR_INV_ARGC, "add_supermaster", "given account name is invalid (alpha chars only)")); |
|
209 |
} |
|
210 |
if (supermaster_exists($master_ip)) |
|
211 |
{ |
|
212 |
error(sprintf(ERR_INV_ARGC, "add_supermaster", "supermaster already exists")); |
|
213 |
} |
|
214 |
else |
|
215 |
{ |
|
216 |
$db->query("INSERT INTO supermasters VALUES ('$master_ip', '$ns_name', '$account')"); |
|
217 |
return true; |
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
function delete_supermaster($master_ip) |
|
222 |
{ |
|
223 |
global $db; |
|
224 |
if (!level(5)) |
|
225 |
{ |
|
226 |
error(ERR_LEVEL_5); |
|
227 |
} |
|
228 |
if (is_valid_ip($master_ip) || is_valid_ip6($master_ip)) |
|
229 |
{ |
|
230 |
$db->query("DELETE FROM supermasters WHERE ip = '$master_ip'"); |
|
231 |
return true; |
|
232 |
} |
|
233 |
else |
|
234 |
{ |
|
235 |
error(sprintf(ERR_INV_ARGC, "delete_supermaster", "No or no valid ipv4 or ipv6 address given.")); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
function get_supermaster_info_from_ip($master_ip) |
|
240 |
{ |
|
241 |
global $db; |
|
242 |
if (!level(5)) |
|
243 |
{ |
|
244 |
error(ERR_LEVEL_5); |
|
245 |
} |
|
246 |
if (is_valid_ip($master_ip) || is_valid_ip6($master_ip)) |
|
247 |
{ |
|
248 |
$result = $db->queryRow("SELECT ip,nameserver,account FROM supermasters WHERE ip = '$master_ip'"); |
|
249 |
|
|
250 |
$ret = array( |
|
251 |
"master_ip" => $result["ip"], |
|
252 |
"ns_name" => $result["nameserver"], |
|
253 |
"account" => $result["account"] |
|
254 |
); |
|
255 |
|
|
256 |
return $ret; |
|
257 |
} |
|
258 |
else |
|
259 |
{ |
|
260 |
error(sprintf(ERR_INV_ARGC, "get_supermaster_info_from_ip", "No or no valid ipv4 or ipv6 address given.")); |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
|
1
|
265 |
/* |
|
266 |
* Delete a record by a given id. |
|
267 |
* return values: true, this function is always succesful. |
|
268 |
*/ |
|
269 |
function delete_record($id) |
|
270 |
{ |
|
271 |
global $db; |
|
272 |
|
|
273 |
// Check if the user has access. |
|
274 |
if (!xs(recid_to_domid($id))) |
|
275 |
{ |
|
276 |
error(ERR_RECORD_ACCESS_DENIED); |
|
277 |
} |
|
278 |
|
|
279 |
// Retrieve the type of record to see if we can actually remove it. |
|
280 |
$recordtype = get_recordtype_from_id($id); |
|
281 |
|
|
282 |
// If the record type is NS and the user tries to delete it while ALLOW_NS_EDIT is set to 0 |
|
283 |
// OR |
|
284 |
// check if the name of the record isnt the domain name (if so it should delete all records) |
|
285 |
// OR |
|
286 |
// check if we are dealing with a SOA field (same story as NS) |
|
287 |
if (($recordtype == "NS" && $GLOBALS["ALLOW_NS_EDIT"] != 1 && (get_name_from_record_id($id) == get_domain_name_from_id(recid_to_domid($id)))) || ($recordtype == "SOA" && $GLOBALS["ALLOW_SOA_EDIT"] != 1)) |
|
288 |
{ |
|
289 |
error(sprintf(ERR_RECORD_DELETE_TYPE_DENIED, $recordtype)); |
|
290 |
|
|
291 |
} |
|
292 |
if (is_numeric($id)) |
|
293 |
{ |
|
294 |
$did = recid_to_domid($id); |
|
295 |
$db->query('DELETE FROM records WHERE id=' . $id . ' LIMIT 1'); |
|
296 |
if ($type != 'SOA') |
|
297 |
{ |
|
298 |
update_soa_serial($did); |
|
299 |
} |
|
300 |
// $id doesnt exist in database anymore so its deleted or just not there which means "true" |
|
301 |
return true; |
|
302 |
} |
|
303 |
else |
|
304 |
{ |
|
305 |
error(sprintf(ERR_INV_ARG, "delete_record")); |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
|
|
310 |
/* |
|
311 |
* Add a domain to the database. |
|
312 |
* A domain is name obligatory, so is an owner. |
|
313 |
* return values: true when succesful. |
|
314 |
* Empty means templates dont have to be applied. |
|
315 |
* -------------------------------------------------------------------------- |
|
316 |
* This functions eats a template and by that it inserts various records. |
|
317 |
* first we start checking if something in an arpa record |
|
318 |
* remember to request nextID's from the database to be able to insert record. |
|
319 |
* if anything is invalid the function will error |
|
320 |
*/ |
13
|
321 |
function add_domain($domain, $owner, $webip, $mailip, $empty, $type, $slave_master) |
1
|
322 |
{ |
|
323 |
|
|
324 |
global $db; |
|
325 |
|
|
326 |
if (!level(5)) |
|
327 |
{ |
|
328 |
error(ERR_LEVEL_5); |
|
329 |
} |
|
330 |
|
|
331 |
// If domain, owner and mailip are given |
|
332 |
// OR |
|
333 |
// empty is given and owner and domain |
|
334 |
// OR |
|
335 |
// the domain is an arpa record and owner is given |
13
|
336 |
// OR |
|
337 |
// the type is slave, domain, owner and slave_master are given |
1
|
338 |
// THAN |
|
339 |
// Continue this function |
13
|
340 |
if (($domain && $owner && $webip && $mailip) || ($empty && $owner && $domain) || (eregi('in-addr.arpa', $domain) && $owner) || $type=="SLAVE" && $domain && $owner && $slave_master) |
1
|
341 |
{ |
8
|
342 |
// First insert zone into domain table |
|
343 |
$db->query("INSERT INTO domains (name, type) VALUES ('$domain', '$type')"); |
1
|
344 |
|
8
|
345 |
// Determine id of insert zone (in other words, find domain_id) |
|
346 |
$iddomain = $db->lastInsertId('domains', 'id'); |
|
347 |
if (PEAR::isError($iddomain)) { |
|
348 |
die($id->getMessage()); |
|
349 |
} |
1
|
350 |
|
8
|
351 |
// Second, insert into zones tables |
|
352 |
$db->query("INSERT INTO zones (domain_id, owner) VALUES ('$iddomain', $owner)"); |
1
|
353 |
|
13
|
354 |
if ($type == "SLAVE") |
1
|
355 |
{ |
13
|
356 |
$db->query("UPDATE domains SET master = '$slave_master' WHERE id = '$iddomain';"); |
|
357 |
|
|
358 |
// Done |
|
359 |
return true; |
|
360 |
} |
|
361 |
else |
|
362 |
{ |
|
363 |
// Generate new timestamp. We need this one anyhow. |
|
364 |
$now = time(); |
1
|
365 |
|
13
|
366 |
if ($empty && $iddomain) |
|
367 |
{ |
|
368 |
// If we come into this if statement we dont want to apply templates. |
|
369 |
// Retrieve configuration settings. |
|
370 |
$ns1 = $GLOBALS["NS1"]; |
|
371 |
$hm = $GLOBALS["HOSTMASTER"]; |
|
372 |
$ttl = $GLOBALS["DEFAULT_TTL"]; |
1
|
373 |
|
13
|
374 |
// Build and execute query |
|
375 |
$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES ('$iddomain', '$domain', '$ns1 $hm 1', 'SOA', $ttl, '', '$now')"; |
|
376 |
$db->query($sql); |
1
|
377 |
|
13
|
378 |
// Done |
|
379 |
return true; |
|
380 |
} |
|
381 |
elseif ($iddomain) |
1
|
382 |
{ |
13
|
383 |
// If we are here we want to apply templates. |
|
384 |
global $template; |
|
385 |
|
|
386 |
// Iterate over the template and apply it for each field. |
|
387 |
foreach ($template as $r) |
1
|
388 |
{ |
13
|
389 |
// Same type of if statement as previous. |
|
390 |
if ((eregi('in-addr.arpa', $domain) && ($r["type"] == "NS" || $r["type"] == "SOA")) || (!eregi('in-addr.arpa', $domain))) |
1
|
391 |
{ |
13
|
392 |
// Parse the template. |
|
393 |
$name = parse_template_value($r["name"], $domain, $webip, $mailip); |
|
394 |
$type = $r["type"]; |
|
395 |
$content = parse_template_value($r["content"], $domain, $webip, $mailip); |
|
396 |
$ttl = $r["ttl"]; |
|
397 |
$prio = $r["prio"]; |
1
|
398 |
|
13
|
399 |
// If no ttl is given, use the default. |
|
400 |
if (!$ttl) |
|
401 |
{ |
|
402 |
$ttl = $GLOBALS["DEFAULT_TTL"]; |
|
403 |
} |
|
404 |
|
|
405 |
$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES ('$iddomain', '$name','$content','$type','$ttl','$prio','$now')"; |
|
406 |
$db->query($sql); |
|
407 |
} |
1
|
408 |
} |
13
|
409 |
// All done. |
|
410 |
return true; |
|
411 |
} |
|
412 |
else |
|
413 |
{ |
|
414 |
error(sprintf(ERR_INV_ARGC, "add_domain", "could not create zone")); |
|
415 |
} |
|
416 |
} |
1
|
417 |
} |
|
418 |
else |
|
419 |
{ |
|
420 |
error(sprintf(ERR_INV_ARG, "add_domain")); |
|
421 |
} |
|
422 |
} |
|
423 |
|
|
424 |
|
|
425 |
/* |
|
426 |
* Deletes a domain by a given id. |
|
427 |
* Function always succeeds. If the field is not found in the database, thats what we want anyway. |
|
428 |
*/ |
|
429 |
function delete_domain($id) |
|
430 |
{ |
|
431 |
global $db; |
|
432 |
|
|
433 |
if (!level(5)) |
|
434 |
{ |
|
435 |
error(ERR_LEVEL_5); |
|
436 |
} |
|
437 |
|
|
438 |
// See if the ID is numeric. |
|
439 |
if (is_numeric($id)) |
|
440 |
{ |
|
441 |
$db->query("DELETE FROM zones WHERE domain_id=$id"); |
|
442 |
$db->query("DELETE FROM domains WHERE id=$id"); |
|
443 |
$db->query("DELETE FROM records WHERE domain_id=$id"); |
|
444 |
// Nothing in the database. If the delete deleted 0 records it means the id is just not there. |
|
445 |
// therefore the is no need to check the affectedRows values. |
|
446 |
return true; |
|
447 |
} |
|
448 |
else |
|
449 |
{ |
|
450 |
error(sprintf(ERR_INV_ARGC, "delete_domain", "id must be a number")); |
|
451 |
} |
|
452 |
} |
|
453 |
|
|
454 |
|
|
455 |
/* |
|
456 |
* Gets the id of the domain by a given record id. |
|
457 |
* return values: the domain id that was requested. |
|
458 |
*/ |
|
459 |
function recid_to_domid($id) |
|
460 |
{ |
|
461 |
global $db; |
|
462 |
if (is_numeric($id)) |
|
463 |
{ |
|
464 |
$result = $db->query("SELECT domain_id FROM records WHERE id=$id"); |
|
465 |
$r = $result->fetchRow(); |
|
466 |
return $r["domain_id"]; |
|
467 |
} |
|
468 |
else |
|
469 |
{ |
|
470 |
error(sprintf(ERR_INV_ARGC, "recid_to_domid", "id must be a number")); |
|
471 |
} |
|
472 |
} |
|
473 |
|
|
474 |
|
|
475 |
/* |
|
476 |
* Sorts a zone by records. |
|
477 |
* return values: the sorted zone. |
|
478 |
*/ |
|
479 |
function sort_zone($records) |
|
480 |
{ |
|
481 |
$ar_so = array(); |
|
482 |
$ar_ns = array(); |
|
483 |
$ar_mx = array(); |
|
484 |
$ar_mb = array(); |
|
485 |
$ar_ur = array(); |
|
486 |
$ar_ov = array(); |
|
487 |
foreach ($records as $c) |
|
488 |
{ |
|
489 |
switch(strtoupper($c['type'])) |
|
490 |
{ |
|
491 |
case "SOA": |
|
492 |
$ar_so[] = $c; |
|
493 |
break; |
|
494 |
case "NS": |
|
495 |
$ar_ns[] = $c; |
|
496 |
break; |
|
497 |
case "MX": |
|
498 |
$ar_mx[] = $c; |
|
499 |
break; |
|
500 |
case "MBOXFW": |
|
501 |
$ar_mb[] = $c; |
|
502 |
break; |
|
503 |
case "URL": |
|
504 |
$ar_ur[] = $c; |
|
505 |
break; |
|
506 |
default: |
|
507 |
$ar_ov[] = $c; |
|
508 |
break; |
|
509 |
} |
|
510 |
} |
|
511 |
|
|
512 |
$res = array_merge($ar_so, $ar_ns, $ar_mx, $ar_mb, $ar_ur, $ar_ov); |
|
513 |
|
|
514 |
if (count($records) == count($res)) |
|
515 |
{ |
|
516 |
$records = $res; |
|
517 |
} |
|
518 |
else |
|
519 |
{ |
|
520 |
error(sprintf(ERR_INV_ARGC, "sort_zone", "records sorting failed!")); |
|
521 |
} |
|
522 |
return $records; |
|
523 |
} |
|
524 |
|
|
525 |
|
|
526 |
/* |
|
527 |
* Change owner of a domain. |
|
528 |
* Function should actually be in users.inc.php. But its more of a record modification than a user modification |
|
529 |
* return values: true when succesful. |
|
530 |
*/ |
|
531 |
function add_owner($domain, $newowner) |
|
532 |
{ |
|
533 |
global $db; |
|
534 |
|
|
535 |
if (!level(5)) |
|
536 |
{ |
|
537 |
error(ERR_LEVEL_5); |
|
538 |
} |
|
539 |
|
|
540 |
if (is_numeric($domain) && is_numeric($newowner) && is_valid_user($newowner)) |
|
541 |
{ |
8
|
542 |
if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=$newowner AND domain_id=$domain") == 0) |
1
|
543 |
{ |
8
|
544 |
$db->query("INSERT INTO zones (domain_id, owner) VALUES($domain, $newowner)"); |
1
|
545 |
} |
|
546 |
return true; |
|
547 |
} |
|
548 |
else |
|
549 |
{ |
|
550 |
error(sprintf(ERR_INV_ARGC, "change_owner", "$domain / $newowner")); |
|
551 |
} |
|
552 |
} |
|
553 |
|
|
554 |
|
|
555 |
function delete_owner($domain, $owner) |
|
556 |
{ |
|
557 |
global $db; |
8
|
558 |
if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=$owner AND domain_id=$domain") != 0) |
1
|
559 |
{ |
|
560 |
$db->query("DELETE FROM zones WHERE owner=$owner AND domain_id=$domain"); |
|
561 |
} |
|
562 |
return true; |
|
563 |
} |
|
564 |
|
|
565 |
/* |
|
566 |
* Retrieves all supported dns record types |
|
567 |
* This function might be deprecated. |
|
568 |
* return values: array of types in string form. |
|
569 |
*/ |
|
570 |
function get_record_types() |
|
571 |
{ |
|
572 |
global $rtypes; |
|
573 |
return $rtypes; |
|
574 |
} |
|
575 |
|
|
576 |
|
|
577 |
/* |
|
578 |
* Retrieve all records by a given type and domain id. |
|
579 |
* Example: get all records that are of type A from domain id 1 |
|
580 |
* return values: a DB class result object |
|
581 |
*/ |
|
582 |
function get_records_by_type_from_domid($type, $recid) |
|
583 |
{ |
|
584 |
global $rtypes; |
|
585 |
global $db; |
|
586 |
|
|
587 |
// Does this type exist? |
|
588 |
if(!in_array(strtoupper($type), $rtypes)) |
|
589 |
{ |
|
590 |
error(sprintf(ERR_INV_ARGC, "get_records_from_type", "this is not a supported record")); |
|
591 |
} |
|
592 |
|
|
593 |
// Get the domain id. |
|
594 |
$domid = recid_to_domid($recid); |
|
595 |
|
|
596 |
$result = $db->query("select id, type from records where domain_id=$recid and type='$type'"); |
|
597 |
return $result; |
|
598 |
} |
|
599 |
|
|
600 |
|
|
601 |
/* |
|
602 |
* Retrieves the type of a record from a given id. |
|
603 |
* return values: the type of the record (one of the records types in $rtypes assumable). |
|
604 |
*/ |
|
605 |
function get_recordtype_from_id($id) |
|
606 |
{ |
|
607 |
global $db; |
|
608 |
if (is_numeric($id)) |
|
609 |
{ |
|
610 |
$result = $db->query("SELECT type FROM records WHERE id=$id"); |
|
611 |
$r = $result->fetchRow(); |
|
612 |
return $r["type"]; |
|
613 |
} |
|
614 |
else |
|
615 |
{ |
|
616 |
error(sprintf(ERR_INV_ARG, "get_recordtype_from_id")); |
|
617 |
} |
|
618 |
} |
|
619 |
|
|
620 |
|
|
621 |
/* |
|
622 |
* Retrieves the name (e.g. bla.test.com) of a record by a given id. |
|
623 |
* return values: the name associated with the id. |
|
624 |
*/ |
|
625 |
function get_name_from_record_id($id) |
|
626 |
{ |
|
627 |
global $db; |
|
628 |
if (is_numeric($id)) |
|
629 |
{ |
|
630 |
$result = $db->query("SELECT name FROM records WHERE id=$id"); |
|
631 |
$r = $result->fetchRow(); |
|
632 |
return $r["name"]; |
|
633 |
} |
|
634 |
else |
|
635 |
{ |
|
636 |
error(sprintf(ERR_INV_ARG, "get_name_from_record_id")); |
|
637 |
} |
|
638 |
} |
|
639 |
|
|
640 |
|
|
641 |
/* |
|
642 |
* Get all the domains from a database of which the user is the owner. |
|
643 |
* return values: an array with the id of the domain and its name. |
|
644 |
*/ |
|
645 |
function get_domains_from_userid($id) |
|
646 |
{ |
|
647 |
global $db; |
|
648 |
if (is_numeric($id)) |
|
649 |
{ |
|
650 |
$result = $db->query("SELECT domains.id AS domain_id, domains.name AS name FROM domains LEFT JOIN zones ON domains.id=zones.domain_id WHERE owner=$id"); |
|
651 |
|
|
652 |
$ret = array(); |
|
653 |
|
|
654 |
// Put all the information in a big array. |
|
655 |
while ($r = $result->fetchRow()) |
|
656 |
{ |
|
657 |
$ret[] = array( |
|
658 |
"id" => $r["domain_id"], |
|
659 |
"name" => $r["name"] |
|
660 |
); |
|
661 |
} |
|
662 |
return $ret; |
|
663 |
} |
|
664 |
else |
|
665 |
{ |
|
666 |
error(sprintf(ERR_INV_ARGC, "get_domains_from_userid", "This is not a valid userid: $id")); |
|
667 |
} |
|
668 |
} |
|
669 |
|
|
670 |
|
|
671 |
/* |
|
672 |
* Get domain name from a given id |
|
673 |
* return values: the name of the domain associated with the id. |
|
674 |
*/ |
|
675 |
function get_domain_name_from_id($id) |
|
676 |
{ |
|
677 |
global $db; |
|
678 |
if (!xs($id)) |
|
679 |
{ |
|
680 |
error(ERR_RECORD_ACCESS_DENIED); |
|
681 |
} |
|
682 |
if (is_numeric($id)) |
|
683 |
{ |
|
684 |
$result = $db->query("SELECT name FROM domains WHERE id=$id"); |
|
685 |
if ($result->numRows() == 1) |
|
686 |
{ |
|
687 |
$r = $result->fetchRow(); |
|
688 |
return $r["name"]; |
|
689 |
} |
|
690 |
else |
|
691 |
{ |
|
692 |
error(sprintf(ERR_INV_ARGC, "get_domain_name_from_id", "more than one domain found?! whaaa! BAD! BAD! Contact admin!")); |
|
693 |
} |
|
694 |
} |
|
695 |
else |
|
696 |
{ |
|
697 |
error(sprintf(ERR_INV_ARGC, "get_domain_name_from_id", "Not a valid domainid: $id")); |
|
698 |
} |
|
699 |
} |
|
700 |
|
|
701 |
|
|
702 |
/* |
|
703 |
* Get information about a domain name from a given domain id. |
|
704 |
* the function looks up the domainname, the owner of the domain and the number of records in it. |
|
705 |
* return values: an array containing the information. |
|
706 |
*/ |
|
707 |
function get_domain_info_from_id($id) |
|
708 |
{ |
|
709 |
global $db; |
|
710 |
if (!xs($id)) |
|
711 |
{ |
|
712 |
error(ERR_RECORD_ACCESS_DENIED); |
|
713 |
} |
|
714 |
if (is_numeric($id)) |
|
715 |
{ |
|
716 |
|
|
717 |
if ($_SESSION[$id."_ispartial"] == 1) { |
|
718 |
|
13
|
719 |
$sqlq = "SELECT |
|
720 |
domains.type AS type, |
|
721 |
domains.name AS name, |
1
|
722 |
users.fullname AS owner, |
|
723 |
count(record_owners.id) AS aantal |
|
724 |
FROM domains, users, record_owners, records |
|
725 |
|
|
726 |
WHERE record_owners.user_id = ".$_SESSION["userid"]." |
|
727 |
AND record_owners.record_id = records.id |
|
728 |
AND records.domain_id = ".$id." |
|
729 |
|
|
730 |
GROUP BY name, owner, users.fullname |
|
731 |
ORDER BY name"; |
|
732 |
|
8
|
733 |
$result = $db->queryRow($sqlq); |
1
|
734 |
|
|
735 |
$ret = array( |
|
736 |
"name" => $result["name"], |
|
737 |
"ownerid" => $_SESSION["userid"], |
|
738 |
"owner" => $result["owner"], |
13
|
739 |
"type" => $result["type"], |
1
|
740 |
"numrec" => $result["aantal"] |
|
741 |
); |
|
742 |
|
|
743 |
return $ret; |
|
744 |
|
|
745 |
} else{ |
|
746 |
|
|
747 |
// Query that retrieves the information we need. |
13
|
748 |
$sqlq = "SELECT |
|
749 |
domains.type AS type, |
|
750 |
domains.name AS name, |
1
|
751 |
min(zones.owner) AS ownerid, |
|
752 |
users.fullname AS owner, |
|
753 |
count(records.domain_id) AS aantal |
|
754 |
FROM domains |
|
755 |
LEFT JOIN records ON domains.id=records.domain_id |
|
756 |
LEFT JOIN zones ON domains.id=zones.domain_id |
|
757 |
LEFT JOIN users ON zones.owner=users.id |
|
758 |
WHERE domains.id=$id |
|
759 |
GROUP BY name, owner, users.fullname |
|
760 |
ORDER BY zones.id"; |
|
761 |
|
|
762 |
// Put the first occurence in an array and return it. |
8
|
763 |
$result = $db->queryRow($sqlq); |
1
|
764 |
|
8
|
765 |
//$result["ownerid"] = ($result["ownerid"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $result["ownerid"]; |
1
|
766 |
|
|
767 |
$ret = array( |
|
768 |
"name" => $result["name"], |
|
769 |
"ownerid" => $result["ownerid"], |
|
770 |
"owner" => $result["owner"], |
13
|
771 |
"type" => $result["type"], |
1
|
772 |
"numrec" => $result["aantal"] |
|
773 |
); |
|
774 |
return $ret; |
|
775 |
} |
|
776 |
|
|
777 |
} |
|
778 |
else |
|
779 |
{ |
|
780 |
error(sprintf(ERR_INV_ARGC, "get_domain_num_records_from_id", "This is not a valid domainid: $id")); |
|
781 |
} |
|
782 |
} |
|
783 |
|
|
784 |
|
|
785 |
/* |
|
786 |
* Check if a domain is already existing. |
|
787 |
* return values: true if existing, false if it doesnt exist. |
|
788 |
*/ |
|
789 |
function domain_exists($domain) |
|
790 |
{ |
|
791 |
global $db; |
|
792 |
|
|
793 |
if (!level(5)) |
|
794 |
{ |
|
795 |
error(ERR_LEVEL_5); |
|
796 |
} |
|
797 |
if (is_valid_domain($domain)) |
|
798 |
{ |
|
799 |
$result = $db->query("SELECT id FROM domains WHERE name='$domain'"); |
|
800 |
if ($result->numRows() == 0) |
|
801 |
{ |
|
802 |
return false; |
|
803 |
} |
|
804 |
elseif ($result->numRows() >= 1) |
|
805 |
{ |
|
806 |
return true; |
|
807 |
} |
|
808 |
} |
|
809 |
else |
|
810 |
{ |
|
811 |
error(ERR_DOMAIN_INVALID); |
|
812 |
} |
|
813 |
} |
|
814 |
|
13
|
815 |
function get_supermasters() |
|
816 |
{ |
|
817 |
global $db; |
|
818 |
$result = $db->query("SELECT ip, nameserver, account FROM supermasters"); |
|
819 |
$ret = array(); |
|
820 |
|
|
821 |
if($result->numRows() == 0) |
|
822 |
{ |
|
823 |
return -1; |
|
824 |
} |
|
825 |
else |
|
826 |
{ |
|
827 |
while ($r = $result->fetchRow()) |
|
828 |
{ |
|
829 |
$ret[] = array( |
|
830 |
"master_ip" => $r["ip"], |
|
831 |
"ns_name" => $r["nameserver"], |
|
832 |
"account" => $r["account"], |
|
833 |
); |
|
834 |
return $ret; |
|
835 |
} |
|
836 |
} |
|
837 |
} |
|
838 |
|
|
839 |
function supermaster_exists($master_ip) |
|
840 |
{ |
|
841 |
global $db; |
|
842 |
if (!level(5)) |
|
843 |
{ |
|
844 |
error(ERR_LEVEL_5); |
|
845 |
} |
|
846 |
if (is_valid_ip($master_ip) || is_valid_ip6($master_ip)) |
|
847 |
{ |
|
848 |
$result = $db->query("SELECT ip FROM supermasters WHERE ip = '$master_ip'"); |
|
849 |
if ($result->numRows() == 0) |
|
850 |
{ |
|
851 |
return false; |
|
852 |
} |
|
853 |
elseif ($result->numRows() >= 1) |
|
854 |
{ |
|
855 |
return true; |
|
856 |
} |
|
857 |
} |
|
858 |
else |
|
859 |
{ |
|
860 |
error(sprintf(ERR_INV_ARGC, "supermaster_exists", "No or no valid IPv4 or IPv6 address given.")); |
|
861 |
} |
|
862 |
} |
|
863 |
|
1
|
864 |
|
|
865 |
/* |
13
|
866 |
* Get all domains from the database |
1
|
867 |
* This function gets all the domains from the database unless a user id is below 5. |
|
868 |
* if a user id is below 5 this function will only retrieve records for that user. |
|
869 |
* return values: the array of domains or -1 if nothing is found. |
|
870 |
*/ |
|
871 |
function get_domains($userid=true,$letterstart=all,$rowstart=0,$rowamount=999999) |
|
872 |
{ |
|
873 |
global $db; |
|
874 |
if((!level(5) || !$userid) && !level(10) && !level(5)) |
|
875 |
{ |
|
876 |
$add = " AND zones.owner=".$_SESSION["userid"]; |
|
877 |
} |
|
878 |
else |
|
879 |
{ |
|
880 |
$add = ""; |
|
881 |
} |
|
882 |
|
|
883 |
$sqlq = "SELECT domains.id AS domain_id, |
|
884 |
min(zones.owner) AS owner, |
|
885 |
count(DISTINCT records.id) AS aantal, |
|
886 |
domains.name AS domainname |
|
887 |
FROM domains |
|
888 |
LEFT JOIN zones ON domains.id=zones.domain_id |
|
889 |
LEFT JOIN records ON records.domain_id=domains.id |
|
890 |
WHERE 1 $add "; |
|
891 |
if ($letterstart!=all && $letterstart!=1) { |
|
892 |
$sqlq.=" AND domains.name LIKE '".$letterstart."%' "; |
|
893 |
} elseif ($letterstart==1) { |
|
894 |
$sqlq.=" AND "; |
|
895 |
for ($i=0;$i<=9;$i++) { |
|
896 |
$sqlq.="domains.name LIKE '".$i."%'"; |
|
897 |
if ($i!=9) $sqlq.=" OR "; |
|
898 |
} |
|
899 |
} |
|
900 |
$sqlq.=" GROUP BY domainname, domain_id |
|
901 |
ORDER BY domainname |
|
902 |
LIMIT $rowstart,$rowamount"; |
|
903 |
|
|
904 |
$result = $db->query($sqlq); |
|
905 |
$result2 = $db->query($sqlq); |
|
906 |
|
|
907 |
$andnot=""; |
|
908 |
while($r = $result2->fetchRow()) { |
|
909 |
$andnot.=" AND domains.id!= '".$r["domain_id"]."' "; |
|
910 |
} |
|
911 |
|
|
912 |
if ($letterstart!=all && $letterstart!=1) { |
|
913 |
|
|
914 |
$sqlq = "SELECT domains.id AS domain_id, |
|
915 |
count(DISTINCT record_owners.record_id) AS aantal, |
|
916 |
domains.name AS domainname |
|
917 |
FROM domains, record_owners,records, zones |
|
918 |
WHERE record_owners.user_id = '".$_SESSION["userid"]."' |
|
919 |
AND (records.id = record_owners.record_id |
|
920 |
AND domains.id = records.domain_id) |
|
921 |
$andnot |
|
922 |
AND domains.name LIKE '".$letterstart."%' |
|
923 |
AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."') |
|
924 |
GROUP BY domainname, domain_id |
|
925 |
ORDER BY domainname"; |
|
926 |
|
|
927 |
$result_extra = $db->query($sqlq); |
|
928 |
|
|
929 |
} else { |
|
930 |
|
|
931 |
for ($i=0;$i<=9;$i++) { |
|
932 |
$sqlq = "SELECT domains.id AS domain_id, |
|
933 |
count(DISTINCT record_owners.record_id) AS aantal, |
|
934 |
domains.name AS domainname |
|
935 |
FROM domains, record_owners,records, zones |
|
936 |
WHERE record_owners.user_id = '".$_SESSION["userid"]."' |
|
937 |
AND (records.id = record_owners.record_id |
|
938 |
AND domains.id = records.domain_id) |
|
939 |
$andnot |
|
940 |
AND domains.name LIKE '".$i."%' |
|
941 |
AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."') |
|
942 |
GROUP BY domainname, domain_id |
|
943 |
ORDER BY domainname"; |
|
944 |
|
|
945 |
$result_extra[$i] = $db->query($sqlq); |
|
946 |
} |
|
947 |
|
|
948 |
} |
|
949 |
|
|
950 |
/* |
|
951 |
if ($result->numRows() == 0) |
|
952 |
{ |
|
953 |
// Nothing found. |
|
954 |
return -1; |
|
955 |
} |
|
956 |
*/ |
|
957 |
|
|
958 |
while($r = $result->fetchRow()) |
|
959 |
{ |
8
|
960 |
$r["owner"] = ($r["owner"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $r["owner"]; |
1
|
961 |
$ret[$r["domainname"]] = array( |
|
962 |
"name" => $r["domainname"], |
|
963 |
"id" => $r["domain_id"], |
|
964 |
"owner" => $r["owner"], |
|
965 |
"numrec" => $r["aantal"] |
|
966 |
); |
|
967 |
} |
|
968 |
|
|
969 |
|
|
970 |
if ($letterstart!=all && $letterstart!=1) { |
|
971 |
|
|
972 |
while($r = $result_extra->fetchRow()) |
|
973 |
{ |
|
974 |
$ret[$r["domainname"]] = array( |
|
975 |
"name" => $r["domainname"]."*", |
|
976 |
"id" => $r["domain_id"], |
|
977 |
"owner" => $_SESSION["userid"], |
|
978 |
"numrec" => $r["aantal"] |
|
979 |
); |
|
980 |
$_SESSION["partial_".$r["domainname"]] = 1; |
|
981 |
} |
|
982 |
|
|
983 |
} else { |
|
984 |
|
|
985 |
foreach ($result_extra as $result_e) { |
|
986 |
while($r = $result_e->fetchRow()) |
|
987 |
{ |
|
988 |
$ret[$r["domainname"]] = array( |
|
989 |
"name" => $r["domainname"]."*", |
|
990 |
"id" => $r["domain_id"], |
|
991 |
"owner" => $_SESSION["userid"], |
|
992 |
"numrec" => $r["aantal"] |
|
993 |
); |
|
994 |
$_SESSION["partial_".$r["domainname"]] = 1; |
|
995 |
} |
|
996 |
} |
|
997 |
|
|
998 |
} |
|
999 |
|
|
1000 |
if (empty($ret)) { |
|
1001 |
return -1; |
|
1002 |
} else { |
|
1003 |
sort($ret); |
|
1004 |
return $ret; |
|
1005 |
} |
|
1006 |
|
|
1007 |
} |
|
1008 |
|
|
1009 |
|
|
1010 |
/* |
|
1011 |
* Get a record from an id. |
|
1012 |
* Retrieve all fields of the record and send it back to the function caller. |
|
1013 |
* return values: the array with information, or -1 is nothing is found. |
|
1014 |
*/ |
|
1015 |
function get_record_from_id($id) |
|
1016 |
{ |
|
1017 |
global $db; |
|
1018 |
if (is_numeric($id)) |
|
1019 |
{ |
|
1020 |
$result = $db->query("SELECT id, domain_id, name, type, content, ttl, prio, change_date FROM records WHERE id=$id"); |
|
1021 |
if($result->numRows() == 0) |
|
1022 |
{ |
|
1023 |
return -1; |
|
1024 |
} |
|
1025 |
elseif ($result->numRows() == 1) |
|
1026 |
{ |
|
1027 |
$r = $result->fetchRow(); |
|
1028 |
$ret = array( |
|
1029 |
"id" => $r["id"], |
|
1030 |
"domain_id" => $r["domain_id"], |
|
1031 |
"name" => $r["name"], |
|
1032 |
"type" => $r["type"], |
|
1033 |
"content" => $r["content"], |
|
1034 |
"ttl" => $r["ttl"], |
|
1035 |
"prio" => $r["prio"], |
|
1036 |
"change_date" => $r["change_date"] |
|
1037 |
); |
|
1038 |
return $ret; |
|
1039 |
} |
|
1040 |
else |
|
1041 |
{ |
|
1042 |
error(sprintf(ERR_INV_ARGC, "get_record_from_id", "More than one row returned! This is bad!")); |
|
1043 |
} |
|
1044 |
} |
|
1045 |
else |
|
1046 |
{ |
|
1047 |
error(sprintf(ERR_INV_ARG, "get_record_from_id")); |
|
1048 |
} |
|
1049 |
} |
|
1050 |
|
|
1051 |
|
|
1052 |
/* |
|
1053 |
* Get all records from a domain id. |
|
1054 |
* Retrieve all fields of the records and send it back to the function caller. |
|
1055 |
* return values: the array with information, or -1 is nothing is found. |
|
1056 |
*/ |
|
1057 |
function get_records_from_domain_id($id,$rowstart=0,$rowamount=999999) |
|
1058 |
{ |
|
1059 |
global $db; |
|
1060 |
if (is_numeric($id)) |
|
1061 |
{ |
|
1062 |
if ($_SESSION[$id."_ispartial"] == 1) { |
|
1063 |
|
|
1064 |
$result = $db->query("SELECT record_owners.record_id as id |
|
1065 |
FROM record_owners,domains,records |
|
1066 |
WHERE record_owners.user_id = ".$_SESSION["userid"]." |
|
1067 |
AND record_owners.record_id = records.id |
|
1068 |
AND records.domain_id = ".$id." |
|
1069 |
GROUP bY record_owners.record_id |
|
1070 |
LIMIT $rowstart,$rowamount"); |
|
1071 |
|
|
1072 |
$ret = array(); |
|
1073 |
if($result->numRows() == 0) |
|
1074 |
{ |
|
1075 |
return -1; |
|
1076 |
} |
|
1077 |
else |
|
1078 |
{ |
|
1079 |
$ret[] = array(); |
|
1080 |
$retcount = 0; |
|
1081 |
while($r = $result->fetchRow()) |
|
1082 |
{ |
|
1083 |
// Call get_record_from_id for each row. |
|
1084 |
$ret[$retcount] = get_record_from_id($r["id"]); |
|
1085 |
$retcount++; |
|
1086 |
} |
|
1087 |
return $ret; |
|
1088 |
} |
|
1089 |
|
|
1090 |
} else { |
|
1091 |
|
|
1092 |
$result = $db->query("SELECT id FROM records WHERE domain_id=$id LIMIT $rowstart,$rowamount"); |
|
1093 |
$ret = array(); |
|
1094 |
if($result->numRows() == 0) |
|
1095 |
{ |
|
1096 |
return -1; |
|
1097 |
} |
|
1098 |
else |
|
1099 |
{ |
|
1100 |
$ret[] = array(); |
|
1101 |
$retcount = 0; |
|
1102 |
while($r = $result->fetchRow()) |
|
1103 |
{ |
|
1104 |
// Call get_record_from_id for each row. |
|
1105 |
$ret[$retcount] = get_record_from_id($r["id"]); |
|
1106 |
$retcount++; |
|
1107 |
} |
|
1108 |
return $ret; |
|
1109 |
} |
|
1110 |
|
|
1111 |
} |
|
1112 |
} |
|
1113 |
else |
|
1114 |
{ |
|
1115 |
error(sprintf(ERR_INV_ARG, "get_records_from_domain_id")); |
|
1116 |
} |
|
1117 |
} |
|
1118 |
|
|
1119 |
|
|
1120 |
function get_users_from_domain_id($id) |
|
1121 |
{ |
|
1122 |
global $db; |
8
|
1123 |
$result = $db->queryCol("SELECT owner FROM zones WHERE domain_id=$id"); |
1
|
1124 |
$ret = array(); |
|
1125 |
foreach($result as $uid) |
|
1126 |
{ |
8
|
1127 |
$fullname = $db->queryOne("SELECT fullname FROM users WHERE id=$uid"); |
1
|
1128 |
$ret[] = array( |
|
1129 |
"id" => $uid, |
|
1130 |
"fullname" => $fullname |
|
1131 |
); |
|
1132 |
} |
|
1133 |
return $ret; |
|
1134 |
} |
|
1135 |
|
|
1136 |
function search_record($question) |
|
1137 |
{ |
|
1138 |
global $db; |
|
1139 |
$question = trim($question); |
|
1140 |
if (empty($question)) |
|
1141 |
{ |
|
1142 |
$S_INPUT_TYPE = -1; |
|
1143 |
} |
|
1144 |
|
|
1145 |
/* now for some input-type searching */ |
|
1146 |
if (is_valid_ip($question) || is_valid_ip6($question)) |
|
1147 |
{ |
|
1148 |
$S_INPUT_TYPE = 0; |
|
1149 |
} |
|
1150 |
elseif(is_valid_domain($question) || |
|
1151 |
is_valid_hostname($question) || |
|
1152 |
is_valid_mboxfw($question)) // I guess this one can appear in records table too (content?!) |
|
1153 |
{ |
|
1154 |
$S_INPUT_TYPE = 1; |
|
1155 |
} |
|
1156 |
else |
|
1157 |
{ |
|
1158 |
$S_INPUT_TYPE = -1; |
|
1159 |
} |
|
1160 |
switch($S_INPUT_TYPE) |
|
1161 |
{ |
|
1162 |
case '0': |
|
1163 |
$sqlq = "SELECT * FROM `records` WHERE `content` = '".$question."' ORDER BY `type` DESC"; |
|
1164 |
$result = $db->query($sqlq); |
|
1165 |
$ret_r = array(); |
|
1166 |
while ($r = $result->fetchRow()) |
|
1167 |
{ |
|
1168 |
if(xs($r['domain_id'])) |
|
1169 |
{ |
|
1170 |
$ret_r[] = array( |
|
1171 |
'id' => $r['id'], |
|
1172 |
'domain_id' => $r['domain_id'], |
|
1173 |
'name' => $r['name'], |
|
1174 |
'type' => $r['type'], |
|
1175 |
'content' => $r['content'], |
|
1176 |
'ttl' => $r['ttl'], |
|
1177 |
'prio' => $r['prio'], |
|
1178 |
'change_date' => $r['change_date'] |
|
1179 |
); |
|
1180 |
} |
|
1181 |
} |
|
1182 |
break; |
|
1183 |
|
|
1184 |
case '1' : |
5
|
1185 |
$sqlq = "SELECT `domains`.*, count(`records`.`id`) AS `numrec`, `zones`.`owner`, `records`.`domain_id` |
1
|
1186 |
FROM `domains`, `records`, `zones` |
|
1187 |
WHERE `domains`.`id` = `records`.`domain_id` |
|
1188 |
AND `zones`.`domain_id` = `domains`.`id` |
|
1189 |
AND `domains`.`name` = '".$question."' |
|
1190 |
GROUP BY (`domains`.`id`)"; |
|
1191 |
|
|
1192 |
$result = $db->query($sqlq); |
|
1193 |
$ret_d = array(); |
|
1194 |
while ($r = $result->fetchRow()) |
|
1195 |
{ |
|
1196 |
if(xs($r['domain_id'])) |
|
1197 |
{ |
|
1198 |
$ret_d[] = array( |
|
1199 |
'id' => $r['id'], |
|
1200 |
'name' => $r['name'], |
|
1201 |
'numrec' => $r['numrec'], |
|
1202 |
'owner' => $r['owner'] |
|
1203 |
); |
|
1204 |
} |
|
1205 |
} |
|
1206 |
|
|
1207 |
$sqlq = "SELECT * FROM `records` WHERE `name` = '".$question."' OR `content` = '".$question."' ORDER BY `type` DESC"; |
|
1208 |
$result = $db->query($sqlq); |
|
1209 |
while ($r = $result->fetchRow()) |
|
1210 |
{ |
|
1211 |
if(xs($r['domain_id'])) |
|
1212 |
{ |
|
1213 |
$ret_r[] = array( |
|
1214 |
'id' => $r['id'], |
|
1215 |
'domain_id' => $r['domain_id'], |
|
1216 |
'name' => $r['name'], |
|
1217 |
'type' => $r['type'], |
|
1218 |
'content' => $r['content'], |
|
1219 |
'ttl' => $r['ttl'], |
|
1220 |
'prio' => $r['prio'], |
|
1221 |
); |
|
1222 |
} |
|
1223 |
} |
|
1224 |
break; |
|
1225 |
} |
|
1226 |
if($S_INPUT_TYPE == 1) |
|
1227 |
{ |
|
1228 |
return array('domains' => $ret_d, 'records' => $ret_r); |
|
1229 |
} |
|
1230 |
return array('records' => $ret_r); |
|
1231 |
} |
|
1232 |
|
|
1233 |
function get_domain_type($id) |
|
1234 |
{ |
|
1235 |
global $db; |
13
|
1236 |
if (is_numeric($id)) |
1
|
1237 |
{ |
13
|
1238 |
$type = $db->queryOne("SELECT `type` FROM `domains` WHERE `id` = '".$id."'"); |
|
1239 |
if($type == "") |
|
1240 |
{ |
|
1241 |
$type = "NATIVE"; |
|
1242 |
} |
|
1243 |
return $type; |
|
1244 |
} |
|
1245 |
else |
|
1246 |
{ |
|
1247 |
error(sprintf(ERR_INV_ARG, "get_record_from_id", "no or no valid zoneid given")); |
|
1248 |
} |
|
1249 |
} |
|
1250 |
|
|
1251 |
function get_domain_slave_master($id) |
|
1252 |
{ |
|
1253 |
global $db; |
|
1254 |
if (is_numeric($id)) |
|
1255 |
{ |
|
1256 |
$slave_master = $db->queryOne("SELECT `master` FROM `domains` WHERE `type` = 'SLAVE' and `id` = '".$id."'"); |
|
1257 |
return $slave_master; |
|
1258 |
} |
|
1259 |
else |
|
1260 |
{ |
|
1261 |
error(sprintf(ERR_INV_ARG, "get_domain_slave_master", "no or no valid zoneid given")); |
|
1262 |
} |
1
|
1263 |
} |
|
1264 |
|
|
1265 |
function change_domain_type($type, $id) |
|
1266 |
{ |
13
|
1267 |
global $db; |
|
1268 |
unset($add); |
|
1269 |
if (is_numeric($id)) |
|
1270 |
{ |
|
1271 |
// It is not really neccesary to clear the master field if a |
|
1272 |
// zone is not of the type "slave" as powerdns will ignore that |
|
1273 |
// fiedl, but it is cleaner anyway. |
|
1274 |
if ($type != "SLAVE") |
|
1275 |
{ |
|
1276 |
$add = ", master=''"; |
|
1277 |
} |
|
1278 |
$result = $db->query("UPDATE `domains` SET `type` = '" .$type. "'".$add." WHERE `id` = '".$id."'"); |
|
1279 |
} |
|
1280 |
else |
|
1281 |
{ |
|
1282 |
error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
|
1283 |
} |
|
1284 |
} |
|
1285 |
|
|
1286 |
function change_domain_slave_master($id, $slave_master) |
|
1287 |
{ |
|
1288 |
global $db; |
|
1289 |
if (is_numeric($id)) |
|
1290 |
{ |
|
1291 |
if (is_valid_ip($slave_master) || is_valid_ip6($slave_master)) |
|
1292 |
{ |
|
1293 |
$result = $db->query("UPDATE `domains` SET `master` = '" .$slave_master. "' WHERE `id` = '".$id."'"); |
|
1294 |
} |
|
1295 |
else |
|
1296 |
{ |
|
1297 |
error(sprintf(ERR_INV_ARGC, "change_domain_slave_master", "This is not a valid IPv4 or IPv6 address: $slave_master")); |
|
1298 |
} |
|
1299 |
} |
|
1300 |
else |
|
1301 |
{ |
|
1302 |
error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
|
1303 |
} |
|
1304 |
} |
|
1305 |
|
|
1306 |
|
|
1307 |
function validate_account($account) |
|
1308 |
{ |
|
1309 |
|
|
1310 |
if(preg_match("/^[A-Z0-9._-]+$/i",$account)) |
|
1311 |
{ |
|
1312 |
return true; |
|
1313 |
} |
|
1314 |
else |
|
1315 |
{ |
|
1316 |
return false; |
|
1317 |
} |
1
|
1318 |
} |
|
1319 |
?> |