Skip to content

Commit

Permalink
new: Web v5.11
Browse files Browse the repository at this point in the history
  • Loading branch information
muxcc committed Feb 13, 2022
1 parent c61e4a1 commit 50014c2
Show file tree
Hide file tree
Showing 33 changed files with 654 additions and 257 deletions.
86 changes: 57 additions & 29 deletions admin/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,9 @@
$data = array();

// Common API functions
if (isset($_GET['status']))
{
$pistatus = pihole_execute('status web');
if(isset($pistatus[0]))
{
$pistatus = $pistatus[0];
}
else
{
$pistatus = null;
}
if ($pistatus === "1")
{
$data = array_merge($data, array("status" => "enabled"));
}
else
{
$data = array_merge($data, array("status" => "disabled"));
}
}
elseif (isset($_GET['enable']) && $auth)
{
if (isset($_GET['status'])) {
$data = array_merge($data, array("status" => piholeStatusAPI()));
} elseif (isset($_GET['enable']) && $auth) {
if(isset($_GET["auth"]))
{
if($_GET["auth"] !== $pwhash)
Expand Down Expand Up @@ -160,17 +141,64 @@

return;
}
elseif(isset($_GET['customdns']) && $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']);
}

switch ($_GET["action"]) {
case 'get':
$_POST['action'] = 'get';
break;
case 'add':
$_POST['action'] = 'add';
break;
case 'delete':
$_POST['action'] = 'delete';
break;
}

require("scripts/pi-hole/php/customdns.php");
}
elseif(isset($_GET['customcname']) && $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']);
}

switch ($_GET["action"]) {
case 'get':
$_POST['action'] = 'get';
break;
case 'add':
$_POST['action'] = 'add';
break;
case 'delete':
$_POST['action'] = 'delete';
break;
}

require("scripts/pi-hole/php/customcname.php");
}

// Other API functions
require("api_FTL.php");

header('Content-type: application/json');
if(isset($_GET["jsonForceObject"]))
{
echo json_encode($data, JSON_FORCE_OBJECT);
}
else
{
echo json_encode($data);
if(isset($_GET["jsonForceObject"])) {
echo json_encode($data, JSON_FORCE_OBJECT);
} else {
echo json_encode($data);
}
?>
38 changes: 30 additions & 8 deletions admin/api_FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,48 @@
$data["version"] = 3;
}

if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET))
{
if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET)) {
require_once("scripts/pi-hole/php/gravity.php");
sendRequestFTL("stats");
$return = getResponseFTL();

$stats = [];
foreach($return as $line)
{
foreach($return as $line) {
$tmp = explode(" ",$line);

if(($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1])) || $tmp[0] === "status")
$stats[$tmp[0]] = $tmp[1]; // Expect string response
else
$stats[$tmp[0]] = floatval($tmp[1]); // Expect float response
if($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1])) {
// Expect string response
$stats[$tmp[0]] = $tmp[1];
} elseif ($tmp[0] === "status") {
// Expect string response
$stats[$tmp[0]] = piholeStatusAPI();
} elseif (isset($_GET['summary'])) {
// "summary" expects a formmated string response
if($tmp[0] !== "ads_percentage_today") {
$stats[$tmp[0]] = number_format($tmp[1]);
} else {
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
}
} else {
// Expect float response
$stats[$tmp[0]] = floatval($tmp[1]);
}

}
$stats['gravity_last_updated'] = gravity_last_update(true);
$data = array_merge($data,$stats);
}

if (isset($_GET["getMaxlogage"]) && $auth) {
sendRequestFTL("maxlogage");
// Convert seconds to hours and rounds to one decimal place.
$ret = round(intval(getResponseFTL()[0]) / 3600, 1);
// Return 24h if value is 0, empty, null or non numeric.
$ret = $ret ?: 24;

$data = array_merge($data, array("maxlogage" => $ret));
}

