mirror of
https://github.com/pi-hole/web.git
synced 2025-12-24 12:48:29 +00:00
285 lines
8.3 KiB
JavaScript
285 lines
8.3 KiB
JavaScript
/* Pi-hole: A black hole for Internet advertisements
|
|
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
* Network-wide ad blocking via your own hardware.
|
|
*
|
|
* This file is copyright under the latest version of the EUPL.
|
|
* Please see LICENSE file for your rights under this license. */
|
|
|
|
$(function () {
|
|
$("[data-static]").on("click", function () {
|
|
var row = $(this).closest("tr");
|
|
var mac = row.find("#MAC").text();
|
|
var ip = row.find("#IP").text();
|
|
var host = row.find("#HOST").text();
|
|
$('input[name="AddHostname"]').val(host);
|
|
$('input[name="AddIP"]').val(ip);
|
|
$('input[name="AddMAC"]').val(mac);
|
|
});
|
|
});
|
|
$(".confirm-poweroff").confirm({
|
|
text: "Are you sure you want to send a poweroff command to your Pi-hole?",
|
|
title: "Confirmation required",
|
|
confirm: function () {
|
|
$("#poweroffform").submit();
|
|
},
|
|
cancel: function () {
|
|
// nothing to do
|
|
},
|
|
confirmButton: "Yes, poweroff",
|
|
cancelButton: "No, go back",
|
|
post: true,
|
|
confirmButtonClass: "btn-danger",
|
|
cancelButtonClass: "btn-success",
|
|
dialogClass: "modal-dialog"
|
|
});
|
|
$(".confirm-reboot").confirm({
|
|
text: "Are you sure you want to send a reboot command to your Pi-hole?",
|
|
title: "Confirmation required",
|
|
confirm: function () {
|
|
$("#rebootform").submit();
|
|
},
|
|
cancel: function () {
|
|
// nothing to do
|
|
},
|
|
confirmButton: "Yes, reboot",
|
|
cancelButton: "No, go back",
|
|
post: true,
|
|
confirmButtonClass: "btn-danger",
|
|
cancelButtonClass: "btn-success",
|
|
dialogClass: "modal-dialog"
|
|
});
|
|
|
|
$(".confirm-restartdns").confirm({
|
|
text: "Are you sure you want to send a restart command to your DNS server?",
|
|
title: "Confirmation required",
|
|
confirm: function () {
|
|
$("#restartdnsform").submit();
|
|
},
|
|
cancel: function () {
|
|
// nothing to do
|
|
},
|
|
confirmButton: "Yes, restart DNS",
|
|
cancelButton: "No, go back",
|
|
post: true,
|
|
confirmButtonClass: "btn-danger",
|
|
cancelButtonClass: "btn-success",
|
|
dialogClass: "modal-dialog"
|
|
});
|
|
|
|
$(".confirm-flushlogs").confirm({
|
|
text: "Are you sure you want to flush your logs?",
|
|
title: "Confirmation required",
|
|
confirm: function () {
|
|
$("#flushlogsform").submit();
|
|
},
|
|
cancel: function () {
|
|
// nothing to do
|
|
},
|
|
confirmButton: "Yes, flush logs",
|
|
cancelButton: "No, go back",
|
|
post: true,
|
|
confirmButtonClass: "btn-danger",
|
|
cancelButtonClass: "btn-success",
|
|
dialogClass: "modal-dialog"
|
|
});
|
|
|
|
$(".confirm-flusharp").confirm({
|
|
text: "Are you sure you want to flush your network table?",
|
|
title: "Confirmation required",
|
|
confirm: function () {
|
|
$("#flusharpform").submit();
|
|
},
|
|
cancel: function () {
|
|
// nothing to do
|
|
},
|
|
confirmButton: "Yes, flush my network table",
|
|
cancelButton: "No, go back",
|
|
post: true,
|
|
confirmButtonClass: "btn-warning",
|
|
cancelButtonClass: "btn-success",
|
|
dialogClass: "modal-dialog"
|
|
});
|
|
|
|
$(".confirm-disablelogging-noflush").confirm({
|
|
text: "Are you sure you want to disable logging?",
|
|
title: "Confirmation required",
|
|
confirm: function () {
|
|
$("#disablelogsform-noflush").submit();
|
|
},
|
|
cancel: function () {
|
|
// nothing to do
|
|
},
|
|
confirmButton: "Yes, disable logs",
|
|
cancelButton: "No, go back",
|
|
post: true,
|
|
confirmButtonClass: "btn-warning",
|
|
cancelButtonClass: "btn-success",
|
|
dialogClass: "modal-dialog"
|
|
});
|
|
|
|
$(".api-token").confirm({
|
|
text:
|
|
"Make sure that nobody else can scan this code around you. They will have full access to the API without having to know the password. Note that the generation of the QR code will take some time.",
|
|
title: "Confirmation required",
|
|
confirm: function () {
|
|
window.open("scripts/pi-hole/php/api_token.php");
|
|
},
|
|
cancel: function () {
|
|
// nothing to do
|
|
},
|
|
confirmButton: "Yes, show API token",
|
|
cancelButton: "No, go back",
|
|
post: true,
|
|
confirmButtonClass: "btn-danger",
|
|
cancelButtonClass: "btn-success",
|
|
dialogClass: "modal-dialog"
|
|
});
|
|
|
|
$("#DHCPchk").click(function () {
|
|
$("input.DHCPgroup").prop("disabled", !this.checked);
|
|
$("#dhcpnotice").prop("hidden", !this.checked).addClass("lookatme");
|
|
});
|
|
|
|
function loadCacheInfo() {
|
|
$.getJSON("api.php?getCacheInfo", function (data) {
|
|
if ("FTLnotrunning" in data) {
|
|
return;
|
|
}
|
|
|
|
// Fill table with obtained values
|
|
$("#cache-size").text(parseInt(data.cacheinfo["cache-size"]));
|
|
$("#cache-inserted").text(parseInt(data.cacheinfo["cache-inserted"]));
|
|
|
|
// Highlight early cache removals when present
|
|
var cachelivefreed = parseInt(data.cacheinfo["cache-live-freed"]);
|
|
$("#cache-live-freed").text(cachelivefreed);
|
|
if (cachelivefreed > 0) {
|
|
$("#cache-live-freed").parent("tr").addClass("lookatme");
|
|
} else {
|
|
$("#cache-live-freed").parent("tr").removeClass("lookatme");
|
|
}
|
|
|
|
// Update cache info every 10 seconds
|
|
setTimeout(loadCacheInfo, 10000);
|
|
});
|
|
}
|
|
|
|
var leasetable, staticleasetable;
|
|
$(document).ready(function () {
|
|
if (document.getElementById("DHCPLeasesTable")) {
|
|
leasetable = $("#DHCPLeasesTable").DataTable({
|
|
dom: "<'row'<'col-sm-12'tr>><'row'<'col-sm-6'i><'col-sm-6'f>>",
|
|
columnDefs: [{ bSortable: false, orderable: false, targets: -1 }],
|
|
paging: false,
|
|
scrollCollapse: true,
|
|
scrollY: "200px",
|
|
scrollX: true,
|
|
order: [[2, "asc"]],
|
|
stateSave: true,
|
|
stateSaveCallback: function(settings, data) {
|
|
// Store current state in client's local storage area
|
|
localStorage.setItem("activeDhcpLeaseTable", JSON.stringify(data));
|
|
},
|
|
stateLoadCallback: function() {
|
|
// Receive previous state from client's local storage area
|
|
var data = localStorage.getItem("activeDhcpLeaseTable");
|
|
// Return if not available
|
|
if (data === null) {
|
|
return null;
|
|
}
|
|
|
|
data = JSON.parse(data);
|
|
// Always start on the first page to show most recent queries
|
|
data.start = 0;
|
|
// Always start with empty search field
|
|
data.search.search = "";
|
|
// Apply loaded state to table
|
|
return data;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (document.getElementById("DHCPStaticLeasesTable")) {
|
|
staticleasetable = $("#DHCPStaticLeasesTable").DataTable({
|
|
dom: "<'row'<'col-sm-12'tr>><'row'<'col-sm-12'i>>",
|
|
columnDefs: [{ bSortable: false, orderable: false, targets: -1 }],
|
|
paging: false,
|
|
scrollCollapse: true,
|
|
scrollY: "200px",
|
|
scrollX: true,
|
|
order: [[2, "asc"]],
|
|
stateSave: true,
|
|
stateSaveCallback: function(settings, data) {
|
|
// Store current state in client's local storage area
|
|
localStorage.setItem("staticDhcpLeaseTable", JSON.stringify(data));
|
|
},
|
|
stateLoadCallback: function() {
|
|
// Receive previous state from client's local storage area
|
|
var data = localStorage.getItem("staticDhcpLeaseTable");
|
|
// Return if not available
|
|
if (data === null) {
|
|
return null;
|
|
}
|
|
|
|
data = JSON.parse(data);
|
|
// Always start on the first page to show most recent queries
|
|
data.start = 0;
|
|
// Always start with empty search field
|
|
data.search.search = "";
|
|
// Apply loaded state to table
|
|
return data;
|
|
}
|
|
});
|
|
}
|
|
|
|
//call draw() on each table... they don't render properly with scrollX and scrollY set... ¯\_(ツ)_/¯
|
|
$('a[data-toggle="tab"]').on("shown.bs.tab", function () {
|
|
leasetable.draw();
|
|
staticleasetable.draw();
|
|
});
|
|
|
|
loadCacheInfo();
|
|
});
|
|
|
|
// Handle hiding of alerts
|
|
$(function () {
|
|
$("[data-hide]").on("click", function () {
|
|
$(this)
|
|
.closest("." + $(this).attr("data-hide"))
|
|
.hide();
|
|
});
|
|
});
|
|
|
|
// DHCP leases tooltips
|
|
$(document).ready(function () {
|
|
$('[data-toggle="tooltip"]').tooltip({ html: true, container: "body" });
|
|
});
|
|
|
|
// Change "?tab=" parameter in URL for save and reload
|
|
$(".nav-tabs a").on("shown.bs.tab", function (e) {
|
|
var tab = e.target.hash.substring(1);
|
|
window.history.pushState("", "", "?tab=" + tab);
|
|
if (tab === "piholedhcp") {
|
|
window.location.reload();
|
|
}
|
|
|
|
window.scrollTo(0, 0);
|
|
});
|
|
|
|
// Auto dismissal for info notifications
|
|
$(document).ready(function () {
|
|
var alInfo = $("#alInfo");
|
|
if (alInfo.length > 0) {
|
|
alInfo.delay(3000).fadeOut(2000, function () {
|
|
alInfo.hide();
|
|
});
|
|
}
|
|
|
|
// Disable autocorrect in the search box
|
|
var input = document.querySelector("input[type=search]");
|
|
input.setAttribute("autocomplete", "off");
|
|
input.setAttribute("autocorrect", "off");
|
|
input.setAttribute("autocapitalize", "off");
|
|
input.setAttribute("spellcheck", false);
|
|
});
|