Files
web/api.php
Adam Warner ee41a78bdd More codacy fixes (#256)
* single quotes to double

* Avoid variables with short names like $a. Configured minimum length is 3.

* list_type > listType https://www.codacy.com/app/Pi-hole/AdminLTE/file/4753758893/issues/source?bid=3919163&fileBranchId=3919163#l30

* define `refresh` before it is used

* single to double quotes

* EsLint expects `{}` after `if`

* singlequotes to doublequotes

* https://www.codacy.com/app/Pi-hole/AdminLTE/file/4753758894/issues/source?bid=3919163&fileBranchId=3919163#l49

* Copy filterArray Function from api.php

* missed a single-quote

* single>double

* `===`, `==`

* single to double

* Usages come AFTER declarations

* missing semi

* function delcaration order change

* more codacy complaints
2016-12-16 13:52:51 +00:00

106 lines
2.9 KiB
PHP

<?php
$api = true;
require "php/password.php";
require "php/auth.php";
check_cors();
include('data.php');
header('Content-type: application/json');
$data = array();
// Non-Auth
if (isset($_GET['summaryRaw'])) {
$data = array_merge($data, getSummaryData());
}
if (isset($_GET['summary']) || !count($_GET)) {
$sum = getSummaryData();
$sum['ads_blocked_today'] = number_format( $sum['ads_blocked_today']);
$sum['dns_queries_today'] = number_format( $sum['dns_queries_today']);
$sum['ads_percentage_today'] = number_format( $sum['ads_percentage_today'], 1, '.', '');
$sum['domains_being_blocked'] = number_format( $sum['domains_being_blocked']);
$data = array_merge($data, $sum);
}
if (isset($_GET['overTimeData'])) {
$data = array_merge($data, getOverTimeData());
}
if (isset($_GET['overTimeData10mins'])) {
$data = array_merge($data, getOverTimeData10mins());
}
// Auth Required
if (isset($_GET['topItems']) && $auth) {
$data = array_merge($data, getTopItems());
}
if (isset($_GET['recentItems']) && $auth) {
if (is_numeric($_GET['recentItems'])) {
$data = array_merge($data, getRecentItems($_GET['recentItems']));
}
}
if (isset($_GET['getQueryTypes']) && $auth) {
$data = array_merge($data, getIpvType());
}
if (isset($_GET['getForwardDestinations']) && $auth) {
$data = array_merge($data, getForwardDestinations());
}
if (isset($_GET['getQuerySources']) && $auth) {
$data = array_merge($data, getQuerySources());
}
if (isset($_GET['getAllQueries']) && $auth) {
$data = array_merge($data, getAllQueries($_GET['getAllQueries']));
}
if (isset($_GET['enable'], $_GET['token']) && $auth) {
check_csrf($_GET['token']);
exec('sudo pihole enable');
$data = array_merge($data, Array(
"status" => "enabled"
));
}
elseif (isset($_GET['disable'], $_GET['token']) && $auth) {
check_csrf($_GET['token']);
exec('sudo pihole disable');
$data = array_merge($data, Array(
"status" => "disabled"
));
}
if (isset($_GET['getGravityDomains'])) {
$data = array_merge($data, getGravityDomains($gravity));
}
function filterArray(&$inArray) {
$outArray = array();
foreach ($inArray as $key=>$value) {
if (is_array($value)) {
$outArray[htmlspecialchars($key)] = filterArray($value);
} else {
$outArray[htmlspecialchars($key)] = htmlspecialchars($value);
}
}
return $outArray;
}
$data = filterArray($data);
if(isset($_GET["jsonForceObject"]))
{
echo json_encode($data, JSON_FORCE_OBJECT);
}
else
{
echo json_encode($data);
}
?>