diff --git a/groups-adlists.php b/groups-adlists.php
index 9b806967..49ddb58b 100644
--- a/groups-adlists.php
+++ b/groups-adlists.php
@@ -72,6 +72,7 @@
+
+
+
+
" + 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(
@@ -83,10 +23,6 @@ function get_groups() {
);
}
-function datetime(date) {
- return moment.unix(Math.floor(date)).format("Y-MM-DD HH:mm:ss z");
-}
-
$(document).ready(function() {
$("#btnAdd").on("click", addAdlist);
@@ -120,9 +56,9 @@ function initTable() {
rowCallback: function(row, data) {
var tooltip =
"Added: " +
- datetime(data.date_added) +
+ utils.datetime(data.date_added) +
"\nLast modified: " +
- datetime(data.date_modified) +
+ utils.datetime(data.date_modified) +
"\nDatabase ID: " +
data.id;
$("td:eq(0)", row).html(
@@ -234,10 +170,11 @@ function addAdlist() {
var address = $("#new_address").val();
var comment = $("#new_comment").val();
- showAlert("info", "", "Adding adlist...", address);
+ utils.disableAll();
+ utils.showAlert("info", "", "Adding adlist...", address);
if (address.length === 0) {
- showAlert("warning", "", "Warning", "Please specify an adlist address");
+ utils.showAlert("warning", "", "Warning", "Please specify an adlist address");
return;
}
@@ -252,17 +189,24 @@ function addAdlist() {
token: token
},
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-plus", "Successfully added adlist", address);
+ utils.showAlert(
+ "success",
+ "glyphicon glyphicon-plus",
+ "Successfully added adlist",
+ address
+ );
$("#new_address").val("");
$("#new_comment").val("");
table.ajax.reload();
} else {
- showAlert("error", "", "Error while adding new adlist: ", response.message);
+ utils.showAlert("error", "", "Error while adding new adlist: ", response.message);
}
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while adding new adlist: ", jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while adding new adlist: ", jqXHR.responseText);
console.log(exception);
}
});
@@ -293,7 +237,8 @@ function editAdlist() {
not_done = "editing groups of";
}
- showAlert("info", "", "Editing adlist...", address);
+ utils.disableAll();
+ utils.showAlert("info", "", "Editing adlist...", address);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
@@ -308,15 +253,16 @@ function editAdlist() {
token: token
},
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert(
+ utils.showAlert(
"success",
"glyphicon glyphicon-pencil",
"Successfully " + done + " adlist ",
address
);
} else {
- showAlert(
+ utils.showAlert(
"error",
"",
"Error while " + not_done + " adlist with ID " + id,
@@ -325,7 +271,8 @@ function editAdlist() {
}
},
error: function(jqXHR, exception) {
- showAlert(
+ utils.enableAll();
+ utils.showAlert(
"error",
"",
"Error while " + not_done + " adlist with ID " + id,
@@ -341,23 +288,33 @@ function deleteAdlist() {
var tr = $(this).closest("tr");
var address = tr.find("#address").text();
- showAlert("info", "", "Deleting adlist...", address);
+ utils.disableAll();
+ utils.showAlert("info", "", "Deleting adlist...", address);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
method: "post",
dataType: "json",
data: { action: "delete_adlist", id: id, token: token },
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-trash", "Successfully deleted adlist ", address);
+ utils.showAlert(
+ "success",
+ "glyphicon glyphicon-trash",
+ "Successfully deleted adlist ",
+ address
+ );
table
.row(tr)
.remove()
.draw(false);
- } else showAlert("error", "", "Error while deleting adlist with ID " + id, response.message);
+ } else {
+ utils.showAlert("error", "", "Error while deleting adlist with ID " + id, response.message);
+ }
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while deleting adlist with ID " + id, jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while deleting adlist with ID " + id, jqXHR.responseText);
console.log(exception);
}
});
diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js
index bb07ea7b..71e0e585 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 utils: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(
@@ -242,10 +184,12 @@ function addClient() {
ip = $("#ip-custom").val();
}
- showAlert("info", "", "Adding client...", ip);
+ utils.disableAll();
+ utils.showAlert("info", "", "Adding client...", ip);
if (ip.length === 0) {
- showAlert("warning", "", "Warning", "Please specify a client IP address");
+ utils.enableAll();
+ utils.showAlert("warning", "", "Warning", "Please specify a client IP address");
return;
}
@@ -255,16 +199,18 @@ function addClient() {
dataType: "json",
data: { action: "add_client", ip: ip, token: token },
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-plus", "Successfully added client", ip);
+ utils.showAlert("success", "glyphicon glyphicon-plus", "Successfully added client", ip);
reload_client_suggestions();
table.ajax.reload();
} else {
- showAlert("error", "", "Error while adding new client", response.message);
+ utils.showAlert("error", "", "Error while adding new client", response.message);
}
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while adding new client", jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while adding new client", jqXHR.responseText);
console.log(exception);
}
});
@@ -290,26 +236,33 @@ function editClient() {
ip_name += " (" + name + ")";
}
- showAlert("info", "", "Editing client...", ip_name);
+ utils.disableAll();
+ utils.showAlert("info", "", "Editing client...", ip_name);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
method: "post",
dataType: "json",
data: { action: "edit_client", id: id, groups: groups, token: token },
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert(
+ utils.showAlert(
"success",
"glyphicon glyphicon-plus",
"Successfully " + done + " client",
ip_name
);
} else {
- showAlert("error", "Error while " + not_done + " client with ID " + id, response.message);
+ utils.showAlert(
+ "error",
+ "Error while " + not_done + " client with ID " + id,
+ response.message
+ );
}
},
error: function(jqXHR, exception) {
- showAlert(
+ utils.enableAll();
+ utils.showAlert(
"error",
"",
"Error while " + not_done + " client with ID " + id,
@@ -331,26 +284,34 @@ function deleteClient() {
ip_name += " (" + name + ")";
}
- showAlert("info", "", "Deleting client...", ip_name);
+ utils.disableAll();
+ utils.showAlert("info", "", "Deleting client...", ip_name);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
method: "post",
dataType: "json",
data: { action: "delete_client", id: id, token: token },
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-trash", "Successfully deleted client ", ip_name);
+ utils.showAlert(
+ "success",
+ "glyphicon glyphicon-trash",
+ "Successfully deleted client ",
+ ip_name
+ );
table
.row(tr)
.remove()
.draw(false);
reload_client_suggestions();
} else {
- showAlert("error", "", "Error while deleting client with ID " + id, response.message);
+ utils.showAlert("error", "", "Error while deleting client with ID " + id, response.message);
}
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while deleting client with ID " + id, jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while deleting client with ID " + id, jqXHR.responseText);
console.log(exception);
}
});
diff --git a/scripts/pi-hole/js/groups-common.js b/scripts/pi-hole/js/groups-common.js
new file mode 100644
index 00000000..8cff4727
--- /dev/null
+++ b/scripts/pi-hole/js/groups-common.js
@@ -0,0 +1,95 @@
+/* Pi-hole: A black hole for Internet advertisements
+ * (c) 2020 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 moment:false */
+
+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");
+}
+
+function disableAll() {
+ $("input").attr("disabled", true);
+ $("select").attr("disabled", true);
+ $("button").attr("disabled", true);
+ $("textarea").attr("disabled", true);
+}
+
+function enableAll() {
+ $("input").attr("disabled", false);
+ $("select").attr("disabled", false);
+ $("button").attr("disabled", false);
+ $("textarea").attr("disabled", false);
+}
+
+window.utils = (function() {
+ return {
+ showAlert: showAlert,
+ datetime: datetime,
+ disableAll: disableAll,
+ enableAll: enableAll
+ };
+})();
diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js
index 907e89f7..e48045e2 100644
--- a/scripts/pi-hole/js/groups-domains.js
+++ b/scripts/pi-hole/js/groups-domains.js
@@ -5,73 +5,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 */
+/* global utils:false */
var table;
var groups = [];
var token = $("#token").html();
-var info = null;
var GETDict = {};
-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(
"scripts/pi-hole/php/groups.php",
@@ -84,10 +24,6 @@ function get_groups() {
);
}
-function datetime(date) {
- return moment.unix(Math.floor(date)).format("Y-MM-DD HH:mm:ss z");
-}
-
$(document).ready(function() {
window.location.search
.substr(1)
@@ -129,9 +65,9 @@ function initTable() {
rowCallback: function(row, data) {
var tooltip =
"Added: " +
- datetime(data.date_added) +
+ utils.datetime(data.date_added) +
"\nLast modified: " +
- datetime(data.date_modified) +
+ utils.datetime(data.date_modified) +
"\nDatabase ID: " +
data.id;
$("td:eq(0)", row).html(
@@ -279,10 +215,12 @@ function addDomain() {
var type = $("#new_type").val();
var comment = $("#new_comment").val();
- showAlert("info", "", "Adding domain...", domain);
+ utils.disableAll();
+ utils.showAlert("info", "", "Adding domain...", domain);
if (domain.length === 0) {
- showAlert("warning", "", "Warning", "Please specify a domain");
+ utils.enableAll();
+ utils.showAlert("warning", "", "Warning", "Please specify a domain");
return;
}
@@ -298,15 +236,17 @@ function addDomain() {
token: token
},
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-plus", "Successfully added domain", domain);
+ utils.showAlert("success", "glyphicon glyphicon-plus", "Successfully added domain", domain);
$("#new_domain").val("");
$("#new_comment").val("");
table.ajax.reload();
- } else showAlert("error", "", "Error while adding new domain", response.message);
+ } else utils.showAlert("error", "", "Error while adding new domain", response.message);
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while adding new domain", jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while adding new domain", jqXHR.responseText);
console.log(exception);
}
});
@@ -344,7 +284,8 @@ function editDomain() {
not_done = "editing groups of";
}
- showAlert("info", "", "Editing domain...", name);
+ utils.disableAll();
+ utils.showAlert("info", "", "Editing domain...", name);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
method: "post",
@@ -359,15 +300,16 @@ function editDomain() {
token: token
},
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert(
+ utils.showAlert(
"success",
"glyphicon glyphicon-pencil",
"Successfully " + done + " domain",
domain
);
} else
- showAlert(
+ utils.showAlert(
"error",
"",
"Error while " + not_done + " domain with ID " + id,
@@ -375,7 +317,8 @@ function editDomain() {
);
},
error: function(jqXHR, exception) {
- showAlert(
+ utils.enableAll();
+ utils.showAlert(
"error",
"",
"Error while " + not_done + " domain with ID " + id,
@@ -391,23 +334,33 @@ function deleteDomain() {
var tr = $(this).closest("tr");
var domain = tr.find("#domain").text();
- showAlert("info", "", "Deleting domain...", domain);
+ utils.disableAll();
+ utils.showAlert("info", "", "Deleting domain...", domain);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
method: "post",
dataType: "json",
data: { action: "delete_domain", id: id, token: token },
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-trash", "Successfully deleted domain", domain);
+ utils.showAlert(
+ "success",
+ "glyphicon glyphicon-trash",
+ "Successfully deleted domain",
+ domain
+ );
table
.row(tr)
.remove()
.draw(false);
- } else showAlert("error", "", "Error while deleting domain with ID " + id, response.message);
+ } else {
+ utils.showAlert("error", "", "Error while deleting domain with ID " + id, response.message);
+ }
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while deleting domain with ID " + id, jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while deleting domain with ID " + id, jqXHR.responseText);
console.log(exception);
}
});
diff --git a/scripts/pi-hole/js/groups.js b/scripts/pi-hole/js/groups.js
index 2ea23c5b..0ffa3dcc 100644
--- a/scripts/pi-hole/js/groups.js
+++ b/scripts/pi-hole/js/groups.js
@@ -5,74 +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 utils: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");
-}
$(document).ready(function() {
$("#btnAdd").on("click", addGroup);
@@ -97,9 +33,9 @@ $(document).ready(function() {
rowCallback: function(row, data) {
var tooltip =
"Added: " +
- datetime(data.date_added) +
+ utils.datetime(data.date_added) +
"\nLast modified: " +
- datetime(data.date_modified) +
+ utils.datetime(data.date_modified) +
"\nDatabase ID: " +
data.id;
$("td:eq(0)", row).html(
@@ -195,10 +131,11 @@ function addGroup() {
var name = $("#new_name").val();
var desc = $("#new_desc").val();
- showAlert("info", "", "Adding group...", name);
+ utils.disableAll();
+ utils.showAlert("info", "", "Adding group...", name);
if (name.length === 0) {
- showAlert("warning", "", "Warning", "Please specify a group name");
+ utils.showAlert("warning", "", "Warning", "Please specify a group name");
return;
}
@@ -208,17 +145,19 @@ function addGroup() {
dataType: "json",
data: { action: "add_group", name: name, desc: desc, token: token },
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-plus", "Successfully added group", name);
+ utils.showAlert("success", "glyphicon glyphicon-plus", "Successfully added group", name);
$("#new_name").val("");
$("#new_desc").val("");
table.ajax.reload();
} else {
- showAlert("error", "", "Error while adding new group", response.message);
+ utils.showAlert("error", "", "Error while adding new group", response.message);
}
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while adding new group", jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while adding new group", jqXHR.responseText);
console.log(exception);
}
});
@@ -248,7 +187,8 @@ function editGroup() {
not_done = "editing description of";
}
- showAlert("info", "", "Editing group...", name);
+ utils.disableAll();
+ utils.showAlert("info", "", "Editing group...", name);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
method: "post",
@@ -262,10 +202,16 @@ function editGroup() {
token: token
},
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-pencil", "Successfully " + done + " group", name);
+ utils.showAlert(
+ "success",
+ "glyphicon glyphicon-pencil",
+ "Successfully " + done + " group",
+ name
+ );
} else {
- showAlert(
+ utils.showAlert(
"error",
"",
"Error while " + not_done + " group with ID " + id,
@@ -274,7 +220,8 @@ function editGroup() {
}
},
error: function(jqXHR, exception) {
- showAlert(
+ utils.enableAll();
+ utils.showAlert(
"error",
"",
"Error while " + not_done + " group with ID " + id,
@@ -290,25 +237,33 @@ function deleteGroup() {
var tr = $(this).closest("tr");
var name = tr.find("#name").val();
- showAlert("info", "", "Deleting group...", name);
+ utils.disableAll();
+ utils.showAlert("info", "", "Deleting group...", name);
$.ajax({
url: "scripts/pi-hole/php/groups.php",
method: "post",
dataType: "json",
data: { action: "delete_group", id: id, token: token },
success: function(response) {
+ utils.enableAll();
if (response.success) {
- showAlert("success", "glyphicon glyphicon-trash", "Successfully deleted group ", name);
+ utils.showAlert(
+ "success",
+ "glyphicon glyphicon-trash",
+ "Successfully deleted group ",
+ name
+ );
table
.row(tr)
.remove()
.draw(false);
} else {
- showAlert("error", "", "Error while deleting group with ID " + id, response.message);
+ utils.showAlert("error", "", "Error while deleting group with ID " + id, response.message);
}
},
error: function(jqXHR, exception) {
- showAlert("error", "", "Error while deleting group with ID " + id, jqXHR.responseText);
+ utils.enableAll();
+ utils.showAlert("error", "", "Error while deleting group with ID " + id, jqXHR.responseText);
console.log(exception);
}
});
diff --git a/scripts/pi-hole/js/ip-address-sorting.js b/scripts/pi-hole/js/ip-address-sorting.js
index 3055b3c1..21343fa2 100644
--- a/scripts/pi-hole/js/ip-address-sorting.js
+++ b/scripts/pi-hole/js/ip-address-sorting.js
@@ -14,6 +14,12 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
}
var i, item;
+ // Use the first IP in case there is a list of IPs
+ // for a given device
+ if (Array.isArray(a)) {
+ a = a[0];
+ }
+
var m = a.split("."),
n = a.split(":"),
x = "",
diff --git a/scripts/pi-hole/js/network.js b/scripts/pi-hole/js/network.js
index 2320dfcd..6203d81d 100644
--- a/scripts/pi-hole/js/network.js
+++ b/scripts/pi-hole/js/network.js
@@ -101,16 +101,22 @@ $(document).ready(function() {
// Set number of queries to localized string (add thousand separators)
$("td:eq(6)", row).html(data.numQueries.toLocaleString());
- var ips = data.ip;
- var shortips = ips;
- if (ips.length > MAXIPDISPLAY) {
- shortips = ips.slice(0, MAXIPDISPLAY - 1);
- shortips.push("...");
+ var ips = [];
+ var maxiter = Math.min(data.ip.length, MAXIPDISPLAY);
+ for (var index = 0; index < maxiter; index++) {
+ var ip = data.ip[index];
+ ips.push('' + ip + "");
}
- $("td:eq(0)", row).html(shortips.join("
"));
+ if (data.ip.length > MAXIPDISPLAY) {
+ // We hit the maximum above, add "..." to symbolize we would
+ // have more to show here
+ ips.push("...");
+ }
+
+ $("td:eq(0)", row).html(ips.join("
"));
$("td:eq(0)", row).hover(function() {
- this.title = ips.join("\n");
+ this.title = data.ip.join("\n");
});
// MAC + Vendor field if available
diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php
index 252e52cd..81a9c31b 100644
--- a/scripts/pi-hole/php/groups.php
+++ b/scripts/pi-hole/php/groups.php
@@ -49,7 +49,7 @@ if ($_POST['action'] == 'get_groups') {
}
echo json_encode(array('data' => $data));
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'add_group') {
// Add new group
@@ -72,9 +72,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'edit_group') {
// Edit group identified by ID
@@ -111,9 +111,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'delete_group') {
// Delete group identified by ID
@@ -142,9 +142,9 @@ if ($_POST['action'] == 'get_groups') {
}
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'get_clients') {
// List all available groups
@@ -193,7 +193,7 @@ if ($_POST['action'] == 'get_groups') {
echo json_encode(array('data' => $data));
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'get_unconfigured_clients') {
// List all available clients WITHOUT already configured clients
@@ -227,7 +227,7 @@ if ($_POST['action'] == 'get_groups') {
echo json_encode($ips);
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'add_client') {
// Add new client
@@ -246,9 +246,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'edit_client') {
// Edit client identified by ID
@@ -288,9 +288,9 @@ if ($_POST['action'] == 'get_groups') {
$db->query('COMMIT;');
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'delete_client') {
// Delete client identified by ID
@@ -322,9 +322,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'get_domains') {
// List all available groups
@@ -352,7 +352,7 @@ if ($_POST['action'] == 'get_groups') {
echo json_encode(array('data' => $data));
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'add_domain') {
// Add new domain
@@ -392,9 +392,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'edit_domain') {
// Edit domain identified by ID
@@ -469,9 +469,9 @@ if ($_POST['action'] == 'get_groups') {
$db->query('COMMIT;');
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'delete_domain') {
// Delete domain identified by ID
@@ -503,9 +503,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'get_adlists') {
// List all available groups
@@ -533,7 +533,7 @@ if ($_POST['action'] == 'get_groups') {
echo json_encode(array('data' => $data));
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'add_adlist') {
// Add new adlist
@@ -556,9 +556,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'edit_adlist') {
// Edit adlist identified by ID
@@ -629,9 +629,9 @@ if ($_POST['action'] == 'get_groups') {
$db->query('COMMIT;');
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} elseif ($_POST['action'] == 'delete_adlist') {
// Delete adlist identified by ID
@@ -663,9 +663,9 @@ if ($_POST['action'] == 'get_groups') {
}
$reload = true;
- return JSON_success();
+ JSON_success();
} catch (\Exception $ex) {
- return JSON_error($ex->getMessage());
+ JSON_error($ex->getMessage());
}
} else {
log_and_die('Requested action not supported!');
diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php
index a7524b77..8ab0922a 100644
--- a/scripts/pi-hole/php/savesettings.php
+++ b/scripts/pi-hole/php/savesettings.php
@@ -35,7 +35,7 @@ function istrue(&$argument) {
// Credit: http://stackoverflow.com/a/4694816/2087442
function validDomain($domain_name)
{
- $validChars = preg_match("/^([_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([a-z\d])*)*$/i", $domain_name);
+ $validChars = preg_match("/^([_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([_a-z\d])*)*$/i", $domain_name);
$lengthCheck = preg_match("/^.{1,253}$/", $domain_name);
$labelLengthCheck = preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name);
return ( $validChars && $lengthCheck && $labelLengthCheck ); //length of each label
@@ -44,7 +44,7 @@ function validDomain($domain_name)
function validDomainWildcard($domain_name)
{
// There has to be either no or at most one "*" at the beginning of a line
- $validChars = preg_match("/^((\*.)?[_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([a-z\d])*)*$/i", $domain_name);
+ $validChars = preg_match("/^((\*.)?[_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([_a-z\d])*)*$/i", $domain_name);
$lengthCheck = preg_match("/^.{1,253}$/", $domain_name);
$labelLengthCheck = preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name);
return ( $validChars && $lengthCheck && $labelLengthCheck ); //length of each label