diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 5a0ad202..f2b7f2d4 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -361,7 +361,7 @@ function addDomain() { success: function (response) { utils.enableAll(); if (response.success) { - utils.showAlert("success", "fas fa-plus", "Successfully added " + domainRegex, domain); + utils.showAlert("success", "fas fa-plus", "Success!", response.message); domainEl.val(""); commentEl.val(""); wildcardEl.prop("checked", false); diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 83ab4969..0d352a04 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -449,6 +449,7 @@ if ($_POST['action'] == 'get_groups') { // Add new domain try { $domains = explode(' ', trim($_POST['domain'])); + $before = intval($db->querySingle("SELECT COUNT(*) FROM domainlist;")); $total = count($domains); $added = 0; $stmt = $db->prepare('REPLACE INTO domainlist (domain,type,comment) VALUES (:domain,:type,:comment)'); @@ -525,8 +526,23 @@ if ($_POST['action'] == 'get_groups') { $added++; } + $after = intval($db->querySingle("SELECT COUNT(*) FROM domainlist;")); + $difference = $after - $before; + if($total === 1) { + if($difference !== 1) { + $msg = "Not adding ". htmlentities(utf8_encode($domain)) . " as it is already on the list"; + } else { + $msg = "Added " . htmlentities(utf8_encode($domain)); + } + } else { + if($difference !== $total) { + $msg = "Added " . ($after-$before) . " out of ". $total . " domains (skipped duplicates)"; + } else { + $msg = "Added " . $total . " domains"; + } + } $reload = true; - JSON_success(); + JSON_success($msg); } catch (\Exception $ex) { JSON_error($ex->getMessage()); } @@ -865,5 +881,4 @@ if ($_POST['action'] == 'get_groups') { // Reload lists in pihole-FTL after having added something if ($reload) { $output = pihole_execute('restartdns reload-lists'); - echo implode("\n", $output); }