forked from pi-hole/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
101 lines (95 loc) · 2.1 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* 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 */
$api = true;
header('Content-type: application/json');
require("scripts/pi-hole/php/FTL.php");
require("scripts/pi-hole/php/password.php");
require("scripts/pi-hole/php/auth.php");
check_cors();
$data = array();
// Common API functions
if (isset($_GET['status']) && $auth)
{
$pistatus = exec('sudo pihole status web');
if ($pistatus == "1")
{
$data = array_merge($data, array("status" => "enabled"));
}
else
{
$data = array_merge($data, array("status" => "disabled"));
}
}
elseif (isset($_GET['enable']) && $auth)
{
if(isset($_GET["auth"]))
{
if($_GET["auth"] !== $pwhash)
die("Not authorized!");
}
else
{
// Skip token validation if explicit auth string is given
check_csrf($_GET['token']);
}
exec('sudo pihole enable');
$data = array_merge($data, array("status" => "enabled"));
unlink("../custom_disable_timer");
}
elseif (isset($_GET['disable']) && $auth)
{
if(isset($_GET["auth"]))
{
if($_GET["auth"] !== $pwhash)
die("Not authorized!");
}
else
{
// Skip token validation if explicit auth string is given
check_csrf($_GET['token']);
}
$disable = intval($_GET['disable']);
// intval returns the integer value on success, or 0 on failure
if($disable > 0)
{
$timestamp = time();
exec("sudo pihole disable ".$disable."s");
file_put_contents("../custom_disable_timer",($timestamp+$disable)*1000);
}
else
{
exec('sudo pihole disable');
unlink("../custom_disable_timer");
}
$data = array_merge($data, array("status" => "disabled"));
}
// Other API functions
if(!testFTL() && !isset($_GET["PHP"]))
{
$data = array_merge($data, array("FTLnotrunning" => true));
}
else
{
if(!isset($_GET["PHP"]))
{
require("api_FTL.php");
}
else
{
require("api_PHP.php");
}
}
if(isset($_GET["jsonForceObject"]))
{
echo json_encode($data, JSON_FORCE_OBJECT);
}
else
{
echo json_encode($data);
}
?>