Deleted two http maps, replaced by redis multimaps, much better tag system

master
andryyy 2017-05-08 15:39:33 +02:00
parent a18bcce93d
commit cdf7c87e20
6 changed files with 34 additions and 104 deletions

View File

@ -1,34 +0,0 @@
<?php
require_once "vars.inc.php";
ini_set('error_reporting', 0);
$has_object = 0;
header('Content-Type: text/plain');
$dsn = $database_type . ':host=' . $database_host . ';dbname=' . $database_name;
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
$stmt = $pdo->query("SELECT `domain` FROM `domain`");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
while ($row = array_shift($rows)) {
$has_object = 1;
echo strtolower(trim($row['domain'])) . PHP_EOL;
}
$stmt = $pdo->query("SELECT `alias_domain` FROM `alias_domain`");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
while ($row = array_shift($rows)) {
$has_object = 1;
echo strtolower(trim($row['alias_domain'])) . PHP_EOL;
}
if ($has_object == 0) {
echo "dummy@domain.local";
}
}
catch (PDOException $e) {
echo "dummy@domain.local";
exit;
}
?>

View File

@ -346,4 +346,4 @@ while ($row = array_shift($rows)) {
<?php
}
?>
}
}

View File

@ -1,41 +0,0 @@
<?php
require_once "vars.inc.php";
ini_set('error_reporting', 0);
$has_object = 0;
header('Content-Type: text/plain');
$dsn = $database_type . ':host=' . $database_host . ';dbname=' . $database_name;
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
$stmt = $pdo->query("SELECT `username` FROM `mailbox` WHERE `wants_tagged_subject` = '1'");
$rows_a = $stmt->fetchAll(PDO::FETCH_ASSOC);
while ($row_a = array_shift($rows_a)) {
$stmt = $pdo->prepare("SELECT `address` FROM `alias` WHERE `goto` REGEXP :username AND goto != `address` AND `address` NOT LIKE '@%'");
$stmt->execute(array(':username' => '(^|,)'.$row_a['username'].'($|,)'));
$rows_a_a = $stmt->fetchAll(PDO::FETCH_ASSOC);
while ($row_a_a = array_shift($rows_a_a)) {
echo strtolower(trim($row_a_a['address'])) . PHP_EOL;
}
$has_object = 1;
echo strtolower(trim($row_a['username'])) . PHP_EOL;
}
$stmt = $pdo->query("SELECT CONCAT(`mailbox`.`local_part`, '@', `alias_domain`.`alias_domain`) AS `tag_ad` FROM `mailbox`
INNER JOIN `alias_domain` ON `mailbox`.`domain` = `alias_domain`.`target_domain` WHERE `mailbox`.`wants_tagged_subject` = '1';");
$rows_b = $stmt->fetchAll(PDO::FETCH_ASSOC);
while ($row_b = array_shift($rows_b)) {
$has_object = 1;
echo strtolower(trim($row_b['tag_ad'])) . PHP_EOL;
}
if ($has_object == 0) {
echo "dummy@domain.local";
}
}
catch (PDOException $e) {
echo "dummy@domain.local";
exit;
}
?>

View File

@ -27,4 +27,4 @@ use_redis = true;
# Hash for DKIM keys in Redis
key_prefix = "DKIM_PRIV_KEYS";
# Selector map
selector_map = "redis://DKIM_SELECTORS";
selector_prefix = "DKIM_SELECTORS";

View File

@ -0,0 +1,11 @@
RCPT_MAILCOW_DOMAIN {
type = "rcpt";
filter = "email:domain"
map = "redis://DOMAIN_MAP"
}
RCPT_WANTS_SUBJECT_TAG {
type = "rcpt";
filter = "email:addr"
map = "redis://RCPT_WANTS_SUBJECT_TAG"
}

View File

@ -13,12 +13,9 @@ modify_subject_map = rspamd_config:add_map({
description = 'Map of users to use subject tags for'
})
auth_domain_map = rspamd_config:add_map({
url = 'http://172.22.1.251:8081/authoritative.php',
type = 'map',
description = 'Map of domains we are authoritative for'
})
local redis_params
redis_params = rspamd_parse_redis_server('tag_settings')
if redis_params then
rspamd_config:register_symbol({
name = 'TAG_MOO',
type = 'postfilter',
@ -27,12 +24,14 @@ rspamd_config:register_symbol({
local rspamd_logger = require "rspamd_logger"
local tagged_rcpt = task:get_symbol("TAGGED_RCPT")
local mailcow_domain = task:get_symbol("RCPT_MAILCOW_DOMAIN")
local user = task:get_recipients(0)[1]['user']
local domain = task:get_recipients(0)[1]['domain']
local rcpt = user .. '@' .. domain
local authdomain = auth_domain_map:get_key(domain)
if tagged_rcpt then
if tagged_rcpt and mailcow_domain then
local tag = tagged_rcpt[1].options[1]
rspamd_logger.infox("found tag: %s", tag)
local action = task:get_metric_action('default')
@ -44,32 +43,27 @@ rspamd_config:register_symbol({
return true
end
if authdomain then
rspamd_logger.infox("found mailcow domain %s", domain)
rspamd_logger.infox("querying tag settings for user %s", rcpt)
local wants_subject_tag = task:get_symbol("RCPT_WANTS_SUBJECT_TAG")
if modify_subject_map:get_key(rcpt) then
rspamd_logger.infox("user wants subject modified for tagged mail")
local sbj = task:get_header('Subject')
new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
task:set_rmilter_reply({
remove_headers = {['Subject'] = 1},
add_headers = {['Subject'] = new_sbj}
})
else
rspamd_logger.infox("Add X-Moo-Tag header")
task:set_rmilter_reply({
add_headers = {['X-Moo-Tag'] = 'YES'}
})
end
if wants_subject_tag then
rspamd_logger.infox("user wants subject modified for tagged mail")
local sbj = task:get_header('Subject')
new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
task:set_rmilter_reply({
remove_headers = {['Subject'] = 1},
add_headers = {['Subject'] = new_sbj}
})
else
rspamd_logger.infox("skip delimiter handling for unknown domain")
rspamd_logger.infox("Add X-Moo-Tag header")
task:set_rmilter_reply({
add_headers = {['X-Moo-Tag'] = 'YES'}
})
end
return false
end
end,
priority = 10
})
end
rspamd_config.MRAPTOR = {
callback = function(task)