From da2d92ebd7b004a6b491a01270776824cf4e6922 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 17 Dec 2019 12:57:45 +0000 Subject: [PATCH] Prevent users from adding empty groups/domains/clients/adlists. Signed-off-by: DL6ER --- scripts/pi-hole/js/groups-adlists.js | 28 +++++++++++++++++++++++++--- scripts/pi-hole/js/groups-clients.js | 28 +++++++++++++++++++++++++--- scripts/pi-hole/js/groups-domains.js | 28 +++++++++++++++++++++++++--- scripts/pi-hole/js/groups.js | 28 +++++++++++++++++++++++++--- 4 files changed, 100 insertions(+), 12 deletions(-) diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index df5cf0ff..3f77cae0 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -10,19 +10,35 @@ function showAlert(type, icon, message) { info = $.notify({ type: "info", icon: "glyphicon glyphicon-time", - message: message + message: " " + message }); break; case "success": - msg = "Successfully " + message; + msg = " Successfully " + message; if (info) { info.update({ type: "success", icon: icon, message: msg }); } else { $.notify({ type: "success", icon: icon, message: msg }); } break; + case "warning": + msg = " " + message; + if (info) { + info.update({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } else { + $.notify({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } + break; case "error": - msg = "Error, something went wrong!
" + message + "
"; + msg = " Error, something went wrong!
" + message + "
"; if (info) { info.update({ type: "danger", @@ -192,6 +208,12 @@ function addAdlist() { var comment = $("#new_comment").val(); showAlert("info", "", "Adding adlist " + address + "..."); + + if (address.length === 0) { + showAlert("warning", "", "Please specify an adlist address"); + return; + } + $.ajax({ url: "scripts/pi-hole/php/groups.php", method: "post", diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index 23f47d53..6e4fc2f4 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -10,19 +10,35 @@ function showAlert(type, icon, message) { info = $.notify({ type: "info", icon: "glyphicon glyphicon-time", - message: message + message: " " + message }); break; case "success": - msg = "Successfully " + message; + msg = " Successfully " + message; if (info) { info.update({ type: "success", icon: icon, message: msg }); } else { $.notify({ type: "success", icon: icon, message: msg }); } break; + case "warning": + msg = " " + message; + if (info) { + info.update({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } else { + $.notify({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } + break; case "error": - msg = "Error, something went wrong!
" + message + "
"; + msg = " Error, something went wrong!
" + message + "
"; if (info) { info.update({ type: "danger", @@ -192,6 +208,12 @@ function addClient() { } showAlert("info", "", "Adding client " + ip + "..."); + + if (ip.length === 0) { + showAlert("warning", "", "Please specify a client"); + return; + } + $.ajax({ url: "scripts/pi-hole/php/groups.php", method: "post", diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index e2481e1f..bb3f70c1 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -10,19 +10,35 @@ function showAlert(type, icon, message) { info = $.notify({ type: "info", icon: "glyphicon glyphicon-time", - message: message + message: " " + message }); break; case "success": - msg = "Successfully " + message; + msg = " Successfully " + message; if (info) { info.update({ type: "success", icon: icon, message: msg }); } else { $.notify({ type: "success", icon: icon, message: msg }); } break; + case "warning": + msg = " " + message; + if (info) { + info.update({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } else { + $.notify({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } + break; case "error": - msg = "Error, something went wrong!
" + message + "
"; + msg = " Error, something went wrong!
" + message + "
"; if (info) { info.update({ type: "danger", @@ -211,6 +227,12 @@ function addDomain() { var comment = $("#new_comment").val(); showAlert("info", "", "Adding domain " + domain + "..."); + + if (domain.length === 0) { + showAlert("warning", "", "Please specify a domain"); + return; + } + $.ajax({ url: "scripts/pi-hole/php/groups.php", method: "post", diff --git a/scripts/pi-hole/js/groups.js b/scripts/pi-hole/js/groups.js index 0860e68e..213ed576 100644 --- a/scripts/pi-hole/js/groups.js +++ b/scripts/pi-hole/js/groups.js @@ -9,19 +9,35 @@ function showAlert(type, icon, message) { info = $.notify({ type: "info", icon: "glyphicon glyphicon-time", - message: message + message: " " + message }); break; case "success": - msg = "Successfully " + message; + msg = " Successfully " + message; if (info) { info.update({ type: "success", icon: icon, message: msg }); } else { $.notify({ type: "success", icon: icon, message: msg }); } break; + case "warning": + msg = " " + message; + if (info) { + info.update({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } else { + $.notify({ + type: "warning", + icon: "glyphicon glyphicon-warning-sign", + message: msg + }); + } + break; case "error": - msg = "Error, something went wrong!
" + message + "
"; + msg = " Error, something went wrong!
" + message + "
"; if (info) { info.update({ type: "danger", @@ -133,6 +149,12 @@ function addGroup() { var desc = $("#new_desc").val(); showAlert("info", "", "Adding group " + name + "..."); + + if (name.length === 0) { + showAlert("warning", "", "Please specify a group name"); + return; + } + $.ajax({ url: "scripts/pi-hole/php/groups.php", method: "post",