Skip to content

Commit 430a0fa

Browse files
committed
Deletion of a mail domain deletes now all depending forwarders, aliases and mailboxes.
1 parent 6417818 commit 430a0fa

File tree

4 files changed

+142
-61
lines changed

4 files changed

+142
-61
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @author Till Brehm
66
* @copyright 2005, Till Brehm, projektfarm Gmbh
7-
* @version 0.1
7+
* @version 0.2
88
* @package ISPConfig
99
*/
1010
/*
@@ -183,7 +183,8 @@ public function toLower($record)
183183
return $out;
184184
}
185185

186-
186+
// deprecated
187+
/*
187188
public function insert($tablename, $form, $debug = 0)
188189
{
189190
if(is_array($form)){
@@ -200,7 +201,8 @@ public function insert($tablename, $form, $debug = 0)
200201
if($debug == 1){ echo 'mySQL Error Message: '.$this->errorMessage; }
201202
}
202203
}
203-
204+
205+
// Deprecated
204206
public function update($tablename, $form, $bedingung, $debug = 0)
205207
{
206208
if(is_array($form)){
@@ -214,6 +216,7 @@ public function update($tablename, $form, $bedingung, $debug = 0)
214216
if($debug == 1){ echo 'mySQL Error Message: '.$this->errorMessage; }
215217
}
216218
}
219+
*/
217220

218221
//** Function to fill the datalog with a full differential record.
219222
public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new) {
@@ -231,7 +234,7 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
231234

232235
if(is_array($record_old) && count($record_old) > 0) {
233236
foreach($record_old as $key => $val) {
234-
if(isset($record_new[$key]) && $record_new[$key] != $val) {
237+
if(!isset($record_new[$key]) || $record_new[$key] != $val) {
235238
// Record has changed
236239
$diffrec_full['old'][$key] = $val;
237240
$diffrec_full['new'][$key] = $record_new[$key];
@@ -258,6 +261,7 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
258261
// Insert the server_id, if the record has a server_id
259262
$server_id = (isset($record_old["server_id"]) && $record_old["server_id"] > 0)?$record_old["server_id"]:0;
260263
if(isset($record_new["server_id"])) $server_id = $record_new["server_id"];
264+
261265

262266
if($diff_num > 0) {
263267
$diffstr = $app->db->quote(serialize($diffrec_full));
@@ -274,7 +278,20 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
274278
return true;
275279
}
276280

277-
//** Updates a record and saves the cahnges into the datalog
281+
//** Updates a record and saves the changes into the datalog
282+
public function datalogInsert($tablename, $insert_data, $index_field) {
283+
global $app;
284+
285+
$old_rec = array();
286+
$this->query("INSERT INTO $tablename $insert_data");
287+
$index_value = $this->insertID();
288+
$new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
289+
$this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
290+
291+
return true;
292+
}
293+
294+
//** Updates a record and saves the changes into the datalog
278295
public function datalogUpdate($tablename, $update_data, $index_field, $index_value) {
279296
global $app;
280297

@@ -285,6 +302,20 @@ public function datalogUpdate($tablename, $update_data, $index_field, $index_val
285302

286303
return true;
287304
}
305+
306+
//** Deletes a record and saves the changes into the datalog
307+
public function datalogDelete($tablename, $index_field, $index_value) {
308+
global $app;
309+
310+
$old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
311+
$this->query("DELETE FROM $tablename WHERE $index_field = '$index_value'");
312+
$new_rec = array();
313+
$this->datalogSave($tablename, 'DELETE', $index_field, $index_value, $old_rec, $new_rec);
314+
315+
return true;
316+
}
317+
318+
288319

289320
public function closeConn()
290321
{
@@ -304,15 +335,19 @@ public function freeResult($query)
304335
return false;
305336
}
306337
}
307-
338+
339+
/*
308340
public function delete()
309341
{
310342
}
311-
343+
*/
344+
345+
/*
312346
public function Transaction($action)
313347
{
314348
//action = begin, commit oder rollback
315349
}
350+
*/
316351

317352
/** Creates a database table with the following format for the $columns array
318353
* <code>
@@ -327,6 +362,8 @@ public function Transaction($action)
327362
* option => unique | primary | index)
328363
* </code>
329364
*/
365+
366+
330367
public function createTable($table_name, $columns)
331368
{
332369
$index = '';

interface/lib/classes/tform.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,8 @@ function datalogSave($action,$primary_id, $record_old, $record_new) {
903903

904904
if(is_array($record_old) && count($record_old) > 0) {
905905
foreach($record_old as $key => $val) {
906-
if(isset($record_new[$key]) && $record_new[$key] != $val) {
906+
//if(isset($record_new[$key]) && $record_new[$key] != $val) {
907+
if(!isset($record_new[$key]) || $record_new[$key] != $val) {
907908
// Record has changed
908909
$diffrec_full['old'][$key] = $val;
909910
$diffrec_full['new'][$key] = $record_new[$key];

interface/lib/classes/tform_actions.inc.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ function onDelete() {
300300

301301
//$this->dataRecord = $app->db->queryOneRecord("SELECT * FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = ".$this->id);
302302
$this->dataRecord = $app->tform->getDataRecord($this->id);
303+
304+
$this->onBeforeDelete();
303305

304306
// Saving record to datalog when db_history enabled
305307
if($app->tform->formDef["db_history"] == 'yes') {
@@ -335,6 +337,10 @@ function onDelete() {
335337
}
336338
exit;
337339

340+
}
341+
342+
function onBeforeDelete() {
343+
global $app, $conf;
338344
}
339345

340346
function onAfterDelete() {
Lines changed: 90 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,91 @@
1-
<?php
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/mail_domain.list.php";
36-
$tform_def_file = "form/mail_domain.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-
$app->uses("tform_actions");
52-
$app->tform_actions->onDelete();
53-
1+
<?php
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/mail_domain.list.php";
36+
$tform_def_file = "form/mail_domain.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->uses('tpl,tform,tform_actions');
53+
$app->load('tform_actions');
54+
55+
class page_action extends tform_actions {
56+
57+
function onBeforeDelete() {
58+
global $app; $conf;
59+
60+
$domain = $this->dataRecord['domain'];
61+
62+
// Before we delete the email domain,
63+
// we will delete all depending records.
64+
65+
// Delete all forwardings where the osurce or destination belongs to this domain
66+
$records = $app->db->queryAllRecords("SELECT forwarding_id as id FROM mail_forwarding WHERE source like '%@".$app->db->quote($domain)."' OR destination like '%@".$app->db->quote($domain)."'");
67+
foreach($records as $rec) {
68+
$app->db->datalogDelete('mail_forwarding','forwarding_id',$rec['id']);
69+
}
70+
71+
// Delete all fetchmail accounts where destination belongs to this domain
72+
$records = $app->db->queryAllRecords("SELECT mailget_id as id FROM mail_get WHERE destination like '%@".$app->db->quote($domain)."'");
73+
foreach($records as $rec) {
74+
$app->db->datalogDelete('mail_get','mailget_id',$rec['id']);
75+
}
76+
77+
// Delete all mailboxes where destination belongs to this domain
78+
$records = $app->db->queryAllRecords("SELECT mailuser_id as id FROM mail_user WHERE email like '%@".$app->db->quote($domain)."'");
79+
foreach($records as $rec) {
80+
$app->db->datalogDelete('mail_user','mailuser_id',$rec['id']);
81+
}
82+
83+
84+
85+
}
86+
}
87+
88+
$page = new page_action;
89+
$page->onDelete();
90+
5491
?>

0 commit comments

Comments
 (0)