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/soa.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 |
|
|
56 |
function onSubmit() {
|
|
57 |
global $app, $conf;
|
|
58 |
|
4cfff7
|
59 |
if($app->tform->getCurrentTab() == 'rr'){
|
F |
60 |
parent::onSubmit();
|
|
61 |
return true;
|
|
62 |
}
|
|
63 |
|
d1ba8c
|
64 |
if($this->dataRecord['id'] > 0){
|
2ebd32
|
65 |
if(!$app->tform->checkPerm($this->dataRecord['id'],'u')) $app->error($app->tform->wordbook['error_no_permission']);
|
d1ba8c
|
66 |
} else {
|
2ebd32
|
67 |
if(!$app->tform->checkPerm($this->dataRecord['id'],'i')) $app->error($app->tform->wordbook['error_no_permission']);
|
d1ba8c
|
68 |
}
|
F |
69 |
|
7bdb8d
|
70 |
$app->uses('validate_dns');
|
F |
71 |
$app->tform->errorMessage .= $app->validate_dns->validate_soa($this->dataRecord);
|
|
72 |
|
4cfd9d
|
73 |
$increased_serials[] = -1;
|
5667a9
|
74 |
// update serial
|
F |
75 |
$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$this->dataRecord["id"]);
|
|
76 |
$serial = $soa['serial'];
|
|
77 |
$update = 0;
|
4cfd9d
|
78 |
if($soa){
|
F |
79 |
foreach($soa as $key => $val){
|
5667a9
|
80 |
if($this->dataRecord[$key] != $val && $key != 'active') $update += 1;
|
F |
81 |
}
|
|
82 |
} else { // new record
|
|
83 |
$update = 1;
|
|
84 |
}
|
e7ea7d
|
85 |
if(strlen($this->dataRecord["serial"]) == 10 && intval($this->dataRecord["serial"]) == $this->dataRecord["serial"] && $this->dataRecord["serial"] != $serial){
|
F |
86 |
$update = 0;
|
|
87 |
$increased_serials[] = $soa['id'];
|
|
88 |
}
|
5667a9
|
89 |
if($update > 0){
|
4cfd9d
|
90 |
$new_serial = $app->validate_dns->increase_serial($serial);
|
F |
91 |
$increased_serials[] = $soa['id'];
|
5667a9
|
92 |
$this->dataRecord["serial"] = $new_serial;
|
F |
93 |
}
|
|
94 |
|
4cfd9d
|
95 |
if($soa){
|
F |
96 |
// update rr if origin has changed
|
|
97 |
if($soa['origin'] != $this->dataRecord['origin']){
|
5667a9
|
98 |
|
4cfd9d
|
99 |
if($rrs = $app->db->queryAllRecords("SELECT * FROM rr")){
|
F |
100 |
$update_soas = array();
|
|
101 |
foreach($rrs as $rr){
|
|
102 |
if($soa['origin'] == substr($rr['name'], -(strlen($soa['origin']))) || $soa['origin'] == substr($rr['data'], -(strlen($soa['origin'])))) $update_soas[] = $rr['zone'];
|
|
103 |
//$update_soas[] = $app->db->queryAllRecords("SELECT DISTINCT zone FROM rr WHERE name LIKE '%".$soa['origin']."' OR data LIKE '%".$soa['origin']."'");
|
5667a9
|
104 |
|
e7ea7d
|
105 |
$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']);
|
F |
106 |
|
|
107 |
$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']);
|
5667a9
|
108 |
|
F |
109 |
if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
|
e7ea7d
|
110 |
$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']);
|
F |
111 |
|
|
112 |
$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']);
|
|
113 |
|
4cfd9d
|
114 |
}
|
F |
115 |
}
|
|
116 |
|
|
117 |
// increase serial
|
|
118 |
if(!empty($update_soas)){
|
|
119 |
$update_soas = array_unique($update_soas);
|
|
120 |
foreach($update_soas as $update_soa){
|
|
121 |
$u_soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$update_soa);
|
|
122 |
if(!in_array($u_soa['id'], $increased_serials)){
|
|
123 |
$new_serial = $app->validate_dns->increase_serial($u_soa['serial']);
|
|
124 |
if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
|
|
125 |
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$update_soa);
|
|
126 |
} else {
|
|
127 |
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$update_soa." AND origin NOT LIKE '%.in-addr.arpa.'");
|
|
128 |
}
|
3dedce
|
129 |
$increased_serials[] = $u_soa['id'];
|
4cfd9d
|
130 |
}
|
5667a9
|
131 |
}
|
F |
132 |
}
|
|
133 |
}
|
|
134 |
}
|
3dedce
|
135 |
|
F |
136 |
|
|
137 |
// PTR
|
|
138 |
if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
|
|
139 |
|
|
140 |
if($soa['active'] = 'Y' && $this->dataRecord['active'][0] == 'N'){
|
|
141 |
|
|
142 |
if($soa_rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = ".$this->dataRecord['id']." AND type = 'A'")){
|
|
143 |
foreach($soa_rrs as $soa_rr){
|
|
144 |
if(substr($soa_rr['name'], -1) == '.'){
|
|
145 |
$fqdn = $soa_rr['name'];
|
|
146 |
} else {
|
|
147 |
$fqdn = $soa_rr['name'].(trim($soa_rr['name']) == '' ? '' : '.').$this->dataRecord['origin'];
|
|
148 |
}
|
|
149 |
list($a, $b, $c, $d) = explode('.', $soa_rr['data']);
|
|
150 |
$ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
|
|
151 |
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."'")){
|
|
152 |
############
|
e7ea7d
|
153 |
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']."'")){
|
3dedce
|
154 |
if(substr($a_rr_with_same_ip['name'], -1) == '.'){
|
F |
155 |
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'];
|
|
156 |
} else {
|
|
157 |
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'].(trim($a_rr_with_same_ip['name']) == '' ? '' : '.').$a_rr_with_same_ip['origin'];
|
|
158 |
}
|
|
159 |
$app->db->query("UPDATE rr SET data = '".$new_ptr_soa_rr_data."' WHERE zone = '".$ptr['id']."' AND name = '".$d."' AND type = 'PTR'");
|
|
160 |
} else {
|
|
161 |
$app->db->query("DELETE FROM rr WHERE zone = '".$ptr['id']."' AND name = '".$d."' AND type = 'PTR'");
|
|
162 |
|
|
163 |
if(!$app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr['id']."'")){
|
|
164 |
$app->db->query("DELETE FROM soa WHERE id = ".$ptr['id']);
|
|
165 |
} else {
|
|
166 |
// increase serial
|
|
167 |
if(!in_array($ptr['id'], $increased_serials)){
|
|
168 |
$new_serial = $app->validate_dns->increase_serial($ptr['serial']);
|
|
169 |
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$ptr['id']);
|
|
170 |
$increased_serials[] = $ptr['id'];
|
|
171 |
}
|
|
172 |
}
|
|
173 |
}
|
|
174 |
############
|
|
175 |
}
|
|
176 |
}
|
|
177 |
}
|
|
178 |
|
|
179 |
/* */
|
|
180 |
|
|
181 |
|
|
182 |
}
|
|
183 |
|
|
184 |
if($soa['active'] = 'N' && $this->dataRecord['active'][0] == 'Y'){
|
|
185 |
|
e7ea7d
|
186 |
if($soa_rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = ".$this->dataRecord['id']." AND type = 'A'")){
|
F |
187 |
foreach($soa_rrs as $soa_rr){
|
|
188 |
#################
|
|
189 |
list($a, $b, $c, $d) = explode('.', $soa_rr['data']);
|
|
190 |
$ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
|
|
191 |
if(substr($soa_rr['name'], -1) == '.'){
|
|
192 |
$ptr_soa_rr_data = $soa_rr['name'];
|
|
193 |
} else {
|
|
194 |
$ptr_soa_rr_data = $soa_rr['name'].(trim($soa_rr['name']) == '' ? '' : '.').$this->dataRecord['origin'];
|
|
195 |
}
|
|
196 |
|
|
197 |
if(!$ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
|
1d3319
|
198 |
$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']."')");
|
e7ea7d
|
199 |
$ptr_soa_id = $app->db->insertID();
|
1d3319
|
200 |
$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']."')");
|
e7ea7d
|
201 |
} else {
|
F |
202 |
if($ptr_soa_exist['active'] != 'Y') $app->db->query("UPDATE soa SET active = 'Y' WHERE id = ".$ptr_soa_exist['id']);
|
|
203 |
if(!$ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR'")){
|
1d3319
|
204 |
$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']."')");
|
e7ea7d
|
205 |
// increase serial of PTR SOA
|
F |
206 |
if(!in_array($ptr_soa_exist['id'], $increased_serials)){
|
|
207 |
$ptr_soa_new_serial = $app->validate_dns->increase_serial($ptr_soa_exist['serial']);
|
|
208 |
$increased_serials[] = $ptr_soa_exist['id'];
|
|
209 |
$app->db->query("UPDATE soa SET serial = '".$ptr_soa_new_serial."' WHERE id = ".$ptr_soa_exist['id']);
|
|
210 |
}
|
|
211 |
}
|
|
212 |
}
|
|
213 |
################
|
|
214 |
}
|
|
215 |
}
|
|
216 |
|
|
217 |
|
3dedce
|
218 |
}
|
F |
219 |
}
|
5667a9
|
220 |
}
|
F |
221 |
|
|
222 |
|
|
223 |
parent::onSubmit();
|
|
224 |
}
|
|
225 |
|
|
226 |
}
|
|
227 |
|
|
228 |
$app->tform_actions = new page_action;
|
|
229 |
$app->tform_actions->onLoad();
|
|
230 |
|
|
231 |
?> |