From 8c2416b711dad1aa91f9168e36e73f956d60be9c Mon Sep 17 00:00:00 2001 From: andryyy Date: Sat, 4 Mar 2017 00:23:38 +0100 Subject: [PATCH] Never return empty map --- data/conf/rspamd/dynmaps/authoritative.php | 32 +++++++++++++--------- data/conf/rspamd/dynmaps/tags.php | 32 +++++++++++++--------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/data/conf/rspamd/dynmaps/authoritative.php b/data/conf/rspamd/dynmaps/authoritative.php index bfd0b76e..ffbfacf6 100644 --- a/data/conf/rspamd/dynmaps/authoritative.php +++ b/data/conf/rspamd/dynmaps/authoritative.php @@ -9,20 +9,26 @@ $opt = [ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; -$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; +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"; + } } -$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) { +catch (PDOException $e) { echo "dummy@domain.local"; + exit; } ?> \ No newline at end of file diff --git a/data/conf/rspamd/dynmaps/tags.php b/data/conf/rspamd/dynmaps/tags.php index 7b955da4..20210ef1 100644 --- a/data/conf/rspamd/dynmaps/tags.php +++ b/data/conf/rspamd/dynmaps/tags.php @@ -9,20 +9,26 @@ $opt = [ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; -$pdo = new PDO($dsn, $database_user, $database_pass, $opt); -$stmt = $pdo->query("SELECT `username` FROM `mailbox` WHERE `wants_tagged_subject` = '1'"); -$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); -while ($row = array_shift($rows)) { - $has_object = 1; - echo strtolower(trim($row['username'])) . PHP_EOL; +try { + $pdo = new PDO($dsn, $database_user, $database_pass, $opt); + $stmt = $pdo->query("SELECT `username` FROM `mailbox` WHERE `wants_tagged_subject` = '1'"); + $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); + while ($row = array_shift($rows)) { + $has_object = 1; + echo strtolower(trim($row['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 = $stmt->fetchAll(PDO::FETCH_ASSOC); + while ($row = array_shift($rows)) { + $has_object = 1; + echo strtolower(trim($row['tag_ad'])) . PHP_EOL; + } + if ($has_object == 0) { + echo "dummy@domain.local"; + } } -$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 = $stmt->fetchAll(PDO::FETCH_ASSOC); -while ($row = array_shift($rows)) { - $has_object = 1; - echo strtolower(trim($row['tag_ad'])) . PHP_EOL; -} -if ($has_object == 0) { +catch (PDOException $e) { echo "dummy@domain.local"; + exit; } ?>