2016-12-10 00:39:27 +01: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-18 21:26:49 +01:00
|
|
|
|
2017-07-02 11:25:14 +02:00
|
|
|
ini_set('error_reporting', 0);
|
2017-03-03 04:44:51 +01:00
|
|
|
|
2016-12-10 00:39:27 +01: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,
|
|
|
|
];
|
2017-03-04 00:19:10 +01:00
|
|
|
try {
|
2017-03-04 00:27:57 +01:00
|
|
|
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
|
2017-03-04 00:19:10 +01:00
|
|
|
$stmt = $pdo->query("SELECT * FROM `filterconf`");
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
|
|
|
echo 'settings { }';
|
|
|
|
exit;
|
|
|
|
}
|
2017-03-04 00:27:57 +01:00
|
|
|
|
2017-07-01 23:14:27 +02:00
|
|
|
function parse_email($email) {
|
|
|
|
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
|
|
|
|
$a = strrpos($email, '@');
|
|
|
|
return array('local' => substr($email, 0, $a), 'domain' => substr($email, $a));
|
|
|
|
}
|
|
|
|
|
|
|
|
function ucl_rcpts($object, $type) {
|
|
|
|
global $pdo;
|
|
|
|
if ($type == 'mailbox') {
|
|
|
|
// Standard aliases
|
|
|
|
$stmt = $pdo->prepare("SELECT `address` FROM `alias`
|
|
|
|
WHERE `goto` LIKE :object_goto
|
|
|
|
AND `address` NOT LIKE '@%'
|
|
|
|
AND `address` != :object_address");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':object_goto' => '%' . $object . '%',
|
|
|
|
':object_address' => $object
|
|
|
|
));
|
|
|
|
$standard_aliases = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
while ($row = array_shift($standard_aliases)) {
|
|
|
|
$local = parse_email($row['address'])['local'];
|
|
|
|
$domain = parse_email($row['address'])['domain'];
|
|
|
|
if (!empty($local) && !empty($domain)) {
|
2017-08-27 13:45:18 +02:00
|
|
|
$rcpt[] = '/' . $local . '\+.*' . $domain . '/i';
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|
|
|
|
$rcpt[] = $row['address'];
|
|
|
|
}
|
|
|
|
// Aliases by alias domains
|
|
|
|
$stmt = $pdo->prepare("SELECT CONCAT(`local_part`, '@', `alias_domain`.`alias_domain`) AS `alias` FROM `mailbox`
|
|
|
|
LEFT OUTER JOIN `alias_domain` ON `mailbox`.`domain` = `alias_domain`.`target_domain`
|
|
|
|
WHERE `mailbox`.`username` = :object");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':object' => $object
|
|
|
|
));
|
|
|
|
$by_domain_aliases = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
array_filter($by_domain_aliases);
|
|
|
|
while ($row = array_shift($by_domain_aliases)) {
|
|
|
|
if (!empty($row['alias'])) {
|
|
|
|
$local = parse_email($row['alias'])['local'];
|
|
|
|
$domain = parse_email($row['alias'])['domain'];
|
|
|
|
if (!empty($local) && !empty($domain)) {
|
2017-08-27 13:45:18 +02:00
|
|
|
$rcpt[] = '/' . $local . '\+.*' . $domain . '/i';
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|
|
|
|
$rcpt[] = $row['alias'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Mailbox self
|
|
|
|
$local = parse_email($row['object'])['local'];
|
|
|
|
$domain = parse_email($row['object'])['domain'];
|
|
|
|
if (!empty($local) && !empty($domain)) {
|
2017-08-27 13:45:18 +02:00
|
|
|
$rcpt[] = '/' . $local . '\+.*' . $domain . '/i';
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|
|
|
|
$rcpt[] = $object;
|
|
|
|
}
|
|
|
|
elseif ($type == 'domain') {
|
|
|
|
// Domain self
|
2017-08-27 13:45:18 +02:00
|
|
|
$rcpt[] = '/.*@' . $object . '/i';
|
2017-07-01 23:14:27 +02:00
|
|
|
$stmt = $pdo->prepare("SELECT `alias_domain` FROM `alias_domain`
|
|
|
|
WHERE `target_domain` = :object");
|
2017-08-27 14:05:38 +02:00
|
|
|
$stmt->execute(array(':object' => $object));
|
2017-07-01 23:14:27 +02:00
|
|
|
$alias_domains = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
array_filter($alias_domains);
|
|
|
|
while ($row = array_shift($alias_domains)) {
|
2017-08-27 13:45:18 +02:00
|
|
|
$rcpt[] = '/.*@' . $row['alias_domain'] . '/i';
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($rcpt)) {
|
|
|
|
return $rcpt;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
?>
|
|
|
|
settings {
|
2017-05-07 08:50:28 +02:00
|
|
|
<?php
|
2017-05-06 08:09:40 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
// Start custom scores for users
|
|
|
|
*/
|
|
|
|
|
2016-12-10 00:39:27 +01:00
|
|
|
$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;?> {
|
2017-07-01 23:14:27 +02:00
|
|
|
priority = 4;
|
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2017-07-01 23:14:27 +02:00
|
|
|
?>
|
|
|
|
rcpt = "<?=$rcpt;?>";
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
$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);
|
|
|
|
?>
|
2016-12-11 14:13:17 +01:00
|
|
|
apply "default" {
|
|
|
|
actions {
|
|
|
|
reject = <?=$spamscore['highspamlevel'][0];?>;
|
|
|
|
greylist = <?=$spamscore['lowspamlevel'][0] - 1;?>;
|
|
|
|
"add header" = <?=$spamscore['lowspamlevel'][0];?>;
|
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
}
|
2017-01-29 13:56:24 +01:00
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
|
|
|
}
|
2016-12-29 21:12:19 +01:00
|
|
|
|
2016-12-10 00:39:27 +01: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])));
|
|
|
|
?>
|
2017-08-27 13:45:18 +02:00
|
|
|
from = "/(<?=$value_sane;?>)/i";
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
|
|
|
if (!filter_var(trim($row['object']), FILTER_VALIDATE_EMAIL)) {
|
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
priority = 5;
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2016-12-10 00:39:27 +01:00
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
rcpt = "<?=$rcpt;?>";
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
priority = 6;
|
2017-03-04 14:05:06 +01:00
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2017-03-04 14:05:06 +01:00
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
rcpt = "<?=$rcpt;?>";
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
}
|
2017-08-27 13:49:34 +02:00
|
|
|
?>
|
|
|
|
apply "default" {
|
|
|
|
MAILCOW_WHITE = -999.0;
|
|
|
|
}
|
|
|
|
symbols [
|
|
|
|
"MAILCOW_WHITE"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
whitelist_header_<?=$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])));
|
|
|
|
?>
|
2017-09-16 18:46:28 +02:00
|
|
|
header = {
|
|
|
|
"From" = "/(<?=$value_sane;?>)/i";
|
2017-08-27 13:49:34 +02:00
|
|
|
}
|
|
|
|
<?php
|
|
|
|
if (!filter_var(trim($row['object']), FILTER_VALIDATE_EMAIL)) {
|
|
|
|
?>
|
|
|
|
priority = 5;
|
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2017-08-27 13:49:34 +02:00
|
|
|
?>
|
|
|
|
rcpt = "<?=$rcpt;?>";
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
|
|
|
priority = 6;
|
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2017-08-27 13:49:34 +02:00
|
|
|
?>
|
|
|
|
rcpt = "<?=$rcpt;?>";
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
?>
|
|
|
|
apply "default" {
|
2017-04-21 10:19:45 +02:00
|
|
|
MAILCOW_WHITE = -999.0;
|
2016-12-10 00:39:27 +01:00
|
|
|
}
|
2017-04-21 10:19:45 +02:00
|
|
|
symbols [
|
|
|
|
"MAILCOW_WHITE"
|
|
|
|
]
|
2016-12-10 00:39:27 +01:00
|
|
|
}
|
|
|
|
<?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])));
|
|
|
|
?>
|
2017-08-27 13:45:18 +02:00
|
|
|
from = "/(<?=$value_sane;?>)/i";
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
|
|
|
if (!filter_var(trim($row['object']), FILTER_VALIDATE_EMAIL)) {
|
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
priority = 5;
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2016-12-10 00:39:27 +01:00
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
rcpt = "<?=$rcpt;?>";
|
2016-12-10 00:39:27 +01:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
priority = 6;
|
2017-03-04 14:05:06 +01:00
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2017-03-04 14:05:06 +01:00
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
rcpt = "<?=$rcpt;?>";
|
2017-03-04 14:05:06 +01:00
|
|
|
<?php
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
}
|
2017-08-27 13:49:34 +02:00
|
|
|
?>
|
|
|
|
apply "default" {
|
|
|
|
MAILCOW_BLACK = 999.0;
|
|
|
|
}
|
|
|
|
symbols [
|
|
|
|
"MAILCOW_BLACK"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
blacklist_header_<?=$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])));
|
|
|
|
?>
|
2017-09-16 18:46:28 +02:00
|
|
|
header = {
|
|
|
|
"From" = "/(<?=$value_sane;?>)/i";
|
2017-08-27 13:49:34 +02:00
|
|
|
}
|
|
|
|
<?php
|
|
|
|
if (!filter_var(trim($row['object']), FILTER_VALIDATE_EMAIL)) {
|
|
|
|
?>
|
|
|
|
priority = 5;
|
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2017-08-27 13:49:34 +02:00
|
|
|
?>
|
|
|
|
rcpt = "<?=$rcpt;?>";
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
|
|
|
priority = 6;
|
|
|
|
<?php
|
2017-08-27 14:05:38 +02:00
|
|
|
foreach (ucl_rcpts($row['object'], strpos($row['object'], '@') === FALSE ? 'domain' : 'mailbox') as $rcpt) {
|
2017-08-27 13:49:34 +02:00
|
|
|
?>
|
|
|
|
rcpt = "<?=$rcpt;?>";
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
2016-12-10 00:39:27 +01:00
|
|
|
?>
|
|
|
|
apply "default" {
|
2017-04-21 10:19:45 +02:00
|
|
|
MAILCOW_BLACK = 999.0;
|
2016-12-10 00:39:27 +01:00
|
|
|
}
|
2017-04-21 10:19:45 +02:00
|
|
|
symbols [
|
|
|
|
"MAILCOW_BLACK"
|
|
|
|
]
|
2016-12-10 00:39:27 +01:00
|
|
|
}
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|
2017-07-01 23:14:27 +02:00
|
|
|
}
|