Move enable/disable to API

Also check CORS for all API calls. With the same import, we can
enable CSRF token checking on the API.
This commit is contained in:
Mcat12
2016-12-03 13:40:04 -05:00
parent 40c6ee9f5a
commit ee0913a7a2
3 changed files with 51 additions and 25 deletions
+5 -15
View File
@@ -4,16 +4,6 @@
check_cors();
if (isset($_GET['enable']) && $auth) {
exec('sudo pihole enable');
$refer = $_SERVER['HTTP_REFERER'];
header("location:$refer");
} elseif (isset($_GET['disable']) && $auth) {
exec('sudo pihole disable');
$refer = $_SERVER['HTTP_REFERER'];
header("location:$refer");
}
// Web based change of temperature unit
if (isset($_GET['tempunit']))
{
@@ -193,11 +183,11 @@
<?php
$pistatus = exec('sudo pihole status web');
if ($pistatus == "1") {
echo '<a href="#"><i class="fa fa-circle" style="color:#7FFF00"></i> Active</a>';
echo '<a href="#" id="status"><i class="fa fa-circle" style="color:#7FFF00"></i> Active</a>';
} elseif ($pistatus == "0") {
echo '<a href="#"><i class="fa fa-circle" style="color:#FF0000"></i> Offline</a>';
echo '<a href="#" id="status"><i class="fa fa-circle" style="color:#FF0000"></i> Offline</a>';
} else {
echo '<a href="#"><i class="fa fa-circle" style="color:#ff9900"></i> Starting</a>';
echo '<a href="#" id="status"><i class="fa fa-circle" style="color:#ff9900"></i> Starting</a>';
}
// CPU Temp
@@ -285,9 +275,9 @@
<!-- Toggle -->
<?php
if ($pistatus == "1") {
echo ' <li><a href="?disable"><i class="fa fa-stop"></i> <span>Disable</span></a></li>';
echo ' <li><a href="#" id="flip-status"><i class="fa fa-stop"></i> <span>Disable</span></a></li>';
} else {
echo ' <li><a href="?enable"><i class="fa fa-play"></i> <span>Enable</span></a></li>';
echo ' <li><a href="#" id="flip-status"><i class="fa fa-play"></i> <span>Enable</span></a></li>';
}
?>
<!-- Logout -->