Improve loop for ?getAllQueries from FTL

Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
Christian König
2022-04-05 10:18:05 +02:00
parent c9c03dd5c7
commit 12be6dd732
+28 -12
View File
@@ -306,19 +306,35 @@ if (isset($_GET['getAllQueries']) && $auth) {
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;
$result = array('data' => $allQueries);
$data = array_merge($data, $result);
}
#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]]);
}
// Finish the JSON string
echo ']}';
}
// exit at the end
exit();
}
if (isset($_GET["recentBlocked"]) && $auth) {