Skip to content

Commit b59dc3f

Browse files
committed
WIP: rspamd whitelisting and rule priorities
1 parent 6502a5b commit b59dc3f

8 files changed

+35
-25
lines changed

install/lib/installer_base.lib.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,7 @@ public function configure_rspamd() {
18141814
$mail_config['dkim_path'] = substr($mail_config['dkim_path'], 0, strlen($mail_config['dkim_path'])-1);
18151815
}
18161816
$dkim_domains = $this->db->queryAllRecords('SELECT `dkim_selector`, `domain` FROM ?? WHERE `dkim` = ? ORDER BY `domain` ASC', $conf['mysql']['database'] . '.mail_domain', 'y');
1817+
# should move maps to local.d/maps.d/ ?
18171818
$fpp = fopen('/etc/rspamd/local.d/dkim_domains.map', 'w');
18181819
$fps = fopen('/etc/rspamd/local.d/dkim_selectors.map', 'w');
18191820
foreach($dkim_domains as $dkim_domain) {
@@ -1824,19 +1825,28 @@ public function configure_rspamd() {
18241825
fclose($fps);
18251826
unset($dkim_domains);
18261827

1828+
# local.d templates with template tags
18271829
$tpl = new tpl();
1828-
$tpl->newTemplate('rspamd_users.conf.master');
1830+
$tpl->newTemplate('rspamd_dkim_signing.conf.master');
1831+
$tpl->setVar('dkim_path', $mail_config['dkim_path']);
1832+
wf('/etc/rspamd/local.d/dkim_signing.conf', $tpl->grab());
1833+
1834+
$tpl = new tpl();
1835+
$tpl->newTemplate('rspamd_options.inc.master');
18291836

1830-
$whitelist_ips = array();
1831-
$ips = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ?", $conf['server_id']);
1837+
echo "\nDEBUGGING local_addrs LOOP\n\n";
1838+
sleep(1);
1839+
$local_addrs = array();
1840+
$ips = $this->db->queryAllRecords('SELECT `ip_address`, `ip_type` FROM ?? WHERE `server_id` = ?', $conf['mysql']['database'].'.server_ip', $conf['server_id']);
18321841
if(is_array($ips) && !empty($ips)){
18331842
foreach($ips as $ip){
1834-
$whitelist_ips[] = array('ip' => $ip['ip_address']);
1843+
$local_addrs[] = array('quoted_ip' => "\"".$ip['ip_address']."\",\n");
18351844
}
18361845
}
1837-
$tpl->setLoop('whitelist_ips', $whitelist_ips);
1838-
wf('/etc/rspamd/local.d/users.conf', $tpl->grab());
1846+
$tpl->setLoop('local_addrs', $local_addrs);
1847+
wf('/etc/rspamd/local.d/options.inc', $tpl->grab());
18391848

1849+
# local.d templates without template tags
18401850
$local_d = array(
18411851
'groups.conf',
18421852
'antivirus.conf',
@@ -1845,10 +1855,10 @@ public function configure_rspamd() {
18451855
'mx_check.conf',
18461856
'redis.conf',
18471857
'milter_headers.conf',
1848-
'options.inc',
18491858
'neural.conf',
18501859
'neural_group.conf',
1851-
'group.conf',
1860+
'users.conf',
1861+
'groups.conf',
18521862
);
18531863
foreach ($local_d as $f) {
18541864
if(file_exists($conf['ispconfig_install_dir']."/server/conf-custom/install/rspamd_${f}.master")) {
@@ -1858,6 +1868,7 @@ public function configure_rspamd() {
18581868
}
18591869
}
18601870

1871+
# override.d templates without template tags
18611872
$override_d = array(
18621873
'rbl_group.conf',
18631874
'surbl_group.conf',
@@ -1866,10 +1877,11 @@ public function configure_rspamd() {
18661877
if(file_exists($conf['ispconfig_install_dir']."/server/conf-custom/install/rspamd_${f}.master")) {
18671878
exec('cp '.$conf['ispconfig_install_dir']."/server/conf-custom/install/rspamd_${f}.master /etc/rspamd/override.d/${f}");
18681879
} else {
1869-
exec("cp tpl/rspamd_{f}.master /etc/rspamd/override.d/${f}");
1880+
exec("cp tpl/rspamd_${f}.master /etc/rspamd/override.d/${f}");
18701881
}
18711882
}
18721883

1884+
# local.d/maps.d templates without template tags
18731885
$maps_d = array(
18741886
'dkim_whitelist.inc',
18751887
'dmarc_whitelist.inc',
@@ -1884,10 +1896,6 @@ public function configure_rspamd() {
18841896
}
18851897
}
18861898

1887-
$tpl = new tpl();
1888-
$tpl->newTemplate('rspamd_dkim_signing.conf.master');
1889-
$tpl->setVar('dkim_path', $mail_config['dkim_path']);
1890-
wf('/etc/rspamd/local.d/dkim_signing.conf', $tpl->grab());
18911899

18921900
exec('chmod a+r /etc/rspamd/local.d/* /etc/rspamd/local.d/maps.d/* /etc/rspamd/override.d/*');
18931901

File renamed without changes.

install/tpl/dmarc_whitelist.inc.master renamed to install/tpl/rspamd_dmarc_whitelist.inc.master

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ geotrust.com
55
geotrusteurope.com
66
howtoforge.com
77
ispconfig.org
8-
letsencrypt.org
98

install/tpl/rspamd_options.inc.master

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
local_addrs = "127.0.0.0/8, ::1";
1+
# Addrs local to this server.
2+
local_addrs = [
3+
"127.0.0.0/8",
4+
"::1",
5+
<tmpl_loop name="local_addrs"> <tmpl_var name='quoted_ip'></tmpl_loop>];
6+
7+
# This list is generated by ISPConfig, place custom addresses/networks in local_networks.inc.
8+
local_networks = "/etc/rspamd/local.d/local_networks.inc";
29

310
dns {
411
nameserver = ["127.0.0.1:53:10"];

install/tpl/spf_dkim_whitelist.inc.master renamed to install/tpl/rspamd_spf_dkim_whitelist.inc.master

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
comodo.com
55
geotrust.com
66
geotrusteurope.com
7-
letsencrypt.org
7+
# letsencrypt is in rspamd's default spf_dkim_whitelist, only needed if strict:
8+
#letsencrypt.org both:1.0
89

File renamed without changes.

install/update.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@
254254

255255
//* initialize the database
256256
$inst->db = new db();
257+
$inst->db->setDBData($conf['mysql']["host"], $conf['mysql']["ispconfig_user"], $conf['mysql']["ispconfig_password"], $conf['mysql']["port"]);
258+
$inst->db->setDBName($conf['mysql']['database']);
257259

258260
//* initialize the master DB, if we have a multiserver setup
259261
if($conf['mysql']['master_slave_setup'] == 'y') {
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
settings {
22
authenticated {
3-
priority = 9;
3+
priority = 10;
44
authenticated = yes;
55
apply "default" {
66
symbols_disabled = [];
77
groups_disabled = ["rbl", "spf"];
88
}
99
}
1010
whitelist {
11-
priority = 7;
11+
priority = 5;
1212
rcpt = "postmaster";
1313
rcpt = "hostmaster";
1414
rcpt = "abuse";
1515
want_spam = yes;
1616
}
17-
whitelist-ip {
18-
priority = 5;
19-
<tmpl_loop name="whitelist_ips">
20-
ip = "<tmpl_var name='ip'>";
21-
</tmpl_loop>
22-
want_spam = yes;
23-
}
2417
.include(try=true; glob=true) "$LOCAL_CONFDIR/local.d/users/*.conf"
2518
.include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/users.local.conf"
2619
}

0 commit comments

Comments
 (0)