diff --git a/scripts/pi-hole/js/auditlog.js b/scripts/pi-hole/js/auditlog.js index c36802b7..9069b087 100644 --- a/scripts/pi-hole/js/auditlog.js +++ b/scripts/pi-hole/js/auditlog.js @@ -106,9 +106,15 @@ function updateTopLists() { function add(domain, list) { var token = $("#token").text(); $.ajax({ - url: "scripts/pi-hole/php/add.php", + url: "scripts/pi-hole/php/groups.php", method: "post", - data: { domain: domain, list: list, token: token }, + data: { + domain: domain, + list: list, + token: token, + action: "add_domain", + comment: "Added from Audit Log" + }, success: function () { updateTopLists(); }, diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index a0554f0d..0b29da02 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -92,16 +92,19 @@ function add(domain, list) { alSuccess.hide(); alFailure.hide(); $.ajax({ - url: "scripts/pi-hole/php/add.php", + url: "scripts/pi-hole/php/groups.php", method: "post", - data: { domain: domain, list: list, token: token }, + data: { + domain: domain, + list: list, + token: token, + action: "add_domain", + comment: "Added from Long-Term-Data Query Log" + }, success: function (response) { - if ( - response.indexOf("not a valid argument") !== -1 || - response.indexOf("is not a valid domain") !== -1 - ) { + if (!response.success) { alFailure.show(); - err.html(response); + err.html(response.message); alFailure.delay(4000).fadeOut(2000, function () { alFailure.hide(); }); diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 413d1bf6..7877d291 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -39,19 +39,21 @@ function add(domain, list) { // add Domain to List after Modal has faded in alertModal.one("shown.bs.modal", function () { $.ajax({ - url: "scripts/pi-hole/php/add.php", + url: "scripts/pi-hole/php/groups.php", method: "post", - data: { domain: domain, list: list, token: token }, + data: { + domain: domain, + list: list, + token: token, + action: "add_domain", + comment: "Added from Query Log" + }, success: function (response) { alProcessing.hide(); - if ( - response.indexOf("not a valid argument") !== -1 || - response.indexOf("is not a valid domain") !== -1 || - response.indexOf("Wrong token") !== -1 - ) { + if (!response.success) { // Failure alNetworkErr.hide(); - alCustomErr.html(response.replace("[✗]", "")); + alCustomErr.html(response.message); alFailure.fadeIn(1000); setTimeout(function () { alertModal.modal("hide"); diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php deleted file mode 100644 index a04fe189..00000000 --- a/scripts/pi-hole/php/add.php +++ /dev/null @@ -1,93 +0,0 @@ - - diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index bb4f7a79..7ba247c5 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -456,7 +456,13 @@ if ($_POST['action'] == 'get_groups') { throw new Exception('While preparing statement: ' . $db->lastErrorMsg()); } - $type = intval($_POST['type']); + if (isset($_POST['type'])) { + $type = intval($_POST['type']); + } else if (isset($_POST['list']) && $_POST['list'] === "white") { + $type = ListType::whitelist; + } else if (isset($_POST['list']) && $_POST['list'] === "black") { + $type = ListType::blacklist; + } if (!$stmt->bindValue(':type', $type, SQLITE3_TEXT)) { throw new Exception('While binding type: ' . $db->lastErrorMsg());