From 70a8a796fc719afbcf05135adcd04ebb97033f61 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 17 Jul 2021 10:31:06 +0100 Subject: [PATCH] probable fix for https://github.com/postfixadmin/postfixadmin/issues/516 - admins can see all domains so no fDomain parameter etc --- public/viewlog.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/public/viewlog.php b/public/viewlog.php index adb56199..6bdc053e 100644 --- a/public/viewlog.php +++ b/public/viewlog.php @@ -67,12 +67,24 @@ if ($error != 1) { $table_log = table_by_key('log'); $page_size = isset($CONF['page_size']) ? intval($CONF['page_size']) : 35; - $query = "SELECT timestamp,username,domain,action,data FROM $table_log WHERE domain= :domain ORDER BY timestamp DESC LIMIT $page_size"; + $where = []; + $params = []; + if($fDomain) { + $where[] = 'domain = :domain' ; + $params['domain'] = $fDomain; + } + + $where_sql = ''; + if(!empty($where)) { + $where_sql = 'WHERE ' . implode(' AND ', $where); + } + + $query = "SELECT timestamp,username,domain,action,data FROM $table_log $where_sql ORDER BY timestamp DESC LIMIT $page_size"; if (db_pgsql()) { - $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM $table_log WHERE domain= :domain ORDER BY timestamp DESC LIMIT $page_size"; + $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM $table_log $where_sql ORDER BY timestamp DESC LIMIT $page_size"; } - $result = db_query_all($query, array('domain' => $fDomain)); + $result = db_query_all($query, $params); foreach ($result as $row) { if (is_array($row) && db_pgsql()) { $row['timestamp'] = gmstrftime('%c %Z', $row['timestamp']);