Skip to content

Commit 76361dc

Browse files
committed
rspamd: add ip whitelist map
1 parent dbc6479 commit 76361dc

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

install/lib/installer_base.lib.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,23 @@ public function configure_rspamd() {
19351935
}
19361936
}
19371937

1938+
# generated local.d/maps.d files
1939+
$filename = '/etc/rspamd/local.d/maps.d/ip_whitelist.inc.ispc';
1940+
@unlink($filename);
1941+
$records = $this->db->queryAllRecords("SELECT `source` FROM ?? WHERE `type` = 'client' AND `access` = 'OK' AND `active` = 'y' AND `server_id` = ? ORDER BY `source` ASC", $conf['mysql']['database'] . '.mail_access', $conf['server_id']);
1942+
if (count($records) > 0) {
1943+
if ($fp = fopen($filename, 'w')) {
1944+
fwrite($fp, "# ISPConfig whitelisted ip addresses\n\n");
1945+
foreach($records as $record) {
1946+
fwrite($fp, $record['source'] . "\n");
1947+
}
1948+
fclose($fp);
1949+
} else {
1950+
$this->error("Error: cannot open $filename for writing");
1951+
}
1952+
}
1953+
1954+
19381955
# rename rspamd templates we no longer use
19391956
if(file_exists("/etc/rspamd/local.d/greylist.conf")) {
19401957
rename("/etc/rspamd/local.d/greylist.conf", "/etc/rspamd/local.d/greylist.old");

install/tpl/rspamd_multimap.conf.master

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
ISPC_WHITELIST_IP {
2+
description = "Whitelisted ip address";
3+
group = "ISPConfig";
4+
type = "ip";
5+
map = [ "$LOCAL_CONFDIR/local.d/maps.d/ip_whitelist.inc.ispc", "$LOCAL_CONFDIR/local.d/maps.d/ip_whitelist.inc.local" ];
6+
prefilter = "true";
7+
action = "accept";
8+
}
9+
10+
# ISPC_BLACKLIST_IP: Postfix blocks blacklisted IP's, no need to configure those here.
11+
112
# from https://rspamd.com/doc/configuration/selectors.html
213
INVALUEMENT_SENDGRID_ID {
314
type = "selector";

server/plugins-available/rspamd_plugin.inc.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ function onLoad() {
119119
$app->plugins->registerEvent('mail_access_insert', $this->plugin_name, 'spamfilter_wblist_insert');
120120
$app->plugins->registerEvent('mail_access_update', $this->plugin_name, 'spamfilter_wblist_update');
121121
$app->plugins->registerEvent('mail_access_delete', $this->plugin_name, 'spamfilter_wblist_delete');
122+
$app->plugins->registerEvent('mail_access_insert', $this->plugin_name, 'mail_access_update');
123+
$app->plugins->registerEvent('mail_access_update', $this->plugin_name, 'mail_access_update');
124+
$app->plugins->registerEvent('mail_access_delete', $this->plugin_name, 'mail_access_update');
122125

123126
//* server
124127
$app->plugins->registerEvent('server_insert', $this->plugin_name, 'server_update');
@@ -498,6 +501,32 @@ function spamfilter_wblist_delete($event_name, $data) {
498501
}
499502
}
500503

504+
function mail_access_update($event_name, $data) {
505+
global $app, $conf;
506+
507+
if(!is_dir('/etc/rspamd')) {
508+
return;
509+
}
510+
511+
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
512+
513+
# generated local.d/maps.d files
514+
$filename = '/etc/rspamd/local.d/maps.d/ip_whitelist.inc.ispc';
515+
@unlink($filename);
516+
$records = $app->db->queryAllRecords("SELECT `source` FROM ?? WHERE `type` = 'client' AND `access` = 'OK' AND `active` = 'y' AND `server_id` = ? ORDER BY `source` ASC", $conf['mysql']['database'] . '.mail_access', $conf['server_id']);
517+
if (count($records) > 0) {
518+
if ($fp = fopen($filename, 'w')) {
519+
fwrite($fp, "# ISPConfig whitelisted ip addresses\n\n");
520+
foreach($records as $record) {
521+
fwrite($fp, $record['source'] . "\n");
522+
}
523+
fclose($fp);
524+
} else {
525+
$app->log("Error: cannot open $filename for writing", LOGLEVEL_WARN);
526+
}
527+
}
528+
}
529+
501530
function server_update($event_name, $data) {
502531
global $app, $conf;
503532

0 commit comments

Comments
 (0)