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

Fix mass-deletion of DHCP leases #2877

Closed
wants to merge 2 commits into from
Closed
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
31 changes: 9 additions & 22 deletions scripts/pi-hole/js/settings-dhcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $(function () {
},
],
drawCallback: function () {
$('button[id^="deleteLease_"]').on("click", deleteLease);
$('button[id^="deleteLease_"]').on("click", delLease);

// Hide buttons if all messages were deleted
var hasRows = this.api().rows({ filter: "applied" }).data().length > 0;
Expand Down Expand Up @@ -115,13 +115,10 @@ $(function () {
className: "btn-sm datatable-bt deleteSelected",
action: function () {
// For each ".selected" row ...
var ids = [];
$("tr.selected").each(function () {
// ... add the row identified by "data-id".
ids.push(parseInt($(this).attr("data-id"), 10));
// ... delete the row identified by "data-id".
delLease($(this).attr("data-id"));
});
// Delete all selected rows at once
delLease(ids);
},
},
],
Expand Down Expand Up @@ -159,25 +156,15 @@ $(function () {
});
});

function deleteLease() {
// Passes the button data-del-id attribute as IP
var ips = [$(this).attr("data-del-ip")];

// Check input validity
if (!Array.isArray(ips)) return;

// Exploit prevention: Return early for non-numeric IDs
for (var ip in ips) {
if (Object.hasOwnProperty.call(ips, ip)) {
delLease(ips);
}
}
}

function delLease(ip) {
function delLease(ip = null) {
utils.disableAll();
utils.showAlert("info", "", "Deleting lease...");

// If no IP is passed, use the button data-del-ip attribute
if (ip === null) {
ip = $(this).attr("data-del-ip");
}

$.ajax({
url: "/api/dhcp/leases/" + ip,
method: "DELETE",
Expand Down