Several optimizations to the new FTL API

This commit is contained in:
DL6ER
2017-02-23 14:20:26 +01:00
parent bb9c669109
commit a6a4c944b0
2 changed files with 33 additions and 15 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
$api = true; $api = true;
require("scripts/pi-hole/php/FTL.php"); require("scripts/pi-hole/php/FTL.php");
if(testFTL()) if(testFTL() && !isset($_GET["PHP"]))
{ {
require("api_FTL.php"); require("api_FTL.php");
} }
+32 -14
View File
@@ -52,7 +52,7 @@ if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET))
} }
else else
{ {
$stats[$tmp[0]] = $tmp[1]; $stats[$tmp[0]] = intval($tmp[1]);
} }
} }
$data = array_merge($data,$stats); $data = array_merge($data,$stats);
@@ -68,8 +68,8 @@ if (isset($_GET['overTimeData10mins']))
foreach($return as $line) foreach($return as $line)
{ {
$tmp = explode(" ",$line); $tmp = explode(" ",$line);
$domains_over_time[$tmp[0]] = $tmp[1]; $domains_over_time[$tmp[0]] = intval($tmp[1]);
$ads_over_time[$tmp[0]] = $tmp[2]; $ads_over_time[$tmp[0]] = intval($tmp[2]);
} }
$result = array('domains_over_time' => $domains_over_time, $result = array('domains_over_time' => $domains_over_time,
'ads_over_time' => $ads_over_time); 'ads_over_time' => $ads_over_time);
@@ -80,7 +80,7 @@ if (isset($_GET['topItems']) && $auth)
{ {
if(is_numeric($_GET['topItems'])) if(is_numeric($_GET['topItems']))
{ {
sendRequestFTL("top-domains ".$_GET['topItems']); sendRequestFTL("top-domains (".$_GET['topItems'].")");
} }
else else
{ {
@@ -92,12 +92,12 @@ if (isset($_GET['topItems']) && $auth)
foreach($return as $line) foreach($return as $line)
{ {
$tmp = explode(" ",$line); $tmp = explode(" ",$line);
$top_queries[$tmp[2]] = $tmp[1]; $top_queries[$tmp[2]] = intval($tmp[1]);
} }
if(is_numeric($_GET['topItems'])) if(is_numeric($_GET['topItems']))
{ {
sendRequestFTL("top-ads ".$_GET['topItems']); sendRequestFTL("top-ads (".$_GET['topItems'].")");
} }
else else
{ {
@@ -109,7 +109,7 @@ if (isset($_GET['topItems']) && $auth)
foreach($return as $line) foreach($return as $line)
{ {
$tmp = explode(" ",$line); $tmp = explode(" ",$line);
$top_ads[$tmp[2]] = $tmp[1]; $top_ads[$tmp[2]] = intval($tmp[1]);
} }
$result = array('top_queries' => $top_queries, $result = array('top_queries' => $top_queries,
@@ -120,7 +120,25 @@ if (isset($_GET['topItems']) && $auth)
if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth) if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth)
{ {
sendRequestFTL("top-clients");
if(isset($_GET['topClients']))
{
$number = $_GET['topClients'];
}
elseif(isset($_GET['getQuerySources']))
{
$number = $_GET['getQuerySources'];
}
if(is_numeric($number))
{
sendRequestFTL("top-clients (".$number.")");
}
else
{
sendRequestFTL("top-clients");
}
$return = getResponseFTL(); $return = getResponseFTL();
$top_clients = array(); $top_clients = array();
foreach($return as $line) foreach($return as $line)
@@ -128,11 +146,11 @@ if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth)
$tmp = explode(" ",$line); $tmp = explode(" ",$line);
if(count($tmp) == 4) if(count($tmp) == 4)
{ {
$top_clients[$tmp[3]."|".$tmp[2]] = $tmp[1]; $top_clients[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
} }
else else
{ {
$top_clients[$tmp[2]] = $tmp[1]; $top_clients[$tmp[2]] = intval($tmp[1]);
} }
} }
@@ -150,11 +168,11 @@ if (isset($_GET['getForwardDestinations']) && $auth)
$tmp = explode(" ",$line); $tmp = explode(" ",$line);
if(count($tmp) == 4) if(count($tmp) == 4)
{ {
$forward_dest[$tmp[3]."|".$tmp[2]] = $tmp[1]; $forward_dest[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
} }
else else
{ {
$forward_dest[$tmp[2]] = $tmp[1]; $forward_dest[$tmp[2]] = intval($tmp[1]);
} }
} }
@@ -170,7 +188,7 @@ if (isset($_GET['getQueryTypes']) && $auth)
foreach($return as $ret) foreach($return as $ret)
{ {
$tmp = explode(": ",$ret); $tmp = explode(": ",$ret);
$querytypes[$tmp[0]] = $tmp[1]; $querytypes[$tmp[0]] = intval($tmp[1]);
} }
$result = array('querytypes' => $querytypes); $result = array('querytypes' => $querytypes);
@@ -234,7 +252,7 @@ elseif (isset($_GET['disable'], $_GET['token']) && $auth) {
if(isset($_GET["recentBlocked"])) if(isset($_GET["recentBlocked"]))
{ {
sendRequestFTL("recentBlocked"); sendRequestFTL("recentBlocked");
echo getResponseFTL()[0]; die(getResponseFTL()[0]);
unset($data); unset($data);
} }