From 6e0e1bbb41a56b9a31f8edf60dc6516b60e55c6c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 23 Nov 2020 13:35:40 +0100 Subject: [PATCH] Add button to remove dynamic DHCP leases. They are immediately removed both from FTL and the dhcp.leases file (FTL takes care of updating the file!) WITHOUT the need for a restart of the DHCP/DNS resolver. Signed-off-by: DL6ER --- api_FTL.php | 7 ++++++ scripts/pi-hole/js/settings.js | 46 ++++++++++++++++++++++++++++++++++ settings.php | 3 +++ 3 files changed, 56 insertions(+) diff --git a/api_FTL.php b/api_FTL.php index daf72307d..85227dd7a 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -416,6 +416,13 @@ $data = array_merge($data, $result); } + if (isset($_GET['delete_lease']) && $auth) + { + sendRequestFTL("delete-lease ".$_GET['delete_lease']); + $return = getResponseFTL(); + $data["delete_lease"] = $return[0]; + } + disconnectFTL(); } ?> diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index c50c7554e..6853e0c75 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -6,6 +6,7 @@ * Please see LICENSE file for your rights under this license. */ /* global utils:false */ +var token = $("#token").text(); $(function () { $("[data-static]").on("click", function () { @@ -283,3 +284,48 @@ $(function () { localStorage.setItem("barchart_chkbox", bargraphs.prop("checked")); }); }); + +// Delete dynamic DHCP lease +$('button[id="removedynamic"]').on("click", function () { + var tr = $(this).closest("tr"); + var ipaddr = utils.escapeHtml(tr.children("#IP").text()); + var name = utils.escapeHtml(tr.children("#HOST").text()); + var ipname = name + " (" + ipaddr + ")"; + + utils.disableAll(); + utils.showAlert("info", "", "Deleting DHCP lease...", ipname); + $.ajax({ + url: "api.php", + method: "get", + dataType: "json", + data: { + delete_lease: ipaddr, + token: token + }, + success: function (response) { + utils.enableAll(); + if (response.delete_lease.startsWith("OK")) { + utils.showAlert( + "success", + "far fa-trash-alt", + "Successfully deleted DHCP lease for ", + ipname + ); + // Remove column on success + tr.remove(); + // We have to hide the tooltips explicitly or they will stay there forever as + // the onmouseout event does not fire when the element is already gone + $.each($(".tooltip"), function () { + $(this).remove(); + }); + } else { + utils.showAlert("error", "Error while deleting DHCP lease for " + ipname, response); + } + }, + error: function (jqXHR, exception) { + utils.enableAll(); + utils.showAlert("error", "Error while deleting DHCP lease for " + ipname, jqXHR.responseText); + console.log(exception); // eslint-disable-line no-console + } + }); +}); diff --git a/settings.php b/settings.php index a17309e3c..dfaceacd8 100644 --- a/settings.php +++ b/settings.php @@ -717,6 +717,9 @@ function convertseconds($argument) "> +