2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
The match section performs AND operation on different matches: for example, if you have from and rcpt in the same rule,
|
|
|
|
then the rule matches only when from AND rcpt match. For similar matches, the OR rule applies: if you have multiple rcpt matches,
|
|
|
|
then any of these will trigger the rule. If a rule is triggered then no more rules are matched.
|
|
|
|
*/
|
|
|
|
header('Content-Type: text/plain');
|
|
|
|
require_once "vars.inc.php";
|
2017-01-19 04:26:49 +08:00
|
|
|
|
2017-03-03 11:44:51 +08:00
|
|
|
ini_set('error_reporting', 0);
|
|
|
|
|
2016-12-10 07:39:27 +08:00
|
|
|
$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,
|
|
|
|
];
|
|
|
|
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
|
|
|
|
?>
|
|
|
|
settings {
|
|
|
|
<?php
|
|
|
|
$stmt = $pdo->query("SELECT DISTINCT `object` FROM `filterconf` WHERE `option` = 'highspamlevel' OR `option` = 'lowspamlevel'");
|
|
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
while ($row = array_shift($rows)) {
|
|
|
|
$username_sane = preg_replace("/[^a-zA-Z0-9]+/", "", $row['object']);
|
|
|
|
?>
|
|
|
|
score_<?=$username_sane;?> {
|
2016-12-11 21:13:17 +08:00
|
|
|
priority = low;
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
$stmt = $pdo->prepare("SELECT `option`, `value` FROM `filterconf`
|
|
|
|
WHERE (`option` = 'highspamlevel' OR `option` = 'lowspamlevel')
|
|
|
|
AND `object`= :object");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
|
|
|
$spamscore = $stmt->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP);
|
|
|
|
|
|
|
|
$stmt = $pdo->prepare("SELECT GROUP_CONCAT(REPLACE(`value`, '*', '.*') SEPARATOR '|') AS `value` FROM `filterconf`
|
2017-01-29 20:56:24 +08:00
|
|
|
WHERE (`object`= :object OR `object`= :object_domain)
|
2016-12-10 07:39:27 +08:00
|
|
|
AND (`option` = 'blacklist_from' OR `option` = 'whitelist_from')");
|
2017-01-29 20:56:24 +08:00
|
|
|
$stmt->execute(array(':object' => $row['object'], ':object_domain' => substr(strrchr($row['object'], "@"), 1)));
|
2017-03-03 11:44:51 +08:00
|
|
|
$grouped_lists = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
array_filter($grouped_lists);
|
|
|
|
while ($grouped_list = array_shift($grouped_lists)) {
|
|
|
|
$value_sane = preg_replace("/\.\./", ".", (preg_replace("/\*/", ".*", $grouped_list['value'])));
|
|
|
|
if (!empty($value_sane)) {
|
2016-12-10 07:39:27 +08:00
|
|
|
?>
|
2016-12-11 21:13:17 +08:00
|
|
|
from = "/^((?!<?=$value_sane;?>).)*$/";
|
2017-03-03 11:44:51 +08:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
2016-12-11 21:13:17 +08:00
|
|
|
rcpt = "<?=$row['object'];?>";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
$stmt = $pdo->prepare("SELECT `address` FROM `alias` WHERE `goto` = :object_goto AND `address` NOT LIKE '@%' AND `address` != :object_address");
|
|
|
|
$stmt->execute(array(':object_goto' => $row['object'], ':object_address' => $row['object']));
|
|
|
|
$rows_aliases_1 = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
while ($row_aliases_1 = array_shift($rows_aliases_1)) {
|
|
|
|
?>
|
2016-12-11 21:13:17 +08:00
|
|
|
rcpt = "<?=$row_aliases_1['address'];?>";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT CONCAT(`local_part`, '@', `alias_domain`.`alias_domain`) AS `aliases` FROM `mailbox`
|
|
|
|
LEFT OUTER JOIN `alias_domain` on `mailbox`.`domain` = `alias_domain`.`target_domain`
|
|
|
|
WHERE `mailbox`.`username` = :object");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
|
|
|
$rows_aliases_2 = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2017-03-03 11:44:51 +08:00
|
|
|
array_filter($rows_aliases_2);
|
2017-01-19 04:26:49 +08:00
|
|
|
while ($row_aliases_2 = array_shift($rows_aliases_2)) {
|
2017-01-29 20:56:24 +08:00
|
|
|
if (!empty($row_aliases_2['aliases'])) {
|
2016-12-10 07:39:27 +08:00
|
|
|
?>
|
2016-12-11 21:13:17 +08:00
|
|
|
rcpt = "<?=$row_aliases_2['aliases'];?>";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
2017-01-29 20:56:24 +08:00
|
|
|
}
|
2016-12-10 07:39:27 +08:00
|
|
|
}
|
|
|
|
?>
|
2016-12-11 21:13:17 +08:00
|
|
|
apply "default" {
|
|
|
|
actions {
|
|
|
|
reject = <?=$spamscore['highspamlevel'][0];?>;
|
|
|
|
greylist = <?=$spamscore['lowspamlevel'][0] - 1;?>;
|
|
|
|
"add header" = <?=$spamscore['lowspamlevel'][0];?>;
|
|
|
|
}
|
2016-12-10 07:39:27 +08:00
|
|
|
}
|
2017-01-29 20:56:24 +08:00
|
|
|
}
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
}
|
2016-12-30 04:12:19 +08:00
|
|
|
|
2016-12-10 07:39:27 +08:00
|
|
|
/*
|
|
|
|
// Start whitelist
|
|
|
|
*/
|
|
|
|
|
|
|
|
$stmt = $pdo->query("SELECT DISTINCT `object` FROM `filterconf` WHERE `option` = 'whitelist_from'");
|
|
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
while ($row = array_shift($rows)) {
|
|
|
|
$username_sane = preg_replace("/[^a-zA-Z0-9]+/", "", $row['object']);
|
|
|
|
?>
|
|
|
|
whitelist_<?=$username_sane;?> {
|
|
|
|
<?php
|
|
|
|
$stmt = $pdo->prepare("SELECT GROUP_CONCAT(REPLACE(`value`, '*', '.*') SEPARATOR '|') AS `value` FROM `filterconf`
|
|
|
|
WHERE `object`= :object
|
|
|
|
AND `option` = 'whitelist_from'");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
|
|
|
$grouped_lists = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
$value_sane = preg_replace("/\.\./", ".", (preg_replace("/\*/", ".*", $grouped_lists[0])));
|
|
|
|
?>
|
|
|
|
from = "/(<?=$value_sane;?>)/";
|
|
|
|
<?php
|
|
|
|
if (!filter_var(trim($row['object']), FILTER_VALIDATE_EMAIL)) {
|
|
|
|
?>
|
2017-01-19 04:26:49 +08:00
|
|
|
priority = medium;
|
|
|
|
rcpt = "/.*@<?=$row['object'];?>/";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
$stmt = $pdo->prepare("SELECT `alias_domain` FROM `alias_domain`
|
|
|
|
WHERE `target_domain` = :object");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
|
|
|
$rows_domain_aliases = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2017-03-03 11:44:51 +08:00
|
|
|
array_filter($rows_domain_aliases);
|
2016-12-10 07:39:27 +08:00
|
|
|
while ($row_domain_aliases = array_shift($rows_domain_aliases)) {
|
|
|
|
?>
|
2017-01-19 04:26:49 +08:00
|
|
|
rcpt = "/.*@<?=$row_domain_aliases['alias_domain'];?>/";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
2017-01-19 04:26:49 +08:00
|
|
|
priority = high;
|
2016-12-10 07:39:27 +08:00
|
|
|
rcpt = "<?=$row['object'];?>";
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT `address` FROM `alias` WHERE `goto` = :object_goto AND `address` NOT LIKE '@%' AND `address` != :object_address");
|
|
|
|
$stmt->execute(array(':object_goto' => $row['object'], ':object_address' => $row['object']));
|
|
|
|
$rows_aliases_wl_1 = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2017-03-03 11:44:51 +08:00
|
|
|
array_filter($rows_aliases_wl_1);
|
2016-12-10 07:39:27 +08:00
|
|
|
while ($row_aliases_wl_1 = array_shift($rows_aliases_wl_1)) {
|
|
|
|
?>
|
|
|
|
rcpt = "<?=$row_aliases_wl_1['address'];?>";
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT CONCAT(`local_part`, '@', `alias_domain`.`alias_domain`) AS `aliases` FROM `mailbox`
|
|
|
|
LEFT OUTER JOIN `alias_domain` on `mailbox`.`domain` = `alias_domain`.`target_domain`
|
|
|
|
WHERE `mailbox`.`username` = :object");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
|
|
|
$rows_aliases_wl_2 = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2017-03-03 11:44:51 +08:00
|
|
|
array_filter($rows_aliases_wl_2);
|
2017-01-19 04:26:49 +08:00
|
|
|
while ($row_aliases_wl_2 = array_shift($rows_aliases_wl_2)) {
|
2017-01-29 20:56:24 +08:00
|
|
|
if (!empty($row_aliases_wl_2['aliases'])) {
|
2016-12-10 07:39:27 +08:00
|
|
|
?>
|
|
|
|
rcpt = "<?=$row_aliases_wl_2['aliases'];?>";
|
|
|
|
<?php
|
2017-01-29 20:56:24 +08:00
|
|
|
}
|
2016-12-10 07:39:27 +08:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
apply "default" {
|
|
|
|
MAILCOW_MOO = -999.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Start blacklist
|
|
|
|
*/
|
|
|
|
|
|
|
|
$stmt = $pdo->query("SELECT DISTINCT `object` FROM `filterconf` WHERE `option` = 'blacklist_from'");
|
|
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
while ($row = array_shift($rows)) {
|
|
|
|
$username_sane = preg_replace("/[^a-zA-Z0-9]+/", "", $row['object']);
|
|
|
|
?>
|
|
|
|
blacklist_<?=$username_sane;?> {
|
|
|
|
<?php
|
|
|
|
$stmt = $pdo->prepare("SELECT GROUP_CONCAT(REPLACE(`value`, '*', '.*') SEPARATOR '|') AS `value` FROM `filterconf`
|
|
|
|
WHERE `object`= :object
|
|
|
|
AND `option` = 'blacklist_from'");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
|
|
|
$grouped_lists = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
$value_sane = preg_replace("/\.\./", ".", (preg_replace("/\*/", ".*", $grouped_lists[0])));
|
|
|
|
?>
|
|
|
|
from = "/(<?=$value_sane;?>)/";
|
|
|
|
<?php
|
|
|
|
if (!filter_var(trim($row['object']), FILTER_VALIDATE_EMAIL)) {
|
|
|
|
?>
|
2017-01-19 04:26:49 +08:00
|
|
|
priority = medium;
|
|
|
|
rcpt = "/.*@<?=$row['object'];?>/";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
$stmt = $pdo->prepare("SELECT `alias_domain` FROM `alias_domain`
|
|
|
|
WHERE `target_domain` = :object");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
|
|
|
$rows_domain_aliases = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2017-03-03 11:44:51 +08:00
|
|
|
array_filter($rows_domain_aliases);
|
2016-12-10 07:39:27 +08:00
|
|
|
while ($row_domain_aliases = array_shift($rows_domain_aliases)) {
|
|
|
|
?>
|
2017-01-19 04:26:49 +08:00
|
|
|
rcpt = "/.*@<?=$row_domain_aliases['alias_domain'];?>/";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
2017-01-19 04:26:49 +08:00
|
|
|
priority = high;
|
2016-12-10 07:39:27 +08:00
|
|
|
rcpt = "<?=$row['object'];?>";
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT `address` FROM `alias` WHERE `goto` = :object_goto AND `address` NOT LIKE '@%' AND `address` != :object_address");
|
|
|
|
$stmt->execute(array(':object_goto' => $row['object'], ':object_address' => $row['object']));
|
2017-01-19 04:33:11 +08:00
|
|
|
$rows_aliases_bl_1 = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2017-03-03 11:44:51 +08:00
|
|
|
array_filter($rows_aliases_bl_1);
|
2017-01-19 04:33:11 +08:00
|
|
|
while ($row_aliases_bl_1 = array_shift($rows_aliases_bl_1)) {
|
2016-12-10 07:39:27 +08:00
|
|
|
?>
|
2017-01-19 04:33:11 +08:00
|
|
|
rcpt = "<?=$row_aliases_bl_1['address'];?>";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT CONCAT(`local_part`, '@', `alias_domain`.`alias_domain`) AS `aliases` FROM `mailbox`
|
|
|
|
LEFT OUTER JOIN `alias_domain` on `mailbox`.`domain` = `alias_domain`.`target_domain`
|
|
|
|
WHERE `mailbox`.`username` = :object");
|
|
|
|
$stmt->execute(array(':object' => $row['object']));
|
2017-01-19 04:33:11 +08:00
|
|
|
$rows_aliases_bl_2 = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2017-03-03 11:44:51 +08:00
|
|
|
array_filter($rows_aliases_bl_2);
|
2017-01-19 04:33:11 +08:00
|
|
|
while ($row_aliases_bl_2 = array_shift($rows_aliases_bl_2)) {
|
2017-01-29 20:56:24 +08:00
|
|
|
if (!empty($row_aliases_bl_2['aliases'])) {
|
2016-12-10 07:39:27 +08:00
|
|
|
?>
|
2017-01-19 04:33:11 +08:00
|
|
|
rcpt = "<?=$row_aliases_bl_2['aliases'];?>";
|
2016-12-10 07:39:27 +08:00
|
|
|
<?php
|
2017-01-29 20:56:24 +08:00
|
|
|
}
|
2016-12-10 07:39:27 +08:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
apply "default" {
|
|
|
|
MAILCOW_MOO = 999.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|
2017-01-19 04:26:49 +08:00
|
|
|
}
|