diff --git a/scripts/pi-hole/js/auditlog.js b/scripts/pi-hole/js/auditlog.js index d1e34d4f1..40c019de9 100644 --- a/scripts/pi-hole/js/auditlog.js +++ b/scripts/pi-hole/js/auditlog.js @@ -5,25 +5,12 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ +/* global escapeHtml:false */ + // Define global variables var auditList = [], auditTimeout; -// 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) { diff --git a/scripts/pi-hole/js/common.js b/scripts/pi-hole/js/common.js new file mode 100644 index 000000000..0902e90f9 --- /dev/null +++ b/scripts/pi-hole/js/common.js @@ -0,0 +1,144 @@ +/* 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. */ + +/* global ActiveXObject:false */ + +var info = null; + +function quietfilter(ta, data) { + var lines = data.split("\n"); + for (var i = 0; i < lines.length; i++) { + if (lines[i].indexOf("results") !== -1 && lines[i].indexOf("0 results") === -1) { + var shortstring = lines[i].replace("::: /etc/pihole/", ""); + // Remove "(x results)" + shortstring = shortstring.replace(/\(.*/, ""); + ta.append(shortstring + "\n"); + } + } +} + +// Credit: https://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406 +window.escapeHtml = function(text) { + var map = { + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'" + }; + + return text.replace(/[&<>"']/g, function(m) { + return map[m]; + }); +}; + +// Credit: https://stackoverflow.com/a/10642418/2087442 +window.httpGet = function(ta, theUrl, quiet) { + var xmlhttp; + if (window.XMLHttpRequest) { + // code for IE7+ + xmlhttp = new XMLHttpRequest(); + } else { + // code for IE6, IE5 + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { + ta.show(); + ta.empty(); + if (!quiet) { + ta.append(xmlhttp.responseText); + } else { + quietfilter(ta, xmlhttp.responseText); + } + } + }; + + xmlhttp.open("GET", theUrl, false); + xmlhttp.send(); +}; + +window.padNumber = function(num) { + return ("00" + num).substr(-2, 2); +}; + +// Helper function needed for converting the Objects to Arrays +window.objectToArray = function(p) { + var keys = Object.keys(p); + keys.sort(function(a, b) { + return a - b; + }); + + var arr = [], + idx = []; + for (var i = 0; i < keys.length; i++) { + arr.push(p[keys[i]]); + idx.push(keys[i]); + } + + return [idx, arr]; +}; + +window.showAlert = function(type, icon, title, message) { + var opts = {}; + title = " " + title + "
"; + switch (type) { + case "info": + opts = { + type: "info", + icon: "glyphicon glyphicon-time", + title: title, + message: message + }; + info = $.notify(opts); + break; + case "success": + opts = { + type: "success", + icon: icon, + title: title, + message: message + }; + if (info) { + info.update(opts); + } else { + $.notify(opts); + } + + break; + case "warning": + opts = { + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + title: title, + message: message + }; + if (info) { + info.update(opts); + } else { + $.notify(opts); + } + + break; + case "error": + opts = { + type: "danger", + icon: "glyphicon glyphicon-remove", + title: " Error, something went wrong!
", + message: message + }; + if (info) { + info.update(opts); + } else { + $.notify(opts); + } + + break; + default: + } +}; diff --git a/scripts/pi-hole/js/db_graph.js b/scripts/pi-hole/js/db_graph.js index ab8591228..397a517ed 100644 --- a/scripts/pi-hole/js/db_graph.js +++ b/scripts/pi-hole/js/db_graph.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global Chart:false, moment:false */ +/* global Chart:false, moment:false, objectToArray:false, padNumber:false */ var start__ = moment().subtract(6, "days"); var from = @@ -72,28 +72,6 @@ $(function() { ); }); -function padNumber(num) { - return ("00" + num).substr(-2, 2); -} - -// Helper function needed for converting the Objects to Arrays - -function objectToArray(p) { - var keys = Object.keys(p); - keys.sort(function(a, b) { - return a - b; - }); - - var arr = [], - idx = []; - for (var i = 0; i < keys.length; i++) { - arr.push(p[keys[i]]); - idx.push(keys[i]); - } - - return [idx, arr]; -} - var timeLineChart; function compareNumbers(a, b) { diff --git a/scripts/pi-hole/js/db_lists.js b/scripts/pi-hole/js/db_lists.js index 3f055fe80..89746644c 100644 --- a/scripts/pi-hole/js/db_lists.js +++ b/scripts/pi-hole/js/db_lists.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false */ +/* global moment:false, escapeHtml:false */ var start__ = moment().subtract(6, "days"); var from = @@ -72,21 +72,6 @@ $(function() { ); }); -// 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 updateTopClientsChart() { $("#client-frequency .overlay").show(); $.getJSON("api_db.php?topClients&from=" + from + "&until=" + until, function(data) { diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js index fb0fd35b3..8bf7cfb0e 100644 --- a/scripts/pi-hole/js/debug.js +++ b/scripts/pi-hole/js/debug.js @@ -5,30 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global ActiveXObject: false */ - -// Credit: http://stackoverflow.com/a/10642418/2087442 -function httpGet(ta, theUrl) { - var xmlhttp; - if (window.XMLHttpRequest) { - // code for IE7+ - xmlhttp = new XMLHttpRequest(); - } else { - // code for IE6, IE5 - xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } - - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { - ta.show(); - ta.empty(); - ta.append(xmlhttp.responseText); - } - }; - - xmlhttp.open("GET", theUrl, false); - xmlhttp.send(); -} +/* global httpGet:false */ function eventsource() { var ta = $("#output"); diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index 53a137ba7..0e9e259f0 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -5,71 +5,11 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false */ +/* global moment:false, showAlert:false */ var table; var groups = []; var token = $("#token").html(); -var info = null; - -function showAlert(type, icon, title, message) { - var opts = {}; - title = " " + title + "
"; - switch (type) { - case "info": - opts = { - type: "info", - icon: "glyphicon glyphicon-time", - title: title, - message: message - }; - info = $.notify(opts); - break; - case "success": - opts = { - type: "success", - icon: icon, - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "warning": - opts = { - type: "warning", - icon: "glyphicon glyphicon-warning-sign", - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "error": - opts = { - type: "danger", - icon: "glyphicon glyphicon-remove", - title: " Error, something went wrong!
", - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - default: - } -} function get_groups() { $.post( diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index 68fbed9eb..6dc2a2691 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -5,69 +5,11 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ +/* global showAlert:false */ + var table; var groups = []; var token = $("#token").html(); -var info = null; - -function showAlert(type, icon, title, message) { - var opts = {}; - title = " " + title + "
"; - switch (type) { - case "info": - opts = { - type: "info", - icon: "glyphicon glyphicon-time", - title: title, - message: message - }; - info = $.notify(opts); - break; - case "success": - opts = { - type: "success", - icon: icon, - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "warning": - opts = { - type: "warning", - icon: "glyphicon glyphicon-warning-sign", - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "error": - opts = { - type: "danger", - icon: "glyphicon glyphicon-remove", - title: " Error, something went wrong!
", - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - default: - } -} function reload_client_suggestions() { $.post( diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index b83c52967..4c98eef81 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -5,71 +5,11 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false */ +/* global moment:false, showAlert:false */ var table; var groups = []; var token = $("#token").html(); -var info = null; - -function showAlert(type, icon, title, message) { - var opts = {}; - title = " " + title + "
"; - switch (type) { - case "info": - opts = { - type: "info", - icon: "glyphicon glyphicon-time", - title: title, - message: message - }; - info = $.notify(opts); - break; - case "success": - opts = { - type: "success", - icon: icon, - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "warning": - opts = { - type: "warning", - icon: "glyphicon glyphicon-warning-sign", - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "error": - opts = { - type: "danger", - icon: "glyphicon glyphicon-remove", - title: " Error, something went wrong!
", - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - default: - } -} function get_groups() { $.post( diff --git a/scripts/pi-hole/js/groups.js b/scripts/pi-hole/js/groups.js index b7ec372c2..90ced2b53 100644 --- a/scripts/pi-hole/js/groups.js +++ b/scripts/pi-hole/js/groups.js @@ -5,70 +5,10 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false */ +/* global moment:false, showAlert:false */ var table; var token = $("#token").html(); -var info = null; - -function showAlert(type, icon, title, message) { - var opts = {}; - title = " " + title + "
"; - switch (type) { - case "info": - opts = { - type: "info", - icon: "glyphicon glyphicon-time", - title: title, - message: message - }; - info = $.notify(opts); - break; - case "success": - opts = { - type: "success", - icon: icon, - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "warning": - opts = { - type: "warning", - icon: "glyphicon glyphicon-warning-sign", - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "error": - opts = { - type: "danger", - icon: "glyphicon glyphicon-remove", - title: " Error, something went wrong!
", - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - default: - } -} function datetime(date) { return moment.unix(Math.floor(date)).format("Y-MM-DD HH:mm:ss z"); diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 8348a96e3..661fcf7b6 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -6,32 +6,9 @@ * Please see LICENSE file for your rights under this license. */ // Define global variables -/* global Chart:false, updateSessionTimer:false */ +/* global Chart:false, objectToArray: false, escapeHtml:false, padNumber:false, updateSessionTimer:false */ var timeLineChart, clientsChart; var queryTypePieChart, forwardDestinationPieChart; - -function padNumber(num) { - return ("00" + num).substr(-2, 2); -} - -// Helper function needed for converting the Objects to Arrays - -function objectToArray(p) { - var keys = Object.keys(p); - keys.sort(function(a, b) { - return a - b; - }); - - var arr = [], - idx = []; - for (var i = 0; i < keys.length; i++) { - arr.push(p[keys[i]]); - idx.push(keys[i]); - } - - return [idx, arr]; -} - var lastTooltipTime = 0; var customTooltips = function(tooltip) { @@ -432,21 +409,6 @@ function updateForwardDestinationsPie() { }); } -// 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 updateTopClientsChart() { $.getJSON("api.php?summaryRaw&getQuerySources&topClientsBlocked", function(data) { if ("FTLnotrunning" in data) { diff --git a/scripts/pi-hole/js/queryads.js b/scripts/pi-hole/js/queryads.js index 44865ebda..12da5d641 100644 --- a/scripts/pi-hole/js/queryads.js +++ b/scripts/pi-hole/js/queryads.js @@ -5,49 +5,10 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global ActiveXObject: false */ +/* global httpGet:false, quietfilter:false */ var exact = ""; -function quietfilter(ta, data) { - var lines = data.split("\n"); - for (var i = 0; i < lines.length; i++) { - if (lines[i].indexOf("results") !== -1 && lines[i].indexOf("0 results") === -1) { - var shortstring = lines[i].replace("::: /etc/pihole/", ""); - // Remove "(x results)" - shortstring = shortstring.replace(/\(.*/, ""); - ta.append(shortstring + "\n"); - } - } -} - -// Credit: http://stackoverflow.com/a/10642418/2087442 -function httpGet(ta, quiet, theUrl) { - var xmlhttp; - if (window.XMLHttpRequest) { - // code for IE7+ - xmlhttp = new XMLHttpRequest(); - } else { - // code for IE6, IE5 - xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } - - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { - ta.show(); - ta.empty(); - if (!quiet) { - ta.append(xmlhttp.responseText); - } else { - quietfilter(ta, xmlhttp.responseText); - } - } - }; - - xmlhttp.open("GET", theUrl, false); - xmlhttp.send(); -} - function eventsource() { var ta = $("#output"); var domain = $("#domain") @@ -69,8 +30,8 @@ function eventsource() { if (typeof EventSource !== "function") { httpGet( ta, - quiet, - "scripts/pi-hole/php/queryads.php?domain=" + domain.toLowerCase() + exact + "&IE" + "scripts/pi-hole/php/queryads.php?domain=" + domain.toLowerCase() + exact + "&IE", + quiet ); return; } diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index 668527e80..cafbbeb69 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -233,6 +233,7 @@ function pidofFTL() +