Merge branch 'devel' into tweak/Teleporter_v2.0

This commit is contained in:
DL6ER
2017-10-06 20:26:21 +02:00
20 changed files with 157 additions and 65 deletions
+1 -1
View File
@@ -35,4 +35,4 @@ groups:
- master
required: 4
teams:
- admin
- approvers
+1 -1
View File
@@ -17,7 +17,7 @@ check_cors();
$data = array();
// Common API functions
if (isset($_GET['status']) && $auth)
if (isset($_GET['status']))
{
$pistatus = exec('sudo pihole status web');
if ($pistatus == "1")
+7 -7
View File
@@ -179,11 +179,11 @@ if (isset($_GET['getForwardDestinations']) && $auth)
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
$forward_dest[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
}
else
{
$forward_dest[$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[2]] = floatval($tmp[1]);
}
}
@@ -199,7 +199,7 @@ if (isset($_GET['getQueryTypes']) && $auth)
foreach($return as $ret)
{
$tmp = explode(": ",$ret);
$querytypes[$tmp[0]] = intval($tmp[1]);
$querytypes[$tmp[0]] = floatval($tmp[1]);
}
$result = array('querytypes' => $querytypes);
@@ -257,7 +257,7 @@ if (isset($_GET['overTimeDataForwards']) && $auth)
{
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = intval($tmp[$i+1]);
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
@@ -274,11 +274,11 @@ if (isset($_GET['getForwardDestinationNames']) && $auth)
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
$forward_dest[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
}
else
{
$forward_dest[$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[2]] = floatval($tmp[1]);
}
}
@@ -296,7 +296,7 @@ if (isset($_GET['overTimeDataQueryTypes']) && $auth)
{
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = intval($tmp[$i+1]);
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
+1 -1
View File
@@ -99,7 +99,7 @@ $token = $_SESSION['token'];
<div class="col-md-12">
<div class="box" id="recent-queries">
<div class="box-header with-border">
<h3 class="box-title">Recent Queries <?php echo $showing; ?></h3>
<h3 class="box-title">Recent Queries</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
+18 -1
View File
@@ -48,10 +48,27 @@
</div>
</div>
</div>
<?php
$gravitylist = "/etc/pihole/gravity.list";
if (file_exists($gravitylist))
{
$gravitydiff = date_diff(date_create("@".filemtime($gravitylist)),date_create("now"));
if($gravitydiff->d > 1)
$gravitydate = $gravitydiff->format("Blocking list updated %a days, %H:%I ago");
elseif($gravitydiff->d == 1)
$gravitydate = $gravitydiff->format("Blocking list updated one day, %H:%I ago");
else
$gravitydate = $gravitydiff->format("Blocking list updated %H:%I ago");
}
else
{
$gravitydate = "Blocking list not found";
}
?>
<!-- ./col -->
<div class="col-lg-3 col-xs-12">
<!-- small box -->
<div class="small-box bg-red">
<div class="small-box bg-red" title="<?php echo $gravitydate; ?>">
<div class="inner">
<p>Domains on Blocklist</p>
<h3 class="statistic"><span id="domains_being_blocked">---</span></h3>
+1 -1
View File
@@ -11,7 +11,7 @@ $list = $_GET['l'];
if($list !== "white" && $list !== "black"){
echo "Invalid list parameter";
require "footer.php";
require "scripts/pi-hole/php/footer.php";
die();
}
+3 -3
View File
@@ -90,7 +90,7 @@ function updateTopClientsChart() {
var url = clientname;
percentage = data.top_sources[client] / sum * 100.0;
clienttable.append("<tr> <td>" + url +
"</td> <td>" + data.top_sources[client] + "</td> <td> <div class=\"progress progress-sm\" title=\""+percentage.toFixed(1)+"% of " + data.dns_queries_today + "\"> <div class=\"progress-bar progress-bar-blue\" style=\"width: " +
"</td> <td>" + data.top_sources[client] + "</td> <td> <div class=\"progress progress-sm\" title=\""+percentage.toFixed(1)+"% of " + sum + "\"> <div class=\"progress-bar progress-bar-blue\" style=\"width: " +
percentage + "%\"></div> </div> </td> </tr> ");
}
@@ -128,7 +128,7 @@ function updateTopDomainsChart() {
percentage = data.top_domains[domain] / sum * 100.0;
domaintable.append("<tr> <td>" + domain +
"</td> <td>" + data.top_domains[domain] + "</td> <td> <div class=\"progress progress-sm\" title=\""+percentage.toFixed(1)+"% of " + data.dns_queries_today + "\"> <div class=\"progress-bar progress-bar-blue\" style=\"width: " +
"</td> <td>" + data.top_domains[domain] + "</td> <td> <div class=\"progress progress-sm\" title=\""+percentage.toFixed(1)+"% of " + sum + "\"> <div class=\"progress-bar progress-bar-blue\" style=\"width: " +
percentage + "%\"></div> </div> </td> </tr> ");
}
@@ -165,7 +165,7 @@ function updateTopAdsChart() {
}
percentage = data.top_ads[ad] / sum * 100.0;
adtable.append("<tr> <td>" + ad + "</td> <td>" + data.top_ads[ad] + "</td> <td> <div class=\"progress progress-sm\" title=\""+percentage.toFixed(1)+"% of " + data.dns_queries_today + "\"> <div class=\"progress-bar progress-bar-blue\" style=\"width: " + percentage + "%\"></div> </div> </td> </tr> ");
adtable.append("<tr> <td>" + ad + "</td> <td>" + data.top_ads[ad] + "</td> <td> <div class=\"progress progress-sm\" title=\""+percentage.toFixed(1)+"% of " + sum + "\"> <div class=\"progress-bar progress-bar-blue\" style=\"width: " + percentage + "%\"></div> </div> </td> </tr> ");
}
}
+11 -1
View File
@@ -28,7 +28,17 @@ function eventsource() {
alSuccess.show();
}
ta.append(e.data);
// Detect ${OVER}
if(e.data.indexOf("<------") !== -1)
{
ta.text(ta.text().substring(0, ta.text().lastIndexOf("\n")) + "\n");
var new_string = e.data.replace("<------", "");
ta.append(new_string);
}
else
{
ta.append(e.data);
}
}, false);
+46 -26
View File
@@ -118,17 +118,9 @@ function updateQueryTypesOverTime() {
// New style: Get Unix timestamps
d = new Date(1000*h);
var sum = plotdata[j][0] + plotdata[j][1];
var A = 0, AAAA = 0;
if(sum > 0)
{
A = plotdata[j][0]/sum;
AAAA = plotdata[j][1]/sum;
}
queryTypeChart.data.labels.push(d);
queryTypeChart.data.datasets[0].data.push(A);
queryTypeChart.data.datasets[1].data.push(AAAA);
queryTypeChart.data.datasets[0].data.push(1e-2*plotdata[j][0]);
queryTypeChart.data.datasets[1].data.push(1e-2*plotdata[j][1]);
}
}
$("#query-types .overlay").hide();
@@ -243,18 +235,10 @@ function updateForwardedOverTime() {
for (j in timestamps)
{
if (!{}.hasOwnProperty.call(timestamps, j)) continue;
var sum = 0.0;
for (key in plotdata[j])
{
if (!{}.hasOwnProperty.call(plotdata[j], key)) continue;
sum += plotdata[j][key];
}
var dd = [];
for (key in plotdata[j])
{
if (!{}.hasOwnProperty.call(plotdata[j], key)) continue;
var singlepoint = plotdata[j][key];
forwardDestinationChart.data.datasets[key].data.push(singlepoint/sum);
forwardDestinationChart.data.datasets[key].data.push(1e-2*plotdata[j][key]);
}
var d = new Date(1000*parseInt(timestamps[j]));
@@ -288,17 +272,27 @@ function updateForwardDestinationsPie() {
var colors = [];
// Get colors from AdminLTE
$.each($.AdminLTE.options.colors, function(key, value) { colors.push(value); });
var v = [], c = [], k = [];
// Collect values and colors, immediately push individual labels
var v = [], c = [], k = [], values = [];
// Collect values and colors
$.each(data.forward_destinations, function(key , value) {
v.push(value);
c.push(colors.shift());
if(key.indexOf("|") > -1)
{
key = key.substr(0, key.indexOf("|"));
}
k.push(key);
values.push([key, value, colors.shift()]);
});
// Sort data ASC accorwing to 2nd column, keep already assigned labels and colors
values = values.sort(function(a,b) { return b[1] - a[1]; });
// Split data into individual arrays for the graphs
$.each(values, function(key , value) {
k.push(value[0]);
v.push(value[1]);
c.push(value[2]);
});
// Build a single dataset with the data to be pushed
var dd = {data: v, backgroundColor: c};
// and push it at once
@@ -822,8 +816,21 @@ $(document).ready(function() {
display: true,
position: "right"
},
tooltips: {
enabled: true,
callbacks: {
title: function(tooltipItem, data) {
return "Query types";
},
label: function(tooltipItems, data) {
var dataset = data.datasets[tooltipItems.datasetIndex];
var label = data.labels[tooltipItems.index];
return label + ": " + dataset.data[tooltipItems.index].toFixed(1) + "%";
}
}
},
animation: {
duration: 2000
duration: 750
},
cutoutPercentage: 0
}
@@ -847,8 +854,21 @@ $(document).ready(function() {
display: true,
position: "right"
},
tooltips: {
enabled: true,
callbacks: {
title: function(tooltipItem, data) {
return "Forward destinations";
},
label: function(tooltipItems, data) {
var dataset = data.datasets[tooltipItems.datasetIndex];
var label = data.labels[tooltipItems.index];
return label + ": " + dataset.data[tooltipItems.index].toFixed(1) + "%";
}
}
},
animation: {
duration: 2000
duration: 750
},
cutoutPercentage: 0
}
+1 -2
View File
@@ -143,8 +143,7 @@ function add(arg) {
method: "post",
data: {"domain":domain.val(), "list":locallistType, "token":token},
success: function(response) {
if (response.indexOf("not a valid argument") >= 0 ||
response.indexOf("is not a valid domain") >= 0) {
if (response.indexOf("] Pi-hole blocking is ") === -1) {
alFailure.show();
err.html(response);
alFailure.delay(4000).fadeOut(2000, function() {
+16
View File
@@ -17,6 +17,22 @@ $(function () {
$("input[name=\"AddMAC\"]").val(mac);
});
});
$(".confirm-poweroff").confirm({
text: "Are you sure you want to send a poweroff command to your Pi-Hole?",
title: "Confirmation required",
confirm(button) {
$("#poweroffform").submit();
},
cancel(button) {
// nothing to do
},
confirmButton: "Yes, poweroff",
cancelButton: "No, go back",
post: true,
confirmButtonClass: "btn-danger",
cancelButtonClass: "btn-success",
dialogClass: "modal-dialog modal-mg" // Bootstrap classes for mid-size modal
});
$(".confirm-reboot").confirm({
text: "Are you sure you want to send a reboot command to your Pi-Hole?",
title: "Confirmation required",
+2 -2
View File
@@ -119,7 +119,7 @@ function check_csrf($token) {
function check_domain() {
if(isset($_POST['domain'])){
$domains = explode(" ",$_POST['domain']);
$domains = preg_split('\s+', $_POST['domain']);
foreach($domains as $domain)
{
$validDomain = is_valid_domain_name($domain);
@@ -146,7 +146,7 @@ function list_verify($type) {
require("password.php");
if(strlen($pwhash) == 0)
{
log_and_die("No password set - ".htmlspecialchars($type)."listing with password not supported");
log_and_die("No password set - ".htmlspecialchars($type)."listing without password not supported");
}
elseif($wrongpassword)
{
+4 -6
View File
@@ -11,17 +11,16 @@
</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-dialog modal-sm" 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">
<div class="input-group">
<input id="customTimeout" class="form-control" type="number" value="60">
<div class="input-group-btn" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio"/> Secs
</label>
@@ -29,7 +28,6 @@
<input type="radio" /> Mins
</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
+12 -5
View File
@@ -16,15 +16,22 @@ header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
function echoEvent($datatext) {
echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
// Detect ${OVER} and replace it with something we can safely transmit
$datatext = str_replace("\r","<------",$datatext);
$pos = strpos($datatext,"<------");
// Detect if the ${OVER} line is within this line, e.g.
// "Pending: String to replace${OVER}Done: String has been replaced"
// If this is the case, we have to remove everything before ${OVER}
// and return only the text thereafter
if($pos !== false && $pos !== 0)
{
$datatext = substr($datatext, $pos);
}
echo "data: ".implode("\ndata: ", explode("\n",$datatext))."\n\n";
}
// echoEvent("***START***");
$proc = popen("sudo pihole -g", 'r');
while (!feof($proc)) {
echoEvent(fread($proc, 4096));
}
// echoEvent("***END***");
?>
+5 -5
View File
@@ -353,7 +353,7 @@ if($auth) {
?>
<br/>
<?php
echo "<a><i class=\"fa fa-circle\" style=\"color:";
echo "<a title=\"Detected $nproc cores\"><i class=\"fa fa-circle\" style=\"color:";
if ($loaddata[0] > $nproc) {
echo "#FF0000";
}
@@ -361,7 +361,7 @@ if($auth) {
{
echo "#7FFF00";
}
echo "\" title=\"Detected $nproc cores\"></i> Load:&nbsp;&nbsp;" . $loaddata[0] . "&nbsp;&nbsp;" . $loaddata[1] . "&nbsp;&nbsp;". $loaddata[2] . "</a>";
echo "\"></i> Load:&nbsp;&nbsp;" . $loaddata[0] . "&nbsp;&nbsp;" . $loaddata[1] . "&nbsp;&nbsp;". $loaddata[2] . "</a>";
?>
<br/>
<?php
@@ -420,10 +420,10 @@ if($auth) {
</li>
<li class="treeview<?php if($scriptname === "db_queries.php" || $scriptname === "db_lists.php" || $scriptname === "db_graph.php"){ ?> active<?php } ?>">
<a href="#">
<i class="fa fa-clock-o"></i> <span>Long term data</span>
<span class="pull-right-container">
<i class="fa fa-angle-down pull-right" style="padding-right: 5px;"></i>
</span>
<i class="fa fa-clock-o"></i> <span>Long term data</span>
</a>
<ul class="treeview-menu">
<li<?php if($scriptname === "db_graph.php"){ ?> class="active"<?php } ?>>
@@ -459,10 +459,10 @@ if($auth) {
<li id="pihole-disable" class="treeview"<?php if ($pistatus == "0") { ?> hidden="true"<?php } ?>>
<a href="#">
<i class="fa fa-stop"></i> <span>Disable</span>&nbsp;&nbsp;&nbsp;<span id="flip-status-disable"></span>
<span class="pull-right-container">
<i class="fa fa-angle-down pull-right" style="padding-right: 5px;"></i>
</span>
<i class="fa fa-stop"></i> <span>Disable</span>&nbsp;&nbsp;&nbsp;<span id="flip-status-disable"></span>
</a>
<ul class="treeview-menu">
<li>
@@ -499,10 +499,10 @@ if($auth) {
<!-- Tools -->
<li class="treeview <?php if(in_array($scriptname, array("gravity.php", "queryads.php", "auditlog.php", "taillog.php", "taillog-FTL.php", "debug.php"))){ ?>active<?php } ?>">
<a href="#">
<i class="fa fa-folder"></i> <span>Tools</span>
<span class="pull-right-container">
<i class="fa fa-angle-down pull-right" style="padding-right: 5px;"></i>
</span>
<i class="fa fa-folder"></i> <span>Tools</span>
</a>
<ul class="treeview-menu">
<!-- Run gravity.sh -->
+5
View File
@@ -20,6 +20,7 @@ function echoEvent($datatext) {
}
// Credit: http://stackoverflow.com/a/4694816/2087442
ini_set("pcre.recursion_limit", 1500);
function is_valid_domain_name($domain_name)
{
return (preg_match("/^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/i", $domain_name) // Valid chars check
@@ -48,6 +49,10 @@ if(isset($_GET["exact"]))
{
$exact = "-exact";
}
elseif(isset($_GET["bp"]))
{
$exact = "-bp";
}
else
{
$exact = "";
+6 -1
View File
@@ -46,7 +46,7 @@ function validDomain($domain_name)
function validDomainWildcard($domain_name)
{
// There has to be either no or at most one "*" at the beginning of a line
$validChars = preg_match("/^((\*)?[_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([a-z\d])*)*$/i", $domain_name);
$validChars = preg_match("/^((\*.)?[_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([a-z\d])*)*$/i", $domain_name);
$lengthCheck = preg_match("/^.{1,253}$/", $domain_name);
$labelLengthCheck = preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name);
return ( $validChars && $lengthCheck && $labelLengthCheck ); //length of each label
@@ -420,6 +420,11 @@ function readAdlists()
$success .= "The webUI settings have been updated";
break;
case "poweroff":
exec("sudo pihole -a poweroff");
$success = "The system will poweroff in 5 seconds...";
break;
case "reboot":
exec("sudo pihole -a reboot");
$success = "The system will reboot in 5 seconds...";
+2 -2
View File
@@ -42,14 +42,14 @@ $FTL_current = exec("pihole-FTL version");
$versionfile = "../versions";
$check_version = false;
$date = date_create();
$timestamp = date_timestamp_get($date);
// Check version if version buffer file does not exist
if(is_readable($versionfile))
{
// Obtain latest time stamp from buffer file
$versions = explode(",",file_get_contents($versionfile));
$date = date_create();
$timestamp = date_timestamp_get($date);
// Is last check for updates older than 30 minutes?
if($timestamp >= intval($versions[0]) + 1800)
+5
View File
@@ -842,10 +842,15 @@ readStaticLeasesFile();
<h3 class="box-title">System Administration</h3>
</div>
<div class="box-body">
<button type="button" class="btn btn-default confirm-poweroff">Power off system</button>
<button type="button" class="btn btn-default confirm-reboot">Restart system</button>
<button type="button" class="btn btn-default confirm-restartdns">Restart DNS server</button>
<button type="button" class="btn btn-default confirm-flushlogs">Flush logs</button>
<form role="form" method="post" id="poweroffform">
<input type="hidden" name="field" value="poweroff">
<input type="hidden" name="token" value="<?php echo $token ?>">
</form>
<form role="form" method="post" id="rebootform">
<input type="hidden" name="field" value="reboot">
<input type="hidden" name="token" value="<?php echo $token ?>">
+10
View File
@@ -4,6 +4,7 @@
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
.small-box {
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
@@ -34,3 +35,12 @@ a.lookatme {
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
#all-queries {
table-layout: fixed;
}
#all-queries tbody {
word-wrap: break-word;
}
.main-header>.navbar {
height: 50px;
}