From d124fa1d5ba31235d6dd776cc2ceba452be8326a Mon Sep 17 00:00:00 2001 From: andryyy Date: Thu, 7 Mar 2019 11:44:38 +0100 Subject: [PATCH] [Rspamd] Check if filterconf table was changed and return Last-Modified accordingly --- data/conf/rspamd/dynmaps/settings.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/data/conf/rspamd/dynmaps/settings.php b/data/conf/rspamd/dynmaps/settings.php index 3d42bcf3..6f2f17a2 100644 --- a/data/conf/rspamd/dynmaps/settings.php +++ b/data/conf/rspamd/dynmaps/settings.php @@ -6,6 +6,8 @@ then any of these will trigger the rule. If a rule is triggered then no more rul */ header('Content-Type: text/plain'); require_once "vars.inc.php"; +// Getting headers sent by the client. +$headers = apache_request_headers(); ini_set('error_reporting', 0); @@ -25,6 +27,22 @@ catch (PDOException $e) { exit; } +// Check if db changed and return header +$stmt = $pdo->prepare("SELECT UNIX_TIMESTAMP(UPDATE_TIME) AS `db_update_time` FROM information_schema.tables + WHERE `TABLE_NAME` = 'filterconf' + AND TABLE_SCHEMA = :dbname;"); +$stmt->execute(array( + ':dbname' => $database_name +)); +$db_update_time = $stmt->fetch(PDO::FETCH_ASSOC)['db_update_time']; + +if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == $db_update_time)) { + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $db_update_time).' GMT', true, 304); + exit; +} else { + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $db_update_time).' GMT', true, 200); +} + function parse_email($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return false; $a = strrpos($email, '@');