Move escapeHtml to utils.

Signed-off-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
XhmikosR
2020-05-25 12:32:43 +03:00
parent ac8ece7d05
commit eab6485edb
7 changed files with 47 additions and 70 deletions
+1
View File
@@ -73,6 +73,7 @@
</div>
<!-- /.row -->
<script src="scripts/pi-hole/js/utils.js"></script>
<script src="scripts/pi-hole/js/auditlog.js"></script>
<?php
+1
View File
@@ -148,6 +148,7 @@ else
</div>
<script src="scripts/vendor/daterangepicker.js"></script>
<script src="scripts/pi-hole/js/utils.js"></script>
<script src="scripts/pi-hole/js/db_lists.js"></script>
<?php
+1
View File
@@ -294,6 +294,7 @@ else
<!-- /.row -->
<?php } ?>
<script src="scripts/pi-hole/js/utils.js"></script>
<script src="scripts/pi-hole/js/index.js"></script>
<?php
+4 -17
View File
@@ -5,24 +5,11 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
/* global utils:false */
// Define global variables
var auditTimeout = null;
// Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406
function escapeHtml(text) {
var map = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#039;"
};
return text.replace(/[&<>"']/g, function (m) {
return map[m];
});
}
function updateTopLists() {
$.getJSON("api.php?topItems=audit", function (data) {
if ("FTLnotrunning" in data) {
@@ -38,7 +25,7 @@ function updateTopLists() {
for (domain in data.top_queries) {
if (Object.prototype.hasOwnProperty.call(data.top_queries, domain)) {
// Sanitize domain
domain = escapeHtml(domain);
domain = utils.escapeHtml(domain);
url = '<a href="queries.php?domain=' + domain + '">' + domain + "</a>";
domaintable.append(
"<tr><td>" +
@@ -57,7 +44,7 @@ function updateTopLists() {
if (Object.prototype.hasOwnProperty.call(data.top_ads, domain)) {
var input = domain.split(" ");
// Sanitize domain
var printdomain = escapeHtml(input[0]);
var printdomain = utils.escapeHtml(input[0]);
if (input.length > 1) {
url =
'<a href="queries.php?domain=' +
+10 -25
View File
@@ -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 utils:false, moment:false */
var start__ = moment().subtract(6, "days");
var from = moment(start__).utc().valueOf() / 1000;
@@ -52,21 +52,6 @@ $(function () {
);
});
// Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406
function escapeHtml(text) {
var map = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#039;"
};
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) {
@@ -84,10 +69,10 @@ function updateTopClientsChart() {
for (client in data.top_sources) {
if (Object.prototype.hasOwnProperty.call(data.top_sources, client)) {
// Sanitize client
client = escapeHtml(client);
if (escapeHtml(client) !== client) {
client = utils.escapeHtml(client);
if (utils.escapeHtml(client) !== client) {
// Make a copy with the escaped index if necessary
data.top_sources[escapeHtml(client)] = data.top_sources[client];
data.top_sources[utils.escapeHtml(client)] = data.top_sources[client];
}
if (client.indexOf("|") !== -1) {
@@ -138,10 +123,10 @@ function updateTopDomainsChart() {
for (domain in data.top_domains) {
if (Object.prototype.hasOwnProperty.call(data.top_domains, domain)) {
// Sanitize domain
domain = escapeHtml(domain);
if (escapeHtml(domain) !== domain) {
domain = utils.escapeHtml(domain);
if (utils.escapeHtml(domain) !== domain) {
// Make a copy with the escaped index if necessary
data.top_domains[escapeHtml(domain)] = data.top_domains[domain];
data.top_domains[utils.escapeHtml(domain)] = data.top_domains[domain];
}
percentage = (data.top_domains[domain] / sum) * 100;
@@ -185,10 +170,10 @@ function updateTopAdsChart() {
for (ad in data.top_ads) {
if (Object.prototype.hasOwnProperty.call(data.top_ads, ad)) {
// Sanitize ad
ad = escapeHtml(ad);
if (escapeHtml(ad) !== ad) {
ad = utils.escapeHtml(ad);
if (utils.escapeHtml(ad) !== ad) {
// Make a copy with the escaped index if necessary
data.top_ads[escapeHtml(ad)] = data.top_ads[ad];
data.top_ads[utils.escapeHtml(ad)] = data.top_ads[ad];
}
percentage = (data.top_ads[ad] / sum) * 100;
+14 -28
View File
@@ -5,8 +5,9 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
/* global utils:false, Chart:false, updateSessionTimer:false */
// Define global variables
/* global Chart:false, updateSessionTimer:false */
var timeLineChart, clientsChart;
var queryTypePieChart, forwardDestinationPieChart;
@@ -528,21 +529,6 @@ function updateForwardDestinationsPie() {
});
}
// Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406
function escapeHtml(text) {
var map = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#039;"
};
return text.replace(/[&<>"']/g, function (m) {
return map[m];
});
}
function updateTopClientsChart() {
$.getJSON("api.php?summaryRaw&getQuerySources&topClientsBlocked", function (data) {
if ("FTLnotrunning" in data) {
@@ -556,12 +542,12 @@ function updateTopClientsChart() {
for (client in data.top_sources) {
if (Object.prototype.hasOwnProperty.call(data.top_sources, client)) {
// Sanitize client
if (escapeHtml(client) !== client) {
if (utils.escapeHtml(client) !== client) {
// Make a copy with the escaped index if necessary
data.top_sources[escapeHtml(client)] = data.top_sources[client];
data.top_sources[utils.escapeHtml(client)] = data.top_sources[client];
}
client = escapeHtml(client);
client = utils.escapeHtml(client);
if (client.indexOf("|") !== -1) {
idx = client.indexOf("|");
clientname = client.substr(0, idx);
@@ -602,12 +588,12 @@ function updateTopClientsChart() {
for (client in data.top_sources_blocked) {
if (Object.prototype.hasOwnProperty.call(data.top_sources_blocked, client)) {
// Sanitize client
if (escapeHtml(client) !== client) {
if (utils.escapeHtml(client) !== client) {
// Make a copy with the escaped index if necessary
data.top_sources_blocked[escapeHtml(client)] = data.top_sources_blocked[client];
data.top_sources_blocked[utils.escapeHtml(client)] = data.top_sources_blocked[client];
}
client = escapeHtml(client);
client = utils.escapeHtml(client);
if (client.indexOf("|") !== -1) {
idx = client.indexOf("|");
clientname = client.substr(0, idx);
@@ -674,12 +660,12 @@ function updateTopLists() {
for (domain in data.top_queries) {
if (Object.prototype.hasOwnProperty.call(data.top_queries, domain)) {
// Sanitize domain
if (escapeHtml(domain) !== domain) {
if (utils.escapeHtml(domain) !== domain) {
// Make a copy with the escaped index if necessary
data.top_queries[escapeHtml(domain)] = data.top_queries[domain];
data.top_queries[utils.escapeHtml(domain)] = data.top_queries[domain];
}
domain = escapeHtml(domain);
domain = utils.escapeHtml(domain);
urlText = domain === "" ? "." : domain;
url = '<a href="queries.php?domain=' + domain + '">' + urlText + "</a>";
percentage = (data.top_queries[domain] / data.dns_queries_today) * 100;
@@ -707,12 +693,12 @@ function updateTopLists() {
for (domain in data.top_ads) {
if (Object.prototype.hasOwnProperty.call(data.top_ads, domain)) {
// Sanitize domain
if (escapeHtml(domain) !== domain) {
if (utils.escapeHtml(domain) !== domain) {
// Make a copy with the escaped index if necessary
data.top_ads[escapeHtml(domain)] = data.top_ads[domain];
data.top_ads[utils.escapeHtml(domain)] = data.top_ads[domain];
}
domain = escapeHtml(domain);
domain = utils.escapeHtml(domain);
urlText = domain === "" ? "." : domain;
url = '<a href="queries.php?domain=' + domain + '">' + urlText + "</a>";
percentage = (data.top_ads[domain] / data.ads_blocked_today) * 100;
+16
View File
@@ -7,6 +7,21 @@
/* global moment:false */
// Credit: https://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406
function escapeHtml(text) {
var map = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#039;"
};
return text.replace(/[&<>"']/g, function (m) {
return map[m];
});
}
var info = null;
function showAlert(type, icon, title, message) {
var opts = {};
@@ -172,6 +187,7 @@ function stateLoadCallback(itemName) {
window.utils = (function () {
return {
escapeHtml: escapeHtml,
showAlert: showAlert,
datetime: datetime,
disableAll: disableAll,