mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Merge branch 'devel' into new/FTL-integration
Conflicts: api.php
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// Credit: http://stackoverflow.com/a/10642418/2087442
|
||||
function httpGet(ta,theUrl)
|
||||
{
|
||||
var xmlhttp;
|
||||
if (window.XMLHttpRequest)
|
||||
{
|
||||
// code for IE7+
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
// code for IE6, IE5
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
xmlhttp.onreadystatechange=function()
|
||||
{
|
||||
if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
|
||||
{
|
||||
ta.show();
|
||||
ta.empty();
|
||||
ta.append(xmlhttp.responseText);
|
||||
}
|
||||
};
|
||||
xmlhttp.open("GET", theUrl, false);
|
||||
xmlhttp.send();
|
||||
}
|
||||
|
||||
function eventsource() {
|
||||
var ta = $("#output");
|
||||
var upload = $( "#upload" );
|
||||
var checked = "";
|
||||
|
||||
if(upload.prop("checked"))
|
||||
{
|
||||
checked = "upload";
|
||||
}
|
||||
|
||||
// IE does not support EventSource - load whole content at once
|
||||
if (typeof EventSource !== "function") {
|
||||
httpGet(ta,"/admin/scripts/pi-hole/php/debug.php?IE&"+checked);
|
||||
return;
|
||||
}
|
||||
|
||||
var host = window.location.host;
|
||||
var source = new EventSource("/admin/scripts/pi-hole/php/debug.php?"+checked);
|
||||
|
||||
// Reset and show field
|
||||
ta.empty();
|
||||
ta.show();
|
||||
|
||||
source.addEventListener("message", function(e) {
|
||||
ta.append(e.data);
|
||||
}, false);
|
||||
|
||||
// Will be called when script has finished
|
||||
source.addEventListener("error", function(e) {
|
||||
source.close();
|
||||
}, false);
|
||||
}
|
||||
|
||||
$("#debugBtn").on("click", function(){
|
||||
$("#debugBtn").attr("disabled", true);
|
||||
$("#upload").attr("disabled", true);
|
||||
eventsource();
|
||||
});
|
||||
@@ -14,6 +14,35 @@ $("body").on("click", function(event) {
|
||||
}
|
||||
});
|
||||
|
||||
//The following functions allow us to display time until pi-hole is enabled after disabling.
|
||||
//Works between all pages
|
||||
|
||||
function secondsTimeSpanToHMS(s) {
|
||||
var h = Math.floor(s/3600); //Get whole hours
|
||||
s -= h*3600;
|
||||
var m = Math.floor(s/60); //Get remaining minutes
|
||||
s -= m*60;
|
||||
return h+":"+(m < 10 ? "0"+m : m)+":"+(s < 10 ? "0"+s : s); //zero padding on minutes and seconds
|
||||
}
|
||||
|
||||
function countDown(){
|
||||
var ena = $("#enableLabel");
|
||||
var enaT = $("#enableTimer");
|
||||
var target = new Date(parseInt(enaT.html()));
|
||||
var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000);
|
||||
|
||||
if(seconds > 0){
|
||||
setTimeout(countDown,1000);
|
||||
ena.text("Enable (" + secondsTimeSpanToHMS(seconds) + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
ena.text("Enable");
|
||||
piholeChanged("enabled");
|
||||
localStorage.removeItem("countDownTarget");
|
||||
}
|
||||
}
|
||||
|
||||
function piholeChanged(action)
|
||||
{
|
||||
var status = $("#status");
|
||||
@@ -40,6 +69,7 @@ function piholeChanged(action)
|
||||
function piholeChange(action, duration)
|
||||
{
|
||||
var token = encodeURIComponent($("#token").html());
|
||||
var enaT = $("#enableTimer");
|
||||
var btnStatus;
|
||||
|
||||
switch(action) {
|
||||
@@ -61,52 +91,21 @@ function piholeChange(action, duration)
|
||||
if(data.status === "disabled") {
|
||||
btnStatus.html("");
|
||||
piholeChanged("disabled");
|
||||
enaT.html(new Date().getTime() + duration * 1000);
|
||||
setTimeout(countDown,100);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//The following three functions allow us to display time until pi-hole is enabled after disabling.
|
||||
//Works between all pages
|
||||
|
||||
|
||||
function setCountdownTarget(seconds){
|
||||
var target = new Date();
|
||||
target = new Date(target.getTime() + seconds * 1000);
|
||||
localStorage.setItem("countDownTarget", target);
|
||||
}
|
||||
|
||||
function secondsTimeSpanToHMS(s) {
|
||||
var h = Math.floor(s/3600); //Get whole hours
|
||||
s -= h*3600;
|
||||
var m = Math.floor(s/60); //Get remaining minutes
|
||||
s -= m*60;
|
||||
return h+":"+(m < 10 ? "0"+m : m)+":"+(s < 10 ? "0"+s : s); //zero padding on minutes and seconds
|
||||
}
|
||||
|
||||
function countDown(){
|
||||
var ena = $("#enableLabel");
|
||||
var target = new Date(localStorage.getItem("countDownTarget"));
|
||||
var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000);
|
||||
|
||||
if(seconds > 0){
|
||||
setTimeout(countDown,1000);
|
||||
ena.text("Enable (" + secondsTimeSpanToHMS(seconds) + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
ena.text("Enable");
|
||||
piholeChanged("enabled");
|
||||
localStorage.removeItem("countDownTarget");
|
||||
}
|
||||
}
|
||||
|
||||
$( document ).ready(function() {
|
||||
var countDownTarget = localStorage.getItem("countDownTarget");
|
||||
if (countDownTarget != null)
|
||||
var enaT = $("#enableTimer");
|
||||
var target = new Date(parseInt(enaT.html()));
|
||||
var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000);
|
||||
if (seconds > 0)
|
||||
{
|
||||
setTimeout(countDown,1000);
|
||||
setTimeout(countDown,100);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -123,28 +122,20 @@ $("#pihole-disable-permanently").on("click", function(e){
|
||||
$("#pihole-disable-10s").on("click", function(e){
|
||||
e.preventDefault();
|
||||
piholeChange("disable","10");
|
||||
setCountdownTarget(10);
|
||||
setTimeout(countDown,1000);
|
||||
});
|
||||
$("#pihole-disable-30s").on("click", function(e){
|
||||
e.preventDefault();
|
||||
piholeChange("disable","30");
|
||||
setCountdownTarget(30);
|
||||
setTimeout(countDown,1000);
|
||||
});
|
||||
$("#pihole-disable-5m").on("click", function(e){
|
||||
e.preventDefault();
|
||||
piholeChange("disable","300");
|
||||
setCountdownTarget(300);
|
||||
setTimeout(countDown,1000);
|
||||
});
|
||||
$("#pihole-disable-custom").on("click", function(e){
|
||||
e.preventDefault();
|
||||
var custVal = $("#customTimeout").val();
|
||||
custVal = $("#btnMins").hasClass("active") ? custVal * 60 : custVal;
|
||||
piholeChange("disable",custVal);
|
||||
setCountdownTarget(custVal);
|
||||
setTimeout(countDown,1000);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +68,23 @@ $(".confirm-flushlogs").confirm({
|
||||
dialogClass: "modal-dialog modal-mg"
|
||||
});
|
||||
|
||||
$(".api-token").confirm({
|
||||
text: "Make sure that nobody else can scan this code around you. They will have full access to the API without having to know the password. Note that the generation of the QR code will take some time.",
|
||||
title: "Confirmation required",
|
||||
confirm(button) {
|
||||
window.open("scripts/pi-hole/php/api_token.php");
|
||||
},
|
||||
cancel(button) {
|
||||
// nothing to do
|
||||
},
|
||||
confirmButton: "Yes, show API token",
|
||||
cancelButton: "No, go back",
|
||||
post: true,
|
||||
confirmButtonClass: "btn-danger",
|
||||
cancelButtonClass: "btn-success",
|
||||
dialogClass: "modal-dialog modal-mg"
|
||||
});
|
||||
|
||||
$("#DHCPchk").click(function() {
|
||||
$("input.DHCPgroup").prop("disabled", !this.checked);
|
||||
$("#dhcpnotice").prop("hidden", !this.checked).addClass("lookatme");
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<html><body>
|
||||
<?php
|
||||
require "auth.php";
|
||||
require "password.php";
|
||||
check_cors();
|
||||
|
||||
if($auth)
|
||||
{
|
||||
if(strlen($pwhash) > 0)
|
||||
{
|
||||
require_once("../../vendor/qrcode.php");
|
||||
$qr = QRCode::getMinimumQRCode($pwhash, QR_ERROR_CORRECT_LEVEL_Q);
|
||||
$qr->printHTML("10px");
|
||||
}
|
||||
else
|
||||
{
|
||||
?><p>No password set<?php
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
?><p>Not authorized!</p><?php
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -30,7 +30,7 @@ function check_cors() {
|
||||
$AUTHORIZED_HOSTNAMES = array(
|
||||
$ipv4,
|
||||
$ipv6,
|
||||
$_SERVER["SERVER_NAME"],
|
||||
str_replace(array("[","]"), array("",""), $_SERVER["SERVER_NAME"]),
|
||||
"pi.hole",
|
||||
"localhost"
|
||||
);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
ob_end_flush();
|
||||
ini_set("output_buffering", "0");
|
||||
ob_implicit_flush(true);
|
||||
header('Content-Type: text/event-stream');
|
||||
header('Cache-Control: no-cache');
|
||||
|
||||
function echoEvent($datatext) {
|
||||
if(!isset($_GET["IE"]))
|
||||
echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
|
||||
else
|
||||
echo $datatext;
|
||||
}
|
||||
|
||||
if(isset($_GET["upload"]))
|
||||
{
|
||||
$proc = popen("sudo pihole -d -a -w", "r");
|
||||
}
|
||||
else
|
||||
{
|
||||
$proc = popen("sudo pihole -d -w", "r");
|
||||
}
|
||||
while (!feof($proc)) {
|
||||
echoEvent(fread($proc, 4096));
|
||||
}
|
||||
?>
|
||||
@@ -188,6 +188,7 @@
|
||||
<script src="scripts/pi-hole/js/header.js"></script>
|
||||
<!-- Send token to JS -->
|
||||
<div id="token" hidden><?php if($auth) echo $token; ?></div>
|
||||
<div id="enableTimer" hidden><?php if(file_exists("../custom_disable_timer")){ echo file_get_contents("../custom_disable_timer"); } ?></div>
|
||||
<div class="wrapper">
|
||||
<header class="main-header">
|
||||
<!-- Logo -->
|
||||
@@ -367,7 +368,7 @@
|
||||
<!-- Home Page -->
|
||||
<li<?php if($scriptname === "index.php"){ ?> class="active"<?php } ?>>
|
||||
<a href="index.php">
|
||||
<i class="fa fa-home"></i> <span>Main Page</span>
|
||||
<i class="fa fa-home"></i> <span>Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php if($auth){ ?>
|
||||
@@ -431,7 +432,7 @@
|
||||
<a href="#"><i class="fa fa-play"></i> <span id="enableLabel">Enable</span> <span id="flip-status-enable"></span></a>
|
||||
</li>
|
||||
<!-- Tools -->
|
||||
<li class="treeview <?php if($scriptname === "gravity.php" || $scriptname === "queryads.php"){ ?>active<?php } ?>">
|
||||
<li class="treeview <?php if($scriptname === "gravity.php" || $scriptname === "queryads.php" || $scriptname === "debug.php"){ ?>active<?php } ?>">
|
||||
<a href="#">
|
||||
<i class="fa fa-folder"></i> <span>Tools</span>
|
||||
<span class="pull-right-container">
|
||||
@@ -457,6 +458,12 @@
|
||||
<i class="fa fa-list-ul"></i> <span>Tail pihole.log</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- Generate debug log -->
|
||||
<li<?php if($scriptname === "debug.php"){ ?> class="active"<?php } ?>>
|
||||
<a href="debug.php">
|
||||
<i class="fa fa-ambulance"></i> <span>Generate debug log</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<!-- Settings -->
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
require "password.php";
|
||||
if(!$auth) die("Not authorized");
|
||||
|
||||
ob_end_flush();
|
||||
ini_set("output_buffering", "0");
|
||||
ob_implicit_flush(true);
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
* 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. */ ?>
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
require "password.php";
|
||||
if(!$auth) die("Not authorized");
|
||||
|
||||
<?php
|
||||
require('func.php');
|
||||
function process_zip($name)
|
||||
{
|
||||
|
||||
Vendored
+1543
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user