From 12be6dd73224af2f003e5ec0698c7788b4cd096e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 5 Apr 2022 10:18:05 +0200 Subject: [PATCH 1/5] Improve loop for ?getAllQueries from FTL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- api_FTL.php | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/api_FTL.php b/api_FTL.php index f1c7fbd12..a2196c32a 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -306,19 +306,35 @@ if (array_key_exists("FTLnotrunning", $return)) { $data = array("FTLnotrunning" => true); } else { - $allQueries = array(); - foreach ($return as $line) { - $tmp = str_getcsv($line," "); - // UTF-8 encode domain - $tmp[2] = utf8_encode(str_replace("~"," ",$tmp[2])); - // UTF-8 encode client host name - $tmp[3] = utf8_encode($tmp[3]); - array_push($allQueries,$tmp); + // Start the JSON string + echo '{"data":['; + $first = true; + + #foreach ($return as $line) + foreach($return as $line) { + + // Insert a comma before the next record (except on the first one) + if (!$first) { + echo ","; + } else { + $first = false; + } + + $row = str_getcsv($line," "); + // UTF-8 encode domain + $domain = utf8_encode(str_replace("~"," ",$row[2])); + // UTF-8 encode client host name + $client = utf8_encode($row[3]); + + // Insert into array and output it in JSON format + // array: time type domain client status dnssecStatus reply response_time CNAMEDomain regexID upstream destination EDE + echo json_encode([$row[0], $row[1], $domain, $client, $row[4], $row[5], $row[6], $row[7], $row[8], $row[9], $row[10], $row[11]]); } - - $result = array('data' => $allQueries); - $data = array_merge($data, $result); - } + // Finish the JSON string + echo ']}'; + } + // exit at the end + exit(); } if (isset($_GET["recentBlocked"]) && $auth) { From 32d539f1a97623e70562f7e1d32c529f4f991bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 5 Apr 2022 15:11:06 +0200 Subject: [PATCH 2/5] Add proper guarding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- api_FTL.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api_FTL.php b/api_FTL.php index a2196c32a..92bb0ab9c 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -303,9 +303,13 @@ $return = callFTLAPI("getallqueries"); } +<<<<<<< HEAD if (array_key_exists("FTLnotrunning", $return)) { $data = array("FTLnotrunning" => true); } else { +======= + if (!in_array("FTLnotrunning", $return )) { +>>>>>>> Add proper guarding // Start the JSON string echo '{"data":['; $first = true; From 434dd025f1c35eaaf247fd434a8fe880bf6d9204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 11 Apr 2022 20:21:13 +0200 Subject: [PATCH 3/5] Fix merge conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- api_FTL.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/api_FTL.php b/api_FTL.php index 92bb0ab9c..a2196c32a 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -303,13 +303,9 @@ $return = callFTLAPI("getallqueries"); } -<<<<<<< HEAD if (array_key_exists("FTLnotrunning", $return)) { $data = array("FTLnotrunning" => true); } else { -======= - if (!in_array("FTLnotrunning", $return )) { ->>>>>>> Add proper guarding // Start the JSON string echo '{"data":['; $first = true; From 4642569caeac28e7c554caca1b3dd94ccf875d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 11 Apr 2022 21:16:47 +0200 Subject: [PATCH 4/5] Move exit to the right place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- api_FTL.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api_FTL.php b/api_FTL.php index a2196c32a..664addafb 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -332,9 +332,9 @@ } // Finish the JSON string echo ']}'; + // exit at the end + exit(); } - // exit at the end - exit(); } if (isset($_GET["recentBlocked"]) && $auth) { From edca3ee1c36184b8a54311fc4b7c617e923787e3 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Wed, 13 Apr 2022 07:04:59 +0200 Subject: [PATCH 5/5] Remove obsolete comment --- api_FTL.php | 1 - 1 file changed, 1 deletion(-) diff --git a/api_FTL.php b/api_FTL.php index 664addafb..98b2ee7b2 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -310,7 +310,6 @@ echo '{"data":['; $first = true; - #foreach ($return as $line) foreach($return as $line) { // Insert a comma before the next record (except on the first one)