Skip to content

Commit

Permalink
Fix (and simplify) mass deletion of DHCP lease, diagnosis messages, a…
Browse files Browse the repository at this point in the history
…nd local DNS/CNAME records

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed May 30, 2024
1 parent 24977e8 commit 9c97a8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
7 changes: 2 additions & 5 deletions scripts/pi-hole/js/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,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".
delMsg($(this).attr("data-id"));
});
// Delete all selected rows at once
delMsg(ids);
},
},
],
Expand Down
21 changes: 4 additions & 17 deletions scripts/pi-hole/js/settings-dhcp.js
Original file line number Diff line number Diff line change
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 @@ -161,25 +158,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);
}
}
delLease($(this).attr("data-del-ip"));
}

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

$.ajax({
url: "/api/dhcp/leases/" + ip,
url: "/api/dhcp/leases/" + encodeURIComponent(ip),
method: "DELETE",
})
.done(function (response) {
Expand Down
15 changes: 2 additions & 13 deletions scripts/pi-hole/js/settings-dns-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,8 @@ $(function () {
});

function deleteRecord() {
// Get the tags
var tags = [$(this).attr("data-tag")];
var types = [$(this).attr("data-type")];
// Check input validity
if (!Array.isArray(tags)) return;

// Exploit prevention: Return early for non-numeric IDs
for (var tag in tags) {
if (Object.hasOwnProperty.call(tags, tag)) {
if (types[0] === "hosts") delHosts(tags);
else delCNAME(tags);
}
}
if ($(this).attr("data-type") === "hosts") delHosts($(this).attr("data-tag"));
else delCNAME($(this).attr("data-tag"));
}

function delHosts(elem) {
Expand Down

0 comments on commit 9c97a8c

Please sign in to comment.