diff --git a/data.php b/data.php index 7828f9fe..88c26a86 100644 --- a/data.php +++ b/data.php @@ -1,13 +1,13 @@ Whitelist' ); } else{ - $(row).css('color','green') + $(row).css('color','green'); + $('td:eq(5)', row).html( '' ); } }, @@ -16,13 +18,86 @@ $(document).ready(function() { { "width" : "20%", "type": "date" }, { "width" : "10%" }, { "width" : "40%" }, - { "width" : "15%" }, - { "width" : "15%" } + { "width" : "10%" }, + { "width" : "10%" }, + { "width" : "10%" }, ], "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], - }) + "columnDefs": [ { + "targets": -1, + "data": null, + "defaultContent": '' + } ] + }); + $('#all-queries tbody').on( 'click', 'button', function () { + var data = tableApi.row( $(this).parents('tr') ).data(); + if (data[4] == "Pi-holed") + { + add(data[2],"white"); + } + else + { + add(data[2],"black"); + } + } ); } ); function refreshData() { tableApi.ajax.url("api.php?getAllQueries").load(); } + +function add(domain,list) { + var token = $("#token").html(); + var alInfo = $("#alInfo"); + var alList = $("#alList"); + var alDomain = $("#alDomain"); + alDomain.html(domain); + var alSuccess = $("#alSuccess"); + var alFailure = $("#alFailure"); + + if(list == "white") + { + alList.html("Whitelist"); + } + else + { + alList.html("Blacklist"); + } + + alInfo.show(); + alSuccess.hide(); + alFailure.hide(); + $.ajax({ + url: "php/add.php", + method: "post", + data: {"domain":domain, "list":list, "token":token}, + success: function(response) { + if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) + { + alFailure.show(); + alFailure.delay(1000).fadeOut(2000, function() { alFailure.hide(); }); + } + else + { + alSuccess.show(); + alSuccess.delay(1000).fadeOut(2000, function() { alSuccess.hide(); }); + } + alInfo.delay(1000).fadeOut(2000, function() { + alInfo.hide(); + alList.html(""); + alDomain.html(""); + }); + }, + error: function(jqXHR, exception) { + alFailure.show(); + alFailure.delay(1000).fadeOut(2000, function() { + alFailure.hide(); + }); + alInfo.delay(1000).fadeOut(2000, function() { + alInfo.hide(); + alList.html(""); + alDomain.html(""); + }); + } + }); +} diff --git a/queries.php b/queries.php index 07046bed..43549289 100644 --- a/queries.php +++ b/queries.php @@ -1,6 +1,15 @@ + + + + + + + +
@@ -26,6 +50,7 @@ Domain Client Status + Action @@ -35,6 +60,7 @@ Domain Client Status + Action