NBonline
2005-12-21 e0b6391e945a8aeb556fa73b04235eb36d99d434
commit | author | age
5667a9 1 <?php
F 2 /*
3 Copyright (c) 2005, Till Brehm, projektfarm Gmbh
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/rr.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
41 require_once('../../lib/config.inc.php');
42 require_once('../../lib/app.inc.php');
43
44 // Checking module permissions
45 if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
46         header("Location: ../index.php");
47         exit;
48 }
49
50 // Loading classes
51 $app->uses('tpl,tform,tform_actions');
52 $app->load('tform_actions');
53
54 class page_action extends tform_actions {
55
d1ba8c 56
5667a9 57         function onSubmit() {
F 58                 global $app, $conf;
59
d1ba8c 60                 if($this->dataRecord['id'] > 0){
2ebd32 61                   if(!$app->tform->checkPerm($this->dataRecord['id'],'u')) $app->error($app->tform->wordbook['error_no_permission']);
d1ba8c 62                 } else {
2ebd32 63                   if(!$app->tform->checkPerm($this->dataRecord['id'],'i')) $app->error($app->tform->wordbook['error_no_permission']);
d1ba8c 64                 }
F 65
5667a9 66                 $this->dataRecord["zone"] = $_SESSION['s']['list']['rr']['parent_id'];
F 67
7bdb8d 68                 $app->uses('validate_dns');
F 69                 $app->tform->errorMessage .= $app->validate_dns->validate_rr($this->dataRecord);
70
4cfd9d 71                 $increased_serials[] = -1;
F 72                 if($app->tform->errorMessage == ''){
73                   // update serial
74                   $soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$this->dataRecord["zone"]);
75                   $serial = $soa['serial'];
76                   $update = 0;
77                   if($old_record = $app->db->queryOneRecord("SELECT * FROM rr WHERE id = ".$this->dataRecord["id"])){
78                     foreach($old_record as $key => $val){
79                       if($this->dataRecord[$key] != $val) $update += 1;
5667a9 80                     }
4cfd9d 81                   } else { // new record
F 82                     $update = 1;
83                   }
84
85                   if($update > 0){
86                     $new_serial = $app->validate_dns->increase_serial($serial);
87                     $increased_serials[] = $soa['id'];
88                     $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$this->dataRecord["zone"]);
89                   }
90
91                   // PTR
92                   if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
93                     if($this->dataRecord['type'] == 'A' || $this->dataRecord['type'] == 'AAAA'){
94                       list($a, $b, $c, $d) = explode('.', $this->dataRecord['data']);
95                       $ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
96                       if(substr($this->dataRecord['name'], -1) == '.'){
97                         $ptr_soa_rr_data = $this->dataRecord['name'];
98                       } else {
99                         $ptr_soa_rr_data = $this->dataRecord['name'].(trim($this->dataRecord['name']) == '' ? '' : '.').$soa['origin'];
5667a9 100                       }
4cfd9d 101
F 102                       if(!$ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
1d3319 103                         $app->db->query("INSERT INTO soa (origin, ns, mbox, serial, refresh, retry, expire, minimum, ttl, active, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other) 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', '".$_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']."')");
4cfd9d 104                         $ptr_soa_id = $app->db->insertID();
1d3319 105                         $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_id."', '".$d."', 'PTR', '".$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']."')");
4cfd9d 106                       } else {
F 107                         if($ptr_soa_exist['active'] != 'Y') $app->db->query("UPDATE soa SET active = 'Y' WHERE id = ".$ptr_soa_exist['id']);
108                         if(!$ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR'")){
1d3319 109                           $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', '".$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']."')");
4cfd9d 110                           // increase serial of PTR SOA
F 111                           if(!in_array($ptr_soa_exist['id'], $increased_serials)){
112                             $ptr_soa_new_serial = $app->validate_dns->increase_serial($ptr_soa_exist['serial']);
113                             $increased_serials[] = $ptr_soa_exist['id'];
114                             $app->db->query("UPDATE soa SET serial = '".$ptr_soa_new_serial."' WHERE id = ".$ptr_soa_exist['id']);
115                           }
116                         }
117                       }
118
119                       // if IP address changes, delete/change old PTR record
120                       if(!empty($old_record)){
121                         list($oa, $ob, $oc, $od) = explode('.', $old_record['data']);
122                         if($a_rr_with_same_ip = $app->db->queryOneRecord("SELECT rr.*, soa.origin FROM rr, soa WHERE rr.type = 'A' AND rr.data = '".$old_record['data']."' AND rr.zone = soa.id AND soa.active = 'Y' AND rr.id != ".$this->dataRecord["id"])){
123                           if(substr($a_rr_with_same_ip['name'], -1) == '.'){
124                             $new_ptr_soa_rr_data = $a_rr_with_same_ip['name'];
125                           } else {
126                             $new_ptr_soa_rr_data = $a_rr_with_same_ip['name'].(trim($a_rr_with_same_ip['name']) == '' ? '' : '.').$a_rr_with_same_ip['origin'];
127                           }
128                           $app->db->query("UPDATE rr SET data = '".$new_ptr_soa_rr_data."' WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$od."' AND type = 'PTR'");
129                         } else {
130                           $old_ptr_soa = $oc.'.'.$ob.'.'.$oa.'.in-addr.arpa.';
131                           $old_ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$old_ptr_soa."'");
132                           $app->db->query("DELETE FROM rr WHERE zone = '".$old_ptr_soa_exist['id']."' AND name = '".$od."' AND type = 'PTR'");
133                           //die("DELETE FROM rr WHERE zone = '".$old_record['zone']."' AND name = '".$od."' AND type = 'PTR'");
134                           if(!$app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$old_ptr_soa_exist['id']."'")){
135                             $app->db->query("DELETE FROM soa WHERE id = ".$old_ptr_soa_exist['id']);
136                           } else {
137                             // increase serial
138                             if(!in_array($old_ptr_soa_exist['id'], $increased_serials)){
139                               $new_serial = $app->validate_dns->increase_serial($old_ptr_soa_exist['serial']);
140                               $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$old_ptr_soa_exist['id']);
141                             }
142                           }
143                         }
144                       }
145
5667a9 146                     }
F 147                   }
148                 }
149
150
151                 parent::onSubmit();
152         }
153
154 }
155
156 $app->tform_actions = new page_action;
157 $app->tform_actions->onLoad();
158
159 ?>