From 295fbf117a2f46a12659f2e17b89d48ea9640e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 4 Jul 2022 20:45:51 +0200 Subject: [PATCH] Show names in top clients list from long-term data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- api_db.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api_db.php b/api_db.php index ba172680..06b31e05 100644 --- a/api_db.php +++ b/api_db.php @@ -158,7 +158,11 @@ if (isset($_GET['topClients']) && $auth) { $limit = "WHERE timestamp <= :until"; } - $stmt = $db->prepare('SELECT client,count(client) FROM queries '.$limit.' GROUP by client order by count(client) desc limit 20'); + $dbquery= "Select CASE typeof(client) WHEN 'integer' THEN ("; + $dbquery .= " SELECT CASE TRIM(name) WHEN '' THEN c.ip ELSE c.name END name FROM client_by_id c WHERE c.id = q.client)"; + $dbquery .= " ELSE client END client, count(client) FROM query_storage q ".$limit." GROUP by client order by count(client) desc limit 20"; + + $stmt = $db->prepare($dbquery); $stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER); $stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER); $results = $stmt->execute();