ftimme
2005-12-21 1d3319e2b412c7f301146878700b9733cbc1bab0
commit | author | age
5667a9 1 <?php
F 2
3 /*
4 Copyright (c) 2005, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $list_def_file = "list/rr.list.php";
36 $tform_def_file = "form/rr.tform.php";
37
38 /******************************************
39 * End Form configuration
40 ******************************************/
41
42 require_once('../../lib/config.inc.php');
43 require_once('../../lib/app.inc.php');
44
45 // Checke Berechtigungen für Modul
46 if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
47         header("Location: ../index.php");
48         exit;
49 }
50
51 // Loading classes
52 $app->load('tform_actions');
53
54 class page_action extends tform_actions {
55
56         function onDelete() {
57                 global $app, $conf;
58
d1ba8c 59                 $app->uses('tform');
1d3319 60                 if(!$rr = $app->db->queryOneRecord("SELECT * FROM rr WHERE id = ".$_REQUEST['id']." AND ".$app->tform->getAuthSQL('d'))) $app->error($app->lng('error_no_permission'));
d1ba8c 61
F 62                 //$rr = $app->db->queryOneRecord("SELECT * FROM rr WHERE id = ".$_REQUEST['id']);
5667a9 63                 $zone_id = $rr['zone'];
F 64
65                 // update serial
66                 $soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$zone_id);
67                 $serial = $soa['serial'];
68                 $update = 1;
69
70                 if($update > 0){
71                   $serial_date = substr($serial, 0, 8);
72                   $count = intval(substr($serial, 8, 2));
73                   $current_date = date("Ymd");
74                   if($serial_date == $current_date){
75                     $count += 1;
76                     $count = str_pad($count, 2, "0", STR_PAD_LEFT);
77                     $new_serial = $current_date.$count;
78                   } else {
79                     $new_serial = $current_date.'01';
80                   }
81                   $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$zone_id);
82                 }
83
84                 // PTR
85                 if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
86                   if($rr['type'] == 'A' || $rr['type'] == 'AAAA'){
87                     list($a, $b, $c, $d) = explode('.', $rr['data']);
88                     $ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
89                     if(substr($rr['name'], -1) == '.'){
90                       $ptr_soa_rr_data = $rr['name'];
91                     } else {
92                       $ptr_soa_rr_data = $rr['name'].(trim($rr['name']) == '' ? '' : '.').$soa['origin'];
93                     }
94                     if($ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
95                       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."'")){
96                         $app->db->query("DELETE FROM rr WHERE id = ".$ptr_soa_rr_exist['id']);
97                         // is there another A/AAAA record with that IP address?
98                         if($other_rr = $app->db->queryOneRecord("SELECT * FROM rr WHERE (type = 'A' OR type = 'AAAA') AND data = '".$rr['data']."' AND id != ".$rr['id'])){
99                           $other_soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$other_rr['zone']);
100                           if(substr($other_rr['name'], -1) == '.'){
101                             $other_ptr_soa_rr_data = $other_rr['name'];
102                           } else {
103                             $other_ptr_soa_rr_data = $other_rr['name'].(trim($other_rr['name']) == '' ? '' : '.').$other_soa['origin'];
104                           }
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_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']."')");
5667a9 106                         }
F 107
108                         // if no more records exist for the ptr_soa, delete it
109                         if(!$ptr_soa_rr = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."'")){
110                           $app->db->query("DELETE FROM soa WHERE id = ".$ptr_soa_exist['id']);
111                         } else { // increment serial
112                           $serial_date = substr($ptr_soa_exist['serial'], 0, 8);
113                           $count = intval(substr($ptr_soa_exist['serial'], 8, 2));
114                           $current_date = date("Ymd");
115                           if($serial_date == $current_date){
116                             $count += 1;
117                             $count = str_pad($count, 2, "0", STR_PAD_LEFT);
118                             $new_serial = $current_date.$count;
119                           } else {
120                             $new_serial = $current_date.'01';
121                           }
122                           $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$ptr_soa_exist['id']);
123                         }
124                       }
125                     }
126                   }
127                 }
128
129
130                 parent::onDelete();
131         }
132
133 }
134
135 $app->tform_actions = new page_action;
136 $app->tform_actions->onDelete();
137
138
139 ?>