Conflicts:

api.php
	scripts/pi-hole/php/FTL.php
	scripts/pi-hole/php/auth.php
	scripts/pi-hole/php/password.php
This commit is contained in:
DL6ER
2017-02-19 14:17:52 +01:00
parent aabff35bef
commit f88092175e
9 changed files with 347 additions and 249 deletions
+200 -200
View File
@@ -1,242 +1,242 @@
<!-- Pi-hole: A black hole for Internet advertisements
<?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. -->
<?php
// error_reporting(E_ALL);
$api = true;
* Please see LICENSE file for your rights under this license */
require("scripts/pi-hole/php/FTL.php");
if(!testFTL())
$api = true;
require("scripts/pi-hole/php/FTL.php");
if(!testFTL())
{
require("api_PHP.php");
exit();
}
require "scripts/pi-hole/php/password.php";
require "scripts/pi-hole/php/auth.php";
check_cors();
$socket = connectFTL("127.0.0.1");
header('Content-type: application/json');
$data = [];
if (isset($_GET['summary']) || isset($_GET['summaryRaw']))
{
sendRequestFTL("stats");
$return = getResponseFTL();
$stats = [];
foreach($return as $line)
{
require("api_PHP.php");
exit();
}
$tmp = explode(" ",$line);
require "scripts/pi-hole/php/password.php";
require "scripts/pi-hole/php/auth.php";
check_cors();
$socket = connectFTL("127.0.0.1");
header('Content-type: application/json');
$data = [];
if (isset($_GET['summary']) || isset($_GET['summaryRaw']))
{
sendRequestFTL("stats");
$return = getResponseFTL();
$stats = [];
foreach($return as $line)
if(isset($_GET['summary']))
{
$tmp = explode(" ",$line);
if(isset($_GET['summary']))
if($tmp[0] !== "ads_percentage_today")
{
if($tmp[0] !== "ads_percentage_today")
{
$stats[$tmp[0]] = number_format($tmp[1]);
}
else
{
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
}
$stats[$tmp[0]] = number_format($tmp[1]);
}
else
{
$stats[$tmp[0]] = $tmp[1];
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
}
}
$data = array_merge($data,$stats);
}
if (isset($_GET['overTimeData10mins']))
{
sendRequestFTL("overTime");
$return = getResponseFTL();
$domains_over_time = array();
$ads_over_time = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
$domains_over_time[$tmp[0]] = $tmp[1];
$ads_over_time[$tmp[0]] = $tmp[2];
}
$result = array('domains_over_time' => $domains_over_time,
'ads_over_time' => $ads_over_time);
$data = array_merge($data, $result);
}
if (isset($_GET['topItems']) && $auth)
{
if(is_numeric($_GET['topItems']))
{
sendRequestFTL("top-domains ".$_GET['topItems']);
}
else
{
sendRequestFTL("top-domains");
$stats[$tmp[0]] = $tmp[1];
}
}
$data = array_merge($data,$stats);
}
$return = getResponseFTL();
$top_queries = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
$top_queries[$tmp[2]] = $tmp[1];
}
if (isset($_GET['overTimeData10mins']))
{
sendRequestFTL("overTime");
$return = getResponseFTL();
if(is_numeric($_GET['topItems']))
$domains_over_time = array();
$ads_over_time = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
$domains_over_time[$tmp[0]] = $tmp[1];
$ads_over_time[$tmp[0]] = $tmp[2];
}
$result = array('domains_over_time' => $domains_over_time,
'ads_over_time' => $ads_over_time);
$data = array_merge($data, $result);
}
if (isset($_GET['topItems']) && $auth)
{
if(is_numeric($_GET['topItems']))
{
sendRequestFTL("top-domains ".$_GET['topItems']);
}
else
{
sendRequestFTL("top-domains");
}
$return = getResponseFTL();
$top_queries = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
$top_queries[$tmp[2]] = $tmp[1];
}
if(is_numeric($_GET['topItems']))
{
sendRequestFTL("top-ads ".$_GET['topItems']);
}
else
{
sendRequestFTL("top-ads");
}
$return = getResponseFTL();
$top_ads = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
$top_ads[$tmp[2]] = $tmp[1];
}
$result = array('top_queries' => $top_queries,
'top_ads' => $top_ads);
$data = array_merge($data, $result);
}
if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth)
{
sendRequestFTL("top-clients");
$return = getResponseFTL();
$top_clients = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
sendRequestFTL("top-ads ".$_GET['topItems']);
$top_clients[$tmp[3]."|".$tmp[2]] = $tmp[1];
}
else
{
sendRequestFTL("top-ads");
$top_clients[$tmp[2]] = $tmp[1];
}
$return = getResponseFTL();
$top_ads = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
$top_ads[$tmp[2]] = $tmp[1];
}
$result = array('top_queries' => $top_queries,
'top_ads' => $top_ads);
$data = array_merge($data, $result);
}
if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth)
$result = array('top_sources' => $top_clients);
$data = array_merge($data, $result);
}
if (isset($_GET['getForwardDestinations']) && $auth)
{
sendRequestFTL("forward-dest");
$return = getResponseFTL();
$forward_dest = array();
foreach($return as $line)
{
sendRequestFTL("top-clients");
$return = getResponseFTL();
$top_clients = array();
foreach($return as $line)
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
$top_clients[$tmp[3]."|".$tmp[2]] = $tmp[1];
}
else
{
$top_clients[$tmp[2]] = $tmp[1];
}
}
$result = array('top_sources' => $top_clients);
$data = array_merge($data, $result);
}
if (isset($_GET['getForwardDestinations']) && $auth)
{
sendRequestFTL("forward-dest");
$return = getResponseFTL();
$forward_dest = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
$forward_dest[$tmp[3]."|".$tmp[2]] = $tmp[1];
}
else
{
$forward_dest[$tmp[2]] = $tmp[1];
}
}
$result = array('forward_destinations' => $forward_dest);
$data = array_merge($data, $result);
}
if (isset($_GET['getQueryTypes']) && $auth)
{
sendRequestFTL("querytypes");
$return = getResponseFTL();
$querytypes = array();
foreach($return as $ret)
{
$tmp = explode(": ",$ret);
$querytypes[$tmp[0]] = $tmp[1];
}
$result = array('querytypes' => $querytypes);
$data = array_merge($data, $result);
}
if (isset($_GET['getAllQueries']) && $auth)
{
if(isset($_GET['from']) && isset($_GET['until']))
{
// Get limited time interval
sendRequestFTL("getallqueries-time ".$_GET['from']." ".$_GET['until']);
}
else if(isset($_GET['domain']))
{
// Get specific domain only
sendRequestFTL("getallqueries-domain ".$_GET['domain']);
}
else if(isset($_GET['client']))
{
// Get specific client only
sendRequestFTL("getallqueries-client ".$_GET['client']);
$forward_dest[$tmp[3]."|".$tmp[2]] = $tmp[1];
}
else
{
// Get all queries
sendRequestFTL("getallqueries");
$forward_dest[$tmp[2]] = $tmp[1];
}
$return = getResponseFTL();
$allQueries = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
array_push($allQueries,$tmp);
}
$result = array('data' => $allQueries);
$data = array_merge($data, $result);
}
if (isset($_GET['enable'], $_GET['token']) && $auth) {
check_csrf($_GET['token']);
exec('sudo pihole enable');
$data = array_merge($data, array("status" => "enabled"));
}
elseif (isset($_GET['disable'], $_GET['token']) && $auth) {
check_csrf($_GET['token']);
$disable = intval($_GET['disable']);
// intval returns the integer value on success, or 0 on failure
if($disable > 0)
{
exec("sudo pihole disable ".$disable."s");
}
else
{
exec('sudo pihole disable');
}
$data = array_merge($data, array("status" => "disabled"));
}
$result = array('forward_destinations' => $forward_dest);
$data = array_merge($data, $result);
}
if(isset($_GET["recentBlocked"]))
if (isset($_GET['getQueryTypes']) && $auth)
{
sendRequestFTL("querytypes");
$return = getResponseFTL();
$querytypes = array();
foreach($return as $ret)
{
sendRequestFTL("recentBlocked");
echo getResponseFTL()[0];
unset($data);
$tmp = explode(": ",$ret);
$querytypes[$tmp[0]] = $tmp[1];
}
if(isset($data))
$result = array('querytypes' => $querytypes);
$data = array_merge($data, $result);
}
if (isset($_GET['getAllQueries']) && $auth)
{
if(isset($_GET['from']) && isset($_GET['until']))
{
echo json_encode($data);
// Get limited time interval
sendRequestFTL("getallqueries-time ".$_GET['from']." ".$_GET['until']);
}
else if(isset($_GET['domain']))
{
// Get specific domain only
sendRequestFTL("getallqueries-domain ".$_GET['domain']);
}
else if(isset($_GET['client']))
{
// Get specific client only
sendRequestFTL("getallqueries-client ".$_GET['client']);
}
else
{
// Get all queries
sendRequestFTL("getallqueries");
}
$return = getResponseFTL();
$allQueries = array();
foreach($return as $line)
{
$tmp = explode(" ",$line);
array_push($allQueries,$tmp);
}
disconnectFTL();
$result = array('data' => $allQueries);
$data = array_merge($data, $result);
}
if (isset($_GET['enable'], $_GET['token']) && $auth) {
check_csrf($_GET['token']);
exec('sudo pihole enable');
$data = array_merge($data, array("status" => "enabled"));
}
elseif (isset($_GET['disable'], $_GET['token']) && $auth) {
check_csrf($_GET['token']);
$disable = intval($_GET['disable']);
// intval returns the integer value on success, or 0 on failure
if($disable > 0)
{
exec("sudo pihole disable ".$disable."s");
}
else
{
exec('sudo pihole disable');
}
$data = array_merge($data, array("status" => "disabled"));
}
if(isset($_GET["recentBlocked"]))
{
sendRequestFTL("recentBlocked");
echo getResponseFTL()[0];
unset($data);
}
if(isset($data))
{
echo json_encode($data);
}
disconnectFTL();
?>
+91 -35
View File
@@ -22,17 +22,17 @@ function piholeChanged(action)
switch(action) {
case "enabled":
status.html("<i class='fa fa-circle' style='color:#7FFF00'></i> Active");
ena.hide();
dis.show();
dis.removeClass("active");
break;
status.html("<i class='fa fa-circle' style='color:#7FFF00'></i> Active");
ena.hide();
dis.show();
dis.removeClass("active");
break;
case "disabled":
status.html("<i class='fa fa-circle' style='color:#FF0000'></i> Offline");
ena.show();
dis.hide();
break;
status.html("<i class='fa fa-circle' style='color:#FF0000'></i> Offline");
ena.show();
dis.hide();
break;
}
}
@@ -44,32 +44,76 @@ function piholeChange(action, duration)
switch(action) {
case "enable":
btnStatus = $("#flip-status-enable");
btnStatus.html("<i class='fa fa-spinner'> </i>");
$.getJSON("api.php?enable&token=" + token, function(data) {
if(data.status === "enabled") {
btnStatus.html("");
piholeChanged("enabled");
}
});
break;
btnStatus = $("#flip-status-enable");
btnStatus.html("<i class='fa fa-spinner'> </i>");
$.getJSON("api.php?enable&token=" + token, function(data) {
if(data.status === "enabled") {
btnStatus.html("");
piholeChanged("enabled");
}
});
break;
case "disable":
btnStatus = $("#flip-status-disable");
btnStatus.html("<i class='fa fa-spinner'> </i>");
$.getJSON("api.php?disable=" + duration + "&token=" + token, function(data) {
if(data.status === "disabled") {
btnStatus.html("");
piholeChanged("disabled");
}
});
break;
btnStatus = $("#flip-status-disable");
btnStatus.html("<i class='fa fa-spinner'> </i>");
$.getJSON("api.php?disable=" + duration + "&token=" + token, function(data) {
if(data.status === "disabled") {
btnStatus.html("");
piholeChanged("disabled");
}
});
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)
{
setTimeout(countDown,1000);
}
});
// Handle Enable/Disable
$("#pihole-enable").on("click", function(e){
e.preventDefault();
localStorage.removeItem("countDownTarget");
piholeChange("enable","");
});
$("#pihole-disable-permanently").on("click", function(e){
@@ -79,18 +123,30 @@ $("#pihole-disable-permanently").on("click", function(e){
$("#pihole-disable-10s").on("click", function(e){
e.preventDefault();
piholeChange("disable","10");
setTimeout(function(){piholeChanged("enabled");},10000);
setCountdownTarget(10);
setTimeout(countDown,1000);
});
$("#pihole-disable-30s").on("click", function(e){
e.preventDefault();
piholeChange("disable","30");
setTimeout(function(){piholeChanged("enabled");},30000);
setCountdownTarget(30);
setTimeout(countDown,1000);
});
$("#pihole-disable-5m").on("click", function(e){
e.preventDefault();
piholeChange("disable","300");
setTimeout(function(){piholeChanged("enabled");},300000);
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);
});
var piholeVersion = $("#piholeVersion").html();
var webVersion = $("#webVersion").html();
@@ -200,15 +256,15 @@ else
// Hide "exact match" button on queryads.php page if version is 2.9.5 or lower
if(versionCompare(piholeVersion, "v2.9.5") < 1)
{
$("#btnSearchExact").hide();
$("#btnSearchExact").hide();
}
// Handle Strg + Enter button on Login page
$(document).keypress(function(e) {
if((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $("#loginpw").is(":focus")) {
$("#loginform").attr("action", "settings.php");
$("#loginform").submit();
}
if((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $("#loginpw").is(":focus")) {
$("#loginform").attr("action", "settings.php");
$("#loginform").submit();
}
});
function testCookies()
+7
View File
@@ -1,4 +1,10 @@
<?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. */
function testFTL()
{
@@ -101,3 +107,4 @@ function disconnectFTL($quiet=true)
echo "OK.\n\n";
}
}
?>
+1 -2
View File
@@ -4,9 +4,8 @@
* 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. */
<?php
require('func.php');
$ERRORLOG = getenv('PHP_ERROR_LOG');
if (empty($ERRORLOG)) {
+7 -7
View File
@@ -461,20 +461,20 @@
}
if($orderBy == "orderByClientDomainTime"){
$allQueries['data'][hasHostName($client)][$domain][$time->format('Y-m-d\TH:i:s')] = $status;
$allQueries['data'][hasHostName($client)][$domain][$time->format('Y-m-d T H:i:s')] = $status;
}elseif ($orderBy == "orderByClientTimeDomain"){
$allQueries['data'][hasHostName($client)][$time->format('Y-m-d\TH:i:s')][$domain] = $status;
$allQueries['data'][hasHostName($client)][$time->format('Y-m-d T H:i:s')][$domain] = $status;
}elseif ($orderBy == "orderByTimeClientDomain"){
$allQueries['data'][$time->format('Y-m-d\TH:i:s')][hasHostName($client)][$domain] = $status;
$allQueries['data'][$time->format('Y-m-d T H:i:s')][hasHostName($client)][$domain] = $status;
}elseif ($orderBy == "orderByTimeDomainClient"){
$allQueries['data'][$time->format('Y-m-d\TH:i:s')][$domain][hasHostName($client)] = $status;
$allQueries['data'][$time->format('Y-m-d T H:i:s')][$domain][hasHostName($client)] = $status;
}elseif ($orderBy == "orderByDomainClientTime"){
$allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d\TH:i:s')] = $status;
$allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d T H:i:s')] = $status;
}elseif ($orderBy == "orderByDomainTimeClient"){
$allQueries['data'][$domain][$time->format('Y-m-d\TH:i:s')][hasHostName($client)] = $status;
$allQueries['data'][$domain][$time->format('Y-m-d T H:i:s')][hasHostName($client)] = $status;
}else{
array_push($allQueries['data'], array(
$time->format('Y-m-d\TH:i:s'),
$time->format('Y-m-d T H:i:s'),
$type,
$domain,
hasHostName($client),
+31 -1
View File
@@ -9,6 +9,36 @@
</section>
<!-- /.content -->
</div>
<!-- Modal for custom disable time -->
<div class="modal fade" id="customDisableModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Custom disable timeout</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-3"><input id="customTimeout" class="form-control" type="number" value="60"></div>
<div class="col-sm-9">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio"/> Secs
</label>
<label id="btnMins" class="btn btn-default active">
<input type="radio" /> Mins
</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="pihole-disable-custom" type="button" class="btn btn-primary" data-dismiss="modal">Submit</button>
</div>
</div>
</div>
</div>
<!-- /.content-wrapper -->
<footer class="main-footer">
<?php
@@ -37,7 +67,7 @@
<b>Pi-hole Version </b> <span id="piholeVersion"><?php echo $piholeVersion; ?></span><?php if(isset($piholeCommit)) { echo " (".$piholeBranch.", ".$piholeCommit.")"; } ?>
<b>Web Interface Version </b> <span id="webVersion"><?php echo $webVersion; ?></span><?php if(isset($webCommit)) { echo " (".$webBranch.", ".$webCommit.")"; } ?>
</div>
<div><i class="fa fa-github"></i> <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=3J2L3Z4DHW9UY">Donate</a></strong> if you found this useful.</div>
<div><a href="https://github.com/pi-hole"><i class="fa fa-github"></i></a> <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=3J2L3Z4DHW9UY">Donate</a></strong> if you found this useful.</div>
</footer>
</div>
<!-- ./wrapper -->
+6 -1
View File
@@ -419,11 +419,16 @@
<i class="fa fa-clock-o"></i> <span>For 5 minutes</span>
</a>
</li>
<li>
<a href="#" id="pihole-disable-cst" data-toggle="modal" data-target="#customDisableModal">
<i class="fa fa-clock-o"></i> <span>Custom time</span>
</a>
</li>
</ul>
<!-- <a href="#" id="flip-status"><i class="fa fa-stop"></i> <span>Disable</span></a> -->
</li>
<li id="pihole-enable" class="treeview"<?php if ($pistatus == "1") { ?> hidden="true"<?php } ?>>
<a href="#"><i class="fa fa-play"></i> <span>Enable</span>&nbsp;&nbsp;&nbsp;<span id="flip-status-enable"></span></a>
<a href="#"><i class="fa fa-play"></i> <span id="enableLabel">Enable</span>&nbsp;&nbsp;&nbsp;<span id="flip-status-enable"></span></a>
</li>
<!-- Tools -->
<li class="treeview <?php if($scriptname === "gravity.php" || $scriptname === "queryads.php"){ ?>active<?php } ?>">
+1 -2
View File
@@ -4,9 +4,8 @@
* 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. */
<?php
// Start a new PHP session (or continue an existing one)
session_start();
+3 -1
View File
@@ -101,11 +101,13 @@ function readStaticLeasesFile()
"4.2.2.1" => "Level3 (Primary)",
"199.85.126.10" => "Norton (Primary)",
"8.26.56.26" => "Comodo (Primary)",
"84.200.69.80" => "DNS.WATCH (Primary)",
"8.8.4.4" => "Google (Secondary)",
"208.67.220.220" => "OpenDNS (Secondary)",
"4.2.2.2" => "Level3 (Secondary)",
"199.85.127.10" => "Norton (Secondary)",
"8.20.247.20" => "Comodo (Secondary)"
"8.20.247.20" => "Comodo (Secondary)",
"84.200.70.40" => "DNS.WATCH (Secondary)",
];
$error = "";