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:
@@ -7,8 +7,8 @@
|
||||
* Please see LICENSE file for your rights under this license */
|
||||
|
||||
$api = true;
|
||||
|
||||
require("scripts/pi-hole/php/FTL.php");
|
||||
|
||||
if(testFTL() && !isset($_GET["PHP"]))
|
||||
{
|
||||
require("api_FTL.php");
|
||||
|
||||
+28
-10
@@ -81,28 +81,46 @@
|
||||
$data = array_merge($data, getAllQueries($_GET['getAllQueries']));
|
||||
}
|
||||
|
||||
if (isset($_GET['enable'], $_GET['token']) && $auth) {
|
||||
check_csrf($_GET['token']);
|
||||
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"
|
||||
));
|
||||
$data = array_merge($data, array("status" => "enabled"));
|
||||
unlink("../custom_disable_timer");
|
||||
}
|
||||
elseif (isset($_GET['disable'], $_GET['token']) && $auth) {
|
||||
check_csrf($_GET['token']);
|
||||
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"
|
||||
));
|
||||
$data = array_merge($data, array("status" => "disabled"));
|
||||
}
|
||||
|
||||
if (isset($_GET['getGravityDomains'])) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require "scripts/pi-hole/php/header.php";
|
||||
?>
|
||||
<!-- Title -->
|
||||
<div class="page-header">
|
||||
<h1>Generate debug log</h1>
|
||||
</div>
|
||||
|
||||
<p><input type="checkbox" id="upload" checked> Upload debug log and provide token once finished</p>
|
||||
<p>Once you click this button a debug log will be generated and can automatically be uploaded if we detect a working internet connection.</p>
|
||||
<button class="btn btn-lg btn-primary btn-block" id="debugBtn">Generate debug log</button>
|
||||
<pre id="output" style="width: 100%; height: 100%;" hidden="true"></pre>
|
||||
|
||||
<?php
|
||||
require "scripts/pi-hole/php/footer.php";
|
||||
?>
|
||||
|
||||
|
||||
<script src="scripts/pi-hole/js/debug.js"></script>
|
||||
@@ -43,8 +43,8 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h2>Main page</h2>
|
||||
<p>On the main page, you can see various Pi-hole statistics:</p>
|
||||
<h2>Dashboard</h2>
|
||||
<p>On the dashboard, you can see various Pi-hole statistics:</p>
|
||||
<ul>
|
||||
<li>Summary: A summary of statistics showing how many total DNS queries have been blocked today, what percentage of DNS queries have been blocked, and how many domains are in the compiled ad list. This summary is updated every 10 seconds.</li>
|
||||
<li>Queries over time: Graph showing DNS queries (total and blocked) over 10 minute time intervals. More information can be acquired by hovering over the lines. This graph is updated every 10 minutes.</li>
|
||||
@@ -56,7 +56,7 @@
|
||||
</ul>
|
||||
<p>The Top Domains and Top Advertisers lists may be hidden depending on the privacy Settings on the settings page</p>
|
||||
<?php if($authenticationsystem){ ?>
|
||||
<p>Note that the login session does <em>not</em> expire on the main page, as the summary is updated every 10 seconds which refreshes the session.</p>
|
||||
<p>Note that the login session does <em>not</em> expire on the dashboard, as the summary is updated every 10 seconds which refreshes the session.</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -126,7 +126,7 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h2>Authentication system (currently <?php if($authenticationsystem) { ?>enabled<?php } else { ?>disabled<?php } ?>)</h2>
|
||||
<p>Using the command<pre>sudo pihole -a -p pa22w0rd</pre> where <em>pa22w0rd</em> is the password to be set in this example, one can enable the authentication system of this web interface. Thereafter, a login is required for most pages (the main page will show a limited amount of statistics). Note that the authentication system may be disabled again, by setting an empty password using the command shown above. The Help center will show more details concerning the authentication system only if it is enabled</p>
|
||||
<p>Using the command<pre>sudo pihole -a -p pa22w0rd</pre> where <em>pa22w0rd</em> is the password to be set in this example, one can enable the authentication system of this web interface. Thereafter, a login is required for most pages (the dashboard will show a limited amount of statistics). Note that the authentication system may be disabled again, by setting an empty password using the command shown above. The Help center will show more details concerning the authentication system only if it is enabled</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php if($authenticationsystem) { ?>
|
||||
|
||||
@@ -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
@@ -666,6 +666,7 @@
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<input type="hidden" name="field" value="API">
|
||||
<button type="button" class="btn btn-primary api-token">Show API token</button>
|
||||
<button type="submit" class="btn btn-primary pull-right">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user