if (isset($_GET['overTimeData10mins']))
{
sendRequestFTL("overTime");
Expand Down
33 changes: 26 additions & 7 deletions admin/api_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,36 @@
$stmt->bindValue(":from", intval($from), SQLITE3_INTEGER);
$stmt->bindValue(":until", intval($until), SQLITE3_INTEGER);
$results = $stmt->execute();
if(!is_bool($results))
while ($row = $results->fetchArray())
{
// Convert query type ID to name
if (!is_bool($results)) {
// Start the JSON string
echo '{"data":[';

$first = true;
while ($row = $results->fetchArray()) {
// Insert a comma before the next record (except on the first one)
if (!$first) {
echo ",";
} else {
$first = false;
}

// Convert query type ID to name, encode domain, encode destination
$query_type = getQueryTypeStr($row[1]);
$domain = utf8_encode(str_replace("~"," ",$row[2]));
$destination = utf8_encode($row[5]);

// Insert into array
// array: time type domain client status upstream destination
$allQueries[] = [$row[0], $query_type, utf8_encode(str_replace("~"," ",$row[2])), $row[3], $row[4], utf8_encode($row[5])];
// Insert into array and output it in JSON format
// array: time type domain client status upstream destination
echo json_encode([$row[0], $query_type, $domain, $row[3], $row[4], $destination]);
}

// Finish the JSON string
echo ']}';
}
// exit at the end
exit();
}
// only used if getAllQueries==empty
$result = array('data' => $allQueries);
$data = array_merge($data, $result);
}
Expand Down
2 changes: 1 addition & 1 deletion admin/groups-adlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<th>Status</th>
<th>Comment</th>
<th>Group assignment</th>
<th>Action</th>
<th>&nbsp;</th>
</tr>
</thead>
</table>
Expand Down
2 changes: 1 addition & 1 deletion admin/groups-clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<th title="Acceptable values are: IP address, subnet (CIDR notation), MAC address (AA:BB:CC:DD:EE:FF format) or host names.">Client</th>
<th>Comment</th>
<th>Group assignment</th>
<th>Action</th>
<th>&nbsp;</th>
</tr>
</thead>
</table>
Expand Down
2 changes: 1 addition & 1 deletion admin/groups-domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<th>Status</th>
<th>Comment</th>
<th>Group assignment</th>
<th>Action</th>
<th>&nbsp;</th>
</tr>
</thead>
</table>
Expand Down
2 changes: 1 addition & 1 deletion admin/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<th>Name</th>
<th>Status</th>
<th>Description</th>
<th>Action</th>
<th>&nbsp;</th>
</tr>
</thead>
</table>
Expand Down
28 changes: 8 additions & 20 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
<?php /*
* 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. */
$indexpage = true;
require "scripts/pi-hole/php/header.php";
require_once "scripts/pi-hole/php/gravity.php";

function getinterval()
{
global $piholeFTLConf;
if(isset($piholeFTLConf["MAXLOGAGE"]))
{
return round(floatval($piholeFTLConf["MAXLOGAGE"]), 1);
}
else
{
return "24";
}
}
$indexpage = true;
require "scripts/pi-hole/php/header.php";
require_once "scripts/pi-hole/php/gravity.php";
?>
<!-- Sourceing CSS colors from stylesheet to be used in JS code -->
<span class="queries-permitted"></span>
Expand Down Expand Up @@ -72,7 +60,7 @@ function getinterval()
<!-- small box -->
<div class="small-box bg-red no-user-select" title="<?php echo gravity_last_update(); ?>">
<div class="inner">
<p>Domains on Blocklist</p>
<p>Domains on Adlists</p>
<h3 class="statistic"><span id="domains_being_blocked">---</span></h3>
</div>
<div class="icon">
Expand All @@ -87,7 +75,7 @@ function getinterval()
<div class="col-md-12">
<div class="box" id="queries-over-time">
<div class="box-header with-border">
<h3 class="box-title">Total queries over last <?php echo getinterval(); ?> hours</h3>
<h3 class="box-title">Total queries over last <span class="maxlogage-interval">24</span> hours</h3>
</div>
<div class="box-body">
<div class="chart">
Expand All @@ -112,7 +100,7 @@ function getinterval()
<div class="col-md-12">
<div class="box" id="clients">
<div class="box-header with-border">
<h3 class="box-title">Client activity over last <?php echo getinterval(); ?> hours</h3>
<h3 class="box-title">Client activity over last <span class="maxlogage-interval">24</span> hours</h3>
</div>
<div class="box-body">
<div class="chart">
Expand Down
6 changes: 3 additions & 3 deletions admin/queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
}
else if(isset($_GET["forwarddest"]))
{
if($_GET["forwarddest"] === "blocklist")
$showing .= " queries answered from blocklists";
elseif($_GET["forwarddest"] === "cache")
if($_GET["forwarddest"] === "blocked")
$showing .= " queries blocked by Pi-hole";
elseif($_GET["forwarddest"] === "cached")
$showing .= " queries answered from cache";
else
$showing .= " queries for upstream destination ".htmlentities($_GET["forwarddest"]);
Expand Down
13 changes: 9 additions & 4 deletions admin/scripts/pi-hole/js/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function countDown() {
} else {
ena.text("Enable");
piholeChanged("enabled");
localStorage.removeItem("countDownTarget");
if (localStorage) {
localStorage.removeItem("countDownTarget");
}
}
}

