-
-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: XhmikosR <[email protected]>
- Loading branch information
Showing
17 changed files
with
3,654 additions
and
3,205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,163 @@ | ||
/* 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. */ | ||
* (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 auditList = [], auditTimeout; | ||
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]; }); | ||
return text.replace(/[&<>"']/g, function(m) { | ||
return map[m]; | ||
}); | ||
} | ||
|
||
function updateTopLists() { | ||
$.getJSON("api.php?topItems=audit", function(data) { | ||
|
||
if("FTLnotrunning" in data) | ||
{ | ||
return; | ||
} | ||
$.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; | ||
for (domain in data.top_queries) { | ||
if (Object.prototype.hasOwnProperty.call(data.top_queries,domain)){ | ||
// Sanitize domain | ||
domain = escapeHtml(domain); | ||
url = "<a href=\"queries.php?domain="+domain+"\">"+domain+"</a>"; | ||
domaintable.append("<tr> <td>" + url + | ||
"</td> <td>" + data.top_queries[domain] + "</td> <td> <button class=\"text-red text-nowrap\"><i class=\"fa fa-ban\"></i> Blacklist</button> <button class=\"text-orange text-nowrap\"><i class=\"fa fa-balance-scale\"></i> Audit</button> </td> </tr> "); | ||
} | ||
} | ||
// 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; | ||
for (domain in data.top_queries) { | ||
if (Object.prototype.hasOwnProperty.call(data.top_queries, domain)) { | ||
// Sanitize domain | ||
domain = escapeHtml(domain); | ||
url = '<a href="queries.php?domain=' + domain + '">' + domain + "</a>"; | ||
domaintable.append( | ||
"<tr> <td>" + | ||
url + | ||
"</td> <td>" + | ||
data.top_queries[domain] + | ||
'</td> <td> <button class="text-red text-nowrap"><i class="fa fa-ban"></i> Blacklist</button> <button class="text-orange text-nowrap"><i class="fa fa-balance-scale"></i> Audit</button> </td> </tr> ' | ||
); | ||
} | ||
} | ||
|
||
for (domain in data.top_ads) { | ||
if (Object.prototype.hasOwnProperty.call(data.top_ads,domain)){ | ||
var input = domain.split(" "); | ||
// Sanitize domain | ||
var printdomain = escapeHtml(input[0]); | ||
if(input.length > 1) | ||
{ | ||
url = "<a href=\"queries.php?domain="+printdomain+"\">"+printdomain+"</a> (wildcard blocked)"; | ||
adtable.append("<tr> <td>" + url + | ||
"</td> <td>" + data.top_ads[domain] + "</td> <td> <button class=\"text-orange text-nowrap\"><i class=\"fa fa-balance-scale\"></i> Audit</button> </td> </tr> "); | ||
} | ||
else | ||
{ | ||
url = "<a href=\"queries.php?domain="+printdomain+"\">"+printdomain+"</a>"; | ||
adtable.append("<tr> <td>" + url + | ||
"</td> <td>" + data.top_ads[domain] + "</td> <td> <button class=\"text-green text-nowrap\"><i class=\"fas fa-check\"></i> Whitelist</button> <button class=\"text-orange text-nowrap\"><i class=\"fa fa-balance-scale\"></i> Audit</button> </td> </tr> "); | ||
} | ||
} | ||
for (domain in data.top_ads) { | ||
if (Object.prototype.hasOwnProperty.call(data.top_ads, domain)) { | ||
var input = domain.split(" "); | ||
// Sanitize domain | ||
var printdomain = escapeHtml(input[0]); | ||
if (input.length > 1) { | ||
url = | ||
'<a href="queries.php?domain=' + | ||
printdomain + | ||
'">' + | ||
printdomain + | ||
"</a> (wildcard blocked)"; | ||
adtable.append( | ||
"<tr> <td>" + | ||
url + | ||
"</td> <td>" + | ||
data.top_ads[domain] + | ||
'</td> <td> <button class="text-orange text-nowrap"><i class="fa fa-balance-scale"></i> Audit</button> </td> </tr> ' | ||
); | ||
} else { | ||
url = | ||
'<a href="queries.php?domain=' + | ||
printdomain + | ||
'">' + | ||
printdomain + | ||
"</a>"; | ||
adtable.append( | ||
"<tr> <td>" + | ||
url + | ||
"</td> <td>" + | ||
data.top_ads[domain] + | ||
'</td> <td> <button class="text-green text-nowrap"><i class="fas fa-check"></i> Whitelist</button> <button class="text-orange text-nowrap"><i class="fa fa-balance-scale"></i> Audit</button> </td> </tr> ' | ||
); | ||
} | ||
} | ||
} | ||
|
||
$("#domain-frequency .overlay").hide(); | ||
$("#ad-frequency .overlay").hide(); | ||
// Update top lists data every second | ||
setTimeout(updateTopLists, 1000); | ||
}); | ||
$("#domain-frequency .overlay").hide(); | ||
$("#ad-frequency .overlay").hide(); | ||
// Update top lists data every second | ||
setTimeout(updateTopLists, 1000); | ||
}); | ||
} | ||
|
||
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} | ||
}); | ||
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 } | ||
}); | ||
} | ||
|
||
$(document).ready(function() { | ||
// Pull in data via AJAX | ||
updateTopLists(); | ||
|
||
// Pull in data via AJAX | ||
updateTopLists(); | ||
|
||
$("#domain-frequency tbody").on( "click", "button", function () { | ||
var url = ($(this).parents("tr"))[0].textContent.split(" ")[0]; | ||
if($(this).context.textContent === " Blacklist") | ||
{ | ||
add(url,"audit"); | ||
add(url,"black"); | ||
$("#gravityBtn").prop("disabled", false); | ||
} | ||
else | ||
{ | ||
auditUrl(url); | ||
} | ||
}); | ||
$("#domain-frequency tbody").on("click", "button", function() { | ||
var url = $(this) | ||
.parents("tr")[0] | ||
.textContent.split(" ")[0]; | ||
if ($(this).context.textContent === " Blacklist") { | ||
add(url, "audit"); | ||
add(url, "black"); | ||
$("#gravityBtn").prop("disabled", false); | ||
} else { | ||
auditUrl(url); | ||
} | ||
}); | ||
|
||
$("#ad-frequency tbody").on( "click", "button", function () { | ||
var url = ($(this).parents("tr"))[0].textContent.split(" ")[0].split(" ")[0]; | ||
if($(this).context.textContent === " Whitelist") | ||
{ | ||
add(url,"audit"); | ||
add(url,"white"); | ||
$("#gravityBtn").prop("disabled", false); | ||
} | ||
else | ||
{ | ||
auditUrl(url); | ||
} | ||
}); | ||
$("#ad-frequency tbody").on("click", "button", function() { | ||
var url = $(this) | ||
.parents("tr")[0] | ||
.textContent.split(" ")[0] | ||
.split(" ")[0]; | ||
if ($(this).context.textContent === " Whitelist") { | ||
add(url, "audit"); | ||
add(url, "white"); | ||
$("#gravityBtn").prop("disabled", false); | ||
} else { | ||
auditUrl(url); | ||
} | ||
}); | ||
}); | ||
|
||
function auditUrl(url) { | ||
if (auditList.indexOf(url) > -1) { | ||
return; | ||
} | ||
if (auditTimeout) { | ||
clearTimeout(auditTimeout); | ||
} | ||
auditList.push(url); | ||
// wait 3 seconds to see if more domains need auditing | ||
// and batch them all into a single request | ||
auditTimeout = setTimeout(function() { | ||
add(auditList.join(' '), "audit"); | ||
auditList = []; | ||
}, 3000); | ||
if (auditList.indexOf(url) > -1) { | ||
return; | ||
} | ||
|
||
if (auditTimeout) { | ||
clearTimeout(auditTimeout); | ||
} | ||
|
||
auditList.push(url); | ||
// wait 3 seconds to see if more domains need auditing | ||
// and batch them all into a single request | ||
auditTimeout = setTimeout(function() { | ||
add(auditList.join(" "), "audit"); | ||
auditList = []; | ||
}, 3000); | ||
} | ||
|
||
$("#gravityBtn").on("click", function() { | ||
window.location.replace("gravity.php?go"); | ||
window.location.replace("gravity.php?go"); | ||
}); |
Oops, something went wrong.