forked from pi-hole/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
64 lines (52 loc) · 1.83 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
include('data.php');
header('Content-type: application/json');
$data = array();
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['topItems'])) {
$data = array_merge($data, getTopItems());
}
if (isset($_GET['recentItems'])) {
if (is_numeric($_GET['recentItems'])) {
$data = array_merge($data, getRecentItems($_GET['recentItems']));
}
}
if (isset($_GET['getQueryTypes'])) {
$data = array_merge($data, getIpvType());
}
if (isset($_GET['getForwardDestinations'])) {
$data = array_merge($data, getForwardDestinations());
}
if (isset($_GET['getQuerySources'])) {
$data = array_merge($data, getQuerySources());
}
if (isset($_GET['getAllQueries'])) {
$data = array_merge($data, getAllQueries());
}
function filterArray(&$a) {
$sanArray = array();
foreach ($a as $k=>$v) {
if (is_array($v)) {
$sanArray[htmlspecialchars($k)] = filterArray($v);
} else {
$sanArray[htmlspecialchars($k)] = htmlspecialchars($v);
}
}
return $sanArray;
}
$data = filterArray($data);
echo json_encode($data);
?>