19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 */ |
20 */ |
21 |
21 |
22 function zone_id_exists($zid) { |
22 function zone_id_exists($zid) { |
23 global $db; |
23 global $db; |
24 $query = "SELECT COUNT(id) FROM domains WHERE id = " . $db->quote($zid); |
24 $query = "SELECT COUNT(id) FROM domains WHERE id = " . $db->quote($zid, 'integer'); |
25 $count = $db->queryOne($query); |
25 $count = $db->queryOne($query); |
26 if (PEAR::isError($count)) { error($result->getMessage()); return false; } |
26 if (PEAR::isError($count)) { error($result->getMessage()); return false; } |
27 return $count; |
27 return $count; |
28 } |
28 } |
29 |
29 |
30 |
30 |
31 function get_zone_id_from_record_id($rid) { |
31 function get_zone_id_from_record_id($rid) { |
32 global $db; |
32 global $db; |
33 $query = "SELECT domain_id FROM records WHERE id = " . $db->quote($rid); |
33 $query = "SELECT domain_id FROM records WHERE id = " . $db->quote($rid, 'integer'); |
34 $zid = $db->queryOne($query); |
34 $zid = $db->queryOne($query); |
35 return $zid; |
35 return $zid; |
36 } |
36 } |
37 |
37 |
38 function count_zone_records($zone_id) { |
38 function count_zone_records($zone_id) { |
39 global $db; |
39 global $db; |
40 $sqlq = "SELECT COUNT(id) FROM records WHERE domain_id = ".$db->quote($zone_id); |
40 $sqlq = "SELECT COUNT(id) FROM records WHERE domain_id = ".$db->quote($zone_id, 'integer'); |
41 $record_count = $db->queryOne($sqlq); |
41 $record_count = $db->queryOne($sqlq); |
42 return $record_count; |
42 return $record_count; |
43 } |
43 } |
44 |
44 |
45 function update_soa_serial($domain_id) |
45 function update_soa_serial($domain_id) |
46 { |
46 { |
47 global $db; |
47 global $db; |
48 |
48 |
49 $sqlq = "SELECT notified_serial FROM domains WHERE id = ".$db->quote($domain_id); |
49 $sqlq = "SELECT notified_serial FROM domains WHERE id = ".$db->quote($domain_id, 'integer'); |
50 $notified_serial = $db->queryOne($sqlq); |
50 $notified_serial = $db->queryOne($sqlq); |
51 |
51 |
52 $sqlq = "SELECT content FROM records WHERE type = 'SOA' AND domain_id = ".$db->quote($domain_id); |
52 $sqlq = "SELECT content FROM records WHERE type = ".$db->quote('SOA', 'text')." AND domain_id = ".$db->quote($domain_id, 'integer'); |
53 $content = $db->queryOne($sqlq); |
53 $content = $db->queryOne($sqlq); |
54 $need_to_update = false; |
54 $need_to_update = false; |
55 |
55 |
56 // Getting the serial field. |
56 // Getting the serial field. |
57 $soa = explode(" ", $content); |
57 $soa = explode(" ", $content); |
121 global $db; |
121 global $db; |
122 // TODO: no need to check for numeric-ness of zone id if we check with validate_input as well? |
122 // TODO: no need to check for numeric-ness of zone id if we check with validate_input as well? |
123 if (is_numeric($record['zid'])) { |
123 if (is_numeric($record['zid'])) { |
124 if (validate_input($record['zid'], $record['type'], $record['content'], $record['name'], $record['prio'], $record['ttl'])) { |
124 if (validate_input($record['zid'], $record['type'], $record['content'], $record['name'], $record['prio'], $record['ttl'])) { |
125 $query = "UPDATE records |
125 $query = "UPDATE records |
126 SET name=".$db->quote($record['name']).", |
126 SET name=".$db->quote($record['name'], 'text').", |
127 type=".$db->quote($record['type']).", |
127 type=".$db->quote($record['type'], 'text').", |
128 content='" . $record['content'] . "', |
128 content=" . $db->quote($record['content'], 'text') . ", |
129 ttl=".$db->quote($record['ttl']).", |
129 ttl=".$db->quote($record['ttl'], 'integer').", |
130 prio=".$db->quote($record['prio'], 'integer').", |
130 prio=".$db->quote($record['prio'], 'integer').", |
131 change_date=".$db->quote(time())." |
131 change_date=".$db->quote(time(), 'integer')." |
132 WHERE id=".$db->quote($record['rid']); |
132 WHERE id=".$db->quote($record['rid'], 'integer'); |
133 $result = $db->Query($query); |
133 $result = $db->Query($query); |
134 if (PEAR::isError($result)) { |
134 if (PEAR::isError($result)) { |
135 error($result->getMessage()); |
135 error($result->getMessage()); |
136 return false; |
136 return false; |
137 } elseif ($record['type'] != 'SOA') { |
137 } elseif ($record['type'] != 'SOA') { |
171 return false; |
171 return false; |
172 } else { |
172 } else { |
173 if (validate_input($zoneid, $type, $content, $name, $prio, $ttl) ) { |
173 if (validate_input($zoneid, $type, $content, $name, $prio, $ttl) ) { |
174 $change = time(); |
174 $change = time(); |
175 $query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" |
175 $query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" |
176 . $db->quote($zoneid) . "," |
176 . $db->quote($zoneid, 'integer') . "," |
177 . $db->quote($name) . "," |
177 . $db->quote($name, 'text') . "," |
178 . $db->quote($type) . "," |
178 . $db->quote($type, 'text') . "," |
179 . $db->quote($content) . "," |
179 . $db->quote($content, 'text') . "," |
180 . $db->quote($ttl) . "," |
180 . $db->quote($ttl, 'integer') . "," |
181 . $db->quote($prio, 'integer') . "," |
181 . $db->quote($prio, 'integer') . "," |
182 . $db->quote($change) . ")"; |
182 . $db->quote($change, 'integer') . ")"; |
183 $response = $db->query($query); |
183 $response = $db->query($query); |
184 if (PEAR::isError($response)) { |
184 if (PEAR::isError($response)) { |
185 error($response->getMessage()); |
185 error($response->getMessage()); |
186 return false; |
186 return false; |
187 } else { |
187 } else { |
213 } |
213 } |
214 if (supermaster_exists($master_ip)) { |
214 if (supermaster_exists($master_ip)) { |
215 error(ERR_SM_EXISTS); |
215 error(ERR_SM_EXISTS); |
216 return false; |
216 return false; |
217 } else { |
217 } else { |
218 $db->query("INSERT INTO supermasters VALUES (".$db->quote($master_ip).", ".$db->quote($ns_name).", ".$db->quote($account).")"); |
218 $db->query("INSERT INTO supermasters VALUES (".$db->quote($master_ip, 'text').", ".$db->quote($ns_name, 'text').", ".$db->quote($account, 'text').")"); |
219 return true; |
219 return true; |
220 } |
220 } |
221 } |
221 } |
222 |
222 |
223 function delete_supermaster($master_ip) { |
223 function delete_supermaster($master_ip) { |
224 global $db; |
224 global $db; |
225 if (is_valid_ipv4($master_ip) || is_valid_ipv6($master_ip)) |
225 if (is_valid_ipv4($master_ip) || is_valid_ipv6($master_ip)) |
226 { |
226 { |
227 $db->query("DELETE FROM supermasters WHERE ip = ".$db->quote($master_ip)); |
227 $db->query("DELETE FROM supermasters WHERE ip = ".$db->quote($master_ip, 'text')); |
228 return true; |
228 return true; |
229 } |
229 } |
230 else |
230 else |
231 { |
231 { |
232 error(sprintf(ERR_INV_ARGC, "delete_supermaster", "No or no valid ipv4 or ipv6 address given.")); |
232 error(sprintf(ERR_INV_ARGC, "delete_supermaster", "No or no valid ipv4 or ipv6 address given.")); |
236 function get_supermaster_info_from_ip($master_ip) |
236 function get_supermaster_info_from_ip($master_ip) |
237 { |
237 { |
238 global $db; |
238 global $db; |
239 if (is_valid_ipv4($master_ip) || is_valid_ipv6($master_ip)) |
239 if (is_valid_ipv4($master_ip) || is_valid_ipv6($master_ip)) |
240 { |
240 { |
241 $result = $db->queryRow("SELECT ip,nameserver,account FROM supermasters WHERE ip = ".$db->quote($master_ip)); |
241 $result = $db->queryRow("SELECT ip,nameserver,account FROM supermasters WHERE ip = ".$db->quote($master_ip, 'text')); |
242 |
242 |
243 $ret = array( |
243 $ret = array( |
244 "master_ip" => $result["ip"], |
244 "master_ip" => $result["ip"], |
245 "ns_name" => $result["nameserver"], |
245 "ns_name" => $result["nameserver"], |
246 "account" => $result["account"] |
246 "account" => $result["account"] |
256 |
256 |
257 function get_record_details_from_record_id($rid) { |
257 function get_record_details_from_record_id($rid) { |
258 |
258 |
259 global $db; |
259 global $db; |
260 |
260 |
261 $query = "SELECT id AS rid, domain_id AS zid, name, type, content, ttl, prio, change_date FROM records WHERE id = " . $db->quote($rid) ; |
261 $query = "SELECT id AS rid, domain_id AS zid, name, type, content, ttl, prio, change_date FROM records WHERE id = " . $db->quote($rid, 'integer') ; |
262 |
262 |
263 $response = $db->query($query); |
263 $response = $db->query($query); |
264 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
264 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
265 |
265 |
266 $return = $response->fetchRow(); |
266 $return = $response->fetchRow(); |
285 |
285 |
286 if ( $perm_content_edit == "all" || ($perm_content_edit == "own" && $user_is_zone_owner == "0" )) { |
286 if ( $perm_content_edit == "all" || ($perm_content_edit == "own" && $user_is_zone_owner == "0" )) { |
287 if ($record['type'] == "SOA") { |
287 if ($record['type'] == "SOA") { |
288 error(_('You are trying to delete the SOA record. If are not allowed to remove it, unless you remove the entire zone.')); |
288 error(_('You are trying to delete the SOA record. If are not allowed to remove it, unless you remove the entire zone.')); |
289 } else { |
289 } else { |
290 $query = "DELETE FROM records WHERE id = " . $db->quote($rid); |
290 $query = "DELETE FROM records WHERE id = " . $db->quote($rid, 'integer'); |
291 $response = $db->query($query); |
291 $response = $db->query($query); |
292 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
292 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
293 return true; |
293 return true; |
294 } |
294 } |
295 } else { |
295 } else { |
325 if (($domain && $owner && $webip && $mailip) || |
325 if (($domain && $owner && $webip && $mailip) || |
326 ($empty && $owner && $domain) || |
326 ($empty && $owner && $domain) || |
327 (eregi('in-addr.arpa', $domain) && $owner) || |
327 (eregi('in-addr.arpa', $domain) && $owner) || |
328 $type=="SLAVE" && $domain && $owner && $slave_master) { |
328 $type=="SLAVE" && $domain && $owner && $slave_master) { |
329 |
329 |
330 $response = $db->query("INSERT INTO domains (name, type) VALUES (".$db->quote($domain).", ".$db->quote($type).")"); |
330 $response = $db->query("INSERT INTO domains (name, type) VALUES (".$db->quote($domain, 'text').", ".$db->quote($type, 'text').")"); |
331 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
331 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
332 |
332 |
333 $domain_id = $db->lastInsertId('domains', 'id'); |
333 $domain_id = $db->lastInsertId('domains', 'id'); |
334 if (PEAR::isError($domain_id)) { error($id->getMessage()); return false; } |
334 if (PEAR::isError($domain_id)) { error($id->getMessage()); return false; } |
335 |
335 |
336 $response = $db->query("INSERT INTO zones (domain_id, owner) VALUES (".$db->quote($domain_id).", ".$db->quote($owner).")"); |
336 $response = $db->query("INSERT INTO zones (domain_id, owner) VALUES (".$db->quote($domain_id, 'integer').", ".$db->quote($owner, 'integer').")"); |
337 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
337 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
338 |
338 |
339 if ($type == "SLAVE") { |
339 if ($type == "SLAVE") { |
340 $response = $db->query("UPDATE domains SET master = ".$db->quote($slave_master)." WHERE id = ".$db->quote($domain_id)); |
340 $response = $db->query("UPDATE domains SET master = ".$db->quote($slave_master, 'text')." WHERE id = ".$db->quote($domain_id, 'integer')); |
341 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
341 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
342 return true; |
342 return true; |
343 } else { |
343 } else { |
344 $now = time(); |
344 $now = time(); |
345 if ($empty && $domain_id) { |
345 if ($empty && $domain_id) { |
346 $ns1 = $dns_ns1; |
346 $ns1 = $dns_ns1; |
347 $hm = $dns_hostmaster; |
347 $hm = $dns_hostmaster; |
348 $ttl = $dns_ttl; |
348 $ttl = $dns_ttl; |
349 |
349 |
350 $query = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (" |
350 $query = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (" |
351 . $db->quote($domain_id) . "," |
351 . $db->quote($domain_id, 'integer') . "," |
352 . $db->quote($domain) . "," |
352 . $db->quote($domain, 'text') . "," |
353 . $db->quote($ns1.' '.$hm.' 1') . "," |
353 . $db->quote($ns1.' '.$hm.' 1', 'text') . "," |
354 . $db->quote('SOA')."," |
354 . $db->quote('SOA', 'text')."," |
355 . $db->quote($ttl) |
355 . $db->quote($ttl, 'integer')."," |
356 . ", 0, " |
356 . $db->quote(0, 'integer'). "," |
357 . $db->quote($now).")"; |
357 . $db->quote($now, 'integer').")"; |
358 $response = $db->query($query); |
358 $response = $db->query($query); |
359 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
359 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
360 } elseif ($domain_id) { |
360 } elseif ($domain_id) { |
361 global $template; |
361 global $template; |
362 global $dns_ttl; |
362 global $dns_ttl; |
373 if (!$ttl) { |
373 if (!$ttl) { |
374 $ttl = $dns_ttl; |
374 $ttl = $dns_ttl; |
375 } |
375 } |
376 |
376 |
377 $query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" |
377 $query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" |
378 . $db->quote($domain_id) . "," |
378 . $db->quote($domain_id, 'integer') . "," |
379 . $db->quote($name) . "," |
379 . $db->quote($name, 'text') . "," |
380 . $db->quote($type) . "," |
380 . $db->quote($type, 'text') . "," |
381 . $db->quote($content) . "," |
381 . $db->quote($content, 'text') . "," |
382 . $db->quote($ttl) . "," |
382 . $db->quote($ttl, 'integer') . "," |
383 . $db->quote($prio, 'integer') . "," |
383 . $db->quote($prio, 'integer') . "," |
384 . $db->quote($now) . ")"; |
384 . $db->quote($now, 'integer') . ")"; |
385 $response = $db->query($query); |
385 $response = $db->query($query); |
386 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
386 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
387 } |
387 } |
388 } |
388 } |
389 return true; |
389 return true; |
414 else { $perm_edit = "none" ; } |
414 else { $perm_edit = "none" ; } |
415 $user_is_zone_owner = verify_user_is_owner_zoneid($id); |
415 $user_is_zone_owner = verify_user_is_owner_zoneid($id); |
416 |
416 |
417 if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) { |
417 if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) { |
418 if (is_numeric($id)) { |
418 if (is_numeric($id)) { |
419 $db->query("DELETE FROM zones WHERE domain_id=".$db->quote($id)); |
419 $db->query("DELETE FROM zones WHERE domain_id=".$db->quote($id, 'integer')); |
420 $db->query("DELETE FROM domains WHERE id=".$db->quote($id)); |
420 $db->query("DELETE FROM domains WHERE id=".$db->quote($id, 'integer')); |
421 $db->query("DELETE FROM records WHERE domain_id=".$db->quote($id)); |
421 $db->query("DELETE FROM records WHERE domain_id=".$db->quote($id, 'integer')); |
422 return true; |
422 return true; |
423 } else { |
423 } else { |
424 error(sprintf(ERR_INV_ARGC, "delete_domain", "id must be a number")); |
424 error(sprintf(ERR_INV_ARGC, "delete_domain", "id must be a number")); |
425 return false; |
425 return false; |
426 } |
426 } |
459 global $db; |
459 global $db; |
460 if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) { |
460 if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) { |
461 // User is allowed to make change to meta data of this zone. |
461 // User is allowed to make change to meta data of this zone. |
462 if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id)) |
462 if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id)) |
463 { |
463 { |
464 if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)) == 0) |
464 if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id, 'integer')." AND domain_id=".$db->quote($zone_id, 'integer')) == 0) |
465 { |
465 { |
466 $db->query("INSERT INTO zones (domain_id, owner) VALUES(".$db->quote($zone_id).", ".$db->quote($user_id).")"); |
466 $db->query("INSERT INTO zones (domain_id, owner) VALUES(".$db->quote($zone_id, 'integer').", ".$db->quote($user_id, 'integer').")"); |
467 } |
467 } |
468 return true; |
468 return true; |
469 } else { |
469 } else { |
470 error(sprintf(ERR_INV_ARGC, "add_owner_to_zone", "$zone_id / $user_id")); |
470 error(sprintf(ERR_INV_ARGC, "add_owner_to_zone", "$zone_id / $user_id")); |
471 } |
471 } |
481 if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) { |
481 if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) { |
482 // User is allowed to make change to meta data of this zone. |
482 // User is allowed to make change to meta data of this zone. |
483 if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id)) |
483 if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id)) |
484 { |
484 { |
485 // TODO: Next if() required, why not just execute DELETE query? |
485 // TODO: Next if() required, why not just execute DELETE query? |
486 if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)) != 0) |
486 if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id, 'integer')." AND domain_id=".$db->quote($zone_id, 'integer')) != 0) |
487 { |
487 { |
488 $db->query("DELETE FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)); |
488 $db->query("DELETE FROM zones WHERE owner=".$db->quote($user_id, 'integer')." AND domain_id=".$db->quote($zone_id, 'integer')); |
489 } |
489 } |
490 return true; |
490 return true; |
491 } else { |
491 } else { |
492 error(sprintf(ERR_INV_ARGC, "delete_owner_from_zone", "$zone_id / $user_id")); |
492 error(sprintf(ERR_INV_ARGC, "delete_owner_from_zone", "$zone_id / $user_id")); |
493 } |
493 } |
609 $query = "SELECT domains.type AS type, |
609 $query = "SELECT domains.type AS type, |
610 domains.name AS name, |
610 domains.name AS name, |
611 domains.master AS master_ip, |
611 domains.master AS master_ip, |
612 count(records.domain_id) AS record_count |
612 count(records.domain_id) AS record_count |
613 FROM domains LEFT OUTER JOIN records ON domains.id = records.domain_id |
613 FROM domains LEFT OUTER JOIN records ON domains.id = records.domain_id |
614 WHERE domains.id = " . $db->quote($zid) . " |
614 WHERE domains.id = " . $db->quote($zid, 'integer') . " |
615 GROUP BY domains.id, domains.type, domains.name, domains.master"; |
615 GROUP BY domains.id, domains.type, domains.name, domains.master"; |
616 $result = $db->query($query); |
616 $result = $db->query($query); |
617 if (PEAR::isError($result)) { error($result->getMessage()); return false; } |
617 if (PEAR::isError($result)) { error($result->getMessage()); return false; } |
618 |
618 |
619 if($result->numRows() != 1) { |
619 if($result->numRows() != 1) { |
709 } |
709 } |
710 else |
710 else |
711 { |
711 { |
712 if ($perm == "own") { |
712 if ($perm == "own") { |
713 $sql_add = " AND zones.domain_id = domains.id |
713 $sql_add = " AND zones.domain_id = domains.id |
714 AND zones.owner = ".$db->quote($userid); |
714 AND zones.owner = ".$db->quote($userid, 'integer'); |
715 } |
715 } |
716 if ($letterstart!='all' && $letterstart!=1) { |
716 if ($letterstart!='all' && $letterstart!=1) { |
717 $sql_add .=" AND domains.name LIKE ".$db->quote($letterstart."%")." "; |
717 $sql_add .=" AND domains.name LIKE ".$db->quote($db->quote($letterstart, 'text', false, true)."%", 'text')." "; |
718 } elseif ($letterstart==1) { |
718 } elseif ($letterstart==1) { |
719 $sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'"; |
719 $sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'"; |
720 } |
720 } |
721 } |
721 } |
722 |
722 |
759 } |
759 } |
760 else |
760 else |
761 { |
761 { |
762 if ($perm == "own") { |
762 if ($perm == "own") { |
763 $sql_add = " AND zones.domain_id = domains.id |
763 $sql_add = " AND zones.domain_id = domains.id |
764 AND zones.owner = ".$db->quote($_SESSION['userid']); |
764 AND zones.owner = ".$db->quote($_SESSION['userid'], 'integer'); |
765 $fromTable .= ',zones'; |
765 $fromTable .= ',zones'; |
766 } |
766 } |
767 if ($letterstart!='all' && $letterstart!=1) { |
767 if ($letterstart!='all' && $letterstart!=1) { |
768 $sql_add .=" AND domains.name LIKE ".$db->quote($letterstart."%")." "; |
768 $sql_add .=" AND domains.name LIKE ".$db->quote($db->quote($letterstart, 'text', false, true)."%", 'text')." "; |
769 } elseif ($letterstart==1) { |
769 } elseif ($letterstart==1) { |
770 $sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'"; |
770 $sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'"; |
771 } |
771 } |
772 |
772 |
773 $sqlq = "SELECT COUNT(distinct domains.id) AS count_zones |
773 $sqlq = "SELECT COUNT(distinct domains.id) AS count_zones |
842 if (is_numeric($id)) { |
842 if (is_numeric($id)) { |
843 if ((isset($_SESSION[$id."_ispartial"])) && ($_SESSION[$id."_ispartial"] == 1)) { |
843 if ((isset($_SESSION[$id."_ispartial"])) && ($_SESSION[$id."_ispartial"] == 1)) { |
844 $db->setLimit($rowamount, $rowstart); |
844 $db->setLimit($rowamount, $rowstart); |
845 $result = $db->query("SELECT record_owners.record_id as id |
845 $result = $db->query("SELECT record_owners.record_id as id |
846 FROM record_owners,domains,records |
846 FROM record_owners,domains,records |
847 WHERE record_owners.user_id = " . $db->quote($_SESSION["userid"]) . " |
847 WHERE record_owners.user_id = " . $db->quote($_SESSION["userid"], 'integer') . " |
848 AND record_owners.record_id = records.id |
848 AND record_owners.record_id = records.id |
849 AND records.domain_id = " . $db->quote($id) . " |
849 AND records.domain_id = " . $db->quote($id, 'integer') . " |
850 GROUP BY record_owners.record_id"); |
850 GROUP BY record_owners.record_id"); |
851 |
851 |
852 $ret = array(); |
852 $ret = array(); |
853 if($result->numRows() == 0) { |
853 if($result->numRows() == 0) { |
854 return -1; |
854 return -1; |
934 else { $perm_content_edit = "none" ; } |
934 else { $perm_content_edit = "none" ; } |
935 |
935 |
936 // Search for matching domains |
936 // Search for matching domains |
937 if ($perm == "own") { |
937 if ($perm == "own") { |
938 $sql_add_from = ", zones "; |
938 $sql_add_from = ", zones "; |
939 $sql_add_where = " AND zones.domain_id = domains.id AND zones.owner = " . $db->quote($_SESSION['userid']); |
939 $sql_add_where = " AND zones.domain_id = domains.id AND zones.owner = " . $db->quote($_SESSION['userid'], 'integer'); |
940 } |
940 } |
941 |
941 |
942 $query = "SELECT |
942 $query = "SELECT |
943 domains.id AS zid, |
943 domains.id AS zid, |
944 domains.name AS name, |
944 domains.name AS name, |
945 domains.type AS type, |
945 domains.type AS type, |
946 domains.master AS master |
946 domains.master AS master |
947 FROM domains" . $sql_add_from . " |
947 FROM domains" . $sql_add_from . " |
948 WHERE domains.name LIKE " . $db->quote($holy_grail) |
948 WHERE domains.name LIKE " . $db->quote($holy_grail, 'text') |
949 . $sql_add_where ; |
949 . $sql_add_where ; |
950 |
950 |
951 $response = $db->query($query); |
951 $response = $db->query($query); |
952 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
952 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
953 |
953 |
973 records.content AS content, |
973 records.content AS content, |
974 records.ttl AS ttl, |
974 records.ttl AS ttl, |
975 records.prio AS prio, |
975 records.prio AS prio, |
976 records.domain_id AS zid |
976 records.domain_id AS zid |
977 FROM records" . $sql_add_from . " |
977 FROM records" . $sql_add_from . " |
978 WHERE (records.name LIKE " . $db->quote($holy_grail) . " OR records.content LIKE " . $db->quote($holy_grail) . ")" |
978 WHERE (records.name LIKE " . $db->quote($holy_grail, 'text') . " OR records.content LIKE " . $db->quote($holy_grail, 'text') . ")" |
979 . $sql_add_where ; |
979 . $sql_add_where ; |
980 |
980 |
981 $response = $db->query($query); |
981 $response = $db->query($query); |
982 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
982 if (PEAR::isError($response)) { error($response->getMessage()); return false; } |
983 |
983 |
1026 // It is not really neccesary to clear the field that contains the IP address |
1026 // It is not really neccesary to clear the field that contains the IP address |
1027 // of the master if the type changes from slave to something else. PowerDNS will |
1027 // of the master if the type changes from slave to something else. PowerDNS will |
1028 // ignore the field if the type isn't something else then slave. But then again, |
1028 // ignore the field if the type isn't something else then slave. But then again, |
1029 // it's much clearer this way. |
1029 // it's much clearer this way. |
1030 if ($type != "SLAVE") { |
1030 if ($type != "SLAVE") { |
1031 $add = ", master=''"; |
1031 $add = ", master=".$db->quote('', 'text'); |
1032 } |
1032 } |
1033 $result = $db->query("UPDATE domains SET type = " . $db->quote($type) . $add . " WHERE id = ".$db->quote($id)); |
1033 $result = $db->query("UPDATE domains SET type = " . $db->quote($type, 'text') . $add . " WHERE id = ".$db->quote($id, 'integer')); |
1034 } else { |
1034 } else { |
1035 error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
1035 error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
1036 } |
1036 } |
1037 } |
1037 } |
1038 |
1038 |
1039 function change_zone_slave_master($zone_id, $ip_slave_master) { |
1039 function change_zone_slave_master($zone_id, $ip_slave_master) { |
1040 global $db; |
1040 global $db; |
1041 if (is_numeric($zone_id)) { |
1041 if (is_numeric($zone_id)) { |
1042 if (is_valid_ipv4($ip_slave_master) || is_valid_ipv6($ip_slave_master)) { |
1042 if (is_valid_ipv4($ip_slave_master) || is_valid_ipv6($ip_slave_master)) { |
1043 $result = $db->query("UPDATE domains SET master = " .$db->quote($ip_slave_master). " WHERE id = ".$db->quote($zone_id)); |
1043 $result = $db->query("UPDATE domains SET master = " .$db->quote($ip_slave_master, 'text'). " WHERE id = ".$db->quote($zone_id, 'integer')); |
1044 } else { |
1044 } else { |
1045 error(sprintf(ERR_INV_ARGC, "change_domain_ip_slave_master", "This is not a valid IPv4 or IPv6 address: $ip_slave_master")); |
1045 error(sprintf(ERR_INV_ARGC, "change_domain_ip_slave_master", "This is not a valid IPv4 or IPv6 address: $ip_slave_master")); |
1046 } |
1046 } |
1047 } else { |
1047 } else { |
1048 error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
1048 error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given")); |
1050 } |
1050 } |
1051 |
1051 |
1052 function get_serial_by_zid($zid) { |
1052 function get_serial_by_zid($zid) { |
1053 global $db; |
1053 global $db; |
1054 if (is_numeric($zid)) { |
1054 if (is_numeric($zid)) { |
1055 $query = "SELECT content FROM records where TYPE = 'SOA' and domain_id = " . $db->quote($zid); |
1055 $query = "SELECT content FROM records where TYPE = ".$db->quote('SOA', 'text')." and domain_id = " . $db->quote($zid, 'integer'); |
1056 $rr_soa = $db->queryOne($query); |
1056 $rr_soa = $db->queryOne($query); |
1057 if (PEAR::isError($rr_soa)) { error($rr_soa->getMessage()); return false; } |
1057 if (PEAR::isError($rr_soa)) { error($rr_soa->getMessage()); return false; } |
1058 $rr_soa_fields = explode(" ", $rr_soa); |
1058 $rr_soa_fields = explode(" ", $rr_soa); |
1059 } else { |
1059 } else { |
1060 error(sprintf(ERR_INV_ARGC, "get_serial_by_zid", "id must be a number")); |
1060 error(sprintf(ERR_INV_ARGC, "get_serial_by_zid", "id must be a number")); |