Expand Down Expand Up @@ -148,7 +150,7 @@ function initCheckboxRadioStyle() {
}

// Read from local storage, initialize if needed
var chkboxStyle = localStorage.getItem("theme_icheck");
var chkboxStyle = localStorage ? localStorage.getItem("theme_icheck") : null;
if (chkboxStyle === null) {
chkboxStyle = "primary";
}
Expand All @@ -172,7 +174,10 @@ function initCheckboxRadioStyle() {

function initCPUtemp() {
function setCPUtemp(unit) {
localStorage.setItem("tempunit", tempunit);
if (localStorage) {
localStorage.setItem("tempunit", tempunit);
}

var temperature = parseFloat($("#rawtemp").text());
var displaytemp = $("#tempdisplay");
if (!isNaN(temperature)) {
Expand All @@ -195,7 +200,7 @@ function initCPUtemp() {
}

// Read from local storage, initialize if needed
var tempunit = localStorage.getItem("tempunit");
var tempunit = localStorage ? localStorage.getItem("tempunit") : null;
if (tempunit === null) {
tempunit = "C";
}
Expand Down
5 changes: 3 additions & 2 deletions admin/scripts/pi-hole/js/groups-adlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function initTable() {
{ data: "enabled", searchable: false },
{ data: "comment" },
{ data: "groups", searchable: false },
{ data: null, width: "80px", orderable: false },
{ data: null, width: "22px", orderable: false },
],
columnDefs: [
{
Expand Down Expand Up @@ -291,7 +291,8 @@ function initTable() {
$("td:eq(5)", row).html(button);
},
dom:
"<'row'<'col-sm-4'l><'col-sm-8'f>>" +
"<'row'<'col-sm-12'f>>" +
"<'row'<'col-sm-4'l><'col-sm-8'p>>" +
"<'row'<'col-sm-12'<'table-responsive'tr>>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
lengthMenu: [
Expand Down
5 changes: 3 additions & 2 deletions admin/scripts/pi-hole/js/groups-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function initTable() {
{ data: "ip", type: "ip-address" },
{ data: "comment" },
{ data: "groups", searchable: false },
{ data: "name", width: "80px", orderable: false },
{ data: "name", width: "22px", orderable: false },
],
columnDefs: [
{
Expand Down Expand Up @@ -215,7 +215,8 @@ function initTable() {
$("td:eq(3)", row).html(button);
},
dom:
"<'row'<'col-sm-4'l><'col-sm-8'f>>" +
"<'row'<'col-sm-12'f>>" +
"<'row'<'col-sm-4'l><'col-sm-8'p>>" +
"<'row'<'col-sm-12'<'table-responsive'tr>>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
lengthMenu: [
Expand Down
Loading

0 comments on commit 50014c2

Please sign in to comment.