Skip to content

Commit

Permalink
Merge branch 'master' into new/dark
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed May 10, 2020
2 parents f0f83ed + b86e4a3 commit a7e45e1
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 58 deletions.
15 changes: 15 additions & 0 deletions api_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,30 @@ function resolveHostname($clientip, $printIP)
// Parse the DB result into graph data, filling in missing interval sections with zero
function parseDBData($results, $interval, $from, $until) {
$data = array();
$first_db_timestamp = -1;

if(!is_bool($results)) {
// Read in the data
while($row = $results->fetchArray()) {
// $data[timestamp] = value_in_this_interval
$data[$row[0]] = intval($row[1]);
if($first_db_timestamp === -1)
$first_db_timestamp = intval($row[0]);
}
}

// It is unpredictable what the first timestamp returned by the database
// will be. This depends on live data. Hence, we re-align the FROM
// timestamp to avoid unaligned holes appearing as additional
// (incorrect) data points
$aligned_from = $from + (($first_db_timestamp - $from) % $interval);

// Fill gaps in returned data
for($i = $aligned_from; $i < $until; $i += $interval) {
if(!array_key_exists($i, $data))
$data[$i] = 0;
}

return $data;
}

Expand Down
2 changes: 0 additions & 2 deletions scripts/pi-hole/js/db_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ function escapeHtml(text) {
return map[m];
});
}
var blockedColor = $(".queries-blocked").css("background-color");
var permittedColor = $(".queries-permitted").css("background-color");

