/* Pi-hole: A black hole for Internet advertisements * (c) 2023 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. */ /* global apiFailure:false */ /* exported updateHostInfo, updateCacheInfo */ var hostinfoTimer = null; // eslint-disable-next-line no-unused-vars function updateHostInfo() { $.ajax({ url: "/api/info/host", }) .done(function (data) { var host = data.host; var uname = host.uname; if (uname.domainname !== "(none)") { $("#sysinfo-hostname").text(uname.nodename + "." + uname.domainname); } else { $("#sysinfo-hostname").text(uname.nodename); } $("#sysinfo-kernel").text( uname.sysname + " " + uname.nodename + " " + uname.release + " " + uname.version + " " + uname.machine ); // Update every 120 seconds clearTimeout(hostinfoTimer); hostinfoTimer = setTimeout(updateHostInfo, 120000); }) .fail(function (data) { apiFailure(data); }); } var cacheinfoTimer = null; // eslint-disable-next-line no-unused-vars function updateCacheInfo() { $.ajax({ url: "/api/info/cache", }) .done(function (data) { var cache = data.cache; $("#sysinfo-cache-size").text(cache.size); $("#sysinfo-cache-inserted").text(cache.inserted); $("#sysinfo-cache-evicted").text(cache.evicted); $("#sysinfo-cache-expired").text(cache.expired); $("#sysinfo-cache-immortal").text(cache.immortal); $("#sysinfo-cache-valid-a").text(cache.valid.a); $("#sysinfo-cache-valid-aaaa").text(cache.valid.aaaa); $("#sysinfo-cache-valid-cname").text(cache.valid.cname); $("#sysinfo-cache-valid-srv").text(cache.valid.srv); $("#sysinfo-cache-valid-ds").text(cache.valid.ds); $("#sysinfo-cache-valid-dnskey").text(cache.valid.dnskey); $("#sysinfo-cache-valid-other").text(cache.valid.other); var total = cache.optimized + cache.local + cache.auth + cache.extra.unanswered + cache.extra.forwarded; $("#sysinfo-replies-optimized").text( cache.optimized + " (" + ((100 * cache.optimized) / total).toFixed(1) + "%)" ); $("#sysinfo-replies-local").text( cache.local + " (" + ((100 * cache.local) / total).toFixed(1) + "%)" ); $("#sysinfo-replies-auth").text( cache.auth + " (" + ((100 * cache.auth) / total).toFixed(1) + "%)" ); $("#sysinfo-replies-extra-unanswered").text( cache.extra.unanswered + " (" + ((100 * cache.extra.unanswered) / total).toFixed(1) + "%)" ); $("#sysinfo-replies-extra-forwarded").text( cache.extra.forwarded + " (" + ((100 * cache.extra.forwarded) / total).toFixed(1) + "%)" ); $("#sysinfo-dns-overlay").hide(); // Update every 10 seconds clearTimeout(cacheinfoTimer); cacheinfoTimer = setTimeout(updateCacheInfo, 10000); }) .fail(function (data) { apiFailure(data); }); } $(".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", });