mirror of
https://github.com/pi-hole/web.git
synced 2026-04-24 10:50:23 +01:00
Move API functions that are neither FTL nor PHP specific (enable, disable) to api.php
This commit is contained in:
62
api.php
62
api.php
@@ -7,8 +7,61 @@
|
||||
* 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['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"]))
|
||||
{
|
||||
require("api_FTL.php");
|
||||
@@ -17,4 +70,13 @@ else
|
||||
{
|
||||
require("api_PHP.php");
|
||||
}
|
||||
|
||||
if(isset($_GET["jsonForceObject"]))
|
||||
{
|
||||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode($data);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user