Skip to content

Commit 0c3e00e

Browse files
author
Marius Burkard
committed
- update all depending entries on domain update
1 parent 3f2704a commit 0c3e00e

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

interface/web/mail/mail_domain_edit.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ function onShowEnd() {
226226
$sql = "SELECT domain, dkim_private, dkim_public, dkim_selector FROM mail_domain WHERE domain_id = ?";
227227
$rec = $app->db->queryOneRecord($sql, $app->functions->intval($_GET['id']));
228228
$dns_key = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$rec['dkim_public']);
229-
229+
230230
$keyparts = str_split('v=DKIM1; t=s; p=' . $dns_key, 200);
231231
array_walk($keyparts, function(&$value, $key) { $value = '"'.$value.'"'; } );
232232
$dkim_txt = implode('', $keyparts);
233233

234234
$dns_record = $rec['dkim_selector'] . '._domainkey.' . $rec['domain'] . '. 3600 IN TXT '.$dkim_txt;
235-
235+
236236
$app->tpl->setVar('dkim_selector', $rec['dkim_selector'], true);
237237
$app->tpl->setVar('dkim_private', $rec['dkim_private'], true);
238238
$app->tpl->setVar('dkim_public', $rec['dkim_public'], true);
@@ -296,7 +296,7 @@ function onSubmit() {
296296
$this->dataRecord["domain"] = $app->functions->idn_encode($this->dataRecord["domain"]);
297297
$this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
298298
}
299-
299+
300300
//* server_id must be > 0
301301
if(isset($this->dataRecord["server_id"]) && $this->dataRecord["server_id"] < 1) $app->tform->errorMessage .= $app->lng("server_id_0_error_txt");
302302

