Use 4 spaces to indent PHP files.

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
RD WebDesign
2022-08-01 01:18:26 -03:00
parent 0d62267ceb
commit 2bc918ad6e
46 changed files with 2098 additions and 2018 deletions
+223 -223
View File
@@ -4,7 +4,8 @@
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license */
* Please see LICENSE file for your rights under this license
*/
if (!isset($api)) {
die("Direct call to api_FTL.php is not allowed!");
@@ -21,14 +22,14 @@ if (isset($_GET['version'])) {
if (isset($_GET['status'])) {
$return = callFTLAPI("stats");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
if (in_array("status enabled", $return)) {
$data = array_merge($data, array("status" => "enabled"));
} else {
$data = array_merge($data, array("status" => "disabled"));
}
}
if (in_array("status enabled", $return)) {
$data = array_merge($data, array("status" => "enabled"));
} else {
$data = array_merge($data, array("status" => "disabled"));
}
}
}
if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET)) {
@@ -36,67 +37,67 @@ if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET)) {
$return = callFTLAPI("stats");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$stats = [];
foreach ($return as $line) {
$tmp = explode(" ",$line);
$stats = [];
foreach ($return as $line) {
$tmp = explode(" ",$line);
if ($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1]) || $tmp[0] === "status") {
// Expect string response
$stats[$tmp[0]] = $tmp[1];
} elseif (isset($_GET['summary'])) {
// "summary" expects a formmated string response
if ($tmp[0] !== "ads_percentage_today") {
$stats[$tmp[0]] = number_format($tmp[1]);
} else {
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
}
} else {
// Expect float response
$stats[$tmp[0]] = floatval($tmp[1]);
}
if ($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1]) || $tmp[0] === "status") {
// Expect string response
$stats[$tmp[0]] = $tmp[1];
} elseif (isset($_GET['summary'])) {
// "summary" expects a formmated string response
if ($tmp[0] !== "ads_percentage_today") {
$stats[$tmp[0]] = number_format($tmp[1]);
} else {
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
}
} else {
// Expect float response
$stats[$tmp[0]] = floatval($tmp[1]);
}
}
$stats['gravity_last_updated'] = gravity_last_update(true);
$data = array_merge($data,$stats);
}
$stats['gravity_last_updated'] = gravity_last_update(true);
$data = array_merge($data,$stats);
}
}
if (isset($_GET["getMaxlogage"]) && $auth) {
$return = callFTLAPI("maxlogage");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
// Convert seconds to hours and rounds to one decimal place.
$ret = round(intval($return[0]) / 3600, 1);
// Return 24h if value is 0, empty, null or non numeric.
$ret = $ret ?: 24;
// Convert seconds to hours and rounds to one decimal place.
$ret = round(intval($return[0]) / 3600, 1);
// Return 24h if value is 0, empty, null or non numeric.
$ret = $ret ?: 24;
$data = array_merge($data, array("maxlogage" => $ret));
}
$data = array_merge($data, array("maxlogage" => $ret));
}
}
if (isset($_GET['overTimeData10mins'])) {
$return = callFTLAPI("overTime");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$domains_over_time = array();
$ads_over_time = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$domains_over_time[intval($tmp[0])] = intval($tmp[1]);
$ads_over_time[intval($tmp[0])] = intval($tmp[2]);
}
$domains_over_time = array();
$ads_over_time = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$domains_over_time[intval($tmp[0])] = intval($tmp[1]);
$ads_over_time[intval($tmp[0])] = intval($tmp[2]);
}
$result = array(
'domains_over_time' => $domains_over_time,
'ads_over_time' => $ads_over_time
);
$result = array(
'domains_over_time' => $domains_over_time,
'ads_over_time' => $ads_over_time
);
$data = array_merge($data, $result);
}
$data = array_merge($data, $result);
}
}
if (isset($_GET['topItems']) && $auth) {
@@ -109,18 +110,18 @@ if (isset($_GET['topItems']) && $auth) {
}
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$top_queries = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
if (count($tmp) == 2) {
$tmp[2]="";
}
$domain = utf8_encode($tmp[2]);
$top_queries[$domain] = intval($tmp[1]);
$top_queries = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
if (count($tmp) == 2) {
$tmp[2]="";
}
$domain = utf8_encode($tmp[2]);
$top_queries[$domain] = intval($tmp[1]);
}
}
}
if ($_GET['topItems'] === "audit") {
$return = callFTLAPI("top-ads for audit");
@@ -131,26 +132,26 @@ if (isset($_GET['topItems']) && $auth) {
}
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$top_ads = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$domain = utf8_encode($tmp[2]);
if (count($tmp) > 3) {
$top_ads[$domain." (".$tmp[3].")"] = intval($tmp[1]);
} else {
$top_ads[$domain] = intval($tmp[1]);
}
}
$top_ads = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$domain = utf8_encode($tmp[2]);
if (count($tmp) > 3) {
$top_ads[$domain." (".$tmp[3].")"] = intval($tmp[1]);
} else {
$top_ads[$domain] = intval($tmp[1]);
}
}
$result = array(
'top_queries' => $top_queries,
'top_ads' => $top_ads
);
$result = array(
'top_queries' => $top_queries,
'top_ads' => $top_ads
);
$data = array_merge($data, $result);
}
$data = array_merge($data, $result);
}
}
if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth) {
@@ -167,23 +168,23 @@ if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth) {
$return = callFTLAPI("top-clients");
}
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$top_clients = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$clientip = utf8_encode($tmp[2]);
if (count($tmp) > 3 && strlen($tmp[3]) > 0) {
$clientname = utf8_encode($tmp[3]);
$top_clients[$clientname."|".$clientip] = intval($tmp[1]);
} else {
$top_clients[$clientip] = intval($tmp[1]);
}
}
$top_clients = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$clientip = utf8_encode($tmp[2]);
if (count($tmp) > 3 && strlen($tmp[3]) > 0) {
$clientname = utf8_encode($tmp[3]);
$top_clients[$clientname."|".$clientip] = intval($tmp[1]);
} else {
$top_clients[$clientip] = intval($tmp[1]);
}
}
$result = array('top_sources' => $top_clients);
$data = array_merge($data, $result);
}
$result = array('top_sources' => $top_clients);
$data = array_merge($data, $result);
}
}
if (isset($_GET['topClientsBlocked']) && $auth) {
@@ -198,23 +199,23 @@ if (isset($_GET['topClientsBlocked']) && $auth) {
$return = callFTLAPI("top-clients blocked");
}
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$top_clients = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$clientip = utf8_encode($tmp[2]);
if (count($tmp) > 3 && strlen($tmp[3]) > 0) {
$clientname = utf8_encode($tmp[3]);
$top_clients[$clientname."|".$clientip] = intval($tmp[1]);
} else {
$top_clients[$clientip] = intval($tmp[1]);
}
}
$top_clients = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$clientip = utf8_encode($tmp[2]);
if (count($tmp) > 3 && strlen($tmp[3]) > 0) {
$clientname = utf8_encode($tmp[3]);
$top_clients[$clientname."|".$clientip] = intval($tmp[1]);
} else {
$top_clients[$clientip] = intval($tmp[1]);
}
}
$result = array('top_sources_blocked' => $top_clients);
$data = array_merge($data, $result);
}
$result = array('top_sources_blocked' => $top_clients);
$data = array_merge($data, $result);
}
}
if (isset($_GET['getForwardDestinations']) && $auth) {
@@ -224,57 +225,57 @@ if (isset($_GET['getForwardDestinations']) && $auth) {
$return = callFTLAPI("forward-dest");
}
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$forward_dest = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$forwardip = utf8_encode($tmp[2]);
if (count($tmp) > 3 && strlen($tmp[3]) > 0) {
$forwardname = utf8_encode($tmp[3]);
$forward_dest[$forwardname."|".$forwardip] = floatval($tmp[1]);
} else {
$forward_dest[$forwardip] = floatval($tmp[1]);
}
}
$forward_dest = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$forwardip = utf8_encode($tmp[2]);
if (count($tmp) > 3 && strlen($tmp[3]) > 0) {
$forwardname = utf8_encode($tmp[3]);
$forward_dest[$forwardname."|".$forwardip] = floatval($tmp[1]);
} else {
$forward_dest[$forwardip] = floatval($tmp[1]);
}
}
$result = array('forward_destinations' => $forward_dest);
$data = array_merge($data, $result);
}
$result = array('forward_destinations' => $forward_dest);
$data = array_merge($data, $result);
}
}
if (isset($_GET['getQueryTypes']) && $auth) {
$return = callFTLAPI("querytypes");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$querytypes = array();
foreach ($return as $ret) {
$tmp = explode(": ",$ret);
// Reply cannot contain non-ASCII characters
$querytypes[$tmp[0]] = floatval($tmp[1]);
}
$querytypes = array();
foreach ($return as $ret) {
$tmp = explode(": ",$ret);
// Reply cannot contain non-ASCII characters
$querytypes[$tmp[0]] = floatval($tmp[1]);
}
$result = array('querytypes' => $querytypes);
$data = array_merge($data, $result);
}
$result = array('querytypes' => $querytypes);
$data = array_merge($data, $result);
}
}
if (isset($_GET['getCacheInfo']) && $auth) {
$return = callFTLAPI("cacheinfo");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$cacheinfo = array();
foreach ($return as $ret) {
$tmp = explode(": ",$ret);
// Reply cannot contain non-ASCII characters
$cacheinfo[$tmp[0]] = floatval($tmp[1]);
}
$cacheinfo = array();
foreach ($return as $ret) {
$tmp = explode(": ",$ret);
// Reply cannot contain non-ASCII characters
$cacheinfo[$tmp[0]] = floatval($tmp[1]);
}
$result = array('cacheinfo' => $cacheinfo);
$data = array_merge($data, $result);
}
$result = array('cacheinfo' => $cacheinfo);
$data = array_merge($data, $result);
}
}
if (isset($_GET['getAllQueries']) && $auth) {
@@ -304,38 +305,37 @@ if (isset($_GET['getAllQueries']) && $auth) {
}
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
// Set the header
header('Content-type: application/json');
// Set the header
header('Content-type: application/json');
// Start the JSON string
echo '{"data":[';
$first = true;
// 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;
}
// 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]);
$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();
// 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();
}
}
@@ -348,94 +348,94 @@ if (isset($_GET['getForwardDestinationNames']) && $auth) {
$return = callFTLAPI("forward-names");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$forward_dest = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$forwardip = utf8_encode($tmp[2]);
if (count($tmp) > 3) {
$forwardname = utf8_encode($tmp[3]);
$forward_dest[$forwardname."|".$forwardip] = floatval($tmp[1]);
} else {
$forward_dest[$forwardip] = floatval($tmp[1]);
}
}
$forward_dest = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
$forwardip = utf8_encode($tmp[2]);
if (count($tmp) > 3) {
$forwardname = utf8_encode($tmp[3]);
$forward_dest[$forwardname."|".$forwardip] = floatval($tmp[1]);
} else {
$forward_dest[$forwardip] = floatval($tmp[1]);
}
}
$result = array('forward_destinations' => $forward_dest);
$data = array_merge($data, $result);
}
$result = array('forward_destinations' => $forward_dest);
$data = array_merge($data, $result);
}
}
if (isset($_GET['overTimeDataQueryTypes']) && $auth) {
$return = callFTLAPI("QueryTypesoverTime");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$over_time = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
$data = array_merge($data, $result);
}
$over_time = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
$data = array_merge($data, $result);
}
}
if (isset($_GET['getClientNames']) && $auth) {
$return = callFTLAPI("client-names");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$client_names = array();
foreach ($return as $line) {
$tmp = explode(" ", $line);
$client_names[] = array(
"name" => utf8_encode($tmp[0]),
"ip" => utf8_encode($tmp[1])
);
}
$client_names = array();
foreach ($return as $line) {
$tmp = explode(" ", $line);
$client_names[] = array(
"name" => utf8_encode($tmp[0]),
"ip" => utf8_encode($tmp[1])
);
}
$result = array('clients' => $client_names);
$data = array_merge($data, $result);
}
$result = array('clients' => $client_names);
$data = array_merge($data, $result);
}
}
if (isset($_GET['overTimeDataClients']) && $auth) {
$return = callFTLAPI("ClientsoverTime");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$over_time = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
$data = array_merge($data, $result);
}
$over_time = array();
foreach ($return as $line) {
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
$data = array_merge($data, $result);
}
}
if (isset($_GET['delete_lease']) && $auth) {
$return = callFTLAPI("delete-lease ".$_GET['delete_lease']);
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$data["delete_lease"] = $return[0];
}
$data["delete_lease"] = $return[0];
}
}
if (isset($_GET['dns-port']) && $auth) {
$return = callFTLAPI("dns-port");
if (array_key_exists("FTLnotrunning", $return)) {
$data = array("FTLnotrunning" => true);
$data = array("FTLnotrunning" => true);
} else {
$data["dns-port"] = $return[0];
$data["dns-port"] = $return[0];
}
}
?>