Commit 536e907f authored by Marius Burkard's avatar Marius Burkard

- implemented per-domain-dkim, including custom selector

parent f5b95824
......@@ -1456,6 +1456,20 @@ class installer_base {
}
}
exec("postconf -e 'smtpd_recipient_restrictions = ".implode(", ", $new_options)."'");
if ( substr($mail_config['dkim_path'], strlen($mail_config['dkim_path'])-1) == '/' ) {
$mail_config['dkim_path'] = substr($mail_config['dkim_path'], 0, strlen($mail_config['dkim_path'])-1);
}
$dkim_domains = $this->db->queryAllRecords('SELECT `dkim_selector`, `domain` FROM `mail_domain` WHERE `dkim` = ? ORDER BY `domain` ASC', 'y');
$fpp = fopen('/etc/rspamd/local.d/dkim_domains.map', 'w');
$fps = fopen('/etc/rspamd/local.d/dkim_selectors.map', 'w');
foreach($dkim_domains as $dkim_domain) {
fwrite($fpp, $dkim_domain['domain'] . ' ' . $mail_config['dkim_path'] . '/' . $dkim_domain['domain'] . '.private' . "\n");
fwrite($fps, $dkim_domain['domain'] . ' ' . $dkim_domain['dkim_selector']);
}
fclose($fpp);
fclose($fps);
unset($dkim_domains);
}
if(is_user('_rspamd') && is_group('amavis')) {
......
path = "<tmpl_var name='dkim_path'>/$domain.private";
selector = "default";
\ No newline at end of file
try_fallback = false;
path_map = "/etc/rspamd/local.d/dkim_domains.map";
selector_map = "/etc/rspamd/local.d/dkim_selectors.map";";
\ No newline at end of file
......@@ -1535,7 +1535,14 @@ class system{
$found = 0;
if(is_array($lines)) {
foreach($lines as $line) {
if($strict == 0) {
if($strict == 0 && preg_match('/^REGEX:(.*)$/', $search_pattern)) {
if(preg_match(substr($search_pattern, 6), $line)) {
$out .= $new_line."\n";
$found = 1;
} else {
$out .= $line;
}
} elseif($strict == 0) {
if(stristr($line, $search_pattern)) {
$out .= $new_line."\n";
$found = 1;
......@@ -1573,7 +1580,14 @@ class system{
if($lines = @file($filename)) {
$out = '';
foreach($lines as $line) {
if($strict == 0) {
if($strict == 0 && preg_match('/^REGEX:(.*)$/', $search_pattern)) {
if(preg_match(substr($search_pattern, 6), $line)) {
$out .= $new_line."\n";
$found = 1;
} else {
$out .= $line;
}
} elseif($strict == 0) {
if(!stristr($line, $search_pattern)) {
$out .= $line;
}
......
......@@ -347,6 +347,9 @@ class mail_plugin_dkim {
}
if ($this->write_dkim_key($mail_config['dkim_path']."/".$data['new']['domain'], $data['new']['dkim_private'], $data['new']['domain'])) {
if($mail_config['content_filter'] == 'rspamd') {
$app->system->replaceLine('/etc/rspamd/local.d/dkim_domains.map', 'REGEX:/^' . preg_quote($data['new']['domain'], '/') . ' /', $data['new']['domain'] . ' ' . $mail_config['dkim_path']."/".$data['new']['domain'] . '.private');
$app->system->replaceLine('/etc/rspamd/local.d/dkim_selectors.map', 'REGEX:/^' . preg_quote($data['new']['domain'], '/') . ' /', $data['new']['domain'] . ' ' . $data['new']['dkim_selector']);
$app->services->restartServiceDelayed('rspamd', 'reload');
} elseif ($this->add_to_amavis($data['new']['domain'], $data['new']['dkim_selector'], $data['old']['dkim_selector'] )) {
$this->restart_amavis();
......@@ -373,6 +376,8 @@ class mail_plugin_dkim {
$this->remove_dkim_key($mail_config['dkim_path']."/".$_data['domain'], $_data['domain']);
if($mail_config['content_filter'] == 'rspamd') {
$app->system->removeLine('/etc/rspamd/local.d/dkim_domains.map', 'REGEX:/^' . preg_quote($_data['domain'], '/') . ' /');
$app->system->removeLine('/etc/rspamd/local.d/dkim_selectors.map', 'REGEX:/^' . preg_quote($_data['domain'], '/') . ' /');
$app->services->restartServiceDelayed('rspamd', 'reload');
} elseif ($this->remove_from_amavis($_data['domain'])) {
$this->restart_amavis();
......
......@@ -200,6 +200,21 @@ class postfix_server_plugin {
}
}
exec("postconf -e 'smtpd_recipient_restrictions = ".implode(", ", $new_options)."'");
// get all domains that have dkim enabled
if ( substr($mail_config['dkim_path'], strlen($mail_config['dkim_path'])-1) == '/' ) {
$mail_config['dkim_path'] = substr($mail_config['dkim_path'], 0, strlen($mail_config['dkim_path'])-1);
}
$dkim_domains = $app->db->queryAllRecords('SELECT `dkim_selector`, `domain` FROM `mail_domain` WHERE `dkim` = ? ORDER BY `domain` ASC', 'y');
$fpp = fopen('/etc/rspamd/local.d/dkim_domains.map', 'w');
$fps = fopen('/etc/rspamd/local.d/dkim_selectors.map', 'w');
foreach($dkim_domains as $dkim_domain) {
fwrite($fpp, $dkim_domain['domain'] . ' ' . $mail_config['dkim_path'] . '/' . $dkim_domain['domain'] . '.private' . "\n");
fwrite($fps, $dkim_domain['domain'] . ' ' . $dkim_domain['dkim_selector']);
}
fclose($fpp);
fclose($fps);
unset($dkim_domains);
}
if($mail_config['content_filter'] == 'amavisd'){
exec("postconf -X 'smtpd_milters'");
......
Markdown is supported
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