@@ -305,7 +305,7 @@ function onSubmit() {
305305

306306
function onAfterInsert() {
307307
global $app, $conf;
308-
308+
309309
$domain = $app->functions->idn_encode($this->dataRecord["domain"]);
310310

311311
// Spamfilter policy
@@ -319,10 +319,10 @@ function onAfterInsert() {
319319
$tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
320320
// We create a new record
321321
$insert_data = array(
322-
"sys_userid" => $_SESSION["s"]["user"]["userid"],
322+
"sys_userid" => $_SESSION["s"]["user"]["userid"],
323323
"sys_groupid" => $tmp_domain["sys_groupid"],
324-
"sys_perm_user" => 'riud',
325-
"sys_perm_group" => 'riud',
324+
"sys_perm_user" => 'riud',
325+
"sys_perm_group" => 'riud',
326326
"sys_perm_other" => '',
327327
"server_id" => $this->dataRecord["server_id"],
328328
"priority" => 5,
@@ -350,7 +350,7 @@ function onAfterInsert() {
350350

351351
function onBeforeUpdate() {
352352
global $app, $conf;
353-
353+
354354
$domain = $app->functions->idn_encode($this->dataRecord["domain"]);
355355

356356
//* Check if the server has been changed
@@ -381,7 +381,7 @@ function onAfterUpdate() {
381381
global $app, $conf;
382382

383383
$domain = $app->functions->idn_encode($this->dataRecord["domain"]);
384-
384+
385385
// Spamfilter policy
386386
$policy_id = $app->functions->intval($this->dataRecord["policy"]);
387387
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $domain);
@@ -393,10 +393,10 @@ function onAfterUpdate() {
393393
$tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
394394
// We create a new record
395395
$insert_data = array(
396-
"sys_userid" => $_SESSION["s"]["user"]["userid"],
396+
"sys_userid" => $_SESSION["s"]["user"]["userid"],
397397
"sys_groupid" => $tmp_domain["sys_groupid"],
398-
"sys_perm_user" => 'riud',
399-
"sys_perm_group" => 'riud',
398+
"sys_perm_user" => 'riud',
399+
"sys_perm_group" => 'riud',
400400
"sys_perm_other" => '',
401401
"server_id" => $this->dataRecord["server_id"],
402402
"priority" => 5,
@@ -422,7 +422,7 @@ function onAfterUpdate() {
422422
//* Update the mailboxes
423423
$mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like ?", '%@' . $this->oldDataRecord['domain']);
424424
$sys_groupid = $app->functions->intval((isset($this->dataRecord['client_group_id']))?$this->dataRecord['client_group_id']:$this->oldDataRecord['sys_groupid']);
425-
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = ?", $client_group_id);
425+
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = ?", $sys_groupid);
426426
$client_user_id = $app->functions->intval(($tmp['userid'] > 0)?$tmp['userid']:1);
427427
if(is_array($mailusers)) {
428428
foreach($mailusers as $rec) {
@@ -447,7 +447,7 @@ function onAfterUpdate() {
447447

448448
//* Update the mailinglist
449449
$app->db->query("UPDATE mail_mailinglist SET sys_userid = ?, sys_groupid = ? WHERE domain = ?", $client_user_id, $sys_groupid, $this->oldDataRecord['domain']);
450-
450+
451451
//* Update fetchmail accounts
452452
$fetchmail = $app->db->queryAllRecords("SELECT * FROM mail_get WHERE destination like ?", '%@' . $this->oldDataRecord['domain']);
453453
if(is_array($fetchmail)) {
@@ -456,7 +456,7 @@ function onAfterUpdate() {
456456
$app->db->datalogUpdate('mail_get', array("destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailget_id', $rec['mailget_id']);
457457
}
458458
}
459-
459+
460460
//* Delete the old spamfilter record
461461
$tmp = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $this->oldDataRecord["domain"]);
462462
$app->db->datalogDelete('spamfilter_users', 'id', $tmp["id"]);
@@ -467,10 +467,10 @@ function onAfterUpdate() {
467467
//* update dns-record when the dkim record was changed
468468
// NOTE: only if the domain-name was not changed
469469
if ( $this->dataRecord['active'] == 'y' && $domain == $this->oldDataRecord['domain'] ) {
470-
$dkim_active = @($this->dataRecord['dkim'] == 'y') ? true : false;
470+
$dkim_active = @($this->dataRecord['dkim'] == 'y') ? true : false;
471471
$selector = @($this->dataRecord['dkim_selector'] != $this->oldDataRecord['dkim_selector']) ? true : false;
472472
$dkim_private = @($this->dataRecord['dkim_private'] != $this->oldDataRecord['dkim_private']) ? true : false;
473-
473+
474474
$soaDomain = $domain.'.';
475475
while ((!isset($soa) && (substr_count($soaDomain,'.') > 1))) {
476476
$soa = $app->db->queryOneRecord("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, ttl, serial FROM dns_soa WHERE active = 'Y' AND origin = ?", $soaDomain);
@@ -493,7 +493,7 @@ function onAfterUpdate() {
493493
$soa_id = $app->functions->intval($soa['zone']);
494494
$serial = $app->validate_dns->increase_serial($soa["serial"]);
495495
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
496-
}
496+
}
497497
}
498498
}
499499

@@ -510,8 +510,8 @@ private function update_dns($dataRecord, $new_rr) {
510510
$app->db->datalogDelete('dns_rr', 'id', $r['id']);
511511
}
512512
}
513-
514-
// also delete a dsn-records with same selector
513+
514+
// also delete a dsn-records with same selector
515515
$sql = "SELECT * from dns_rr WHERE name ? AND data LIKE 'v=DKIM1%' AND " . $app->tform->getAuthSQL('r');
516516
$rec = $app->db->queryAllRecords($sql, '._domainkey.'.$dataRecord['dkim_selector'].'.', $dataRecord['domain']);
517517
if (is_array($rec))

server/plugins-available/rspamd_plugin.inc.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function onLoad() {
139139
$app->plugins->registerEvent('mail_forwarding_delete', $this->plugin_name, 'user_settings_update');
140140
}
141141

142-
function user_settings_update($event_name, $data) {
142+
function user_settings_update($event_name, $data, $internal = false) {
143143
global $app, $conf;
144144

145145
if(!is_dir('/etc/rspamd')) {
@@ -206,6 +206,23 @@ function user_settings_update($event_name, $data) {
206206
return;
207207
}
208208

209+
$entries_to_update = [
210+
'mail_user' => [],
211+
'mail_forwarding' => []
212+
];
213+
if($is_domain === true) {
214+
// get all child records to update / delete
215+
$mailusers = $app->db->queryAllRecords("SELECT mu.* FROM mail_user as mu LEFT JOIN spamfilter_users as su ON (su.email = mu.email) WHERE mu.email LIKE ? AND su.id IS NULL", '%' . $email_address);
216+
if(is_array($mailusers) && !empty($mailusers)) {
217+
$entries_to_update['mail_user'] = $mailusers;
218+
}
219+
220+
$forwardings = $app->db->queryAllRecords("SELECT mf.* FROM mail_forwarding as mf LEFT JOIN spamfilter_users as su ON (su.email = mf.source) WHERE mf.source LIKE ? AND su.id IS NULL", '%' . $email_address);
221+
if(is_array($forwardings) && !empty($forwardings)) {
222+
$entries_to_update['mail_forwarding'] = $forwardings;
223+
}
224+
}
225+
209226
$old_settings_name = $settings_name;
210227
$settings_name = $app->functions->idn_encode($settings_name);
211228

@@ -328,7 +345,14 @@ function user_settings_update($event_name, $data) {
328345
}
329346
}
330347

331-
if($mail_config['content_filter'] == 'rspamd'){
348+
foreach($entries_to_update['mail_user'] as $entry) {
349+
$this->user_settings_update('mail_user_' . $mode, $entry, true);
350+
}
351+
foreach($entries_to_update['mail_forwarding'] as $entry) {
352+
$this->user_settings_update('mail_forwarding_' . $mode, $entry, true);
353+
}
354+
355+
if($internal !== true && $mail_config['content_filter'] == 'rspamd'){
332356
$app->services->restartServiceDelayed('rspamd', 'reload');
333357
}
334358
}

0 commit comments

Comments
 (0)