diff --git a/.pullapprove.yml b/.pullapprove.yml deleted file mode 100644 index 42d3b2fb..00000000 --- a/.pullapprove.yml +++ /dev/null @@ -1,38 +0,0 @@ -version: 2 - -always_pending: - title_regex: '(WIP|wip)' - labels: - - wip - explanation: 'This PR is a work in progress...' - -group_defaults: - reset_on_push: - enabled: true - reject_value: -2 - approve_regex: '^(Approved|:shipit:|:\+1:|Engage|:taco:)' - reject_regex: '^(Rejected|:-1:|Borg)' - author_approval: - auto: true - - -groups: - development: - approve_by_comment: - enabled: true - conditions: - branches: - - devel - required: 2 - teams: - - approvers - - master: - approve_by_comment: - enabled: true - conditions: - branches: - - master - required: 4 - teams: - - approvers diff --git a/scripts/pi-hole/js/auditlog.js b/scripts/pi-hole/js/auditlog.js index 7c92a58d..10261a84 100644 --- a/scripts/pi-hole/js/auditlog.js +++ b/scripts/pi-hole/js/auditlog.js @@ -4,8 +4,9 @@ * * 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, auditList = [], auditTimeout; +var auditList = [], auditTimeout; // Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406 function escapeHtml(text) { @@ -35,7 +36,7 @@ function updateTopLists() { var adtable = $("#ad-frequency").find("tbody:last"); var url, domain; for (domain in data.top_queries) { - if ({}.hasOwnProperty.call(data.top_queries,domain)){ + if (Object.prototype.hasOwnProperty.call(data.top_queries,domain)){ // Sanitize domain domain = escapeHtml(domain); url = ""+domain+""; @@ -45,7 +46,7 @@ function updateTopLists() { } for (domain in data.top_ads) { - if ({}.hasOwnProperty.call(data.top_ads,domain)){ + if (Object.prototype.hasOwnProperty.call(data.top_ads,domain)){ var input = domain.split(" "); // Sanitize domain var printdomain = escapeHtml(input[0]); @@ -71,9 +72,8 @@ function updateTopLists() { }); } - function add(domain,list) { - var token = $("#token").html(); + var token = $("#token").text(); $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", @@ -87,8 +87,8 @@ $(document).ready(function() { updateTopLists(); $("#domain-frequency tbody").on( "click", "button", function () { - var url = ($(this).parents("tr"))[0].innerText.split(" ")[0]; - if($(this).context.innerText === " Blacklist") + var url = ($(this).parents("tr"))[0].textContent.split(" ")[0]; + if($(this).context.textContent === " Blacklist") { add(url,"audit"); add(url,"black"); @@ -101,8 +101,8 @@ $(document).ready(function() { }); $("#ad-frequency tbody").on( "click", "button", function () { - var url = ($(this).parents("tr"))[0].innerText.split(" ")[0].split(" ")[0]; - if($(this).context.innerText === " Whitelist") + var url = ($(this).parents("tr"))[0].textContent.split(" ")[0].split(" ")[0]; + if($(this).context.textContent === " Whitelist") { add(url,"audit"); add(url,"white"); @@ -131,7 +131,6 @@ function auditUrl(url) { }, 3000); } - $("#gravityBtn").on("click", function() { window.location.replace("gravity.php?go"); }); diff --git a/scripts/pi-hole/js/customdns.js b/scripts/pi-hole/js/customdns.js index 4ff50223..834211a6 100644 --- a/scripts/pi-hole/js/customdns.js +++ b/scripts/pi-hole/js/customdns.js @@ -1,3 +1,10 @@ +/* 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. */ + var table; function showAlert(type, message) @@ -7,10 +14,10 @@ function showAlert(type, message) switch (type) { - case 'info': alertElement = $('#alInfo'); break; - case 'success': alertElement = $('#alSuccess'); break; - case 'warning': alertElement = $('#alWarning'); messageElement = $('#warn'); break; - case 'error': alertElement = $('#alFailure'); messageElement = $('#err'); break; + case 'info': alertElement = $('#alInfo'); break; + case 'success': alertElement = $('#alSuccess'); break; + case 'warning': alertElement = $('#alWarning'); messageElement = $('#warn'); break; + case 'error': alertElement = $('#alFailure'); messageElement = $('#err'); break; default: return; } @@ -35,7 +42,7 @@ $(document).ready(function() { ""; } } ], - "drawCallback": function( settings ) { + "drawCallback": function() { $('.deleteCustomDNS').on('click', deleteCustomDNS); } }); @@ -60,7 +67,7 @@ function addCustomDNS() else showAlert('error', response.message); }, - error: function(jqXHR, exception) { + error: function() { showAlert('error', "Error while adding this custom DNS entry"); } }); diff --git a/scripts/pi-hole/js/db_graph.js b/scripts/pi-hole/js/db_graph.js index 246698cf..422179e8 100644 --- a/scripts/pi-hole/js/db_graph.js +++ b/scripts/pi-hole/js/db_graph.js @@ -5,9 +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 -*/ +/* global Chart:false, moment:false */ var start__ = moment().subtract(6, "days"); var from = moment(start__).utc().valueOf()/1000; @@ -42,22 +40,8 @@ $(function () { until = moment(endt).utc().valueOf()/1000; }); - }); -// 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 padNumber(num) { return ("00" + num).substr(-2,2); } @@ -100,14 +84,14 @@ function updateQueriesOverTime() { var dates = [], hour; for (hour in data.domains_over_time[0]) { - if ({}.hasOwnProperty.call(data.domains_over_time[0], hour)) { + if (Object.prototype.hasOwnProperty.call(data.domains_over_time[0], hour)) { dates.push(parseInt(data.domains_over_time[0][hour])); } } for (hour in data.ads_over_time[0]) { - if ({}.hasOwnProperty.call(data.ads_over_time[0], hour)) { - if(!dates.includes(parseInt(data.ads_over_time[0][hour]))) + if (Object.prototype.hasOwnProperty.call(data.ads_over_time[0], hour)) { + if(dates.indexOf(parseInt(data.ads_over_time[0][hour])) === -1) { dates.push(parseInt(data.ads_over_time[0][hour])); } @@ -118,7 +102,7 @@ function updateQueriesOverTime() { // Add data for each hour that is available for (hour in dates) { - if ({}.hasOwnProperty.call(dates, hour)) { + if (Object.prototype.hasOwnProperty.call(dates, hour)) { var d, dom = 0, ads = 0; d = new Date(1000*dates[hour]); @@ -147,7 +131,6 @@ function updateQueriesOverTime() { }); } -/* global Chart */ $(document).ready(function() { var ctx = document.getElementById("queryOverTimeChart").getContext("2d"); timeLineChart = new Chart(ctx, { @@ -187,7 +170,7 @@ $(document).ready(function() { responsive: true, mode: "x-axis", callbacks: { - title: function(tooltipItem, data) { + title: function(tooltipItem) { var label = tooltipItem[0].xLabel; var time = new Date(label); var date = time.getFullYear()+"-"+padNumber(time.getMonth()+1)+"-"+padNumber(time.getDate()); @@ -209,10 +192,8 @@ $(document).ready(function() { } return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel + " (" + percentage.toFixed(1) + "%)"; } - else - { - return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel; - } + + return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel; } } }, @@ -257,7 +238,7 @@ $("#queryOverTimeChart").click(function(evt){ if(activePoints.length > 0) { //get the internal index in the chart - var clickedElementindex = activePoints[0]["_index"]; + var clickedElementindex = activePoints[0]._index; //get specific label by index var label = timeLineChart.data.labels[clickedElementindex]; diff --git a/scripts/pi-hole/js/db_lists.js b/scripts/pi-hole/js/db_lists.js index 903384af..b91ce147 100644 --- a/scripts/pi-hole/js/db_lists.js +++ b/scripts/pi-hole/js/db_lists.js @@ -5,9 +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 -*/ +/* global moment:false */ var start__ = moment().subtract(6, "days"); var from = moment(start__).utc().valueOf()/1000; @@ -23,7 +21,7 @@ $(function () { $("#querytime").daterangepicker( { timePicker: true, timePickerIncrement: 15, - locale: { format: "MMMM Do YYYY, HH:mm" }, + locale: { format: dateformat }, startDate: start__, endDate: end__, ranges: { "Today": [moment().startOf("day"), moment()], @@ -67,14 +65,14 @@ function updateTopClientsChart() { var client, percentage, clientname, clientip; var sum = 0; for (client in data.top_sources) { - if ({}.hasOwnProperty.call(data.top_sources, client)){ + if (Object.prototype.hasOwnProperty.call(data.top_sources, client)){ sum += data.top_sources[client]; } } for (client in data.top_sources) { - if ({}.hasOwnProperty.call(data.top_sources, client)){ + if (Object.prototype.hasOwnProperty.call(data.top_sources, client)){ // Sanitize client client = escapeHtml(client); if(escapeHtml(client) !== client) @@ -121,14 +119,14 @@ function updateTopDomainsChart() { var domain, percentage; var sum = 0; for (domain in data.top_domains) { - if ({}.hasOwnProperty.call(data.top_domains, domain)){ + if (Object.prototype.hasOwnProperty.call(data.top_domains, domain)){ sum += data.top_domains[domain]; } } for (domain in data.top_domains) { - if ({}.hasOwnProperty.call(data.top_domains, domain)){ + if (Object.prototype.hasOwnProperty.call(data.top_domains, domain)){ // Sanitize domain domain = escapeHtml(domain); if(escapeHtml(domain) !== domain) @@ -163,14 +161,14 @@ function updateTopAdsChart() { var ad, percentage; var sum = 0; for (ad in data.top_ads) { - if ({}.hasOwnProperty.call(data.top_ads, ad)){ + if (Object.prototype.hasOwnProperty.call(data.top_ads, ad)){ sum += data.top_ads[ad]; } } for (ad in data.top_ads) { - if ({}.hasOwnProperty.call(data.top_ads, ad)){ + if (Object.prototype.hasOwnProperty.call(data.top_ads, ad)){ // Sanitize ad ad = escapeHtml(ad); if(escapeHtml(ad) !== ad) diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index 76ec1f93..56078713 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -5,9 +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 -*/ +/* global moment:false */ var start__ = moment().subtract(6, "days"); var from = moment(start__).utc().valueOf()/1000; @@ -26,8 +24,8 @@ location.search.substr(1).split("&").forEach(function(item) {GETDict[item.split( if("from" in GETDict && "until" in GETDict) { - from = parseInt(GETDict["from"]); - until = parseInt(GETDict["until"]); + from = parseInt(GETDict.from); + until = parseInt(GETDict.until); start__ = moment(1000*from); end__ = moment(1000*until); instantquery = true; @@ -37,7 +35,7 @@ $(function () { daterange = $("#querytime").daterangepicker( { timePicker: true, timePickerIncrement: 15, - locale: { format: "MMMM Do YYYY, HH:mm" }, + locale: { format: dateformat }, startDate: start__, endDate: end__, ranges: { "Today": [moment().startOf("day"), moment()], @@ -60,17 +58,8 @@ $(function () { var tableApi, statistics; -function escapeRegex(text) { - var map = { - "(": "\\(", - ")": "\\)", - ".": "\\.", - }; - return text.replace(/[().]/g, function(m) { return map[m]; }); -} - function add(domain,list) { - var token = $("#token").html(); + var token = $("#token").text(); var alInfo = $("#alInfo"); var alList = $("#alList"); var alDomain = $("#alDomain"); @@ -113,7 +102,7 @@ function add(domain,list) { alDomain.html(""); }); }, - error: function(jqXHR, exception) { + error: function() { alFailure.show(); err.html(""); alFailure.delay(1000).fadeOut(2000, function() { @@ -127,7 +116,7 @@ function add(domain,list) { } }); } -function handleAjaxError( xhr, textStatus, error ) { +function handleAjaxError( xhr, textStatus ) { if ( textStatus === "timeout" ) { alert( "The server took too long to send the data." ); @@ -223,9 +212,8 @@ function refreshTableData() { } $(document).ready(function() { - var status; - var APIstring; + if(instantquery) { APIstring = "api_db.php?getAllQueries&from="+from+"&until="+until; @@ -242,7 +230,7 @@ $(document).ready(function() { } tableApi = $("#all-queries").DataTable( { - "rowCallback": function( row, data, index ){ + "rowCallback": function( row, data ){ var blocked, fieldtext, buttontext, color; switch (data[4]) { @@ -268,31 +256,31 @@ $(document).ready(function() { blocked = true; color = "red"; fieldtext = "Blocked (regex/wildcard)"; - buttontext = "" ; + buttontext = ""; break; case 5: blocked = true; color = "red"; fieldtext = "Blocked (blacklist)"; - buttontext = "" ; + buttontext = ""; break; case 6: blocked = true; color = "red"; fieldtext = "Blocked (external, IP)"; - buttontext = "" ; + buttontext = ""; break; case 7: blocked = true; color = "red"; fieldtext = "Blocked (external, NULL)"; - buttontext = "" ; + buttontext = ""; break; case 8: blocked = true; color = "red"; fieldtext = "Blocked (external, NXRA)"; - buttontext = "" ; + buttontext = ""; break; default: blocked = false; @@ -325,12 +313,12 @@ $(document).ready(function() { "deferRender": true, "order" : [[0, "desc"]], "columns": [ - { "width" : "15%", "render": function (data, type, full, meta) { if(type === "display"){return moment.unix(Math.floor(data/1e6)).format("Y-MM-DD []HH:mm:ss z");}else{return data;} }}, + { "width" : "15%", "render": function (data, type) { if(type === "display"){return moment.unix(Math.floor(data/1e6)).format("Y-MM-DD []HH:mm:ss z");}return data; }}, { "width" : "10%" }, { "width" : "40%" }, { "width" : "20%" }, { "width" : "10%" }, - { "width" : "5%" }, + { "width" : "5%" } ], "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], "columnDefs": [ { @@ -354,7 +342,7 @@ $(document).ready(function() { if(instantquery) { - daterange.val(start__.format("MMMM Do YYYY, HH:mm") + " - " + end__.format("MMMM Do YYYY, HH:mm")); + daterange.val(start__.format(dateformat) + " - " + end__.format(dateformat)); } } ); diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js index 4f5daf6c..d658421b 100644 --- a/scripts/pi-hole/js/debug.js +++ b/scripts/pi-hole/js/debug.js @@ -1,3 +1,12 @@ +/* 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 */ + // Credit: http://stackoverflow.com/a/10642418/2087442 function httpGet(ta,theUrl) { @@ -29,7 +38,7 @@ function eventsource() { var ta = $("#output"); var upload = $( "#upload" ); var checked = ""; - var token = encodeURIComponent($("#token").html()); + var token = encodeURIComponent($("#token").text()); if(upload.prop("checked")) { @@ -53,7 +62,7 @@ function eventsource() { }, false); // Will be called when script has finished - source.addEventListener("error", function(e) { + source.addEventListener("error", function() { source.close(); }, false); } diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index ccdf67a8..3e7b467e 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -4,6 +4,7 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + //The following functions allow us to display time until pi-hole is enabled after disabling. //Works between all pages @@ -58,7 +59,7 @@ function countDown(){ function piholeChange(action, duration) { - var token = encodeURIComponent($("#token").html()); + var token = encodeURIComponent($("#token").text()); var enaT = $("#enableTimer"); var btnStatus; @@ -132,12 +133,13 @@ $("#pihole-disable-custom").on("click", function(e){ }); // Session timer -var sessionvalidity = parseInt(document.getElementById("sessiontimercounter").textContent); -var start = new Date; +var sessionTimerCounter = document.getElementById("sessiontimercounter"); +var sessionvalidity = parseInt(sessionTimerCounter.textContent); +var start = new Date(); function updateSessionTimer() { - start = new Date; + start = new Date(); start.setSeconds(start.getSeconds() + sessionvalidity); } @@ -147,12 +149,8 @@ if(sessionvalidity > 0) updateSessionTimer(); setInterval(function() { - var current = new Date; + var current = new Date(); var totalseconds = (start - current) / 1000; - - // var hours = Math.floor(totalseconds / 3600); - // totalseconds = totalseconds % 3600; - var minutes = Math.floor(totalseconds / 60); if(minutes < 10){ minutes = "0" + minutes; } @@ -161,11 +159,11 @@ if(sessionvalidity > 0) if(totalseconds > 0) { - document.getElementById("sessiontimercounter").textContent = minutes + ":" + seconds; + sessionTimerCounter.textContent = minutes + ":" + seconds; } else { - document.getElementById("sessiontimercounter").textContent = "-- : --"; + sessionTimerCounter.textContent = "-- : --"; } }, 1000); diff --git a/scripts/pi-hole/js/gravity.js b/scripts/pi-hole/js/gravity.js index bf31254b..34aa1477 100644 --- a/scripts/pi-hole/js/gravity.js +++ b/scripts/pi-hole/js/gravity.js @@ -4,6 +4,7 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + function eventsource() { var alInfo = $("#alInfo"); var alSuccess = $("#alSuccess"); @@ -43,7 +44,7 @@ function eventsource() { }, false); // Will be called when script has finished - source.addEventListener("error", function(e) { + source.addEventListener("error", function() { alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); }); source.close(); $("#gravityBtn").removeAttr("disabled"); diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 93d92a1d..18b1773b 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -4,9 +4,10 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + // Define global variables -/* global Chart */ -var timeLineChart, queryTypeChart, forwardDestinationChart; +/* global Chart:false, updateSessionTimer:false */ +var timeLineChart, forwardDestinationChart; var queryTypePieChart, forwardDestinationPieChart, clientsChart; function padNumber(num) { @@ -149,7 +150,7 @@ function updateQueriesOverTime() { // Add data for each hour that is available for (var hour in data.ads_over_time[0]) { - if ({}.hasOwnProperty.call(data.ads_over_time[0], hour)) + if (Object.prototype.hasOwnProperty.call(data.ads_over_time[0], hour)) { var d,h; h = parseInt(data.domains_over_time[0][hour]); @@ -199,7 +200,7 @@ function updateQueryTypesPie() { $.each($.AdminLTE.options.colors, function(key, value) { colors.push(value); }); var v = [], c = [], k = [], iter; // Collect values and colors, and labels - if(data.hasOwnProperty("querytypes")) + if(Object.prototype.hasOwnProperty.call(data, "querytypes")) { iter = data.querytypes; } @@ -232,9 +233,9 @@ function updateQueryTypesPie() { var index = $(this).index(); var ci = e.view.queryTypePieChart; var meta = ci.data.datasets[0]._meta; - for(let i in meta) + for(var i in meta) { - if ({}.hasOwnProperty.call(meta, i)) + if (Object.prototype.hasOwnProperty.call(meta, i)) { var curr = meta[i].data[index]; curr.hidden = !curr.hidden; @@ -274,12 +275,12 @@ function updateClientsOverTime() { // remove last data point since it not representative data.over_time[0].splice(-1,1); var timestamps = data.over_time[0]; - var plotdata = data.over_time[1]; + var plotdata = data.over_time[1]; var labels = []; var key, i, j; for (key in data.clients) { - if (!{}.hasOwnProperty.call(data.clients, key)) + if (!Object.prototype.hasOwnProperty.call(data.clients, key)) { continue; } @@ -318,9 +319,9 @@ function updateClientsOverTime() { clientsChart.data.datasets.push({ data: [], // If we ran out of colors, make a random one - backgroundColor: i < colors.length - ? colors[i] - : "#" + parseInt("" + Math.random() * 0xffffff, 10).toString(16).padStart(6, "0"), + backgroundColor: i < colors.length ? + colors[i] : + "#" + parseInt(String(Math.random() * 0xFFFFFF), 10).toString(16).padStart(6, "0"), pointRadius: 0, pointHitRadius: 5, pointHoverRadius: 5, @@ -332,13 +333,13 @@ function updateClientsOverTime() { // Add data for each dataset that is available for (j in timestamps) { - if (!{}.hasOwnProperty.call(timestamps, j)) + if (!Object.prototype.hasOwnProperty.call(timestamps, j)) { continue; } for (key in plotdata[j]) { - if (!{}.hasOwnProperty.call(plotdata[j], key)) + if (!Object.prototype.hasOwnProperty.call(plotdata[j], key)) { continue; } @@ -415,9 +416,9 @@ function updateForwardDestinationsPie() { var index = $(this).index(); var ci = e.view.forwardDestinationPieChart; var meta = ci.data.datasets[0]._meta; - for(let i in meta) + for(var i in meta) { - if ({}.hasOwnProperty.call(meta, i)) + if (Object.prototype.hasOwnProperty.call(meta, i)) { var curr = meta[i].data[index]; curr.hidden = !curr.hidden; @@ -427,7 +428,7 @@ function updateForwardDestinationsPie() { } else if(e.which === 1) // which == 1 is left mouse button { - var obj = encodeURIComponent(e.target.innerText); + var obj = encodeURIComponent(e.target.textContent); window.open("queries.php?forwarddest="+obj, "_self"); } }); @@ -464,7 +465,7 @@ function updateTopClientsChart() { var client, percentage, clientname, clientip, idx, url; for (client in data.top_sources) { - if ({}.hasOwnProperty.call(data.top_sources, client)){ + if (Object.prototype.hasOwnProperty.call(data.top_sources, client)){ // Sanitize client if(escapeHtml(client) !== client) { @@ -498,7 +499,7 @@ function updateTopClientsChart() { for (client in data.top_sources_blocked) { - if ({}.hasOwnProperty.call(data.top_sources_blocked, client)){ + if (Object.prototype.hasOwnProperty.call(data.top_sources_blocked, client)){ // Sanitize client if(escapeHtml(client) !== client) { @@ -561,7 +562,7 @@ function updateTopLists() { var url, domain, percentage; for (domain in data.top_queries) { - if ({}.hasOwnProperty.call(data.top_queries,domain)){ + if (Object.prototype.hasOwnProperty.call(data.top_queries,domain)){ // Sanitize domain if(escapeHtml(domain) !== domain) { @@ -585,7 +586,7 @@ function updateTopLists() { for (domain in data.top_ads) { - if ({}.hasOwnProperty.call(data.top_ads,domain)){ + if (Object.prototype.hasOwnProperty.call(data.top_ads,domain)){ // Sanitize domain if(escapeHtml(domain) !== domain) { @@ -622,16 +623,15 @@ function updateSummaryData(runOnce) { setTimeout(updateSummaryData, timeInSeconds * 1000); } }; - $.getJSON("api.php?summary", function LoadSummaryData(data) { - + $.getJSON("api.php?summary", function(data) { updateSessionTimer(); if("FTLnotrunning" in data) { - data["dns_queries_today"] = "Lost"; - data["ads_blocked_today"] = "connection"; - data["ads_percentage_today"] = "to"; - data["domains_being_blocked"] = "API"; + data.dns_queries_today = "Lost"; + data.ads_blocked_today = "connection"; + data.ads_percentage_today = "to"; + data.domains_being_blocked = "API"; // Adjust text $("#temperature").html(" FTL offline"); // Show spinner @@ -655,15 +655,19 @@ function updateSummaryData(runOnce) { } ["ads_blocked_today", "dns_queries_today", "ads_percentage_today", "unique_clients"].forEach(function(today) { - var todayElement = $("span#" + today); - todayElement.text() !== data[today] && - todayElement.text() !== data[today] + "%" && - $("span#" + today).addClass("glow"); + var $todayElement = $("span#" + today); + + if ( + $todayElement.text() !== data[today] && + $todayElement.text() !== data[today] + "%" + ) { + $todayElement.addClass("glow"); + } }); - if(data.hasOwnProperty("dns_queries_all_types")) + if(Object.prototype.hasOwnProperty.call(data, "dns_queries_all_types")) { - $("#total_queries").prop("title", "only A + AAAA queries (" + data["dns_queries_all_types"] + " in total)"); + $("#total_queries").prop("title", "only A + AAAA queries (" + data.dns_queries_all_types + " in total)"); } window.setTimeout(function() { @@ -749,7 +753,7 @@ $(document).ready(function() { enabled: true, mode: "x-axis", callbacks: { - title: function(tooltipItem, data) { + title: function(tooltipItem) { var label = tooltipItem[0].xLabel; var time = label.match(/(\d?\d):?(\d?\d?)/); var h = parseInt(time[1], 10); @@ -770,10 +774,8 @@ $(document).ready(function() { } return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel + " (" + percentage.toFixed(1) + "%)"; } - else - { - return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel; - } + + return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel; } } }, @@ -820,7 +822,7 @@ $(document).ready(function() { enabled: true, mode: "x-axis", callbacks: { - title: function(tooltipItem, data) { + title: function(tooltipItem) { var label = tooltipItem[0].xLabel; var time = label.match(/(\d?\d):?(\d?\d?)/); var h = parseInt(time[1], 10); @@ -853,7 +855,7 @@ $(document).ready(function() { mix: 0.0, max: 1.0, beginAtZero: true, - callback: function(value, index, values) { + callback: function(value) { return Math.round(value*100) + " %"; } }, @@ -863,15 +865,13 @@ $(document).ready(function() { maintainAspectRatio: true } }); - - // Pull in data via AJAX - updateForwardedOverTime(); } // Create / load "Top Clients over Time" only if authorized - if(document.getElementById("clientsChart")) + var clientsChartEl = document.getElementById("clientsChart"); + if(clientsChartEl) { - ctx = document.getElementById("clientsChart").getContext("2d"); + ctx = clientsChartEl.getContext("2d"); clientsChart = new Chart(ctx, { type: "line", data: { @@ -887,7 +887,7 @@ $(document).ready(function() { return b.yLabel - a.yLabel; }, callbacks: { - title: function(tooltipItem, data) { + title: function(tooltipItem) { var label = tooltipItem[0].xLabel; var time = label.match(/(\d?\d):?(\d?\d?)/); var h = parseInt(time[1], 10); @@ -931,8 +931,8 @@ $(document).ready(function() { } // Create / load "Top Domains" and "Top Advertisers" only if authorized - if(document.getElementById("domain-frequency") - && document.getElementById("ad-frequency")) + if(document.getElementById("domain-frequency") && + document.getElementById("ad-frequency")) { updateTopLists(); } @@ -948,7 +948,7 @@ $(document).ready(function() { if(activePoints.length > 0) { //get the internal index of slice in pie chart - var clickedElementindex = activePoints[0]["_index"]; + var clickedElementindex = activePoints[0]._index; //get specific label by index var label = timeLineChart.data.labels[clickedElementindex]; @@ -978,7 +978,7 @@ $(document).ready(function() { enabled: false, custom: customTooltips, callbacks: { - title: function(tooltipItem, data) { + title: function() { return "Query types"; }, label: function(tooltipItems, data) { @@ -1016,7 +1016,7 @@ $(document).ready(function() { enabled: false, custom: customTooltips, callbacks: { - title: function(tooltipItem, data) { + title: function() { return "Forward destinations"; }, label: function(tooltipItems, data) { diff --git a/scripts/pi-hole/js/ip-address-sorting.js b/scripts/pi-hole/js/ip-address-sorting.js index 6ef1fd3d..13bf1933 100644 --- a/scripts/pi-hole/js/ip-address-sorting.js +++ b/scripts/pi-hole/js/ip-address-sorting.js @@ -11,24 +11,24 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "ip-address-pre": function ( a ) { - if (!a) { return 0 } + if (!a) { return 0; } var i, item; var m = a.split("."), n = a.split(":"), x = "", xa = ""; - if (m.length == 4) + if (m.length === 4) { // IPV4 for(i = 0; i < m.length; i++) { item = m[i]; - if(item.length == 1) + if(item.length === 1) { x += "00" + item; } - else if(item.length == 2) + else if(item.length === 2) { x += "0" + item; } @@ -55,17 +55,17 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { count += 0; } - else if(item.length == 1) + else if(item.length === 1) { xa += "000" + item; count += 4; } - else if(item.length == 2) + else if(item.length === 2) { xa += "00" + item; count += 4; } - else if(item.length == 3) + else if(item.length === 3) { xa += "0" + item; count += 4; @@ -86,7 +86,7 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, item = n[i]; if (item.length === 0 && paddDone === 0) { - for(var padding = 0 ; padding < (32-count) ; padding++) + for(var padding = 0; padding < (32-count); padding++) { x += "0"; paddDone = 1; diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index d28350da..57bcdbb5 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -4,11 +4,12 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + // IE likes to cache too much :P $.ajaxSetup({cache: false}); // Get PHP info -var token = $("#token").html(); +var token = $("#token").text(); var listType = $("#list-type").html(); var fullName = listType === "white" ? "Whitelist" : "Blacklist"; @@ -69,6 +70,7 @@ function refresh(fade) { } else { + var data, data2; if(listType === "white") { data = response.whitelist.sort(); @@ -101,13 +103,13 @@ function refresh(fade) { list.fadeIn(100); listw.fadeIn(100); }, - error: function(jqXHR, exception) { + error: function() { $("#alFailure").show(); } }); } -window.onload = refresh(false); +window.addEventListener('load', refresh(false)); function sub(index, entry, arg) { var list = "#list"; @@ -122,12 +124,9 @@ function sub(index, entry, arg) { var alInfo = $("#alInfo"); var alSuccess = $("#alSuccess"); var alFailure = $("#alFailure"); - var alWarning = $("#alWarning"); var err = $("#err"); - var warn = $("#warn"); var msg = $("#success-message"); - var domain = $(list+" #"+index); domain.hide("highlight"); $.ajax({ @@ -160,7 +159,7 @@ function sub(index, entry, arg) { } } }, - error: function(jqXHR, exception) { + error: function() { alert("Failed to remove the domain!"); domain.show({queue:true}); } @@ -180,7 +179,6 @@ function add(type) { var alFailure = $("#alFailure"); var alWarning = $("#alWarning"); var err = $("#err"); - var warn = $("#warn"); var msg = $("#success-message"); alInfo.show(); alSuccess.hide(); @@ -214,7 +212,7 @@ function add(type) { refresh(true); } }, - error: function(jqXHR, exception) { + error: function() { alFailure.show(); err.html(""); alFailure.delay(1000).fadeOut(2000, function() { @@ -227,8 +225,6 @@ function add(type) { }); } - - // Handle enter button for adding domains $(document).keypress(function(e) { if(e.which === 13 && $("#domain,#comment").is(":focus")) { diff --git a/scripts/pi-hole/js/network.js b/scripts/pi-hole/js/network.js index d1b05c5d..3d82fa11 100644 --- a/scripts/pi-hole/js/network.js +++ b/scripts/pi-hole/js/network.js @@ -4,6 +4,9 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + +/* global moment:false */ + var tableApi; var APIstring = "api_db.php?network"; @@ -11,16 +14,7 @@ var APIstring = "api_db.php?network"; // How many IPs do we show at most per device? var MAXIPDISPLAY = 3; -function refreshData() { - tableApi.ajax.url(APIstring).load(); -} - -function openInNewTab(url) { - var win = window.open(url, "_blank"); - win.focus(); -} - -function handleAjaxError( xhr, textStatus, error ) { +function handleAjaxError(xhr, textStatus) { if ( textStatus === "timeout" ) { alert( "The server took too long to send the data." ); @@ -52,9 +46,9 @@ function valueToHex(c) { } function rgbToHex(values) { - return "#" + valueToHex(values[0]) - + valueToHex(values[1]) - + valueToHex(values[2]); + return "#" + valueToHex(values[0]) + + valueToHex(values[1]) + + valueToHex(values[2]); } function mixColors(ratio, rgb1, rgb2) @@ -66,9 +60,9 @@ function mixColors(ratio, rgb1, rgb2) $(document).ready(function() { tableApi = $("#network-entries").DataTable( { - "rowCallback": function( row, data, index ) + "rowCallback": function( row, data ) { - var color, mark, lastQuery = parseInt(data["lastQuery"]); + var color, mark, lastQuery = parseInt(data.lastQuery); if(lastQuery > 0) { var diff = getTimestamp()-lastQuery; @@ -76,7 +70,7 @@ $(document).ready(function() { { // Last query came in within the last 24 hours (24*60*60 = 86400) // Color: light-green to light-yellow - var ratio = 1e0*diff/86400; + var ratio = Number(diff)/86400; var lightgreen = [0xE7, 0xFF, 0xDE]; var lightyellow = [0xFF, 0xFF, 0xDF]; color = rgbToHex(mixColors(ratio, lightgreen, lightyellow)); @@ -102,21 +96,21 @@ $(document).ready(function() { // Insert "Never" into Last Query field when we have // never seen a query from this device - if(data["lastQuery"] === 0) + if(data.lastQuery === 0) { $("td:eq(5)", row).html("Never"); } // Set hostname to "N/A" if not available - if(!data["name"] || data["name"].length < 1) + if(!data.name || data.name.length < 1) { $("td:eq(3)", row).html("N/A"); } // Set number of queries to localized string (add thousand separators) - $("td:eq(6)", row).html(data["numQueries"].toLocaleString()); + $("td:eq(6)", row).html(data.numQueries.toLocaleString()); - var ips = data["ip"]; + var ips = data.ip; var shortips = ips; if(ips.length > MAXIPDISPLAY) { @@ -127,9 +121,9 @@ $(document).ready(function() { $("td:eq(0)", row).hover(function () { this.title=ips.join("\n");}); // MAC + Vendor field if available - if(data["macVendor"] && data["macVendor"].length > 0) + if(data.macVendor && data.macVendor.length > 0) { - $("td:eq(1)", row).html(data["hwaddr"]+"
"+data["macVendor"]); + $("td:eq(1)", row).html(data.hwaddr+"
"+data.macVendor); } }, @@ -146,8 +140,8 @@ $(document).ready(function() { {data: "hwaddr", "width" : "10%", "render": $.fn.dataTable.render.text() }, {data: "interface", "width" : "4%", "render": $.fn.dataTable.render.text() }, {data: "name", "width" : "15%", "render": $.fn.dataTable.render.text() }, - {data: "firstSeen", "width" : "8%", "render": function (data, type, full, meta) { if(type === "display"){return moment.unix(data).format("Y-MM-DD []HH:mm:ss z");}else{return data;} }}, - {data: "lastQuery", "width" : "8%", "render": function (data, type, full, meta) { if(type === "display"){return moment.unix(data).format("Y-MM-DD []HH:mm:ss z");}else{return data;} }}, + {data: "firstSeen", "width" : "8%", "render": function (data, type) { if(type === "display"){return moment.unix(data).format("Y-MM-DD []HH:mm:ss z");}return data; }}, + {data: "lastQuery", "width" : "8%", "render": function (data, type) { if(type === "display"){return moment.unix(data).format("Y-MM-DD []HH:mm:ss z");}return data; }}, {data: "numQueries", "width" : "9%", "render": $.fn.dataTable.render.text() }, {data: "", "width" : "6%", "orderable" : false } ], @@ -157,16 +151,16 @@ $(document).ready(function() { // Store current state in client's local storage area localStorage.setItem("network_table", JSON.stringify(data)); }, - stateLoadCallback: function(settings) { + stateLoadCallback: function() { // Receive previous state from client's local storage area var data = localStorage.getItem("network_table"); // Return if not available if(data === null){ return null; } data = JSON.parse(data); // Always start on the first page - data["start"] = 0; + data.start = 0; // Always start with empty search field - data["search"]["search"] = ""; + data.search.search = ""; // Apply loaded state to table return data; }, diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 5ab26bd1..1618cdc9 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -4,24 +4,13 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + +/* global moment:false */ + var tableApi; -function escapeRegex(text) { - var map = { - "(": "\\(", - ")": "\\)", - ".": "\\.", - }; - return text.replace(/[().]/g, function(m) { return map[m]; }); -} - -function refreshData() { - tableApi.ajax.url("api.php?getAllQueries").load(); -// updateSessionTimer(); -} - function add(domain,list) { - var token = $("#token").html(); + var token = $("#token").text(); var alertModal = $("#alertModal"); var alProcessing = alertModal.find(".alProcessing"); var alSuccess = alertModal.find(".alSuccess"); @@ -73,7 +62,7 @@ function add(domain,list) { setTimeout(function() { alertModal.modal("hide"); }, 2000); } }, - error: function(jqXHR, exception) { + error: function() { // Network Error alProcessing.hide(); alNetworkErr.show(); @@ -92,7 +81,7 @@ function add(domain,list) { }); } -function handleAjaxError( xhr, textStatus, error ) { +function handleAjaxError( xhr, textStatus ) { if ( textStatus === "timeout" ) { alert( "The server took too long to send the data." ); @@ -123,24 +112,24 @@ $(document).ready(function() { if("from" in GETDict && "until" in GETDict) { - APIstring += "&from="+GETDict["from"]; - APIstring += "&until="+GETDict["until"]; + APIstring += "&from="+GETDict.from; + APIstring += "&until="+GETDict.until; } else if("client" in GETDict) { - APIstring += "&client="+GETDict["client"]; + APIstring += "&client="+GETDict.client; } else if("domain" in GETDict) { - APIstring += "&domain="+GETDict["domain"]; + APIstring += "&domain="+GETDict.domain; } else if("querytype" in GETDict) { - APIstring += "&querytype="+GETDict["querytype"]; + APIstring += "&querytype="+GETDict.querytype; } else if("forwarddest" in GETDict) { - APIstring += "&forwarddest="+GETDict["forwarddest"]; + APIstring += "&forwarddest="+GETDict.forwarddest; } // If we don't ask filtering and also not for all queries, just request the most recent 100 queries else if(!("all" in GETDict)) @@ -149,7 +138,7 @@ $(document).ready(function() { } tableApi = $("#all-queries").DataTable( { - "rowCallback": function( row, data, index ){ + "rowCallback": function( row, data ){ // DNSSEC status var dnssec_status; switch (data[5]) @@ -199,31 +188,31 @@ $(document).ready(function() { blocked = true; colorClass = "text-red"; fieldtext = "Blocked (regex/wildcard)"; - buttontext = "" ; + buttontext = ""; break; case "5": blocked = true; colorClass = "text-red"; fieldtext = "Blocked (blacklist)"; - buttontext = "" ; + buttontext = ""; break; case "6": blocked = true; colorClass = "text-red"; fieldtext = "Blocked (external, IP)"; - buttontext = "" ; + buttontext = ""; break; case "7": blocked = true; colorClass = "text-red"; fieldtext = "Blocked (external, NULL)"; - buttontext = "" ; + buttontext = ""; break; case "8": blocked = true; colorClass = "text-red"; fieldtext = "Blocked (external, NXRA)"; - buttontext = "" ; + buttontext = ""; break; default: blocked = false; @@ -311,7 +300,7 @@ $(document).ready(function() { "processing": true, "order" : [[0, "desc"]], "columns": [ - { "width" : "15%", "render": function (data, type, full, meta) { if(type === "display"){return moment.unix(Math.floor(data/1e6)).format("Y-MM-DD []HH:mm:ss z");}else{return data;} }}, + { "width" : "15%", "render": function (data, type) { if(type === "display"){return moment.unix(Math.floor(data/1e6)).format("Y-MM-DD []HH:mm:ss z");}return data; }}, { "width" : "4%" }, { "width" : "36%", "render": $.fn.dataTable.render.text() }, { "width" : "8%", "render": $.fn.dataTable.render.text() }, @@ -325,16 +314,16 @@ $(document).ready(function() { // Store current state in client's local storage area localStorage.setItem("query_log_table", JSON.stringify(data)); }, - stateLoadCallback: function(settings) { + stateLoadCallback: function() { // Receive previous state from client's local storage area var data = localStorage.getItem("query_log_table"); // 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; + data.start = 0; // Always start with empty search field - data["search"]["search"] = ""; + data.search.search = ""; // Apply loaded state to table return data; }, @@ -346,11 +335,11 @@ $(document).ready(function() { "initComplete": function () { var api = this.api(); // Query type IPv4 / IPv6 - api.$("td:eq(1)").click( function () { if(autofilter()){ api.search( this.innerHTML ).draw(); $("#resetButton").show(); }}); + api.$("td:eq(1)").click( function () { if(autofilter()){ api.search( this.textContent ).draw(); $("#resetButton").show(); }}); api.$("td:eq(1)").hover( function () { if(autofilter()) { - this.title = "Click to show only " + this.innerHTML + " queries"; + this.title = "Click to show only " + this.textContent + " queries"; this.style.color = "#72afd2"; } else { this.title = ""; @@ -361,11 +350,11 @@ $(document).ready(function() { ); api.$("td:eq(1)").css("cursor","pointer"); // Domain - api.$("td:eq(2)").click( function () { if(autofilter()){ api.search( this.innerHTML ).draw(); $("#resetButton").show(); }}); + api.$("td:eq(2)").click( function () { if(autofilter()){ api.search( this.textContent ).draw(); $("#resetButton").show(); }}); api.$("td:eq(2)").hover( function () { if(autofilter()) { - this.title = "Click to show only queries with domain " + this.innerHTML; + this.title = "Click to show only queries with domain " + this.textContent; this.style.color = "#72afd2"; } else { this.title = ""; @@ -376,11 +365,11 @@ $(document).ready(function() { ); api.$("td:eq(2)").css("cursor","pointer"); // Client - api.$("td:eq(3)").click( function () { if(autofilter()){ api.search( this.innerHTML ).draw(); $("#resetButton").show(); }}); + api.$("td:eq(3)").click( function () { if(autofilter()){ api.search( this.textContent ).draw(); $("#resetButton").show(); }}); api.$("td:eq(3)").hover( function () { if(autofilter()) { - this.title = "Click to show only queries made by " + this.innerHTML; + this.title = "Click to show only queries made by " + this.textContent; this.style.color = "#72afd2"; } else { this.title = ""; diff --git a/scripts/pi-hole/js/queryads.js b/scripts/pi-hole/js/queryads.js index 45a408b1..5eb18dbe 100644 --- a/scripts/pi-hole/js/queryads.js +++ b/scripts/pi-hole/js/queryads.js @@ -4,12 +4,15 @@ * * 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 exact = ""; function quietfilter(ta,data) { var lines = data.split("\n"); - for(var i = 0;i 0) { @@ -192,7 +193,7 @@ $(document).ready(function() { }); } //call draw() on each table... they don't render properly with scrollX and scrollY set... ¯\_(ツ)_/¯ - $("a[data-toggle=\"tab\"]").on("shown.bs.tab", function (e) { + $("a[data-toggle=\"tab\"]").on("shown.bs.tab", function () { leasetable.draw(); staticleasetable.draw(); }); diff --git a/scripts/pi-hole/js/taillog-FTL.js b/scripts/pi-hole/js/taillog-FTL.js index 2645badf..be81a7b3 100644 --- a/scripts/pi-hole/js/taillog-FTL.js +++ b/scripts/pi-hole/js/taillog-FTL.js @@ -4,6 +4,7 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + var offset, timer, pre, scrolling = true; // Check every 200msec for fresh data @@ -14,13 +15,13 @@ function reloadData(){ clearTimeout(timer); $.getJSON("scripts/pi-hole/php/tailLog.php?FTL&offset="+offset, function (data) { - pre.append(data["lines"]); + pre.append(data.lines); - if(scrolling && offset !== data["offset"]) { + if(scrolling && offset !== data.offset) { pre.scrollTop(pre[0].scrollHeight); } - offset = data["offset"]; + offset = data.offset; }); timer = setTimeout(reloadData, interval); @@ -30,7 +31,7 @@ $(function(){ // Get offset at first loading of page $.getJSON("scripts/pi-hole/php/tailLog.php?FTL", function (data) { - offset = data["offset"]; + offset = data.offset; }); pre = $("#output"); // Trigger function that looks for new data diff --git a/scripts/pi-hole/js/taillog.js b/scripts/pi-hole/js/taillog.js index 153bd18d..1363a0ee 100644 --- a/scripts/pi-hole/js/taillog.js +++ b/scripts/pi-hole/js/taillog.js @@ -4,6 +4,7 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + var offset, timer, pre, scrolling = true; // Check every 200msec for fresh data @@ -14,13 +15,13 @@ function reloadData(){ clearTimeout(timer); $.getJSON("scripts/pi-hole/php/tailLog.php?offset="+offset, function (data) { - pre.append(data["lines"]); + pre.append(data.lines); - if(scrolling && offset !== data["offset"]) { + if(scrolling && offset !== data.offset) { pre.scrollTop(pre[0].scrollHeight); } - offset = data["offset"]; + offset = data.offset; }); timer = setTimeout(reloadData, interval); @@ -30,7 +31,7 @@ $(function(){ // Get offset at first loading of page $.getJSON("scripts/pi-hole/php/tailLog.php", function (data) { - offset = data["offset"]; + offset = data.offset; }); pre = $("#output"); // Trigger function that looks for new data diff --git a/scripts/pi-hole/php/FTL.php b/scripts/pi-hole/php/FTL.php index caddd758..c33e061a 100644 --- a/scripts/pi-hole/php/FTL.php +++ b/scripts/pi-hole/php/FTL.php @@ -26,7 +26,7 @@ function sendRequestFTL($requestin) global $socket; $request = ">".$requestin; - fwrite($socket, $request) or die("Could not send data to server\n"); + fwrite($socket, $request) or die('{"error":"Could not send data to server"}'); } function getResponseFTL() @@ -35,9 +35,15 @@ function getResponseFTL() $response = []; + $errCount = 0; while(true) { $out = fgets($socket); + if ($out == "") $errCount++; + if ($errCount > 100) { + // Tried 100 times, but never got proper reply, fail to prevent busy loop + die('{"error":"Tried 100 times to connect to FTL server, but never got proper reply. Please check Port and logs!"}'); + } if(strrpos($out,"---EOM---") !== false) break; diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index 1ea6014d..56f84520 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -10,6 +10,14 @@ require_once('func.php'); $ERRORLOG = getenv('PHP_ERROR_LOG'); if (empty($ERRORLOG)) { $ERRORLOG = '/var/log/lighttpd/error.log'; + + if (!file_exists($ERRORLOG) || !is_writable($ERRORLOG)) { + $ERRORLOG = '/var/log/apache2/error.log'; + + if (!file_exists($ERRORLOG) || !is_writable($ERRORLOG)) { + $ERRORLOG = '/tmp/pi-hole-error.log'; + } + } } function pi_log($message) { diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index 54cb730e..f19980a9 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -270,7 +270,12 @@ if($auth) {