Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to remove dynamic DHCP leases #1634

Merged
merged 1 commit into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api_FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
?>
46 changes: 46 additions & 0 deletions scripts/pi-hole/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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
}
});
});
3 changes: 3 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,9 @@ function convertseconds($argument)
<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>
Expand Down