From 606568054a81805499b252933c6712648d32f06d Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 7 Jun 2020 11:09:20 +0100 Subject: [PATCH 1/7] enable IP sorting on the query/long-term query pages. Appears to work with a mixture of hostnames/IP's Signed-off-by: Adam Warner --- db_queries.php | 2 +- queries.php | 2 +- scripts/pi-hole/js/db_queries.js | 2 +- scripts/pi-hole/js/queries.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db_queries.php b/db_queries.php index fdb2f055..c1d0b6c6 100644 --- a/db_queries.php +++ b/db_queries.php @@ -159,7 +159,7 @@ - + diff --git a/queries.php b/queries.php index 3723ed17..4cc70e6d 100644 --- a/queries.php +++ b/queries.php @@ -150,7 +150,7 @@ if(strlen($showing) > 0) - + diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index d2af6535..184c59eb 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -373,7 +373,7 @@ $(function () { }, { width: "10%" }, { width: "40%" }, - { width: "20%" }, + { width: "20%" , type: "ip-address" }, { width: "10%" }, { width: "5%" } ], diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index e9da5b30..1d2815de 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -390,7 +390,7 @@ $(function () { }, { width: "4%" }, { width: "36%", render: $.fn.dataTable.render.text() }, - { width: "8%", render: $.fn.dataTable.render.text() }, + { width: "8%", type: "ip-address", render: $.fn.dataTable.render.text() }, { width: "14%", orderData: 4 }, { width: "8%", orderData: 6 }, { width: "10%", orderData: 4 } From 3a68efc4b0d23409d3c7cda0ab248a891b1ad3f8 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 16 Jul 2020 18:44:00 +0100 Subject: [PATCH 2/7] fix a complaint from the CI Signed-off-by: Adam Warner --- scripts/pi-hole/js/db_queries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index 184c59eb..7707dee3 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -373,7 +373,7 @@ $(function () { }, { width: "10%" }, { width: "40%" }, - { width: "20%" , type: "ip-address" }, + { width: "20%", type: "ip-address" }, { width: "10%" }, { width: "5%" } ], From 99adb3012b4b96ecd236ef2d497562ea3337be85 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 19 Jul 2020 22:13:05 +0200 Subject: [PATCH 3/7] Fix arpflush command Signed-off-by: DL6ER --- scripts/pi-hole/php/savesettings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index 23e0efdc..af95c901 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -737,7 +737,7 @@ function addStaticDHCPLease($mac, $ip, $hostname) { break; // Flush network table case "flusharp": - pihole_execute("arpflush quiet", $output); + $output = pihole_execute("arpflush quiet"); $error = implode("
", $output); if(strlen($error) == 0) { From 8672c49b4b2f8c46ab163304d68a473cdae46f12 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 Jul 2020 21:43:44 +0200 Subject: [PATCH 4/7] Replace "." by "_" in hostnames to work around a PHP Phar bug. Signed-off-by: DL6ER --- scripts/pi-hole/php/teleporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php index cfd4bc47..8948c19f 100644 --- a/scripts/pi-hole/php/teleporter.php +++ b/scripts/pi-hole/php/teleporter.php @@ -540,7 +540,7 @@ if(isset($_POST["action"])) } else { - $hostname = gethostname() ? gethostname()."-" : ""; + $hostname = gethostname() ? str_replace(".", "_", gethostname())."-" : ""; $tarname = "pi-hole-".$hostname."teleporter_".date("Y-m-d_H-i-s").".tar"; $filename = $tarname.".gz"; $archive_file_name = sys_get_temp_dir() ."/". $tarname; From fdea341c9f059423a76d2e49c03eea49e0cb1377 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 Jul 2020 22:04:59 +0200 Subject: [PATCH 5/7] Fix audit log button doing nothing (resp. wrongthing) Signed-off-by: DL6ER --- scripts/pi-hole/js/auditlog.js | 2 +- scripts/pi-hole/php/groups.php | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/auditlog.js b/scripts/pi-hole/js/auditlog.js index d794fa1d..65b8eecc 100644 --- a/scripts/pi-hole/js/auditlog.js +++ b/scripts/pi-hole/js/auditlog.js @@ -99,7 +99,7 @@ function add(domain, list) { domain: domain, list: list, token: token, - action: "add_domain", + action: list === "audit" ? "add_audit" : "add_domain", comment: "Added from Audit Log" }, success: function () { diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 04a9030c..04871d17 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -893,6 +893,53 @@ if ($_POST['action'] == 'get_groups') { } catch (\Exception $ex) { JSON_error($ex->getMessage()); } +} elseif ($_POST['action'] == 'add_audit') { + // Add new domain + try { + $domains = explode(' ', html_entity_decode(trim($_POST['domain']))); + $before = intval($db->querySingle("SELECT COUNT(*) FROM domain_audit;")); + $total = count($domains); + $added = 0; + $stmt = $db->prepare('REPLACE INTO domain_audit (domain) VALUES (:domain)'); + if (!$stmt) { + throw new Exception('While preparing statement: ' . $db->lastErrorMsg()); + } + + foreach ($domains as $domain) { + $input = $domain; + + if (!$stmt->bindValue(':domain', $domain, SQLITE3_TEXT)) { + throw new Exception('While binding domain: ' . $db->lastErrorMsg() . '
'. + 'Added ' . $added . " out of ". $total . " domains"); + } + + if (!$stmt->execute()) { + throw new Exception('While executing: ' . $db->lastErrorMsg() . '
'. + 'Added ' . $added . " out of ". $total . " domains"); + } + $added++; + } + + $after = intval($db->querySingle("SELECT COUNT(*) FROM domain_audit;")); + $difference = $after - $before; + if($total === 1) { + if($difference !== 1) { + $msg = "Not adding ". htmlentities(utf8_encode($domain)) . " as it is already on the list"; + } else { + $msg = "Added " . htmlentities(utf8_encode($domain)); + } + } else { + if($difference !== $total) { + $msg = "Added " . ($after-$before) . " out of ". $total . " domains (skipped duplicates)"; + } else { + $msg = "Added " . $total . " domains"; + } + } + $reload = true; + JSON_success($msg); + } catch (\Exception $ex) { + JSON_error($ex->getMessage()); + } } else { log_and_die('Requested action not supported!'); } From d6477926552cb5a1a10b83f8e816194e33b84b9a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 Jul 2020 22:27:40 +0200 Subject: [PATCH 6/7] Fix query types links on the dashboard (Query Types pie chart) Signed-off-by: DL6ER --- scripts/pi-hole/js/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 7f587f2e..5c056fbc 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -287,6 +287,7 @@ function updateQueriesOverTime() { }); } +var querytypeids = []; function updateQueryTypesPie() { $.getJSON("api.php?getQueryTypes", function (data) { if ("FTLnotrunning" in data) { @@ -305,12 +306,16 @@ function updateQueryTypesPie() { iter = data; } + querytypeids = []; Object.keys(iter).forEach(function (key) { if (iter[key] > 0) { v.push(iter[key]); - c.push(THEME_COLORS[i++ % THEME_COLORS.length]); + c.push(THEME_COLORS[i % THEME_COLORS.length]); k.push(key); + querytypeids.push(i + 1); } + + i++; }); // Build a single dataset with the data to be pushed @@ -342,7 +347,7 @@ function updateQueryTypesPie() { ci.update(); } else if (e.which === 1) { // which == 1 is left mouse button - window.open("queries.php?querytype=" + ($(this).index() + 1), "_self"); + window.open("queries.php?querytype=" + querytypeids[$(this).index()], "_self"); } }); }).done(function () { From a612b1468030750fa3ebdf77d1365bc627be0c45 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 4 Aug 2020 22:09:33 +0200 Subject: [PATCH 7/7] Do not require first element to be a hex value at any costs. It may also be a : in the valid address ::1 Signed-off-by: DL6ER --- scripts/pi-hole/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 0364ffe0..27b0f6c2 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -150,7 +150,7 @@ function validateIPv6CIDR(ip) { var ipv6validator = new RegExp( "^(((?:" + ipv6elem + - "))((?::" + + "))*((?::" + ipv6elem + "))*::((?:" + ipv6elem +