Commit 0c3e00e7 authored by Marius Burkard's avatar Marius Burkard
Browse files

- update all depending entries on domain update

parent 3f2704af
......@@ -226,13 +226,13 @@ class page_action extends tform_actions {
$sql = "SELECT domain, dkim_private, dkim_public, dkim_selector FROM mail_domain WHERE domain_id = ?";
$rec = $app->db->queryOneRecord($sql, $app->functions->intval($_GET['id']));
$dns_key = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$rec['dkim_public']);
$keyparts = str_split('v=DKIM1; t=s; p=' . $dns_key, 200);
array_walk($keyparts, function(&$value, $key) { $value = '"'.$value.'"'; } );
$dkim_txt = implode('', $keyparts);
$dns_record = $rec['dkim_selector'] . '._domainkey.' . $rec['domain'] . '. 3600 IN TXT '.$dkim_txt;
$app->tpl->setVar('dkim_selector', $rec['dkim_selector'], true);
$app->tpl->setVar('dkim_private', $rec['dkim_private'], true);
$app->tpl->setVar('dkim_public', $rec['dkim_public'], true);
......@@ -296,7 +296,7 @@ class page_action extends tform_actions {
$this->dataRecord["domain"] = $app->functions->idn_encode($this->dataRecord["domain"]);
$this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
}
//* server_id must be > 0
if(isset($this->dataRecord["server_id"]) && $this->dataRecord["server_id"] < 1) $app->tform->errorMessage .= $app->lng("server_id_0_error_txt");
......@@ -305,7 +305,7 @@ class page_action extends tform_actions {
function onAfterInsert() {
global $app, $conf;
$domain = $app->functions->idn_encode($this->dataRecord["domain"]);
// Spamfilter policy
......@@ -319,10 +319,10 @@ class page_action extends tform_actions {
$tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
// We create a new record
$insert_data = array(
"sys_userid" => $_SESSION["s"]["user"]["userid"],
"sys_userid" => $_SESSION["s"]["user"]["userid"],
"sys_groupid" => $tmp_domain["sys_groupid"],
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_other" => '',
"server_id" => $this->dataRecord["server_id"],
"priority" => 5,
......@@ -350,7 +350,7 @@ class page_action extends tform_actions {
function onBeforeUpdate() {
global $app, $conf;
$domain = $app->functions->idn_encode($this->dataRecord["domain"]);
//* Check if the server has been changed
......@@ -381,7 +381,7 @@ class page_action extends tform_actions {
global $app, $conf;
$domain = $app->functions->idn_encode($this->dataRecord["domain"]);
// Spamfilter policy
$policy_id = $app->functions->intval($this->dataRecord["policy"]);
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $domain);
......@@ -393,10 +393,10 @@ class page_action extends tform_actions {
$tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
// We create a new record
$insert_data = array(
"sys_userid" => $_SESSION["s"]["user"]["userid"],
"sys_userid" => $_SESSION["s"]["user"]["userid"],
"sys_groupid" => $tmp_domain["sys_groupid"],
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_other" => '',
"server_id" => $this->dataRecord["server_id"],
"priority" => 5,
......@@ -422,7 +422,7 @@ class page_action extends tform_actions {
//* Update the mailboxes
$mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like ?", '%@' . $this->oldDataRecord['domain']);
$sys_groupid = $app->functions->intval((isset($this->dataRecord['client_group_id']))?$this->dataRecord['client_group_id']:$this->oldDataRecord['sys_groupid']);
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = ?", $client_group_id);
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = ?", $sys_groupid);
$client_user_id = $app->functions->intval(($tmp['userid'] > 0)?$tmp['userid']:1);
if(is_array($mailusers)) {
foreach($mailusers as $rec) {
......@@ -447,7 +447,7 @@ class page_action extends tform_actions {
//* Update the mailinglist
$app->db->query("UPDATE mail_mailinglist SET sys_userid = ?, sys_groupid = ? WHERE domain = ?", $client_user_id, $sys_groupid, $this->oldDataRecord['domain']);
//* Update fetchmail accounts
$fetchmail = $app->db->queryAllRecords("SELECT * FROM mail_get WHERE destination like ?", '%@' . $this->oldDataRecord['domain']);
if(is_array($fetchmail)) {
......@@ -456,7 +456,7 @@ class page_action extends tform_actions {
$app->db->datalogUpdate('mail_get', array("destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailget_id', $rec['mailget_id']);
}
}
//* Delete the old spamfilter record
$tmp = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $this->oldDataRecord["domain"]);
$app->db->datalogDelete('spamfilter_users', 'id', $tmp["id"]);
......@@ -467,10 +467,10 @@ class page_action extends tform_actions {
//* update dns-record when the dkim record was changed
// NOTE: only if the domain-name was not changed
if ( $this->dataRecord['active'] == 'y' && $domain == $this->oldDataRecord['domain'] ) {
$dkim_active = @($this->dataRecord['dkim'] == 'y') ? true : false;
$dkim_active = @($this->dataRecord['dkim'] == 'y') ? true : false;
$selector = @($this->dataRecord['dkim_selector'] != $this->oldDataRecord['dkim_selector']) ? true : false;
$dkim_private = @($this->dataRecord['dkim_private'] != $this->oldDataRecord['dkim_private']) ? true : false;
$soaDomain = $domain.'.';
while ((!isset($soa) && (substr_count($soaDomain,'.') > 1))) {
$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 @@ class page_action extends tform_actions {
$soa_id = $app->functions->intval($soa['zone']);
$serial = $app->validate_dns->increase_serial($soa["serial"]);
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
}
}
}
}
......@@ -510,8 +510,8 @@ class page_action extends tform_actions {
$app->db->datalogDelete('dns_rr', 'id', $r['id']);
}
}
// also delete a dsn-records with same selector
// also delete a dsn-records with same selector
$sql = "SELECT * from dns_rr WHERE name ? AND data LIKE 'v=DKIM1%' AND " . $app->tform->getAuthSQL('r');
$rec = $app->db->queryAllRecords($sql, '._domainkey.'.$dataRecord['dkim_selector'].'.', $dataRecord['domain']);
if (is_array($rec))
......
......@@ -139,7 +139,7 @@ class rspamd_plugin {
$app->plugins->registerEvent('mail_forwarding_delete', $this->plugin_name, 'user_settings_update');
}
function user_settings_update($event_name, $data) {
function user_settings_update($event_name, $data, $internal = false) {
global $app, $conf;
if(!is_dir('/etc/rspamd')) {
......@@ -206,6 +206,23 @@ class rspamd_plugin {
return;
}
$entries_to_update = [
'mail_user' => [],
'mail_forwarding' => []
];
if($is_domain === true) {
// get all child records to update / delete
$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);
if(is_array($mailusers) && !empty($mailusers)) {
$entries_to_update['mail_user'] = $mailusers;
}
$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);
if(is_array($forwardings) && !empty($forwardings)) {
$entries_to_update['mail_forwarding'] = $forwardings;
}
}
$old_settings_name = $settings_name;
$settings_name = $app->functions->idn_encode($settings_name);
......@@ -328,7 +345,14 @@ class rspamd_plugin {
}
}
if($mail_config['content_filter'] == 'rspamd'){
foreach($entries_to_update['mail_user'] as $entry) {
$this->user_settings_update('mail_user_' . $mode, $entry, true);
}
foreach($entries_to_update['mail_forwarding'] as $entry) {
$this->user_settings_update('mail_forwarding_' . $mode, $entry, true);
}
if($internal !== true && $mail_config['content_filter'] == 'rspamd'){
$app->services->restartServiceDelayed('rspamd', 'reload');
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment