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 <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-11-23 13:35:40 +01:00
parent 1ea21911cf
commit 6e0e1bbb41
3 changed files with 56 additions and 0 deletions

View File

@@ -416,6 +416,13 @@ else
$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();
}
?>

View File

@@ -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
}
});
});

View File

@@ -717,6 +717,9 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "adlists", "
<td id="IP" data-order="<?php echo bin2hex(inet_pton($lease["IP"])); ?>"><?php echo $lease["IP"]; ?></td>
<td id="HOST"><?php echo $lease["host"]; ?></td>
<td>
<button type="button" class="btn btn-danger btn-xs" id="removedynamic">
<span class="fas fas fa-trash-alt"></span>
</button>
<button type="button" id="button" class="btn btn-warning btn-xs" data-static="alert">
<span class="fas fas fa-file-import"></span>
</button>