function updateTopClientsChart() {
$("#client-frequency .overlay").show();
Expand Down
8 changes: 8 additions & 0 deletions scripts/pi-hole/js/db_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ $(document).ready(function() {
$(row).css("color", color);
$("td:eq(4)", row).html(fieldtext);
$("td:eq(5)", row).html(buttontext);

// Substitute domain by "." if empty
var domain = data[2];
if (domain.length === 0) {
domain = ".";
}

$("td:eq(2)", row).text(domain);
},
dom:
"<'row'<'col-sm-12'f>>" +
Expand Down
9 changes: 5 additions & 4 deletions scripts/pi-hole/js/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ $(document).ready(function() {
if (seconds > 0) {
setTimeout(countDown, 100);
}

if (!testCookies() && $("#cookieInfo").length) {
$("#cookieInfo").show();
}

var checkbox_theme = $("#checkbox_theme").text();
$('input').icheck({
checkboxClass: 'icheckbox_' + checkbox_theme,
radioClass: 'iradio_' + checkbox_theme,
increaseArea: '20%'
$("input").icheck({
checkboxClass: "icheckbox_" + checkbox_theme,
radioClass: "iradio_" + checkbox_theme,
increaseArea: "20%"
});
});

Expand Down
20 changes: 9 additions & 11 deletions scripts/pi-hole/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ function updateTopLists() {
.remove();
var domaintable = $("#domain-frequency").find("tbody:last");
var adtable = $("#ad-frequency").find("tbody:last");
var url, domain, percentage;
var url, domain, percentage, urlText;
for (domain in data.top_queries) {
if (Object.prototype.hasOwnProperty.call(data.top_queries, domain)) {
// Sanitize domain
Expand All @@ -686,7 +686,8 @@ function updateTopLists() {
}

domain = escapeHtml(domain);
url = '<a href="queries.php?domain=' + domain + '">' + domain + "</a>";
urlText = domain === "" ? "." : domain;
url = '<a href="queries.php?domain=' + domain + '">' + urlText + "</a>";
percentage = (data.top_queries[domain] / data.dns_queries_today) * 100;
domaintable.append(
"<tr> <td>" +
Expand Down Expand Up @@ -720,7 +721,8 @@ function updateTopLists() {
}

domain = escapeHtml(domain);
url = '<a href="queries.php?domain=' + domain + '">' + domain + "</a>";
urlText = domain === "" ? "." : domain;
url = '<a href="queries.php?domain=' + domain + '">' + urlText + "</a>";
percentage = (data.top_ads[domain] / data.ads_blocked_today) * 100;
adtable.append(
"<tr> <td>" +
Expand Down Expand Up @@ -938,13 +940,11 @@ $(document).ready(function() {
{
stacked: true,
ticks: {
beginAtZero: true
beginAtZero: true,
fontColor: ticksColor
},
gridLines: {
color: gridColor
},
ticks: {
fontColor: ticksColor
}
}
]
Expand Down Expand Up @@ -1017,14 +1017,12 @@ $(document).ready(function() {
yAxes: [
{
ticks: {
beginAtZero: true
beginAtZero: true,
fontColor: ticksColor
},
stacked: true,
gridLines: {
color: gridColor
},
ticks: {
fontColor: ticksColor
}
}
]
Expand Down
12 changes: 10 additions & 2 deletions scripts/pi-hole/js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ $(document).ready(function() {
if (colorClass !== false) {
$(row).addClass(colorClass);
}

$("td:eq(4)", row).html(fieldtext);
$("td:eq(6)", row).html(buttontext);

Expand All @@ -295,11 +296,18 @@ $(document).ready(function() {
$("td:eq(4)", row).addClass("pointer");
}

// Add domain in CNAME chain causing the query to have been blocked
// Substitute domain by "." if empty
var domain = data[2];
var CNAME_domain = data[8];
if (domain.length === 0) {
domain = ".";
}

if (isCNAME) {
var CNAME_domain = data[8];
// Add domain in CNAME chain causing the query to have been blocked
$("td:eq(2)", row).text(domain + "\n(blocked " + CNAME_domain + ")");
} else {
$("td:eq(2)", row).text(domain);
}

// Check for existence of sixth column and display only if not Pi-holed
Expand Down
57 changes: 43 additions & 14 deletions scripts/pi-hole/php/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function JSON_error($message = null)
} elseif ($_POST['action'] == 'add_group') {
// Add new group
try {
$names = explode(' ', $_POST['name']);
$names = explode(' ', trim($_POST['name']));
$total = count($names);
$added = 0;
$stmt = $db->prepare('INSERT INTO "group" (name,description) VALUES (:name,:desc)');
if (!$stmt) {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
Expand All @@ -66,12 +68,15 @@ function JSON_error($message = null)

foreach ($names as $name) {
if (!$stmt->bindValue(':name', $name, SQLITE3_TEXT)) {
throw new Exception('While binding name: ' . $db->lastErrorMsg());
throw new Exception('While binding name: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " groups");
}

if (!$stmt->execute()) {
throw new Exception('While executing: ' . $db->lastErrorMsg());
throw new Exception('While executing: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " groups");
}
$added++;
}

$reload = true;
Expand Down Expand Up @@ -234,7 +239,9 @@ function JSON_error($message = null)
} elseif ($_POST['action'] == 'add_client') {
// Add new client
try {
$ips = explode(' ', $_POST['ip']);
$ips = explode(' ', trim($_POST['ip']));
$total = count($ips);
$added = 0;
$stmt = $db->prepare('INSERT INTO client (ip,comment) VALUES (:ip,:comment)');
if (!$stmt) {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
Expand All @@ -251,12 +258,15 @@ function JSON_error($message = null)
$comment = null;
}
if (!$stmt->bindValue(':comment', $comment, SQLITE3_TEXT)) {
throw new Exception('While binding comment: ' . $db->lastErrorMsg());
throw new Exception('While binding comment: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " clients");
}

if (!$stmt->execute()) {
throw new Exception('While executing: ' . $db->lastErrorMsg());
throw new Exception('While executing: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " clients");
}
$added++;
}

$reload = true;
Expand Down Expand Up @@ -430,7 +440,9 @@ function JSON_error($message = null)
} elseif ($_POST['action'] == 'add_domain') {
// Add new domain
try {
$domains = explode(' ', $_POST['domain']);
$domains = explode(' ', trim($_POST['domain']));
$total = count($domains);
$added = 0;
$stmt = $db->prepare('INSERT INTO domainlist (domain,type,comment) VALUES (:domain,:type,:comment)');
if (!$stmt) {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
Expand All @@ -447,6 +459,7 @@ function JSON_error($message = null)
}

foreach ($domains as $domain) {
$input = $domain;
// Convert domain name to IDNA ASCII form for international domains
if (extension_loaded("intl")) {
// Be prepared that this may fail and see our comments above
Expand Down Expand Up @@ -475,17 +488,27 @@ function JSON_error($message = null)
$domain = strtolower($domain);
if(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false)
{
throw new Exception('Domain ' . htmlentities(utf8_encode($domain)) . 'is not a valid domain.');
// This is the case when idn_to_ascii() modified the string
if($input !== $domain && strlen($domain) > 0)
$errormsg = 'Domain ' . htmlentities($input) . ' (converted to "' . htmlentities(utf8_encode($domain)) . '") is not a valid domain.';
elseif($input !== $domain)
$errormsg = 'Domain ' . htmlentities($input) . ' is not a valid domain.';
else
$errormsg = 'Domain ' . htmlentities(utf8_encode($domain)) . ' is not a valid domain.';
throw new Exception($errormsg . '<br>Added ' . $added . " out of ". $total . " domains");
}
}

if (!$stmt->bindValue(':domain', $domain, SQLITE3_TEXT)) {
throw new Exception('While binding domain: ' . $db->lastErrorMsg());
throw new Exception('While binding domain: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " domains");
}

if (!$stmt->execute()) {
throw new Exception('While executing: ' . $db->lastErrorMsg());
throw new Exception('While executing: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " domains");
}
$added++;
}

$reload = true;
Expand Down Expand Up @@ -637,7 +660,9 @@ function JSON_error($message = null)
} elseif ($_POST['action'] == 'add_adlist') {
// Add new adlist
try {
$addresses = explode(' ', $_POST['address']);
$addresses = explode(' ', trim($_POST['address']));
$total = count($addresses);
$added = 0;

$stmt = $db->prepare('INSERT INTO adlist (address,comment) VALUES (:address,:comment)');
if (!$stmt) {
Expand All @@ -650,16 +675,20 @@ function JSON_error($message = null)

foreach ($addresses as $address) {
if(preg_match("/[^a-zA-Z0-9:\/?&%=~._()-]/", $address) !== 0) {
throw new Exception('Invalid adlist URL');
throw new Exception('<strong>Invalid adlist URL ' . htmlentities($address) . '</strong><br>'.
'Added ' . $added . " out of ". $total . " adlists");
}

if (!$stmt->bindValue(':address', $address, SQLITE3_TEXT)) {
throw new Exception('While binding address: ' . $db->lastErrorMsg());
throw new Exception('While binding address: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " adlists");
}

if (!$stmt->execute()) {
throw new Exception('While executing: ' . $db->lastErrorMsg());
throw new Exception('While executing: <strong>' . $db->lastErrorMsg() . '</strong><br>'.
'Added ' . $added . " out of ". $total . " adlists");
}
$added++;
}

$reload = true;
Expand Down
4 changes: 2 additions & 2 deletions scripts/pi-hole/php/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function pidofFTL()
*/ ?>
<!-- PayPal -->
<div class="text-center">
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=3J2L3Z4DHW9UY" rel="noopener" target="_blank" style="background:none">
<a href="https://pi-hole.net/donate/" rel="noopener" target="_blank" style="background:none">
<img src="img/donate.gif" alt="Donate">
</a>
</div>
Expand Down Expand Up @@ -662,7 +662,7 @@ function pidofFTL()
<?php } ?>
<!-- Donate -->
<li>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY" rel="noopener" target="_blank">
<a href="https://pi-hole.net/donate/" rel="noopener" target="_blank">
<i class="fa-paypal-icon fab fa-paypal"></i> <span>Donate</span>
</a>
</li>
Expand Down
12 changes: 6 additions & 6 deletions scripts/pi-hole/php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function readStaticLeasesFile($origin_file="/etc/dnsmasq.d/04-pihole-static-dhcp
$dhcp_static_leases = array();
if(!file_exists($origin_file) || !is_readable($origin_file))
return false;

$dhcpstatic = @fopen($origin_file, 'r');
if(!is_resource($dhcpstatic))
return false;
Expand Down Expand Up @@ -148,16 +148,16 @@ function readDNSserversList()
$line = explode(';', $line);
$name = $line[0];
$values = [];
if (!empty($line[1])) {
if (!empty($line[1]) && validIP($line[1])) {
$values["v4_1"] = $line[1];
}
if (!empty($line[2])) {
if (!empty($line[2]) && validIP($line[2])) {
$values["v4_2"] = $line[2];
}
if (!empty($line[3])) {
if (!empty($line[3]) && validIP($line[3])) {
$values["v6_1"] = $line[3];
}
if (!empty($line[4])) {
if (!empty($line[4]) && validIP($line[4])) {
$values["v6_2"] = $line[4];
}
$list[$name] = $values;
Expand Down Expand Up @@ -202,7 +202,7 @@ function addStaticDHCPLease($mac, $ip, $hostname) {

// Test if this lease is already included
readStaticLeasesFile();

foreach($dhcp_static_leases as $lease) {
if($lease["hwaddr"] === $mac)
{
Expand Down
2 changes: 1 addition & 1 deletion style/pi-hole.css
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,5 @@ code.breakall
}

.input-group-addon {
padding: 0px 12px;
padding: 0 12px;
}
Loading

0 comments on commit a7e45e1

Please sign in to comment.