From e7ea7dcfd0a2df4e41348d2fa4a0866e78f65807 Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Mon, 05 Dec 2005 17:43:16 -0500
Subject: [PATCH]
---
interface/web/dns/soa_edit.php | 174 +++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 123 insertions(+), 51 deletions(-)
diff --git a/interface/web/dns/soa_edit.php b/interface/web/dns/soa_edit.php
index 77fc417..5ad043c 100644
--- a/interface/web/dns/soa_edit.php
+++ b/interface/web/dns/soa_edit.php
@@ -59,79 +59,151 @@
$app->uses('validate_dns');
$app->tform->errorMessage .= $app->validate_dns->validate_soa($this->dataRecord);
+ $increased_serials[] = -1;
// update serial
$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$this->dataRecord["id"]);
$serial = $soa['serial'];
$update = 0;
- if($old_record = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$this->dataRecord["id"])){
- foreach($old_record as $key => $val){
+ if($soa){
+ foreach($soa as $key => $val){
if($this->dataRecord[$key] != $val && $key != 'active') $update += 1;
}
} else { // new record
$update = 1;
}
+ if(strlen($this->dataRecord["serial"]) == 10 && intval($this->dataRecord["serial"]) == $this->dataRecord["serial"] && $this->dataRecord["serial"] != $serial){
+ $update = 0;
+ $increased_serials[] = $soa['id'];
+ }
if($update > 0){
- $serial_date = substr($serial, 0, 8);
- $count = intval(substr($serial, 8, 2));
- $current_date = date("Ymd");
- if($serial_date == $current_date){
- $count += 1;
- $count = str_pad($count, 2, "0", STR_PAD_LEFT);
- $new_serial = $current_date.$count;
- } else {
- $new_serial = $current_date.'01';
- }
+ $new_serial = $app->validate_dns->increase_serial($serial);
+ $increased_serials[] = $soa['id'];
$this->dataRecord["serial"] = $new_serial;
}
- // update rr if origin has changed
- if($soa['origin'] != $this->dataRecord['origin']){
- /*
- if($rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = ".$soa['id'])){
- foreach($rrs as $rr){
- if(substr($rr['name'], -(strlen($this->dataRecord['origin']))) != $this->dataRecord['origin']) $app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE id = ".$rr['id']);
- if(substr($rr['data'], -(strlen($this->dataRecord['origin']))) != $this->dataRecord['origin']) $app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE id = ".$rr['id']);
+ if($soa){
+ // update rr if origin has changed
+ if($soa['origin'] != $this->dataRecord['origin']){
+
+ if($rrs = $app->db->queryAllRecords("SELECT * FROM rr")){
+ $update_soas = array();
+ foreach($rrs as $rr){
+ if($soa['origin'] == substr($rr['name'], -(strlen($soa['origin']))) || $soa['origin'] == substr($rr['data'], -(strlen($soa['origin'])))) $update_soas[] = $rr['zone'];
+ //$update_soas[] = $app->db->queryAllRecords("SELECT DISTINCT zone FROM rr WHERE name LIKE '%".$soa['origin']."' OR data LIKE '%".$soa['origin']."'");
+
+ $app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type != 'PTR' AND id = ".$rr['id']);
+
+ $app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type != 'PTR' AND id = ".$rr['id']);
+
+ if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
+ $app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type = 'PTR' AND id = ".$rr['id']);
+
+ $app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type = 'PTR' AND id = ".$rr['id']);
+
+ }
+ }
+
+ // increase serial
+ if(!empty($update_soas)){
+ $update_soas = array_unique($update_soas);
+ foreach($update_soas as $update_soa){
+ $u_soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$update_soa);
+ if(!in_array($u_soa['id'], $increased_serials)){
+ $new_serial = $app->validate_dns->increase_serial($u_soa['serial']);
+ if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
+ $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$update_soa);
+ } else {
+ $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$update_soa." AND origin NOT LIKE '%.in-addr.arpa.'");
+ }
+ $increased_serials[] = $u_soa['id'];
+ }
+ }
+ }
}
}
- */
- if($rrs = $app->db->queryAllRecords("SELECT * FROM rr")){
- $update_soas = array();
- foreach($rrs as $rr){
- if($soa['origin'] == substr($rr['name'], -(strlen($soa['origin']))) || $soa['origin'] == substr($rr['data'], -(strlen($soa['origin'])))) $update_soas[] = $rr['zone'];
- //$update_soas[] = $app->db->queryAllRecords("SELECT DISTINCT zone FROM rr WHERE name LIKE '%".$soa['origin']."' OR data LIKE '%".$soa['origin']."'");
- $app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type != 'PTR'");
- $app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type != 'PTR'");
- if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
- $app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type = 'PTR'");
- $app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type = 'PTR'");
+ // PTR
+ if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
+
+ if($soa['active'] = 'Y' && $this->dataRecord['active'][0] == 'N'){
+
+ if($soa_rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = ".$this->dataRecord['id']." AND type = 'A'")){
+ foreach($soa_rrs as $soa_rr){
+ if(substr($soa_rr['name'], -1) == '.'){
+ $fqdn = $soa_rr['name'];
+ } else {
+ $fqdn = $soa_rr['name'].(trim($soa_rr['name']) == '' ? '' : '.').$this->dataRecord['origin'];
+ }
+ list($a, $b, $c, $d) = explode('.', $soa_rr['data']);
+ $ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
+ if($ptr = $app->db->queryOneRecord("SELECT soa.id, soa.serial FROM soa, rr WHERE rr.type = 'PTR' AND rr.data = '".$fqdn."' AND rr.zone = soa.id AND soa.origin = '".$ptr_soa."'")){
+ ############
+ if($a_rr_with_same_ip = $app->db->queryOneRecord("SELECT rr.*, soa.origin FROM rr, soa WHERE rr.type = 'A' AND rr.data = '".$soa_rr['data']."' AND rr.zone = soa.id AND soa.active = 'Y' AND rr.id != ".$soa_rr["id"]." AND rr.zone != '".$this->dataRecord['zone']."'")){
+ if(substr($a_rr_with_same_ip['name'], -1) == '.'){
+ $new_ptr_soa_rr_data = $a_rr_with_same_ip['name'];
+ } else {
+ $new_ptr_soa_rr_data = $a_rr_with_same_ip['name'].(trim($a_rr_with_same_ip['name']) == '' ? '' : '.').$a_rr_with_same_ip['origin'];
+ }
+ $app->db->query("UPDATE rr SET data = '".$new_ptr_soa_rr_data."' WHERE zone = '".$ptr['id']."' AND name = '".$d."' AND type = 'PTR'");
+ } else {
+ $app->db->query("DELETE FROM rr WHERE zone = '".$ptr['id']."' AND name = '".$d."' AND type = 'PTR'");
+
+ if(!$app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr['id']."'")){
+ $app->db->query("DELETE FROM soa WHERE id = ".$ptr['id']);
+ } else {
+ // increase serial
+ if(!in_array($ptr['id'], $increased_serials)){
+ $new_serial = $app->validate_dns->increase_serial($ptr['serial']);
+ $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$ptr['id']);
+ $increased_serials[] = $ptr['id'];
+ }
+ }
+ }
+ ############
+ }
+ }
}
+
+ /* */
+
+
}
- // increase serial
- if(!empty($update_soas)){
- //print_r($update_soas);
- //die();
- $update_soas = array_unique($update_soas);
- foreach($update_soas as $update_soa){
- $u_soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$update_soa);
- $serial_date = substr($u_soa['serial'], 0, 8);
- $count = intval(substr($u_soa['serial'], 8, 2));
- $current_date = date("Ymd");
- if($serial_date == $current_date){
- $count += 1;
- $count = str_pad($count, 2, "0", STR_PAD_LEFT);
- $new_serial = $current_date.$count;
- } else {
- $new_serial = $current_date.'01';
- }
- if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
- $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$update_soa);
- } else {
- $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$update_soa." AND origin NOT LIKE '%.in-addr.arpa.'");
+ if($soa['active'] = 'N' && $this->dataRecord['active'][0] == 'Y'){
+
+ if($soa_rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = ".$this->dataRecord['id']." AND type = 'A'")){
+ foreach($soa_rrs as $soa_rr){
+ #################
+ list($a, $b, $c, $d) = explode('.', $soa_rr['data']);
+ $ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
+ if(substr($soa_rr['name'], -1) == '.'){
+ $ptr_soa_rr_data = $soa_rr['name'];
+ } else {
+ $ptr_soa_rr_data = $soa_rr['name'].(trim($soa_rr['name']) == '' ? '' : '.').$this->dataRecord['origin'];
+ }
+
+ if(!$ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
+ $app->db->query("INSERT INTO soa (origin, ns, mbox, serial, refresh, retry, expire, minimum, ttl, active) VALUES ('".$ptr_soa."', '".trim($conf['default_ns'])."', '".trim($conf['default_mbox'])."', '".date("Ymd").'01'."', '".$conf['default_refresh']."', '".$conf['default_retry']."', '".$conf['default_expire']."', '".$conf['default_minimum_ttl']."', '".$conf['default_ttl']."', 'Y')");
+ $ptr_soa_id = $app->db->insertID();
+ $app->db->query("INSERT INTO rr (zone, name, type, data, aux, ttl) VALUES ('".$ptr_soa_id."', '".$d."', 'PTR', '".$ptr_soa_rr_data."', '0', '".$conf['default_ttl']."')");
+ } else {
+ if($ptr_soa_exist['active'] != 'Y') $app->db->query("UPDATE soa SET active = 'Y' WHERE id = ".$ptr_soa_exist['id']);
+ if(!$ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR'")){
+ $app->db->query("INSERT INTO rr (zone, name, type, data, aux, ttl) VALUES ('".$ptr_soa_exist['id']."', '".$d."', 'PTR', '".$ptr_soa_rr_data."', '0', '".$conf['default_ttl']."')");
+ // increase serial of PTR SOA
+ if(!in_array($ptr_soa_exist['id'], $increased_serials)){
+ $ptr_soa_new_serial = $app->validate_dns->increase_serial($ptr_soa_exist['serial']);
+ $increased_serials[] = $ptr_soa_exist['id'];
+ $app->db->query("UPDATE soa SET serial = '".$ptr_soa_new_serial."' WHERE id = ".$ptr_soa_exist['id']);
+ }
+ }
+ }
+ ################
}
}
+
+
}
}
}
--
Gitblit v1.9.1