From 912e2ddbd98aba8e8db321d9baedda3752615206 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 13 Dec 2019 15:29:42 +0000 Subject: [PATCH] Add Domain Group Management Signed-off-by: DL6ER --- groups-domains.php | 105 ++++++++++++ groups.php | 2 +- scripts/pi-hole/js/groups-clients.js | 12 +- scripts/pi-hole/js/groups-domains.js | 214 ++++++++++++++++++++++++ scripts/pi-hole/js/groups.js | 6 +- scripts/pi-hole/php/groups.php | 235 +++++++++++++++++++++++++++ 6 files changed, 563 insertions(+), 11 deletions(-) create mode 100644 groups-domains.php create mode 100644 scripts/pi-hole/js/groups-domains.js diff --git a/groups-domains.php b/groups-domains.php new file mode 100644 index 00000000..27f3046f --- /dev/null +++ b/groups-domains.php @@ -0,0 +1,105 @@ + + + + + + + + + + + + +
+
+
+ +
+

+ Add a new domain +

+
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+
+
+
+
+
+

+ List of configured domains +

+
+ +
+ + + + + + + + + + + +
DomainTypeStatusCommentGroup assignmentAction
+
+ +
+ +
+
+ + + + diff --git a/groups.php b/groups.php index 063cb444..d95213f3 100644 --- a/groups.php +++ b/groups.php @@ -31,7 +31,7 @@ Warning, see output below:

- +
diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index 43f31e4c..174f4cac 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -70,8 +70,8 @@ $(document).ready(function() { { data: null, width: "60px", "orderable": false } ], "drawCallback": function( settings ) { - $('.deleteClient').on('click', deleteClient); $('.editClient').on('click', editClient); + $('.deleteClient').on('click', deleteClient); }, "rowCallback": function( row, data ) { $('td:eq(1)', row).html( ""+data["ip"]+"" ); @@ -96,26 +96,22 @@ $(document).ready(function() { let button = ""; - if(data["id"] !== 0) - { - button += + "" + "  " + ""; - } $('td:eq(3)', row).html( button ); }, "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], "stateSave": true, stateSaveCallback: function(settings, data) { // Store current state in client's local storage area - localStorage.setItem("groups-table", JSON.stringify(data)); + localStorage.setItem("groups-clients-table", JSON.stringify(data)); }, stateLoadCallback: function(settings) { // Receive previous state from client's local storage area - var data = localStorage.getItem("groups-table"); + var data = localStorage.getItem("groups-clients-table"); // Return if not available if(data === null){ return null; } data = JSON.parse(data); diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js new file mode 100644 index 00000000..082af2dc --- /dev/null +++ b/scripts/pi-hole/js/groups-domains.js @@ -0,0 +1,214 @@ +var table, groups; + +function showAlert(type, message) +{ + var alertElement = null; + var messageElement = null; + + switch (type) + { + case 'info': alertElement = $('#alInfo'); break; + case 'success': alertElement = $('#alSuccess'); break; + case 'warning': alertElement = $('#alWarning'); messageElement = $('#warn'); break; + case 'error': alertElement = $('#alFailure'); messageElement = $('#err'); break; + default: return; + } + + if (messageElement != null) + messageElement.html(message); + + alertElement.fadeIn(200); + alertElement.delay(8000).fadeOut(2000); +} + +function get_groups() +{ + $.get("scripts/pi-hole/php/groups.php", { 'action': 'get_groups' }, + function(data) { + groups = data.data; + }, "json"); +} + +$.fn.redraw = function(){ + return $(this).each(function(){ + var redraw = this.offsetHeight; + }); +}; + +$(document).ready(function() { + + $('#btnAdd').on('click', addDomain); + + get_groups(); + + $('#select').on('change', function() { + $("#ip-custom").val(""); + $("#ip-custom").prop( "disabled" , $( "#select option:selected" ).val() !== "custom"); + }); + + table = $("#domainsTable").DataTable( { + "ajax": "scripts/pi-hole/php/groups.php?action=get_domains", + order: [[ 1, 'asc' ]], + columns: [ + { data: null }, + { data: null, "orderable": false }, + { data: null, "orderable": false }, + { data: null, "orderable": false }, + { data: null, "orderable": false }, + { data: null, width: "60px", "orderable": false } + ], + "drawCallback": function( settings ) { + $('.editDomain').on('click', editDomain); + $('.deleteDomain').on('click', deleteDomain); + }, + "rowCallback": function( row, data ) { + $('td:eq(0)', row).html( ''+data["domain"]+'' ); + + $('td:eq(1)', row).html( '' ); + + const disabled = data["enabled"] === 0; + $('td:eq(2)', row).html( '' ); + + $('td:eq(3)', row).html( '' ); + $('#comment', row).val(data["comment"]); + + $('td:eq(4)', row).empty(); + $('td:eq(4)', row).append( '' ); + var sel = $('#multiselect', row); + // Add all known groups + for (var i = 0; i < groups.length; i++) { + var extra = 'ID ' + groups[i].id; + if(!groups[i].enabled) + { + extra += ', disabled'; + } + sel.append($('