tbrehm
2007-03-07 45f11e2be23676e9efc084b7c447993e58f5b670
interface/web/dns/soa_del.php
@@ -57,12 +57,12 @@
                global $app, $conf;
                $app->uses('tform');
                if(!$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$_REQUEST['id']." AND ".$app->tform->getAuthSQL('d'))) $app->error($app->tform->wordbook['error_no_permission']);
                if(!$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$_REQUEST['id']." AND ".$app->tform->getAuthSQL('d'))) $app->error($app->tform->wordbook['error_no_permission']);
                // PTR
                if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
                  //$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$_REQUEST['id']);
                  $rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = '".$_REQUEST['id']."' AND (type = 'A' OR type = 'AAAA')");
                  $rrs = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = '".$_REQUEST['id']."' AND (type = 'A' OR type = 'AAAA')");
                  if(!empty($rrs)){
                    foreach($rrs as $rr){
                      list($a, $b, $c, $d) = explode('.', $rr['data']);
@@ -72,23 +72,23 @@
                      } else {
                        $ptr_soa_rr_data = $rr['name'].(trim($rr['name']) == '' ? '' : '.').$soa['origin'];
                      }
                      if($ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
                        if($ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR' AND data = '".$ptr_soa_rr_data."'")){
                          $app->db->query("DELETE FROM rr WHERE id = ".$ptr_soa_rr_exist['id']);
                      if($ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE origin = '".$ptr_soa."'")){
                        if($ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR' AND data = '".$ptr_soa_rr_data."'")){
                          $app->db->query("DELETE FROM dns_rr WHERE id = ".$ptr_soa_rr_exist['id']);
                          // is there another A/AAAA record with that IP address?
                          if($other_rr = $app->db->queryOneRecord("SELECT * FROM rr WHERE (type = 'A' OR type = 'AAAA') AND data = '".$rr['data']."' AND id != ".$rr['id']." AND zone != ".$rr['zone'])){
                            $other_soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$other_rr['zone']);
                          if($other_rr = $app->db->queryOneRecord("SELECT * FROM dns_rr WHERE (type = 'A' OR type = 'AAAA') AND data = '".$rr['data']."' AND id != ".$rr['id']." AND zone != ".$rr['zone'])){
                            $other_soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$other_rr['zone']);
                            if(substr($other_rr['name'], -1) == '.'){
                              $other_ptr_soa_rr_data = $other_rr['name'];
                            } else {
                              $other_ptr_soa_rr_data = $other_rr['name'].(trim($other_rr['name']) == '' ? '' : '.').$other_soa['origin'];
                            }
                            $app->db->query("INSERT INTO rr (zone, name, type, data, aux, ttl, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other) VALUES ('".$ptr_soa_exist['id']."', '".$d."', 'PTR', '".$other_ptr_soa_rr_data."', '0', '".$conf['default_ttl']."', '".$_SESSION['s']['user']['sys_userid']."', '".$_SESSION['s']['user']['sys_groupid']."', '".$_SESSION['s']['user']['sys_perm_user']."', '".$_SESSION['s']['user']['sys_perm_group']."', '".$_SESSION['s']['user']['sys_perm_other']."')");
                            $app->db->query("INSERT INTO dns_rr (zone, name, type, data, aux, ttl, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other) VALUES ('".$ptr_soa_exist['id']."', '".$d."', 'PTR', '".$other_ptr_soa_rr_data."', '0', '".$conf['default_ttl']."', '".$_SESSION['s']['user']['sys_userid']."', '".$_SESSION['s']['user']['sys_groupid']."', '".$_SESSION['s']['user']['sys_perm_user']."', '".$_SESSION['s']['user']['sys_perm_group']."', '".$_SESSION['s']['user']['sys_perm_other']."')");
                          }
                          // if no more records exist for the ptr_soa, delete it
                          if(!$ptr_soa_rr = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."'")){
                            $app->db->query("DELETE FROM soa WHERE id = ".$ptr_soa_exist['id']);
                          if(!$ptr_soa_rr = $app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = '".$ptr_soa_exist['id']."'")){
                            $app->db->query("DELETE FROM dns_soa WHERE id = ".$ptr_soa_exist['id']);
                          } else { // increment serial
                            $serial_date = substr($ptr_soa_exist['serial'], 0, 8);
                            $count = intval(substr($ptr_soa_exist['serial'], 8, 2));
@@ -100,7 +100,7 @@
                            } else {
                              $new_serial = $current_date.'01';
                            }
                            $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$ptr_soa_exist['id']);
                            $app->db->query("UPDATE dns_soa SET serial = '".$new_serial."' WHERE id = ".$ptr_soa_exist['id']);
                          }
                        }
                      }
@@ -109,7 +109,7 @@
                }
                // delete associated records
                $app->db->query("DELETE FROM rr WHERE zone = ".$_REQUEST['id']);
                $app->db->query("DELETE FROM dns_rr WHERE zone = ".$_REQUEST['id']);
                parent::onDelete();
        }