Skip to content

Commit

Permalink
Improve loop for ?getAllQueries from FTL
Browse files Browse the repository at this point in the history
Signed-off-by: Christian König <ckoenig@posteo.de>
  • Loading branch information
yubiuser committed Apr 5, 2022
1 parent da53e62 commit 2852c5b
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions api_FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,36 @@
$return = callFTLAPI("getallqueries");
}

$allQueries = array();
foreach ($return as $line) {
$tmp = str_getcsv($line," ");
if (!is_bool($return)) {
// 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
$tmp[2] = utf8_encode(str_replace("~"," ",$tmp[2]));
$domain = utf8_encode(str_replace("~"," ",$row[2]));
// UTF-8 encode client host name
$tmp[3] = utf8_encode($tmp[3]);
array_push($allQueries,$tmp);
$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 ']}';
}

$result = array('data' => $allQueries);
$data = array_merge($data, $result);
// exit at the end
exit();
}

if (isset($_GET["recentBlocked"]) && $auth) {
Expand Down

0 comments on commit 2852c5b

Please sign in to comment.