From a62b2a3cba4405973127021f9ca306fa09b8ca3f Mon Sep 17 00:00:00 2001 From: George Shaw Date: Thu, 30 Nov 2017 16:05:08 -0600 Subject: [PATCH 1/3] adding filtered IPs now works --- .../js/panelHandlers/security/filter_ip.js | 22 ++++++ .../js/panelHandlers/security/ipFiltering.js | 22 ------ .../js/panelHandlers/security/ip_list.js | 66 ++++++++++++++++++ account/gPanel.html | 16 ++++- pkg/api/ip/filter.go | 59 ++++++++++++++++ pkg/api/ip/list.go | 67 +++++++++++++++++++ pkg/api/ip/unfilter.go | 7 ++ pkg/database/database.go | 22 ++++-- pkg/database/ip_filtering.go | 49 ++++++++++++++ pkg/gpaccount/apihandler.go | 5 ++ pkg/networking/ip_address.go | 37 ++++++---- 11 files changed, 332 insertions(+), 40 deletions(-) create mode 100644 account/assets/js/panelHandlers/security/filter_ip.js delete mode 100644 account/assets/js/panelHandlers/security/ipFiltering.js create mode 100644 account/assets/js/panelHandlers/security/ip_list.js create mode 100644 pkg/api/ip/filter.go create mode 100644 pkg/api/ip/list.go create mode 100644 pkg/api/ip/unfilter.go create mode 100644 pkg/database/ip_filtering.go diff --git a/account/assets/js/panelHandlers/security/filter_ip.js b/account/assets/js/panelHandlers/security/filter_ip.js new file mode 100644 index 0000000..9ae04bb --- /dev/null +++ b/account/assets/js/panelHandlers/security/filter_ip.js @@ -0,0 +1,22 @@ +var ipModal = jQuery('.ip-filter-modal'); + +jQuery('._js_ip-filter-form').on('submit', function(e){ + e.preventDefault(); + + var requestData = {}; + requestData["ip"] = jQuery(this).find('input[name="ip"]').val(); + requestData["type"] = jQuery(this).find('input[name="type"]').val(); + + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.send(JSON.stringify(requestData)); + + xhr.onloadend = function() { + if (xhr.status == 204) { + ipModal.find('._js_currently-filtered-ips').append('
  • '+requestData["ip"]+'
  • '); + } + else { + alert("Something went wrong trying to filter that IP, please contact your administrator if problem persists."); + } + } +}); diff --git a/account/assets/js/panelHandlers/security/ipFiltering.js b/account/assets/js/panelHandlers/security/ipFiltering.js deleted file mode 100644 index 329c948..0000000 --- a/account/assets/js/panelHandlers/security/ipFiltering.js +++ /dev/null @@ -1,22 +0,0 @@ -var ipModal = jQuery('.ip-filter-modal'); - -jQuery('._js_ip-filtering-open').on('click', function(e){ - e.preventDefault(); - - var title; - switch(jQuery(this).attr('data')) { - case "general": - title = "General"; - break; - case "maintenance": - title = "Maintenance Mode"; - break; - default: - alert("Error, refresh and try again. If problem persists contact server administrator."); - return; - } - title += " IP Filtering"; - - ipModal.find('.modal-title').html(title); - ipModal.modal('show'); -}); diff --git a/account/assets/js/panelHandlers/security/ip_list.js b/account/assets/js/panelHandlers/security/ip_list.js new file mode 100644 index 0000000..47a93bd --- /dev/null +++ b/account/assets/js/panelHandlers/security/ip_list.js @@ -0,0 +1,66 @@ +var ipModal = jQuery('.ip-filter-modal'); + +jQuery('._js_ip-filtering-open').on('click', function(e){ + e.preventDefault(); + + var title; + switch(jQuery(this).attr('data')) { + case "general": + title = "General"; + ipModal.find('input[name="type"]').attr('value', 'general'); + ipModal.find('#filterIPHelp').html("Filtering this IP under the general filter type will disallow access to the website for all modes."); + break; + case "maintenance": + title = "Maintenance Mode"; + ipModal.find('input[name="type"]').attr('value', 'maintenance'); + ipModal.find('#filterIPHelp').html("Whitelisting this IP under the maintenance filter type will allow access to the website during maintenance mode."); + break; + default: + alert("Error, refresh and try again. If problem persists contact server administrator."); + return; + } + title += " IP Filtering"; + + ipModal.find('.modal-title').html(title); + + listFilteredIPs(jQuery(this).attr('data')); + + ipModal.modal('show'); +}); + +function listFilteredIPs(type) { + ipModal.find('._js_currently-filtered-ips').html(''); + + var requestData = {} + requestData["type"] = type; + + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'api/ip/list', true); + xhr.send(JSON.stringify(requestData)); + + xhr.onloadend = function() { + if(xhr.status == 200) { + if(xhr.response != undefined && xhr.response.length != 0) { + jsonResponse = JSON.parse(xhr.response) + console.log(xhr.response); + jQuery.each(jsonResponse, function(k, v) { + ipModal.find('._js_currently-filtered-ips').append("
  • "+v.ip+"
  • "); + }); + } + else { + ipModal.find('.modal-body').html("An error has occurred, please refresh. If problem persists contact your administrator."); + } + } + else if(xhr.status == 204) { + ipModal.find('._js_currently-filtered-ips').append("
  • No Filtered IPs Currently Exist.
  • "); + } + else { + if(xhr.response != undefined && xhr.response.length != 0) { + ipModal.find('.modal-body').html(xhr.response); + } + else { + ipModal.find('.modal-body').html("An error has occurred, please refresh. If problem persists contact your administrator."); + } + } + } +} diff --git a/account/gPanel.html b/account/gPanel.html index a7ba849..f789d19 100644 --- a/account/gPanel.html +++ b/account/gPanel.html @@ -59,7 +59,18 @@ diff --git a/pkg/api/ip/filter.go b/pkg/api/ip/filter.go index c46e7b8..d3370cb 100644 --- a/pkg/api/ip/filter.go +++ b/pkg/api/ip/filter.go @@ -29,7 +29,7 @@ func Filter(res http.ResponseWriter, req *http.Request, logger *log.Logger, dir return false } - if blockIPRequestData.Type != "maintenance" && blockIPRequestData.Type != "general" { + if blockIPRequestData.Type != "maintenance" && blockIPRequestData.Type != "block" { logger.Println(req.URL.Path + "::" + " filtered IP type is invalid") http.Error(res, err.Error(), http.StatusBadRequest) return false diff --git a/pkg/api/ip/list.go b/pkg/api/ip/list.go index c9429b1..2993a82 100644 --- a/pkg/api/ip/list.go +++ b/pkg/api/ip/list.go @@ -27,7 +27,7 @@ func List(res http.ResponseWriter, req *http.Request, logger *log.Logger, dir st return false } - if listIPRequestData.Type != "maintenance" && listIPRequestData.Type != "general" { + if listIPRequestData.Type != "maintenance" && listIPRequestData.Type != "block" { logger.Println(req.URL.Path + "::" + " filtered IP type is invalid") http.Error(res, err.Error(), http.StatusBadRequest) return false From 5aba3b60ddb26cd7b93db74043406dffb5053271 Mon Sep 17 00:00:00 2001 From: George Shaw Date: Thu, 30 Nov 2017 16:16:17 -0600 Subject: [PATCH 3/3] refactoring listing bundles on server --- pkg/api/bundle/list.go | 1 - .../document_root/assets/js/panelHandlers/bundles/manage.js | 6 +++--- server/document_root/gPanel.html | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/api/bundle/list.go b/pkg/api/bundle/list.go index b8d744b..6720c77 100644 --- a/pkg/api/bundle/list.go +++ b/pkg/api/bundle/list.go @@ -17,7 +17,6 @@ func List(res http.ResponseWriter, req *http.Request, logger *log.Logger, bundle } if len(bundles) <= 0 { - logger.Println("no bundles :: http response returns no content") res.WriteHeader(http.StatusNoContent) return true } diff --git a/server/document_root/assets/js/panelHandlers/bundles/manage.js b/server/document_root/assets/js/panelHandlers/bundles/manage.js index e736850..3590427 100644 --- a/server/document_root/assets/js/panelHandlers/bundles/manage.js +++ b/server/document_root/assets/js/panelHandlers/bundles/manage.js @@ -19,10 +19,9 @@ jQuery('._js_bundles-manage').on('click', function(e){ else { manageBundlesModal.find('.modal-body').html("An error has occurred. Please try again. If problem persists contact server administrator.") } - manageBundlesModal.modal('show'); } else if(xhr.status == 204) { - manageBundlesModal.modal('show'); + manageBundlesModal.find('.modal-body').html("

    No bundles current exist on the server.

    ") } else { if(xhr.response != undefined && xhr.response.length != 0) { @@ -31,7 +30,8 @@ jQuery('._js_bundles-manage').on('click', function(e){ else { manageBundlesModal.find('.modal-body').html(xhr.status + " Error!") } - manageBundlesModal.modal('show'); } } + + manageBundlesModal.modal('show'); }); diff --git a/server/document_root/gPanel.html b/server/document_root/gPanel.html index 5d34e64..2d3ec54 100644 --- a/server/document_root/gPanel.html +++ b/server/document_root/gPanel.html @@ -74,9 +74,7 @@ - +