/* 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. */ // Define global variables var timeLineChart, queryTypeChart, forwardDestinationChart; // Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406 function escapeHtml(text) { var map = { "&": "&", "<": "<", ">": ">", "\"": """, "\'": "'" }; return text.replace(/[&<>"']/g, function(m) { return map[m]; }); } function updateTopLists() { $.getJSON("api.php?topItems=audit", function(data) { if("FTLnotrunning" in data) { return; } // Clear tables before filling them with data $("#domain-frequency td").parent().remove(); $("#ad-frequency td").parent().remove(); var domaintable = $("#domain-frequency").find("tbody:last"); var adtable = $("#ad-frequency").find("tbody:last"); var url, domain, percentage; for (domain in data.top_queries) { if ({}.hasOwnProperty.call(data.top_queries,domain)){ // Sanitize domain domain = escapeHtml(domain); url = ""+domain+""; percentage = data.top_queries[domain] / data.dns_queries_today * 100; domaintable.append(" " + url + " " + data.top_queries[domain] + " "); } } for (domain in data.top_ads) { if ({}.hasOwnProperty.call(data.top_ads,domain)){ // Sanitize domain console.log(domain); console.log(); var input = domain.split(" "); var printdomain = escapeHtml(input[0]); if(input.length > 1) { url = ""+printdomain+" (wildcard blocked)"; adtable.append(" " + url + " " + data.top_ads[domain] + " "); } else { url = ""+printdomain+""; adtable.append(" " + url + " " + data.top_ads[domain] + " "); } } } $("#domain-frequency .overlay").hide(); $("#ad-frequency .overlay").hide(); // Update top lists data every 10 seconds setTimeout(updateTopLists, 10000); }); } function add(domain,list) { var token = $("#token").html(); $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", data: {"domain":domain, "list":list, "token":token, "auditlog":1}, success: function(response) { setTimeout(updateTopLists, 300); } }); } $(document).ready(function() { // Pull in data via AJAX updateTopLists(); $("#domain-frequency tbody").on( "click", "button", function () { var url = ($(this).parents("tr"))[0].innerText.split(" ")[0]; if($(this).context.innerText === "Blacklist") add(url,"black"); else add(url,"audit"); }); $("#ad-frequency tbody").on( "click", "button", function () { var url = ($(this).parents("tr"))[0].innerText.split(" ")[0].split(" ")[0]; if($(this).context.innerText === "Whitelist") add(url,"white"); else add(url,"audit"); }); });