71
|
1 |
<?php |
1
|
2 |
|
119
|
3 |
/* Poweradmin, a friendly web-based admin tool for PowerDNS. |
47
|
4 |
* See <https://rejo.zenger.nl/poweradmin> for more details. |
|
5 |
* |
|
6 |
* Copyright 2007, 2008 Rejo Zenger <rejo@zenger.nl> |
|
7 |
* |
|
8 |
* This program is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
1
|
21 |
|
120
|
22 |
function get_zone_id_from_record_id($rid) { |
|
23 |
global $db; |
|
24 |
$query = "SELECT domain_id FROM records WHERE id = " . $db->quote($rid); |
|
25 |
$zid = $db->queryOne($query); |
|
26 |
return $zid; |
|
27 |
} |
|
28 |
|
82
|
29 |
function count_zone_records($zone_id) { |
|
30 |
global $db; |
|
31 |
$sqlq = "SELECT COUNT(id) FROM records WHERE domain_id = ".$db->quote($zone_id); |
|
32 |
$record_count = $db->queryOne($sqlq); |
|
33 |
return $record_count; |
|
34 |
} |
|
35 |
|
1
|
36 |
function update_soa_serial($domain_id) |
|
37 |
{ |
82
|
38 |
global $db; |
1
|
39 |
|
65
|
40 |
$sqlq = "SELECT notified_serial FROM domains WHERE id = ".$db->quote($domain_id); |
8
|
41 |
$notified_serial = $db->queryOne($sqlq); |
1
|
42 |
|
65
|
43 |
$sqlq = "SELECT content FROM records WHERE type = 'SOA' AND domain_id = ".$db->quote($domain_id); |
8
|
44 |
$content = $db->queryOne($sqlq); |
82
|
45 |
$need_to_update = false; |
|
46 |
|
1
|
47 |
// Getting the serial field. |
|
48 |
$soa = explode(" ", $content); |
82
|
49 |
|
|
50 |
if(empty($notified_serial)) { |
|
51 |
// Ok native replication, so we have to update. |
|
52 |
$need_to_update = true; |
|
53 |
} elseif($notified_serial >= $soa[2]) { |
|
54 |
$need_to_update = true; |
|
55 |
} elseif(strlen($soa[2]) != 10) { |
|
56 |
$need_to_update = true; |
|
57 |
} else { |
|
58 |
$need_to_update = false; |
|
59 |
} |
|
60 |
|
|
61 |
if($need_to_update) { |
|
62 |
// Ok so we have to update it seems. |
|
63 |
$current_serial = $soa[2]; |
1
|
64 |
$new_serial = date('Ymd'); // we will add revision number later |
|
65 |
|
82
|
66 |
if(strncmp($new_serial, $current_serial, 8) === 0) { |
|
67 |
$revision_number = (int) substr($current_serial, -2); |
|
68 |
if ($revision_number == 99) return false; // ok, we cannot update anymore tonight |
|
69 |
++$revision_number; |
|
70 |
// here it is ... same date, new revision |
|
71 |
$new_serial .= str_pad($revision_number, 2, "0", STR_PAD_LEFT); |
|
72 |
} else { |
|
73 |
/* |
1
|
74 |
* Current serial is not RFC1912 compilant, so let's make a new one |
|
75 |
*/ |
82
|
76 |
$new_serial .= '00'; |
1
|
77 |
} |
82
|
78 |
$soa[2] = $new_serial; // change serial in SOA array |
1
|
79 |
$new_soa = ""; |
|
80 |
// build new soa and update SQL after that |
82
|
81 |
for ($i = 0; $i < count($soa); $i++) { |
1
|
82 |
$new_soa .= $soa[$i] . " "; |
|
83 |
} |
65
|
84 |
$sqlq = "UPDATE records SET content = ".$db->quote($new_soa)." WHERE domain_id = ".$db->quote($domain_id)." AND type = 'SOA'"; |
1
|
85 |
$db->Query($sqlq); |
|
86 |
return true; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
/* |
|
91 |
* Edit a record. |
|
92 |
* This function validates it if correct it inserts it into the database. |
|
93 |
* return values: true if succesful. |
|
94 |
*/ |
82
|
95 |
function edit_record($record) { |
|
96 |
|
126
|
97 |
if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; } |
|
98 |
elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; } |
82
|
99 |
else { $perm_content_edit = "none" ; } |
|
100 |
|
|
101 |
$user_is_zone_owner = verify_user_is_owner_zoneid($record['zid']); |
|
102 |
$zone_type = get_domain_type($record['zid']); |
|
103 |
|
|
104 |
if ( $zone_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0" ) { |
111
|
105 |
error(ERR_PERM_EDIT_RECORD); |
|
106 |
return false; |
82
|
107 |
} else { |
|
108 |
if($record['content'] == "") { |
111
|
109 |
error(ERR_DNS_CONTENT); |
|
110 |
return false; |
82
|
111 |
} |
|
112 |
global $db; |
|
113 |
// TODO: no need to check for numeric-ness of zone id if we check with validate_input as well? |
|
114 |
if (is_numeric($record['zid'])) { |
|
115 |
validate_input($record['zid'], $record['type'], $record['content'], $record['name'], $record['prio'], $record['ttl']); |
|
116 |
$query = "UPDATE records |
|
117 |
SET name=".$db->quote($record['name']).", |
|
118 |
type=".$db->quote($record['type']).", |
|
119 |
content=".$db->quote($record['content']).", |
|
120 |
ttl=".$db->quote($record['ttl']).", |
|
121 |
prio=".$db->quote($record['prio']).", |
|
122 |
change_date=".$db->quote(time())." |
|
123 |
WHERE id=".$db->quote($record['rid']); |
|
124 |
$result = $db->Query($query); |
|
125 |
if (PEAR::isError($result)) { |
|
126 |
error($result->getMessage()); |
|
127 |
return false; |
|
128 |
} elseif ($record['type'] != 'SOA') { |
|
129 |
update_soa_serial($record['zid']); |
|
130 |
} |
|
131 |
return true; |
|
132 |
} |
|
133 |
else |
|
134 |
{ |
|
135 |
// TODO change to error style as above (returning directly) |
|
136 |
error(sprintf(ERR_INV_ARGC, "edit_record", "no zoneid given")); |
|
137 |
} |
1
|
138 |
} |
82
|
139 |
return true; |
1
|
140 |
} |
|
141 |
|
|
142 |
|
|
143 |
/* |
|
144 |
* Adds a record. |
|
145 |
* This function validates it if correct it inserts it into the database. |
|
146 |
* return values: true if succesful. |
|
147 |
*/ |
82
|
148 |
function add_record($zoneid, $name, $type, $content, $ttl, $prio) { |
1
|
149 |
global $db; |
82
|
150 |
|
126
|
151 |
if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; } |
|
152 |
elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; } |
82
|
153 |
else { $perm_content_edit = "none" ; } |
|
154 |
|
|
155 |
$user_is_zone_owner = verify_user_is_owner_zoneid($zoneid); |
|
156 |
$zone_type = get_domain_type($zoneid); |
1
|
157 |
|
82
|
158 |
if ( $zone_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0" ) { |
|
159 |
error(ERR_PERM_ADD_RECORD); |
|
160 |
return false; |
|
161 |
} else { |
|
162 |
if (validate_input($zoneid, $type, $content, $name, $prio, $ttl) ) { |
|
163 |
$change = time(); |
106
|
164 |
$query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" |
82
|
165 |
. $db->quote($zoneid) . "," |
|
166 |
. $db->quote($name) . "," |
|
167 |
. $db->quote($type) . "," |
|
168 |
. $db->quote($content) . "," |
|
169 |
. $db->quote($ttl) . "," |
|
170 |
. $db->quote($prio) . "," |
|
171 |
. $db->quote($change) . ")"; |
|
172 |
$response = $db->query($query); |
|
173 |
if (PEAR::isError($response)) { |
|
174 |
error($response->getMessage()); |
|
175 |
return false; |
|
176 |
} else { |
|
177 |
if ($type != 'SOA') { update_soa_serial($zoneid); } |
|
178 |
return true; |
|
179 |
} |
|
180 |
} else { |
|
181 |
return false; |
1
|
182 |
} |
|
183 |
return true; |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
|
13
|
188 |
function add_supermaster($master_ip, $ns_name, $account) |
|
189 |
{ |
|
190 |
global $db; |
82
|
191 |
if (!is_valid_ip($master_ip) && !is_valid_ip6($master_ip)) { |
|
192 |
error(ERR_DNS_IP); |
|
193 |
return false; |
13
|
194 |
} |
82
|
195 |
if (!is_valid_hostname($ns_name)) { |
13
|
196 |
error(ERR_DNS_HOSTNAME); |
82
|
197 |
return false; |
13
|
198 |
} |
82
|
199 |
if (!validate_account($account)) { |
13
|
200 |
error(sprintf(ERR_INV_ARGC, "add_supermaster", "given account name is invalid (alpha chars only)")); |
82
|
201 |
return false; |
13
|
202 |
} |
82
|
203 |
if (supermaster_exists($master_ip)) { |
|
204 |
error(ERR_SM_EXISTS); |
|
205 |
return false; |
|
206 |
} else { |
65
|
207 |
$db->query("INSERT INTO supermasters VALUES (".$db->quote($master_ip).", ".$db->quote($ns_name).", ".$db->quote($account).")"); |
13
|
208 |
return true; |
|
209 |
} |
|
210 |
} |
|
211 |
|
82
|
212 |
function delete_supermaster($master_ip) { |
|
213 |
global $db; |
13
|
214 |
if (is_valid_ip($master_ip) || is_valid_ip6($master_ip)) |
|
215 |
{ |
65
|
216 |
$db->query("DELETE FROM supermasters WHERE ip = ".$db->quote($master_ip)); |
13
|
217 |
return true; |
|
218 |
} |
|
219 |
else |
|
220 |
{ |
|
221 |
error(sprintf(ERR_INV_ARGC, "delete_supermaster", "No or no valid ipv4 or ipv6 address given.")); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
function get_supermaster_info_from_ip($master_ip) |
|
226 |
{ |
|
227 |
global $db; |
|
228 |
if (is_valid_ip($master_ip) || is_valid_ip6($master_ip)) |
|
229 |
{ |
65
|
230 |
$result = $db->queryRow("SELECT ip,nameserver,account FROM supermasters WHERE ip = ".$db->quote($master_ip)); |
13
|
231 |
|
|
232 |
$ret = array( |
|
233 |
"master_ip" => $result["ip"], |
|
234 |
"ns_name" => $result["nameserver"], |
|
235 |
"account" => $result["account"] |
|
236 |
); |
|
237 |
|
|
238 |
return $ret; |
|
239 |
} |
|
240 |
else |
|
241 |
{ |
|
242 |
error(sprintf(ERR_INV_ARGC, "get_supermaster_info_from_ip", "No or no valid ipv4 or ipv6 address given.")); |
|
243 |
} |
|
244 |
} |
|
245 |
|
82
|
246 |
function get_record_details_from_record_id($rid) { |
|
247 |
|
|
248 |
global $db; |
|
249 |
|
98
|
250 |
$query = "SELECT id AS rid, domain_id AS zid, name, type, content, ttl, prio, change_date FROM records WHERE id = " . $db->quote($rid) ; |
82
|
251 |
|
|
252 |
$response = $db->query($query); |
|
253 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
98
|
254 |
|
|
255 |
$return = $response->fetchRow(); |
82
|
256 |
return $return; |
|
257 |
} |
13
|
258 |
|
1
|
259 |
/* |
|
260 |
* Delete a record by a given id. |
|
261 |
* return values: true, this function is always succesful. |
|
262 |
*/ |
82
|
263 |
function delete_record($rid) |
1
|
264 |
{ |
|
265 |
global $db; |
|
266 |
|
126
|
267 |
if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; } |
|
268 |
elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; } |
82
|
269 |
else { $perm_content_edit = "none" ; } |
1
|
270 |
|
82
|
271 |
// Determine ID of zone first. |
|
272 |
$record = get_record_details_from_record_id($rid); |
|
273 |
$user_is_zone_owner = verify_user_is_owner_zoneid($record['zid']); |
1
|
274 |
|
82
|
275 |
if ( $perm_content_edit == "all" || ($perm_content_edit == "own" && $user_is_zone_owner == "0" )) { |
|
276 |
if ($record['type'] == "SOA") { |
|
277 |
error(_('You are trying to delete the SOA record. If are not allowed to remove it, unless you remove the entire zone.')); |
|
278 |
} else { |
98
|
279 |
$query = "DELETE FROM records WHERE id = " . $db->quote($rid); |
82
|
280 |
$response = $db->query($query); |
|
281 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
|
282 |
return true; |
1
|
283 |
} |
82
|
284 |
} else { |
|
285 |
error(ERR_PERM_DEL_RECORD); |
|
286 |
return false; |
1
|
287 |
} |
|
288 |
} |
|
289 |
|
|
290 |
|
|
291 |
/* |
|
292 |
* Add a domain to the database. |
|
293 |
* A domain is name obligatory, so is an owner. |
|
294 |
* return values: true when succesful. |
|
295 |
* Empty means templates dont have to be applied. |
|
296 |
* -------------------------------------------------------------------------- |
|
297 |
* This functions eats a template and by that it inserts various records. |
|
298 |
* first we start checking if something in an arpa record |
|
299 |
* remember to request nextID's from the database to be able to insert record. |
|
300 |
* if anything is invalid the function will error |
|
301 |
*/ |
13
|
302 |
function add_domain($domain, $owner, $webip, $mailip, $empty, $type, $slave_master) |
1
|
303 |
{ |
126
|
304 |
if(verify_permission('zone_master_add')) { $zone_master_add = "1" ; } ; |
|
305 |
if(verify_permission('zone_slave_add')) { $zone_slave_add = "1" ; } ; |
1
|
306 |
|
82
|
307 |
// TODO: make sure only one is possible if only one is enabled |
86
|
308 |
if($zone_master_add == "1" || $zone_slave_add == "1") { |
1
|
309 |
|
82
|
310 |
global $db; |
|
311 |
if (($domain && $owner && $webip && $mailip) || |
|
312 |
($empty && $owner && $domain) || |
|
313 |
(eregi('in-addr.arpa', $domain) && $owner) || |
|
314 |
$type=="SLAVE" && $domain && $owner && $slave_master) { |
|
315 |
|
|
316 |
$response = $db->query("INSERT INTO domains (name, type) VALUES (".$db->quote($domain).", ".$db->quote($type).")"); |
|
317 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
1
|
318 |
|
82
|
319 |
$domain_id = $db->lastInsertId('domains', 'id'); |
|
320 |
if (PEAR::isError($domain_id)) { error($id->getMessage()); return false; } |
|
321 |
|
|
322 |
$response = $db->query("INSERT INTO zones (domain_id, owner) VALUES (".$db->quote($domain_id).", ".$db->quote($owner).")"); |
|
323 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
1
|
324 |
|
82
|
325 |
if ($type == "SLAVE") { |
|
326 |
$response = $db->query("UPDATE domains SET master = ".$db->quote($slave_master)." WHERE id = ".$db->quote($domain_id)); |
|
327 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
|
328 |
return true; |
|
329 |
} else { |
|
330 |
$now = time(); |
|
331 |
if ($empty && $domain_id) { |
|
332 |
$ns1 = $GLOBALS['NS1']; |
|
333 |
$hm = $GLOBALS['HOSTMASTER']; |
|
334 |
$ttl = $GLOBALS['DEFAULT_TTL']; |
1
|
335 |
|
106
|
336 |
$query = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (" |
82
|
337 |
. $db->quote($domain_id) . "," |
|
338 |
. $db->quote($domain) . "," |
133
|
339 |
. $db->quote($ns1.' '.$hm.' 1') . "," |
106
|
340 |
. $db->quote('SOA')."," |
82
|
341 |
. $db->quote($ttl) |
|
342 |
. ", 0, " |
|
343 |
. $db->quote($now).")"; |
|
344 |
$response = $db->query($query); |
|
345 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
|
346 |
} elseif ($domain_id) { |
|
347 |
global $template; |
1
|
348 |
|
82
|
349 |
foreach ($template as $r) { |
|
350 |
if ((eregi('in-addr.arpa', $domain) && ($r["type"] == "NS" || $r["type"] == "SOA")) || (!eregi('in-addr.arpa', $domain))) |
|
351 |
{ |
|
352 |
$name = parse_template_value($r["name"], $domain, $webip, $mailip); |
|
353 |
$type = $r["type"]; |
|
354 |
$content = parse_template_value($r["content"], $domain, $webip, $mailip); |
|
355 |
$ttl = $r["ttl"]; |
|
356 |
$prio = intval($r["prio"]); |
13
|
357 |
|
82
|
358 |
if (!$ttl) { |
|
359 |
$ttl = $GLOBALS["DEFAULT_TTL"]; |
|
360 |
} |
1
|
361 |
|
106
|
362 |
$query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" |
82
|
363 |
. $db->quote($domain_id) . "," |
|
364 |
. $db->quote($name) . "," |
87
|
365 |
. $db->quote($type) . "," |
82
|
366 |
. $db->quote($content) . "," |
|
367 |
. $db->quote($ttl) . "," |
|
368 |
. $db->quote($prio) . "," |
|
369 |
. $db->quote($now) . ")"; |
|
370 |
$response = $db->query($query); |
|
371 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
13
|
372 |
} |
|
373 |
} |
82
|
374 |
return true; |
|
375 |
} else { |
|
376 |
error(sprintf(ERR_INV_ARGC, "add_domain", "could not create zone")); |
|
377 |
} |
|
378 |
} |
|
379 |
} else { |
|
380 |
error(sprintf(ERR_INV_ARG, "add_domain")); |
13
|
381 |
} |
82
|
382 |
} else { |
|
383 |
error(ERR_PERM_ADD_ZONE_MASTER); |
|
384 |
return false; |
1
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
|
|
389 |
/* |
|
390 |
* Deletes a domain by a given id. |
|
391 |
* Function always succeeds. If the field is not found in the database, thats what we want anyway. |
|
392 |
*/ |
|
393 |
function delete_domain($id) |
|
394 |
{ |
|
395 |
global $db; |
|
396 |
|
126
|
397 |
if (verify_permission('zone_content_edit_others')) { $perm_edit = "all" ; } |
|
398 |
elseif (verify_permission('zone_content_edit_own')) { $perm_edit = "own" ; } |
82
|
399 |
else { $perm_edit = "none" ; } |
|
400 |
$user_is_zone_owner = verify_user_is_owner_zoneid($id); |
1
|
401 |
|
82
|
402 |
if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) { |
|
403 |
if (is_numeric($id)) { |
|
404 |
$db->query("DELETE FROM zones WHERE domain_id=".$db->quote($id)); |
|
405 |
$db->query("DELETE FROM domains WHERE id=".$db->quote($id)); |
|
406 |
$db->query("DELETE FROM records WHERE domain_id=".$db->quote($id)); |
|
407 |
return true; |
|
408 |
} else { |
|
409 |
error(sprintf(ERR_INV_ARGC, "delete_domain", "id must be a number")); |
|
410 |
return false; |
|
411 |
} |
|
412 |
} else { |
|
413 |
error(ERR_PERM_DEL_ZONE); |
1
|
414 |
} |
|
415 |
} |
|
416 |
|
|
417 |
|
|
418 |
/* |
|
419 |
* Gets the id of the domain by a given record id. |
|
420 |
* return values: the domain id that was requested. |
|
421 |
*/ |
|
422 |
function recid_to_domid($id) |
|
423 |
{ |
|
424 |
global $db; |
|
425 |
if (is_numeric($id)) |
|
426 |
{ |
65
|
427 |
$result = $db->query("SELECT domain_id FROM records WHERE id=".$db->quote($id)); |
1
|
428 |
$r = $result->fetchRow(); |
|
429 |
return $r["domain_id"]; |
|
430 |
} |
|
431 |
else |
|
432 |
{ |
|
433 |
error(sprintf(ERR_INV_ARGC, "recid_to_domid", "id must be a number")); |
|
434 |
} |
|
435 |
} |
|
436 |
|
|
437 |
|
|
438 |
/* |
|
439 |
* Change owner of a domain. |
|
440 |
* return values: true when succesful. |
|
441 |
*/ |
82
|
442 |
function add_owner_to_zone($zone_id, $user_id) |
1
|
443 |
{ |
|
444 |
global $db; |
126
|
445 |
if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) { |
82
|
446 |
// User is allowed to make change to meta data of this zone. |
|
447 |
if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id)) |
1
|
448 |
{ |
82
|
449 |
if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)) == 0) |
|
450 |
{ |
|
451 |
$db->query("INSERT INTO zones (domain_id, owner) VALUES(".$db->quote($zone_id).", ".$db->quote($user_id).")"); |
|
452 |
} |
|
453 |
return true; |
|
454 |
} else { |
|
455 |
error(sprintf(ERR_INV_ARGC, "add_owner_to_zone", "$zone_id / $user_id")); |
1
|
456 |
} |
82
|
457 |
} else { |
|
458 |
return false; |
1
|
459 |
} |
|
460 |
} |
|
461 |
|
|
462 |
|
82
|
463 |
function delete_owner_from_zone($zone_id, $user_id) |
1
|
464 |
{ |
|
465 |
global $db; |
126
|
466 |
if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) { |
82
|
467 |
// User is allowed to make change to meta data of this zone. |
|
468 |
if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id)) |
|
469 |
{ |
|
470 |
// TODO: Next if() required, why not just execute DELETE query? |
|
471 |
if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)) != 0) |
|
472 |
{ |
|
473 |
$db->query("DELETE FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)); |
|
474 |
} |
|
475 |
return true; |
|
476 |
} else { |
|
477 |
error(sprintf(ERR_INV_ARGC, "delete_owner_from_zone", "$zone_id / $user_id")); |
|
478 |
} |
|
479 |
} else { |
|
480 |
return false; |
1
|
481 |
} |
82
|
482 |
|
1
|
483 |
} |
|
484 |
|
|
485 |
/* |
|
486 |
* Retrieves all supported dns record types |
|
487 |
* This function might be deprecated. |
|
488 |
* return values: array of types in string form. |
|
489 |
*/ |
|
490 |
function get_record_types() |
|
491 |
{ |
|
492 |
global $rtypes; |
|
493 |
return $rtypes; |
|
494 |
} |
|
495 |
|
|
496 |
|
|
497 |
/* |
|
498 |
* Retrieve all records by a given type and domain id. |
|
499 |
* Example: get all records that are of type A from domain id 1 |
|
500 |
* return values: a DB class result object |
|
501 |
*/ |
|
502 |
function get_records_by_type_from_domid($type, $recid) |
|
503 |
{ |
|
504 |
global $rtypes; |
|
505 |
global $db; |
|
506 |
|
|
507 |
// Does this type exist? |
|
508 |
if(!in_array(strtoupper($type), $rtypes)) |
|
509 |
{ |
|
510 |
error(sprintf(ERR_INV_ARGC, "get_records_from_type", "this is not a supported record")); |
|
511 |
} |
|
512 |
|
|
513 |
// Get the domain id. |
|
514 |
$domid = recid_to_domid($recid); |
|
515 |
|
65
|
516 |
$result = $db->query("select id, type from records where domain_id=".$db->quote($recid)." and type=".$db->quote($type)); |
1
|
517 |
return $result; |
|
518 |
} |
|
519 |
|
|
520 |
|
|
521 |
/* |
|
522 |
* Retrieves the type of a record from a given id. |
|
523 |
* return values: the type of the record (one of the records types in $rtypes assumable). |
|
524 |
*/ |
|
525 |
function get_recordtype_from_id($id) |
|
526 |
{ |
|
527 |
global $db; |
|
528 |
if (is_numeric($id)) |
|
529 |
{ |
65
|
530 |
$result = $db->query("SELECT type FROM records WHERE id=".$db->quote($id)); |
1
|
531 |
$r = $result->fetchRow(); |
|
532 |
return $r["type"]; |
|
533 |
} |
|
534 |
else |
|
535 |
{ |
|
536 |
error(sprintf(ERR_INV_ARG, "get_recordtype_from_id")); |
|
537 |
} |
|
538 |
} |
|
539 |
|
|
540 |
|
|
541 |
/* |
|
542 |
* Retrieves the name (e.g. bla.test.com) of a record by a given id. |
|
543 |
* return values: the name associated with the id. |
|
544 |
*/ |
|
545 |
function get_name_from_record_id($id) |
|
546 |
{ |
|
547 |
global $db; |
82
|
548 |
if (is_numeric($id)) { |
65
|
549 |
$result = $db->query("SELECT name FROM records WHERE id=".$db->quote($id)); |
1
|
550 |
$r = $result->fetchRow(); |
|
551 |
return $r["name"]; |
82
|
552 |
} else { |
1
|
553 |
error(sprintf(ERR_INV_ARG, "get_name_from_record_id")); |
|
554 |
} |
|
555 |
} |
|
556 |
|
|
557 |
|
|
558 |
/* |
|
559 |
* Get domain name from a given id |
|
560 |
* return values: the name of the domain associated with the id. |
|
561 |
*/ |
|
562 |
function get_domain_name_from_id($id) |
|
563 |
{ |
|
564 |
global $db; |
82
|
565 |
|
1
|
566 |
if (is_numeric($id)) |
|
567 |
{ |
65
|
568 |
$result = $db->query("SELECT name FROM domains WHERE id=".$db->quote($id)); |
82
|
569 |
$rows = $result->numRows() ; |
|
570 |
if ($rows == 1) { |
1
|
571 |
$r = $result->fetchRow(); |
|
572 |
return $r["name"]; |
82
|
573 |
} elseif ($rows == "0") { |
|
574 |
error(sprintf("Zone does not exist.")); |
|
575 |
return false; |
|
576 |
} else { |
1
|
577 |
error(sprintf(ERR_INV_ARGC, "get_domain_name_from_id", "more than one domain found?! whaaa! BAD! BAD! Contact admin!")); |
82
|
578 |
return false; |
1
|
579 |
} |
|
580 |
} |
|
581 |
else |
|
582 |
{ |
|
583 |
error(sprintf(ERR_INV_ARGC, "get_domain_name_from_id", "Not a valid domainid: $id")); |
|
584 |
} |
|
585 |
} |
|
586 |
|
82
|
587 |
function get_zone_info_from_id($zone_id) { |
1
|
588 |
|
126
|
589 |
if (verify_permission('zone_content_view_others')) { $perm_view = "all" ; } |
|
590 |
elseif (verify_permission('zone_content_view_own')) { $perm_view = "own" ; } |
82
|
591 |
else { $perm_view = "none" ;} |
1
|
592 |
|
82
|
593 |
if ($perm_view == "none") { |
|
594 |
error(ERR_PERM_VIEW_ZONE); |
|
595 |
} else { |
|
596 |
global $db; |
1
|
597 |
|
82
|
598 |
$query = "SELECT domains.type AS type, |
|
599 |
domains.name AS name, |
|
600 |
domains.master AS master_ip, |
|
601 |
count(records.domain_id) AS record_count |
|
602 |
FROM domains, records |
|
603 |
WHERE domains.id = " . $db->quote($zone_id) . " |
|
604 |
AND domains.id = records.domain_id |
|
605 |
GROUP BY domains.id"; |
88
|
606 |
$result = $db->query($query); |
|
607 |
if (PEAR::isError($result)) { error($result->getMessage()); return false; } |
1
|
608 |
|
88
|
609 |
if($result->numRows() != 1) { |
|
610 |
error(_('Function returned an error (multiple zones matching this zone ID).')); |
|
611 |
return false; |
|
612 |
} else { |
|
613 |
$r = $result->fetchRow(); |
|
614 |
$return = array( |
|
615 |
"name" => $r['name'], |
|
616 |
"type" => $r['type'], |
|
617 |
"master_ip" => $r['master_ip'], |
|
618 |
"record_count" => $r['record_count'] |
|
619 |
); |
|
620 |
} |
82
|
621 |
return $return; |
1
|
622 |
} |
|
623 |
} |
|
624 |
|
|
625 |
|
|
626 |
/* |
|
627 |
* Check if a domain is already existing. |
|
628 |
* return values: true if existing, false if it doesnt exist. |
|
629 |
*/ |
|
630 |
function domain_exists($domain) |
|
631 |
{ |
|
632 |
global $db; |
|
633 |
|
82
|
634 |
if (is_valid_domain($domain)) { |
65
|
635 |
$result = $db->query("SELECT id FROM domains WHERE name=".$db->quote($domain)); |
82
|
636 |
if ($result->numRows() == 0) { |
1
|
637 |
return false; |
82
|
638 |
} elseif ($result->numRows() >= 1) { |
1
|
639 |
return true; |
|
640 |
} |
82
|
641 |
} else { |
1
|
642 |
error(ERR_DOMAIN_INVALID); |
|
643 |
} |
|
644 |
} |
|
645 |
|
13
|
646 |
function get_supermasters() |
|
647 |
{ |
|
648 |
global $db; |
82
|
649 |
|
|
650 |
$result = $db->query("SELECT ip, nameserver, account FROM supermasters"); |
|
651 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
|
652 |
|
13
|
653 |
$ret = array(); |
|
654 |
|
82
|
655 |
if($result->numRows() == 0) { |
13
|
656 |
return -1; |
82
|
657 |
} else { |
|
658 |
while ($r = $result->fetchRow()) { |
13
|
659 |
$ret[] = array( |
|
660 |
"master_ip" => $r["ip"], |
|
661 |
"ns_name" => $r["nameserver"], |
|
662 |
"account" => $r["account"], |
|
663 |
); |
|
664 |
} |
36
|
665 |
return $ret; |
13
|
666 |
} |
|
667 |
} |
|
668 |
|
|
669 |
function supermaster_exists($master_ip) |
|
670 |
{ |
|
671 |
global $db; |
|
672 |
if (is_valid_ip($master_ip) || is_valid_ip6($master_ip)) |
|
673 |
{ |
65
|
674 |
$result = $db->query("SELECT ip FROM supermasters WHERE ip = ".$db->quote($master_ip)); |
13
|
675 |
if ($result->numRows() == 0) |
|
676 |
{ |
|
677 |
return false; |
|
678 |
} |
|
679 |
elseif ($result->numRows() >= 1) |
|
680 |
{ |
|
681 |
return true; |
|
682 |
} |
|
683 |
} |
|
684 |
else |
|
685 |
{ |
|
686 |
error(sprintf(ERR_INV_ARGC, "supermaster_exists", "No or no valid IPv4 or IPv6 address given.")); |
|
687 |
} |
|
688 |
} |
|
689 |
|
1
|
690 |
|
126
|
691 |
function get_zones($perm,$userid=0,$letterstart='all',$rowstart=0,$rowamount=999999) |
1
|
692 |
{ |
|
693 |
global $db; |
55
|
694 |
global $sql_regexp; |
126
|
695 |
$sql_add = ''; |
82
|
696 |
if ($perm != "own" && $perm != "all") { |
|
697 |
error(ERR_PERM_VIEW_ZONE); |
|
698 |
return false; |
1
|
699 |
} |
|
700 |
else |
|
701 |
{ |
82
|
702 |
if ($perm == "own") { |
|
703 |
$sql_add = " AND zones.domain_id = domains.id |
|
704 |
AND zones.owner = ".$db->quote($userid); |
|
705 |
} |
126
|
706 |
if ($letterstart!='all' && $letterstart!=1) { |
82
|
707 |
$sql_add .=" AND domains.name LIKE ".$db->quote($letterstart."%")." "; |
|
708 |
} elseif ($letterstart==1) { |
|
709 |
$sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'"; |
|
710 |
} |
1
|
711 |
} |
82
|
712 |
|
|
713 |
$sqlq = "SELECT domains.id, |
|
714 |
domains.name, |
|
715 |
domains.type, |
|
716 |
COUNT(DISTINCT records.id) AS count_records |
|
717 |
FROM domains |
|
718 |
LEFT JOIN zones ON domains.id=zones.domain_id |
|
719 |
LEFT JOIN records ON records.domain_id=domains.id |
|
720 |
WHERE 1=1".$sql_add." |
106
|
721 |
GROUP BY domains.name, domains.id, domains.type |
82
|
722 |
ORDER BY domains.name"; |
|
723 |
|
74
|
724 |
$db->setLimit($rowamount, $rowstart); |
1
|
725 |
$result = $db->query($sqlq); |
|
726 |
|
|
727 |
while($r = $result->fetchRow()) |
|
728 |
{ |
82
|
729 |
$ret[$r["name"]] = array( |
|
730 |
"id" => $r["id"], |
|
731 |
"name" => $r["name"], |
|
732 |
"type" => $r["type"], |
|
733 |
"count_records" => $r["count_records"] |
|
734 |
); |
1
|
735 |
} |
82
|
736 |
return $ret; |
1
|
737 |
} |
|
738 |
|
82
|
739 |
// TODO: letterstart limitation and userid permission limitiation should be applied at the same time? |
126
|
740 |
function zone_count_ng($perm, $letterstart='all') { |
82
|
741 |
global $db; |
55
|
742 |
global $sql_regexp; |
115
|
743 |
|
|
744 |
$fromTable = 'domains'; |
126
|
745 |
$sql_add = ''; |
115
|
746 |
|
82
|
747 |
if ($perm != "own" && $perm != "all") { |
|
748 |
$zone_count = "0"; |
|
749 |
} |
|
750 |
else |
|
751 |
{ |
|
752 |
if ($perm == "own") { |
|
753 |
$sql_add = " AND zones.domain_id = domains.id |
|
754 |
AND zones.owner = ".$db->quote($_SESSION['userid']); |
115
|
755 |
$fromTable .= ',zones'; |
82
|
756 |
} |
126
|
757 |
if ($letterstart!='all' && $letterstart!=1) { |
82
|
758 |
$sql_add .=" AND domains.name LIKE ".$db->quote($letterstart."%")." "; |
|
759 |
} elseif ($letterstart==1) { |
|
760 |
$sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'"; |
37
|
761 |
} |
|
762 |
|
82
|
763 |
$sqlq = "SELECT COUNT(distinct domains.id) AS count_zones |
115
|
764 |
FROM ".$fromTable." WHERE 1=1 |
82
|
765 |
".$sql_add.";"; |
|
766 |
|
|
767 |
$zone_count = $db->queryOne($sqlq); |
|
768 |
} |
|
769 |
return $zone_count; |
|
770 |
} |
30
|
771 |
|
82
|
772 |
function zone_count_for_uid($uid) { |
|
773 |
global $db; |
|
774 |
$query = "SELECT COUNT(domain_id) |
|
775 |
FROM zones |
|
776 |
WHERE owner = " . $db->quote($uid) . " |
|
777 |
ORDER BY domain_id"; |
|
778 |
$zone_count = $db->queryOne($query); |
|
779 |
return $zone_count; |
|
780 |
} |
30
|
781 |
|
|
782 |
|
|
783 |
/* |
1
|
784 |
* Get a record from an id. |
|
785 |
* Retrieve all fields of the record and send it back to the function caller. |
|
786 |
* return values: the array with information, or -1 is nothing is found. |
|
787 |
*/ |
|
788 |
function get_record_from_id($id) |
|
789 |
{ |
|
790 |
global $db; |
|
791 |
if (is_numeric($id)) |
|
792 |
{ |
65
|
793 |
$result = $db->query("SELECT id, domain_id, name, type, content, ttl, prio, change_date FROM records WHERE id=".$db->quote($id)); |
1
|
794 |
if($result->numRows() == 0) |
|
795 |
{ |
|
796 |
return -1; |
|
797 |
} |
|
798 |
elseif ($result->numRows() == 1) |
|
799 |
{ |
|
800 |
$r = $result->fetchRow(); |
|
801 |
$ret = array( |
82
|
802 |
"id" => $r["id"], |
|
803 |
"domain_id" => $r["domain_id"], |
|
804 |
"name" => $r["name"], |
|
805 |
"type" => $r["type"], |
|
806 |
"content" => $r["content"], |
|
807 |
"ttl" => $r["ttl"], |
|
808 |
"prio" => $r["prio"], |
|
809 |
"change_date" => $r["change_date"] |
|
810 |
); |
1
|
811 |
return $ret; |
|
812 |
} |
|
813 |
else |
|
814 |
{ |
|
815 |
error(sprintf(ERR_INV_ARGC, "get_record_from_id", "More than one row returned! This is bad!")); |
|
816 |
} |
|
817 |
} |
|
818 |
else |
|
819 |
{ |
|
820 |
error(sprintf(ERR_INV_ARG, "get_record_from_id")); |
|
821 |
} |
|
822 |
} |
|
823 |
|
|
824 |
|
|
825 |
/* |
|
826 |
* Get all records from a domain id. |
|
827 |
* Retrieve all fields of the records and send it back to the function caller. |
|
828 |
* return values: the array with information, or -1 is nothing is found. |
|
829 |
*/ |
82
|
830 |
function get_records_from_domain_id($id,$rowstart=0,$rowamount=999999) { |
1
|
831 |
global $db; |
82
|
832 |
if (is_numeric($id)) { |
126
|
833 |
if ((isset($_SESSION[$id."_ispartial"])) && ($_SESSION[$id."_ispartial"] == 1)) { |
82
|
834 |
$db->setLimit($rowamount, $rowstart); |
|
835 |
$result = $db->query("SELECT record_owners.record_id as id |
|
836 |
FROM record_owners,domains,records |
|
837 |
WHERE record_owners.user_id = " . $db->quote($_SESSION["userid"]) . " |
|
838 |
AND record_owners.record_id = records.id |
|
839 |
AND records.domain_id = " . $db->quote($id) . " |
|
840 |
GROUP BY record_owners.record_id"); |
1
|
841 |
|
82
|
842 |
$ret = array(); |
|
843 |
if($result->numRows() == 0) { |
|
844 |
return -1; |
|
845 |
} else { |
|
846 |
$ret[] = array(); |
|
847 |
$retcount = 0; |
|
848 |
while($r = $result->fetchRow()) |
|
849 |
{ |
|
850 |
// Call get_record_from_id for each row. |
|
851 |
$ret[$retcount] = get_record_from_id($r["id"]); |
|
852 |
$retcount++; |
|
853 |
} |
|
854 |
return $ret; |
|
855 |
} |
1
|
856 |
|
|
857 |
} else { |
82
|
858 |
$db->setLimit($rowamount, $rowstart); |
|
859 |
$result = $db->query("SELECT id FROM records WHERE domain_id=".$db->quote($id)); |
|
860 |
$ret = array(); |
|
861 |
if($result->numRows() == 0) |
|
862 |
{ |
|
863 |
return -1; |
|
864 |
} |
|
865 |
else |
1
|
866 |
{ |
82
|
867 |
$ret[] = array(); |
|
868 |
$retcount = 0; |
|
869 |
while($r = $result->fetchRow()) |
|
870 |
{ |
|
871 |
// Call get_record_from_id for each row. |
|
872 |
$ret[$retcount] = get_record_from_id($r["id"]); |
|
873 |
$retcount++; |
|
874 |
} |
|
875 |
return $ret; |
1
|
876 |
} |
|
877 |
|
|
878 |
} |
|
879 |
} |
|
880 |
else |
|
881 |
{ |
|
882 |
error(sprintf(ERR_INV_ARG, "get_records_from_domain_id")); |
|
883 |
} |
|
884 |
} |
|
885 |
|
|
886 |
|
82
|
887 |
function get_users_from_domain_id($id) { |
1
|
888 |
global $db; |
82
|
889 |
$sqlq = "SELECT owner FROM zones WHERE domain_id =" .$db->quote($id); |
|
890 |
$id_owners = $db->query($sqlq); |
|
891 |
if ($id_owners->numRows() == 0) { |
|
892 |
return -1; |
|
893 |
} else { |
|
894 |
while ($r = $id_owners->fetchRow()) { |
|
895 |
$fullname = $db->queryOne("SELECT fullname FROM users WHERE id=".$r['owner']); |
|
896 |
$owners[] = array( |
|
897 |
"id" => $r['owner'], |
|
898 |
"fullname" => $fullname |
|
899 |
); |
|
900 |
} |
1
|
901 |
} |
82
|
902 |
return $owners; |
1
|
903 |
} |
|
904 |
|
82
|
905 |
|
|
906 |
function search_zone_and_record($holy_grail,$perm) { |
|
907 |
|
1
|
908 |
global $db; |
82
|
909 |
|
|
910 |
$holy_grail = trim($holy_grail); |
|
911 |
|
126
|
912 |
$sql_add_from = ''; |
|
913 |
$sql_add_where = ''; |
|
914 |
|
|
915 |
$return_zones = array(); |
|
916 |
$return_records = array(); |
|
917 |
|
|
918 |
if (verify_permission('zone_content_view_others')) { $perm_view = "all" ; } |
|
919 |
elseif (verify_permission('zone_content_view_own')) { $perm_view = "own" ; } |
82
|
920 |
else { $perm_view = "none" ; } |
|
921 |
|
126
|
922 |
if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; } |
|
923 |
elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; } |
82
|
924 |
else { $perm_content_edit = "none" ; } |
|
925 |
|
|
926 |
// Search for matching domains |
|
927 |
if ($perm == "own") { |
|
928 |
$sql_add_from = ", zones "; |
|
929 |
$sql_add_where = " AND zones.domain_id = domains.id AND zones.owner = " . $db->quote($userid); |
|
930 |
} |
|
931 |
|
|
932 |
$query = "SELECT |
|
933 |
domains.id AS zid, |
|
934 |
domains.name AS name, |
|
935 |
domains.type AS type, |
|
936 |
domains.master AS master |
|
937 |
FROM domains" . $sql_add_from . " |
|
938 |
WHERE domains.name LIKE " . $db->quote($holy_grail) |
|
939 |
. $sql_add_where ; |
|
940 |
|
|
941 |
$response = $db->query($query); |
|
942 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
62
|
943 |
|
82
|
944 |
while ($r = $response->fetchRow()) { |
|
945 |
$return_zones[] = array( |
|
946 |
"zid" => $r['zid'], |
|
947 |
"name" => $r['name'], |
|
948 |
"type" => $r['type'], |
|
949 |
"master" => $r['master']); |
1
|
950 |
} |
|
951 |
|
82
|
952 |
// Search for matching records |
|
953 |
|
|
954 |
if ($perm == "own") { |
|
955 |
$sql_add_from = ", zones "; |
|
956 |
$sql_add_where = " AND zones.domain_id = record.id AND zones.owner = " . $db->quote($userid); |
|
957 |
} |
|
958 |
|
|
959 |
$query = "SELECT |
|
960 |
records.id AS rid, |
|
961 |
records.name AS name, |
|
962 |
records.type AS type, |
|
963 |
records.content AS content, |
|
964 |
records.ttl AS ttl, |
|
965 |
records.prio AS prio, |
|
966 |
records.domain_id AS zid |
|
967 |
FROM records" . $sql_add_from . " |
|
968 |
WHERE (records.name LIKE " . $db->quote($holy_grail) . " OR records.content LIKE " . $db->quote($holy_grail) . ")" |
|
969 |
. $sql_add_where ; |
|
970 |
|
|
971 |
$response = $db->query($query); |
|
972 |
if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
|
973 |
|
|
974 |
while ($r = $response->fetchRow()) { |
|
975 |
$return_records[] = array( |
|
976 |
"rid" => $r['rid'], |
|
977 |
"name" => $r['name'], |
|
978 |
"type" => $r['type'], |
|
979 |
"content" => $r['content'], |
|
980 |
"ttl" => $r['ttl'], |
|
981 |
"zid" => $r['zid'], |
|
982 |
"prio" => $r['prio']); |
|
983 |
} |
|
984 |
return array('zones' => $return_zones, 'records' => $return_records); |
1
|
985 |
} |
|
986 |
|
82
|
987 |
function get_domain_type($id) { |
1
|
988 |
global $db; |
82
|
989 |
if (is_numeric($id)) { |
65
|
990 |
$type = $db->queryOne("SELECT type FROM domains WHERE id = ".$db->quote($id)); |
82
|
991 |
if ($type == "") { |
13
|
992 |
$type = "NATIVE"; |
|
993 |
} |
|
994 |
return $type; |
82
|
995 |
} else { |
13
|
996 |
error(sprintf(ERR_INV_ARG, "get_record_from_id", "no or no valid zoneid given")); |
|
997 |
} |
|
998 |
} |
|
999 |
|
82
|
1000 |
function get_domain_slave_master($id){ |
13
|
1001 |
global $db; |
82
|
1002 |
if (is_numeric($id)) { |
65
|
1003 |
$slave_master = $db->queryOne("SELECT master FROM domains WHERE type = 'SLAVE' and id = ".$db->quote($id)); |
13
|
1004 |
return $slave_master; |
82
|
1005 |
} else { |
13
|
1006 |
error(sprintf(ERR_INV_ARG, "get_domain_slave_master", "no or no valid zoneid given")); |
|
1007 |
} |
1
|
1008 |
} |
|
1009 |
|
82
|
1010 |
function change_zone_type($type, $id) |
1
|
1011 |
{ |
13
|
1012 |
global $db; |
79
|
1013 |
$add = ''; |
13
|
1014 |
if (is_numeric($id)) |
|
1015 |
{ |
82
|
1016 |
// It is not really neccesary to clear the field that contains the IP address |
|
1017 |
// of the master if the type changes from slave to something else. PowerDNS will |
|
1018 |
// ignore the field if the type isn't something else then slave. But then again, |
|
1019 |
// it's much clearer this way. |
|
1020 |
if ($type != "SLAVE") { |
13
|
1021 |
$add = ", master=''"; |
|
1022 |
} |
82
|
1023 |
$result = $db->query("UPDATE domains SET type = " . $db->quote($type) . $add . " WHERE id = ".$db->quote($id)); |
|
1024 |
} else { |
13
|
1025 |
error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
|
1026 |
} |
|
1027 |
} |
|
1028 |
|
82
|
1029 |
function change_zone_slave_master($zone_id, $ip_slave_master) { |
13
|
1030 |
global $db; |
82
|
1031 |
if (is_numeric($zone_id)) { |
|
1032 |
if (is_valid_ip($ip_slave_master) || is_valid_ip6($ip_slave_master)) { |
|
1033 |
$result = $db->query("UPDATE domains SET master = " .$db->quote($ip_slave_master). " WHERE id = ".$db->quote($zone_id)); |
|
1034 |
} else { |
|
1035 |
error(sprintf(ERR_INV_ARGC, "change_domain_ip_slave_master", "This is not a valid IPv4 or IPv6 address: $ip_slave_master")); |
13
|
1036 |
} |
82
|
1037 |
} else { |
13
|
1038 |
error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
|
1039 |
} |
|
1040 |
} |
|
1041 |
|
|
1042 |
|
82
|
1043 |
function validate_account($account) { |
|
1044 |
if(preg_match("/^[A-Z0-9._-]+$/i",$account)) { |
13
|
1045 |
return true; |
82
|
1046 |
} else { |
13
|
1047 |
return false; |
|
1048 |
} |
1
|
1049 |
} |
82
|
1050 |
|
|
1051 |
|
1
|
1052 |
?> |