Optionally enable spam filter for forwarding hosts

This commit is contained in:
Michael Kuron
2017-05-07 08:50:28 +02:00
parent 8c8bfc0108
commit ae6d7d63fc
6 changed files with 60 additions and 13 deletions

View File

@@ -5094,7 +5094,7 @@ function get_u2f_registrations($username) {
}
function get_forwarding_hosts() {
global $pdo;
$sel = $pdo->prepare("SELECT host, source FROM `forwarding_hosts`");
$sel = $pdo->prepare("SELECT * FROM `forwarding_hosts`");
$sel->execute();
return $sel->fetchAll(PDO::FETCH_OBJ);
}
@@ -5111,6 +5111,7 @@ function add_forwarding_host($postarray) {
}
$source = $postarray['hostname'];
$host = $postarray['hostname'];
$filter_spam = !empty($postarray['filter_spam']);
$hosts = array();
if (preg_match('/^[0-9a-fA-F:\/]+$/', $host)) { // IPv6 address
$hosts = array($host);
@@ -5133,10 +5134,15 @@ function add_forwarding_host($postarray) {
if ($source == $host)
$source = '';
try {
$stmt = $pdo->prepare("INSERT IGNORE INTO `forwarding_hosts` (`host`, `source`) VALUES (:host, :source)");
if ($filter_spam) { // if the host already exists, REPLACE it with the spam filter turned on
$stmt = $pdo->prepare("REPLACE INTO `forwarding_hosts` (`host`, `source`, `filter_spam`) VALUES (:host, :source, :filter_spam)");
} else { // if the host already exists, IGNORE it no matter whether the spam filter is already turned on
$stmt = $pdo->prepare("INSERT IGNORE INTO `forwarding_hosts` (`host`, `source`, `filter_spam`) VALUES (:host, :source, :filter_spam)");
}
$stmt->execute(array(
':host' => $host,
':source' => $source,
':filter_spam' => $filter_spam ? 1 : 0,
));
}
catch (PDOException $e) {

View File

@@ -3,7 +3,7 @@ function init_db_schema() {
try {
global $pdo;
$db_version = "01052017_1702";
$db_version = "07052017_0824";
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
@@ -268,7 +268,8 @@ function init_db_schema() {
"forwarding_hosts" => array(
"cols" => array(
"host" => "VARCHAR(255) NOT NULL",
"source" => "VARCHAR(255) NOT NULL"
"source" => "VARCHAR(255) NOT NULL",
"filter_spam" => "TINYINT(1) NOT NULL DEFAULT '0'"
),
"keys" => array(
"primary" => array(