ftimme
2005-12-06 d1ba8c934978e24617e6ba8614a6e607192f1fe0
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/soa.list.php";
36 $tform_def_file = "form/soa.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');
F 60                 if(!$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$_REQUEST['id']." AND ".$app->tform->getAuthSQL('d'))) $app->error('not allowed');
61
5667a9 62                 // PTR
F 63                 if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
d1ba8c 64                   //$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$_REQUEST['id']);
5667a9 65                   $rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = '".$_REQUEST['id']."' AND (type = 'A' OR type = 'AAAA')");
F 66                   if(!empty($rrs)){
67                     foreach($rrs as $rr){
68                       list($a, $b, $c, $d) = explode('.', $rr['data']);
69                       $ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
70                       if(substr($rr['name'], -1) == '.'){
71                         $ptr_soa_rr_data = $rr['name'];
72                       } else {
73                         $ptr_soa_rr_data = $rr['name'].(trim($rr['name']) == '' ? '' : '.').$soa['origin'];
74                       }
75                       if($ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
76                         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."'")){
77                           $app->db->query("DELETE FROM rr WHERE id = ".$ptr_soa_rr_exist['id']);
78                           // is there another A/AAAA record with that IP address?
79                           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'])){
80                             $other_soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$other_rr['zone']);
81                             if(substr($other_rr['name'], -1) == '.'){
82                               $other_ptr_soa_rr_data = $other_rr['name'];
83                             } else {
84                               $other_ptr_soa_rr_data = $other_rr['name'].(trim($other_rr['name']) == '' ? '' : '.').$other_soa['origin'];
85                             }
86                             $app->db->query("INSERT INTO rr (zone, name, type, data, aux, ttl) VALUES ('".$ptr_soa_exist['id']."', '".$d."', 'PTR', '".$other_ptr_soa_rr_data."', '0', '".$conf['default_ttl']."')");
87                           }
88
89                           // if no more records exist for the ptr_soa, delete it
90                           if(!$ptr_soa_rr = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."'")){
91                             $app->db->query("DELETE FROM soa WHERE id = ".$ptr_soa_exist['id']);
92                           } else { // increment serial
93                             $serial_date = substr($ptr_soa_exist['serial'], 0, 8);
94                             $count = intval(substr($ptr_soa_exist['serial'], 8, 2));
95                             $current_date = date("Ymd");
96                             if($serial_date == $current_date){
97                               $count += 1;
98                               $count = str_pad($count, 2, "0", STR_PAD_LEFT);
99                               $new_serial = $current_date.$count;
100                             } else {
101                               $new_serial = $current_date.'01';
102                             }
103                             $app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$ptr_soa_exist['id']);
104                           }
105                         }
106                       }
107                     }
108                   }
109                 }
110
111                 // delete associated records
112                 $app->db->query("DELETE FROM rr WHERE zone = ".$_REQUEST['id']);
113
114                 parent::onDelete();
115         }
116
117 }
118
119 $app->tform_actions = new page_action;
120 $app->tform_actions->onDelete();
121
122 ?>