From fe011fe8de639da66c62045e93f20ca6e09ecc89 Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Wed, 21 Nov 2018 14:50:27 +0500 Subject: [PATCH] dkim fix for subdomains --- cloudAPI/cloudManager.py | 58 + cloudAPI/views.py | 17 +- firewall/firewallManager.py | 32 +- firewall/static/firewall/firewall.js | 3444 +++++++++++++------------- install/install.py | 48 +- install/installCyberPanel.py | 19 +- mailServer/mailserverManager.py | 15 +- plogical/mailUtilities.py | 4 +- serverLogs/views.py | 25 +- static/firewall/firewall.js | 3444 +++++++++++++------------- 10 files changed, 3573 insertions(+), 3533 deletions(-) diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index 1a51e80ee..391d6d0b6 100644 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -15,6 +15,8 @@ from plogical.backupManager import BackupManager import userManagment.views as um from packages.packagesManager import PackagesManager from plogical.processUtilities import ProcessUtilities +from firewall.firewallManager import FirewallManager +from serverLogs.views import getLogsFromFile class CloudManager: def __init__(self, data=None, admin = None): @@ -674,3 +676,59 @@ class CloudManager: return HttpResponse(json_data) except BaseException, msg: return self.ajaxPre(0, str(msg)) + + def getSSHConfigs(self): + try: + fm = FirewallManager() + return fm.getSSHConfigs(self.admin.pk, self.data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def saveSSHConfigs(self): + try: + fm = FirewallManager() + return fm.saveSSHConfigs(self.admin.pk, self.data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def deleteSSHKey(self): + try: + fm = FirewallManager() + return fm.deleteSSHKey(self.admin.pk, self.data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def addSSHKey(self): + try: + fm = FirewallManager() + return fm.addSSHKey(self.admin.pk, self.data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def getCurrentRules(self): + try: + fm = FirewallManager() + return fm.getCurrentRules(self.admin.pk) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def addRule(self): + try: + fm = FirewallManager() + return fm.addRule(self.admin.pk, self.data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def deleteRule(self): + try: + fm = FirewallManager() + return fm.deleteRule(self.admin.pk, self.data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def getLogsFromFile(self, request): + try: + request.session['userID'] = self.admin.pk + return getLogsFromFile(request) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) diff --git a/cloudAPI/views.py b/cloudAPI/views.py index adeb31d5c..fe2ff8206 100644 --- a/cloudAPI/views.py +++ b/cloudAPI/views.py @@ -23,7 +23,6 @@ def router(request): else: return cm.verifyLogin(request)[1] - if controller == 'verifyLogin': return cm.verifyLogin(request)[1] elif controller == 'fetchWebsites': @@ -144,6 +143,22 @@ def router(request): return cm.submitApplicationInstall(request) elif controller == 'obtainServer': return cm.obtainServer(request) + elif controller == 'getSSHConfigs': + return cm.getSSHConfigs() + elif controller == 'saveSSHConfigs': + return cm.saveSSHConfigs() + elif controller == 'deleteSSHKey': + return cm.deleteSSHKey() + elif controller == 'addSSHKey': + return cm.addSSHKey() + elif controller == 'getCurrentRules': + return cm.getCurrentRules() + elif controller == 'addRule': + return cm.addRule() + elif controller == 'deleteRule': + return cm.deleteRule() + elif controller == 'getLogsFromFile': + return cm.getLogsFromFile(request) except BaseException, msg: cm = CloudManager(None) diff --git a/firewall/firewallManager.py b/firewall/firewallManager.py index d34581a31..2e611104d 100644 --- a/firewall/firewallManager.py +++ b/firewall/firewallManager.py @@ -69,7 +69,8 @@ class FirewallManager: checker = 0 for items in rules: - dic = {'id': items.id, + dic = { + 'id': items.id, 'name': items.name, 'proto': items.proto, 'port': items.port, @@ -83,11 +84,11 @@ class FirewallManager: json_data = json_data + ',' + json.dumps(dic) json_data = json_data + ']' - final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data}) + final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data}) return HttpResponse(final_json) except BaseException, msg: - final_dic = {'fetchStatus': 0, 'error_message': str(msg)} + final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) @@ -111,12 +112,12 @@ class FirewallManager: newFWRule = FirewallRules(name=ruleName, proto=ruleProtocol, port=rulePort, ipAddress=ruleIP) newFWRule.save() - final_dic = {'add_status': 1, 'error_message': "None"} + final_dic = {'status': 1, 'add_status': 1, 'error_message': "None"} final_json = json.dumps(final_dic) return HttpResponse(final_json) except BaseException, msg: - final_dic = {'add_status': 0, 'error_message': str(msg)} + final_dic = {'status': 0, 'add_status': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) @@ -141,12 +142,12 @@ class FirewallManager: delRule = FirewallRules.objects.get(id=ruleID) delRule.delete() - final_dic = {'delete_status': 1, 'error_message': "None"} + final_dic = {'status': 1, 'delete_status': 1, 'error_message': "None"} final_json = json.dumps(final_dic) return HttpResponse(final_json) except BaseException, msg: - final_dic = {'delete_status': 0, 'error_message': str(msg)} + final_dic = {'status': 0, 'delete_status': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) @@ -325,7 +326,7 @@ class FirewallManager: res = subprocess.call(cmd) - final_dic = {'permitRootLogin': permitRootLogin, 'sshPort': sshPort} + final_dic = {'status': 1, 'permitRootLogin': permitRootLogin, 'sshPort': sshPort} final_json = json.dumps(final_dic) return HttpResponse(final_json) else: @@ -406,7 +407,7 @@ class FirewallManager: try: updateFW = FirewallRules.objects.get(name="SSHCustom") - FirewallUtilities.deleteRule("tcp", updateFW.port) + FirewallUtilities.deleteRule("tcp", updateFW.port, "0.0.0.0/0") updateFW.port = sshPort updateFW.save() except: @@ -467,12 +468,12 @@ class FirewallManager: ## - final_dic = {'saveStatus': 1} + final_dic = {'status': 1, 'saveStatus': 1} final_json = json.dumps(final_dic) return HttpResponse(final_json) except BaseException, msg: - final_dic = {'saveStatus': 0, 'error_message': str(msg)} + final_dic = {'status': 0 ,'saveStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) @@ -522,12 +523,12 @@ class FirewallManager: ## - final_dic = {'delete_status': 1} + final_dic = {'status': 1, 'delete_status': 1} final_json = json.dumps(final_dic) return HttpResponse(final_json) except BaseException, msg: - final_dic = {'delete_status': 0, 'error_mssage': str(msg)} + final_dic = {'status': 0, 'delete_status': 0, 'error_mssage': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) @@ -584,13 +585,12 @@ class FirewallManager: ## - - final_dic = {'add_status': 1} + final_dic = {'status': 1, 'add_status': 1} final_json = json.dumps(final_dic) return HttpResponse(final_json) except BaseException, msg: - final_dic = {'add_status': 0, 'error_mssage': str(msg)} + final_dic = {'status': 0, 'add_status': 0, 'error_mssage': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) diff --git a/firewall/static/firewall/firewall.js b/firewall/static/firewall/firewall.js index bb0e4a07f..441d0daf0 100644 --- a/firewall/static/firewall/firewall.js +++ b/firewall/static/firewall/firewall.js @@ -5,7 +5,92 @@ /* Java script code to ADD Firewall Rules */ -app.controller('firewallController', function($scope,$http) { +app.controller('firewallController', function ($scope, $http) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + $scope.rulesDetails = false; + + firewallStatus(); + + populateCurrentRecords(); + + $scope.addRule = function () { + + $scope.rulesLoading = false; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + + url = "/firewall/addRule"; + + + var ruleName = $scope.ruleName; + var ruleProtocol = $scope.ruleProtocol; + var rulePort = $scope.rulePort; + + + var data = { + ruleName: ruleName, + ruleProtocol: ruleProtocol, + rulePort: rulePort, + ruleIP: $scope.ruleIP, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.add_status == 1) { + + + populateCurrentRecords(); + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = false; + $scope.couldNotConnect = true; + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = false; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { $scope.rulesLoading = true; $scope.actionFailed = true; @@ -13,531 +98,410 @@ app.controller('firewallController', function($scope,$http) { $scope.canNotAddRule = true; $scope.ruleAdded = true; - $scope.couldNotConnect = true; - $scope.rulesDetails = false; + $scope.couldNotConnect = false; + } - firewallStatus(); + }; + + function populateCurrentRecords() { + + $scope.rulesLoading = false; + $scope.actionFailed = true; + $scope.actionSuccess = true; - populateCurrentRecords(); + url = "/firewall/getCurrentRules"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $scope.addRule = function(){ + function ListInitialDatas(response) { + if (response.data.fetchStatus === 1) { + $scope.rules = JSON.parse(response.data.data); + $scope.rulesLoading = true; + } + else { + $scope.rulesLoading = true; + $scope.errorMessage = response.data.error_message; + } + } - $scope.rulesLoading = false; - $scope.actionFailed = true; - $scope.actionSuccess = true; + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; + } + + }; + + $scope.deleteRule = function (id, proto, port, ruleIP) { + + $scope.rulesLoading = false; + + url = "/firewall/deleteRule"; + + var data = { + id: id, + proto: proto, + port: port, + ruleIP: ruleIP + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - url = "/firewall/addRule"; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - var ruleName = $scope.ruleName; - var ruleProtocol = $scope.ruleProtocol; - var rulePort = $scope.rulePort; + function ListInitialDatas(response) { - - var data = { - ruleName:ruleName, - ruleProtocol:ruleProtocol, - rulePort:rulePort, - ruleIP:$scope.ruleIP, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + if (response.data.delete_status === 1) { - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + populateCurrentRecords(); + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; - function ListInitialDatas(response) { + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = false; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = true; + $scope.errorMessage = response.data.error_message; - if(response.data.add_status == 1){ + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; - populateCurrentRecords(); - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = false; - $scope.couldNotConnect = true; + } - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = false; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; + }; - $scope.errorMessage = response.data.error_message; - } + $scope.reloadFireWall = function () { + + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = false; + + url = "/firewall/reloadFirewall"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.reload_status == 1) { + + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = false; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = false; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; + + + } + + + }; + + $scope.startFirewall = function () { + + + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = false; + + url = "/firewall/startFirewall"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.start_status == 1) { + + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = false; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesDetails = false; + + firewallStatus(); + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = false; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; + + + } + + + }; + + + $scope.stopFirewall = function () { + + + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = false; + + url = "/firewall/stopFirewall"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.stop_status == 1) { + + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = false; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesDetails = true; + + firewallStatus(); + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = false; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; + + + } + + + }; + + + function firewallStatus() { + + + url = "/firewall/firewallStatus"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.status == 1) { + + if (response.data.firewallStatus == 1) { + $scope.rulesDetails = false; + $scope.status = "ON"; } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - + else { + $scope.rulesDetails = true; + $scope.status = "OFF"; } + } + else { - }; + $scope.rulesDetails = true; + $scope.status = "OFF"; + } + } - function populateCurrentRecords(){ - - $scope.rulesLoading = false; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - - url = "/firewall/getCurrentRules"; - - var data = { - - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.fetchStatus == 1){ - - $scope.rules = JSON.parse(response.data.data); - $scope.rulesLoading = true; - - } - else{ - $scope.rulesLoading = true; - $scope.errorMessage = response.data.error_message; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - - } - - }; - - - - $scope.deleteRule = function(id,proto,port,ruleIP){ - - - - - $scope.rulesLoading = false; - - url = "/firewall/deleteRule"; - - var data = { - id:id, - proto:proto, - port:port, - ruleIP:ruleIP, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.delete_status == 1){ - - - populateCurrentRecords(); - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = false; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = true; - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - - } - - - }; - - - $scope.reloadFireWall = function(){ - - - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = false; - - url = "/firewall/reloadFirewall"; - - var data = { - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.reload_status == 1){ - - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = false; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = false; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - } - - - }; - - $scope.startFirewall = function(){ - - - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = false; - - url = "/firewall/startFirewall"; - - var data = { - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.start_status == 1){ - - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = false; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesDetails = false; - - firewallStatus(); - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = false; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - } - - - }; - - - $scope.stopFirewall = function(){ - - - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = false; - - url = "/firewall/stopFirewall"; - - var data = { - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.stop_status == 1){ - - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = false; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesDetails = true; - - firewallStatus(); - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = false; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - } - - - }; - - - function firewallStatus(){ - - - - url = "/firewall/firewallStatus"; - - var data = { - - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.status == 1){ - - if(response.data.firewallStatus == 1){ - $scope.rulesDetails = false; - $scope.status = "ON"; - } - else{ - $scope.rulesDetails = true; - $scope.status = "OFF"; - } - } - else{ - - $scope.rulesDetails = true; - $scope.status = "OFF"; - } - - - } - function cantLoadInitialDatas(response) { - - $scope.couldNotConnect = false; - - - } - - }; + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + } + }; }); @@ -546,274 +510,272 @@ app.controller('firewallController', function($scope,$http) { /* Java script code to Secure SSH */ -app.controller('secureSSHCTRL', function($scope,$http) { +app.controller('secureSSHCTRL', function ($scope, $http) { - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - $scope.keyDeleted = true; - $scope.keyBox = true; - $scope.showKeyBox = false; - $scope.saveKeyBtn = true; + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + $scope.keyDeleted = true; + $scope.keyBox = true; + $scope.showKeyBox = false; + $scope.saveKeyBtn = true; - $scope.addKey = function(){ + $scope.addKey = function () { + $scope.saveKeyBtn = false; + $scope.showKeyBox = true; + $scope.keyBox = false; + }; + + + getSSHConfigs(); + populateCurrentKeys(); + + // Checking root login + + var rootLogin = false; + + $('#rootLogin').change(function () { + rootLogin = $(this).prop('checked'); + }); + + + function getSSHConfigs() { + + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = false; + + url = "/firewall/getSSHConfigs"; + + var data = { + type: "1", + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.sshPort = response.data.sshPort; + + if (response.data.permitRootLogin == 1) { + $('#rootLogin').bootstrapToggle('on'); + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + } + else { + $scope.errorMessage = response.data.error_message; + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + + } + + } + + $scope.saveChanges = function () { + + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = false; + + url = "/firewall/saveSSHConfigs"; + + var data = { + type: "1", + sshPort: $scope.sshPort, + rootLogin: rootLogin + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.saveStatus == 1) { + $scope.couldNotSave = true; + $scope.detailsSaved = false; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + } + else { + + $scope.couldNotSave = false; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + + } + }; + + + function populateCurrentKeys() { + + url = "/firewall/getSSHConfigs"; + + var data = { + type: "2" + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + $scope.records = JSON.parse(response.data.data); + } + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + } + + + } + + $scope.deleteKey = function (key) { + + $scope.secureSSHLoading = false; + + url = "/firewall/deleteSSHKey"; + + var data = { + key: key, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.delete_status === 1) { + $scope.secureSSHLoading = true; + $scope.keyDeleted = false; + populateCurrentKeys(); + } + else { + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + + } + + + } + + + $scope.saveKey = function (key) { + + $scope.secureSSHLoading = false; + + url = "/firewall/addSSHKey"; + + var data = { + key: $scope.keyData, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.add_status === 1) { + $scope.secureSSHLoading = true; + $scope.saveKeyBtn = true; + $scope.showKeyBox = false; + $scope.keyBox = true; + + + populateCurrentKeys(); + } + else { + $scope.secureSSHLoading = true; $scope.saveKeyBtn = false; $scope.showKeyBox = true; - $scope.keyBox = false; - }; + $scope.keyBox = true; + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + } + } - getSSHConfigs(); - populateCurrentKeys(); + function cantLoadInitialDatas(response) { + $scope.secureSSHLoading = true; + $scope.saveKeyBtn = false; + $scope.showKeyBox = true; + $scope.keyBox = true; + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; - // Checking root login + } - var rootLogin = false; - $('#rootLogin').change(function() { - rootLogin = $(this).prop('checked'); - }); - - - function getSSHConfigs(){ - - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = false; - - url = "/firewall/getSSHConfigs"; - - var data = { - type:"1", - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.sshPort = response.data.sshPort; - - if(response.data.permitRootLogin == 1){ - $('#rootLogin').bootstrapToggle('on'); - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - } - else{ - $scope.errorMessage = response.data.error_message; - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - - } - - }; - - $scope.saveChanges = function () { - - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = false; - - url = "/firewall/saveSSHConfigs"; - - var data = { - type:"1", - sshPort:$scope.sshPort, - rootLogin:rootLogin, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.saveStatus == 1){ - $scope.couldNotSave = true; - $scope.detailsSaved = false; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - } - else{ - - $scope.couldNotSave = false; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - - $scope.errorMessage = response.data.error_message; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - - } - }; - - - function populateCurrentKeys(){ - - url = "/firewall/getSSHConfigs"; - - var data = { - type:"2", - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.status == 1){ - $scope.records = JSON.parse(response.data.data); - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - - } - - - } - - $scope.deleteKey = function(key){ - - $scope.secureSSHLoading = false; - - url = "/firewall/deleteSSHKey"; - - var data = { - key:key, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.delete_status === 1){ - $scope.secureSSHLoading = true; - $scope.keyDeleted = false; - populateCurrentKeys(); - } - else{ - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - - } - - - } - - - $scope.saveKey = function(key){ - - $scope.secureSSHLoading = false; - - url = "/firewall/addSSHKey"; - - var data = { - key:$scope.keyData, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.add_status === 1){ - $scope.secureSSHLoading = true; - $scope.saveKeyBtn = true; - $scope.showKeyBox = false; - $scope.keyBox = true; - - - populateCurrentKeys(); - } - else{ - $scope.secureSSHLoading = true; - $scope.saveKeyBtn = false; - $scope.showKeyBox = true; - $scope.keyBox = true; - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.secureSSHLoading = true; - $scope.saveKeyBtn = false; - $scope.showKeyBox = true; - $scope.keyBox = true; - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - - } - - - } + } }); @@ -821,736 +783,739 @@ app.controller('secureSSHCTRL', function($scope,$http) { /* Java script code for ModSec */ -app.controller('modSec', function($scope, $http, $timeout, $window) { +app.controller('modSec', function ($scope, $http, $timeout, $window) { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + $scope.installModSec = function () { - $scope.installModSec = function(){ + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + url = "/firewall/installModSec"; - url = "/firewall/installModSec"; + var data = {}; - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - if(response.data.installModSec === 1){ + if (response.data.installModSec === 1) { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - getRequestStatus(); + getRequestStatus(); + } + else { + $scope.errorMessage = response.data.error_message; + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = false; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + } + + } + + function cantLoadInitialDatas(response) { + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + } + + }; + + function getRequestStatus() { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + url = "/firewall/installStatusModSec"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.abort === 0) { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + $scope.requestData = response.data.requestStatus; + $timeout(getRequestStatus, 1000); + } + else { + // Notifications + $timeout.cancel(); + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + + $scope.requestData = response.data.requestStatus; + + if (response.data.installed === 0) { + $scope.installationFailed = false; + $scope.errorMessage = response.data.error_message; + } else { + $scope.modSecSuccessfullyInstalled = false; + $timeout(function () { + $window.location.reload(); + }, 3000); + } + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + + } + + } + + ///// ModSec configs + + var modsecurity_status = false; + var SecAuditEngine = false; + var SecRuleEngine = false; + + + $('#modsecurity_status').change(function () { + modsecurity_status = $(this).prop('checked'); + }); + + $('#SecAuditEngine').change(function () { + SecAuditEngine = $(this).prop('checked'); + }); + + + $('#SecRuleEngine').change(function () { + SecRuleEngine = $(this).prop('checked'); + }); + + fetchModSecSettings(); + function fetchModSecSettings() { + + $scope.modsecLoading = false; + + $('#modsecurity_status').bootstrapToggle('off'); + $('#SecAuditEngine').bootstrapToggle('off'); + $('#SecRuleEngine').bootstrapToggle('off'); + + url = "/firewall/fetchModSecSettings"; + + var phpSelection = $scope.phpSelection; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.modsecLoading = true; + + if (response.data.fetchStatus === 1) { + + if (response.data.installed === 1) { + + if (response.data.modsecurity === 1) { + $('#modsecurity_status').bootstrapToggle('on'); } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = false; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; + if (response.data.SecAuditEngine === 1) { + $('#SecAuditEngine').bootstrapToggle('on'); + } + if (response.data.SecRuleEngine === 1) { + $('#SecRuleEngine').bootstrapToggle('on'); } - } - function cantLoadInitialDatas(response) { - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - } - - }; - - function getRequestStatus(){ - - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - - url = "/firewall/installStatusModSec"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.abort === 0){ - - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - - $scope.requestData = response.data.requestStatus; - $timeout(getRequestStatus,1000); - } - else{ - // Notifications - $timeout.cancel(); - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - - $scope.requestData = response.data.requestStatus; - - if(response.data.installed === 0) { - $scope.installationFailed = false; - $scope.errorMessage = response.data.error_message; - }else{ - $scope.modSecSuccessfullyInstalled = false; - $timeout(function() { $window.location.reload(); }, 3000); - } - - } - - } - function cantLoadInitialDatas(response) { - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - + $scope.SecDebugLogLevel = response.data.SecDebugLogLevel; + $scope.SecAuditLogParts = response.data.SecAuditLogParts; + $scope.SecAuditLogRelevantStatus = response.data.SecAuditLogRelevantStatus; + $scope.SecAuditLogType = response.data.SecAuditLogType; } - } + } - ///// ModSec configs + } - var modsecurity_status = false; - var SecAuditEngine = false; - var SecRuleEngine = false; + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + } + + } - $('#modsecurity_status').change(function() { - modsecurity_status = $(this).prop('checked'); - }); + ///// - $('#SecAuditEngine').change(function() { - SecAuditEngine = $(this).prop('checked'); - }); + /// Save ModSec Changes + + $scope.failedToSave = true; + $scope.successfullySaved = true; + + $scope.saveModSecConfigurations = function () { + + $scope.failedToSave = true; + $scope.successfullySaved = true; + $scope.modsecLoading = false; + $scope.couldNotConnect = true; - $('#SecRuleEngine').change(function() { - SecRuleEngine = $(this).prop('checked'); - }); + url = "/firewall/saveModSecConfigurations"; - fetchModSecSettings(); - function fetchModSecSettings(){ + var data = { + modsecurity_status: modsecurity_status, + SecAuditEngine: SecAuditEngine, + SecRuleEngine: SecRuleEngine, + SecDebugLogLevel: $scope.SecDebugLogLevel, + SecAuditLogParts: $scope.SecAuditLogParts, + SecAuditLogRelevantStatus: $scope.SecAuditLogRelevantStatus, + SecAuditLogType: $scope.SecAuditLogType, + }; - $scope.modsecLoading = false; - - $('#modsecurity_status').bootstrapToggle('off'); - $('#SecAuditEngine').bootstrapToggle('off'); - $('#SecRuleEngine').bootstrapToggle('off'); - - url = "/firewall/fetchModSecSettings"; - - var phpSelection = $scope.phpSelection; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { - - $scope.modsecLoading = true; - - if(response.data.fetchStatus === 1){ - - if(response.data.installed === 1) { - - if (response.data.modsecurity === 1) { - $('#modsecurity_status').bootstrapToggle('on'); - } - if (response.data.SecAuditEngine === 1) { - $('#SecAuditEngine').bootstrapToggle('on'); - } - if (response.data.SecRuleEngine === 1) { - $('#SecRuleEngine').bootstrapToggle('on'); - } - - $scope.SecDebugLogLevel = response.data.SecDebugLogLevel; - $scope.SecAuditLogParts = response.data.SecAuditLogParts; - $scope.SecAuditLogRelevantStatus = response.data.SecAuditLogRelevantStatus; - $scope.SecAuditLogType = response.data.SecAuditLogType; - - } - - } - - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - } - - } + function ListInitialDatas(response) { - ///// + if (response.data.saveStatus === 1) { - /// Save ModSec Changes + $scope.failedToSave = true; + $scope.successfullySaved = false; + $scope.modsecLoading = true; + $scope.couldNotConnect = true; - $scope.failedToSave = true; - $scope.successfullySaved = true; + } + else { + $scope.errorMessage = response.data.error_message; - $scope.saveModSecConfigurations = function () { + $scope.failedToSave = false; + $scope.successfullySaved = true; + $scope.modsecLoading = true; + $scope.couldNotConnect = true; + } - $scope.failedToSave = true; - $scope.successfullySaved = true; - $scope.modsecLoading = false; - $scope.couldNotConnect = true; + } + + function cantLoadInitialDatas(response) { + $scope.failedToSave = true; + $scope.successfullySaved = false; + $scope.modsecLoading = true; + $scope.couldNotConnect = true; + } - url = "/firewall/saveModSecConfigurations"; - - var data = { - modsecurity_status:modsecurity_status, - SecAuditEngine:SecAuditEngine, - SecRuleEngine:SecRuleEngine, - SecDebugLogLevel:$scope.SecDebugLogLevel, - SecAuditLogParts:$scope.SecAuditLogParts, - SecAuditLogRelevantStatus:$scope.SecAuditLogRelevantStatus, - SecAuditLogType:$scope.SecAuditLogType, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.saveStatus === 1){ - - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.modsecLoading = true; - $scope.couldNotConnect = true; - - } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.failedToSave = false; - $scope.successfullySaved = true; - $scope.modsecLoading = true; - $scope.couldNotConnect = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.modsecLoading = true; - $scope.couldNotConnect = true; - } - - - }; + }; }); -app.controller('modSecRules', function($scope, $http) { +app.controller('modSecRules', function ($scope, $http) { - $scope.modsecLoading = true; - $scope.rulesSaved = true; - $scope.couldNotConnect = true; - $scope.couldNotSave = true; + $scope.modsecLoading = true; + $scope.rulesSaved = true; + $scope.couldNotConnect = true; + $scope.couldNotSave = true; - fetchModSecRules(); - function fetchModSecRules(){ + fetchModSecRules(); + function fetchModSecRules() { - $scope.modsecLoading = false; - $scope.modsecLoading = true; - $scope.rulesSaved = true; - $scope.couldNotConnect = true; + $scope.modsecLoading = false; + $scope.modsecLoading = true; + $scope.rulesSaved = true; + $scope.couldNotConnect = true; - url = "/firewall/fetchModSecRules"; + url = "/firewall/fetchModSecRules"; - var data = {}; + var data = {}; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - $scope.modsecLoading = true; + $scope.modsecLoading = true; - if(response.data.modSecInstalled === 1){ + if (response.data.modSecInstalled === 1) { - $scope.currentModSecRules = response.data.currentModSecRules; + $scope.currentModSecRules = response.data.currentModSecRules; - } + } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - } + } - } + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + } - $scope.saveModSecRules = function(){ + } - $scope.modsecLoading = false; - $scope.rulesSaved = true; - $scope.couldNotConnect = true; - $scope.couldNotSave = true; + $scope.saveModSecRules = function () { + + $scope.modsecLoading = false; + $scope.rulesSaved = true; + $scope.couldNotConnect = true; + $scope.couldNotSave = true; - url = "/firewall/saveModSecRules"; + url = "/firewall/saveModSecRules"; - var data = { - modSecRules:$scope.currentModSecRules - }; + var data = { + modSecRules: $scope.currentModSecRules + }; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - $scope.modsecLoading = true; + $scope.modsecLoading = true; - if(response.data.saveStatus === 1){ + if (response.data.saveStatus === 1) { - $scope.rulesSaved = false; - $scope.couldNotConnect = true; - $scope.couldNotSave = true; + $scope.rulesSaved = false; + $scope.couldNotConnect = true; + $scope.couldNotSave = true; - }else{ - $scope.rulesSaved = true; - $scope.couldNotConnect = true; - $scope.couldNotSave = false; + } else { + $scope.rulesSaved = true; + $scope.couldNotConnect = true; + $scope.couldNotSave = false; - $scope.errorMessage = response.data.error_message; - } + $scope.errorMessage = response.data.error_message; + } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - $scope.rulesSaved = true; - $scope.couldNotConnect = false; - $scope.couldNotSave = true; - } - } + } + + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + $scope.rulesSaved = true; + $scope.couldNotConnect = false; + $scope.couldNotSave = true; + } + } }); /* Java script code for ModSec */ -app.controller('modSecRulesPack', function($scope, $http, $timeout, $window) { +app.controller('modSecRulesPack', function ($scope, $http, $timeout, $window) { - $scope.modsecLoading = true; - $scope.owaspDisable = true; - $scope.comodoDisable = true; + $scope.modsecLoading = true; + $scope.owaspDisable = true; + $scope.comodoDisable = true; - // + // - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = true; - $scope.ruleFiles = true; + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = true; + $scope.ruleFiles = true; - ///// + ///// - var owaspInstalled = false; - var comodoInstalled = false; - var counterOWASP = 0; - var counterComodo = 0; + var owaspInstalled = false; + var comodoInstalled = false; + var counterOWASP = 0; + var counterComodo = 0; - $('#owaspInstalled').change(function() { + $('#owaspInstalled').change(function () { - owaspInstalled = $(this).prop('checked'); - $scope.ruleFiles = true; + owaspInstalled = $(this).prop('checked'); + $scope.ruleFiles = true; - if(counterOWASP !== 0) { - if (owaspInstalled === true) { - installModSecRulesPack('installOWASP'); + if (counterOWASP !== 0) { + if (owaspInstalled === true) { + installModSecRulesPack('installOWASP'); + } else { + installModSecRulesPack('disableOWASP') + } + } + + counterOWASP = counterOWASP + 1; + }); + + $('#comodoInstalled').change(function () { + + $scope.ruleFiles = true; + comodoInstalled = $(this).prop('checked'); + + if (counterComodo !== 0) { + + if (comodoInstalled === true) { + installModSecRulesPack('installComodo'); + } else { + installModSecRulesPack('disableComodo') + } + } + + counterComodo = counterComodo + 1; + + }); + + + getOWASPAndComodoStatus(true); + function getOWASPAndComodoStatus(updateToggle) { + + $scope.modsecLoading = false; + + + url = "/firewall/getOWASPAndComodoStatus"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.modsecLoading = true; + + if (response.data.modSecInstalled === 1) { + + if (updateToggle === true) { + + if (response.data.owaspInstalled === 1) { + $('#owaspInstalled').bootstrapToggle('on'); + $scope.owaspDisable = false; } else { - installModSecRulesPack('disableOWASP') + $('#owaspInstalled').bootstrapToggle('off'); + $scope.owaspDisable = true; + } + if (response.data.comodoInstalled === 1) { + $('#comodoInstalled').bootstrapToggle('on'); + $scope.comodoDisable = false; + } else { + $('#comodoInstalled').bootstrapToggle('off'); + $scope.comodoDisable = true; + } + } else { + + if (response.data.owaspInstalled === 1) { + $scope.owaspDisable = false; + } else { + $scope.owaspDisable = true; + } + if (response.data.comodoInstalled === 1) { + $scope.comodoDisable = false; + } else { + $scope.comodoDisable = true; } } - counterOWASP = counterOWASP + 1; - }); + } - $('#comodoInstalled').change(function() { + } - $scope.ruleFiles = true; - comodoInstalled = $(this).prop('checked'); + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + } - if(counterComodo !== 0) { + } - if (comodoInstalled === true) { - installModSecRulesPack('installComodo'); - } else { - installModSecRulesPack('disableComodo') - } - } + ///// - counterComodo = counterComodo + 1; + function installModSecRulesPack(packName) { - }); + $scope.modsecLoading = false; + url = "/firewall/installModSecRulesPack"; - getOWASPAndComodoStatus(true); - function getOWASPAndComodoStatus(updateToggle){ + var data = { + packName: packName + }; - $scope.modsecLoading = false; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - url = "/firewall/getOWASPAndComodoStatus"; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - var data = {}; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + function ListInitialDatas(response) { + $scope.modsecLoading = true; + if (response.data.installStatus === 1) { - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $scope.modsecLoading = true; + // - function ListInitialDatas(response) { + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = false; - $scope.modsecLoading = true; + getOWASPAndComodoStatus(false); - if(response.data.modSecInstalled === 1){ + } else { + $scope.modsecLoading = true; - if (updateToggle === true){ + // - if (response.data.owaspInstalled === 1) { - $('#owaspInstalled').bootstrapToggle('on'); - $scope.owaspDisable = false; - } else { - $('#owaspInstalled').bootstrapToggle('off'); - $scope.owaspDisable = true; - } - if (response.data.comodoInstalled === 1) { - $('#comodoInstalled').bootstrapToggle('on'); - $scope.comodoDisable = false; - } else { - $('#comodoInstalled').bootstrapToggle('off'); - $scope.comodoDisable = true; - } - }else{ + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = false; + $scope.installationSuccess = true; - if (response.data.owaspInstalled === 1) { - $scope.owaspDisable = false; - } else { - $scope.owaspDisable = true; - } - if (response.data.comodoInstalled === 1) { - $scope.comodoDisable = false; - } else { - $scope.comodoDisable = true; - } - } + $scope.errorMessage = response.data.error_message; + } - } + } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - } + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; - } + // - ///// + $scope.installationQuote = true; + $scope.couldNotConnect = false; + $scope.installationFailed = true; + $scope.installationSuccess = true; + } - function installModSecRulesPack(packName) { - $scope.modsecLoading = false; + } - url = "/firewall/installModSecRulesPack"; + ///// - var data = { - packName:packName - }; + $scope.fetchRulesFile = function (packName) { - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.modsecLoading = false; + $scope.ruleFiles = false; + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = true; + url = "/firewall/getRulesFiles"; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + var data = { + packName: packName + }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - function ListInitialDatas(response) { - $scope.modsecLoading = true; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - if(response.data.installStatus === 1){ - $scope.modsecLoading = true; + function ListInitialDatas(response) { - // + $scope.modsecLoading = true; - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = false; + if (response.data.fetchStatus === 1) { + $scope.records = JSON.parse(response.data.data); + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = false; - getOWASPAndComodoStatus(false); + } + else { + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = false; + $scope.installationSuccess = true; + $scope.errorMessage = response.data.error_message; + } - }else{ - $scope.modsecLoading = true; + } - // + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + $scope.installationQuote = true; + $scope.couldNotConnect = false; + $scope.installationFailed = true; + $scope.installationSuccess = true; + } - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = false; - $scope.installationSuccess = true; + }; - $scope.errorMessage = response.data.error_message; - } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; + $scope.removeRuleFile = function (fileName, packName, status) { - // + $scope.modsecLoading = false; - $scope.installationQuote = true; - $scope.couldNotConnect = false; - $scope.installationFailed = true; - $scope.installationSuccess = true; - } + url = "/firewall/enableDisableRuleFile"; - } + var data = { + packName: packName, + fileName: fileName, + status: status + }; - ///// + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $scope.fetchRulesFile = function (packName) { - $scope.modsecLoading = false; - $scope.ruleFiles = false; - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = true; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - url = "/firewall/getRulesFiles"; - var data = { - packName:packName - }; + function ListInitialDatas(response) { - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.modsecLoading = true; + if (response.data.saveStatus === 1) { + $scope.modsecLoading = true; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + // + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = false; - function ListInitialDatas(response) { + $scope.fetchRulesFile(packName); - $scope.modsecLoading = true; + } else { + $scope.modsecLoading = true; - if(response.data.fetchStatus === 1){ - $scope.records = JSON.parse(response.data.data); - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = false; + // - } - else{ - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = false; - $scope.installationSuccess = true; - $scope.errorMessage = response.data.error_message; - } + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = false; + $scope.installationSuccess = true; - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - $scope.installationQuote = true; - $scope.couldNotConnect = false; - $scope.installationFailed = true; - $scope.installationSuccess = true; - } + $scope.errorMessage = response.data.error_message; + } - }; + } + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; - $scope.removeRuleFile = function (fileName, packName, status) { + // - $scope.modsecLoading = false; - - - - url = "/firewall/enableDisableRuleFile"; - - var data = { - packName:packName, - fileName:fileName, - status:status - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.modsecLoading = true; - - if(response.data.saveStatus === 1){ - - $scope.modsecLoading = true; - - // - - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = false; - - $scope.fetchRulesFile(packName); - - }else{ - $scope.modsecLoading = true; - - // - - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = false; - $scope.installationSuccess = true; - - $scope.errorMessage = response.data.error_message; - } - - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - - // - - $scope.installationQuote = true; - $scope.couldNotConnect = false; - $scope.installationFailed = true; - $scope.installationSuccess = true; - } - - } + $scope.installationQuote = true; + $scope.couldNotConnect = false; + $scope.installationFailed = true; + $scope.installationSuccess = true; + } + } }); @@ -1561,551 +1526,550 @@ app.controller('modSecRulesPack', function($scope, $http, $timeout, $window) { /* Java script code for CSF */ -app.controller('csf', function($scope, $http, $timeout, $window) { +app.controller('csf', function ($scope, $http, $timeout, $window) { - $scope.csfLoading = true; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.csfLoading = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + $scope.installCSF = function () { - $scope.installCSF = function(){ + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + url = "/firewall/installCSF"; - url = "/firewall/installCSF"; + var data = {}; - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - if(response.data.installStatus === 1){ + if (response.data.installStatus === 1) { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - getRequestStatus(); + getRequestStatus(); - } - else{ - $scope.errorMessage = response.data.error_message; + } + else { + $scope.errorMessage = response.data.error_message; - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = false; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - } + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = false; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + } - } - function cantLoadInitialDatas(response) { + } - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + function cantLoadInitialDatas(response) { + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + } + + }; + function getRequestStatus() { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + url = "/firewall/installStatusCSF"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.abort === 0) { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + $scope.requestData = response.data.requestStatus; + $timeout(getRequestStatus, 1000); + } + else { + // Notifications + $timeout.cancel(); + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + + $scope.requestData = response.data.requestStatus; + + if (response.data.installed === 0) { + $scope.installationFailed = false; + $scope.errorMessage = response.data.error_message; + } else { + $scope.modSecSuccessfullyInstalled = false; + $timeout(function () { + $window.location.reload(); + }, 3000); } - }; - function getRequestStatus(){ + } - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + } - url = "/firewall/installStatusCSF"; + function cantLoadInitialDatas(response) { - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + } - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + } - function ListInitialDatas(response) { + // After installation + + var currentMain = "generalLI"; + var currentChild = "general"; + + $scope.activateTab = function (newMain, newChild) { + $("#" + currentMain).removeClass("ui-tabs-active"); + $("#" + currentMain).removeClass("ui-state-active"); + + $("#" + newMain).addClass("ui-tabs-active"); + $("#" + newMain).addClass("ui-state-active"); + + $('#' + currentChild).hide(); + $('#' + newChild).show(); + + currentMain = newMain; + currentChild = newChild; + }; - if(response.data.abort === 0){ + $scope.removeCSF = function () { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.csfLoading = false; - $scope.requestData = response.data.requestStatus; - $timeout(getRequestStatus,1000); - } - else{ - // Notifications - $timeout.cancel(); - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.requestData = response.data.requestStatus; + url = "/firewall/removeCSF"; - if(response.data.installed === 0) { - $scope.installationFailed = false; - $scope.errorMessage = response.data.error_message; - }else{ - $scope.modSecSuccessfullyInstalled = false; - $timeout(function() { $window.location.reload(); }, 3000); - } + var data = {}; - } + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.csfLoading = true; + + + if (response.data.installStatus === 1) { + + new PNotify({ + title: 'Successfully removed!', + text: 'CSF successfully removed from server, refreshing page in 3 seconds..', + type: 'success' + }); + + $timeout(function () { + $window.location.reload(); + }, 3000); + + } + else { + new PNotify({ + title: 'Operation failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + + new PNotify({ + title: 'Operation failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } + + }; + + //////// Fetch settings + + // + var testingMode = false; + var testingCounter = 0; + + + $('#testingMode').change(function () { + testingMode = $(this).prop('checked'); + + if (testingCounter !== 0) { + + if (testingMode === true) { + $scope.changeStatus('testingMode', 'enable'); + } else { + $scope.changeStatus('testingMode', 'disable'); + } + } + testingCounter = testingCounter + 1; + }); + // + + // + var firewallStatus = false; + var firewallCounter = 0; + + + $('#firewallStatus').change(function () { + firewallStatus = $(this).prop('checked'); + + if (firewallCounter !== 0) { + + if (firewallStatus === true) { + $scope.changeStatus('csf', 'enable'); + } else { + $scope.changeStatus('csf', 'disable'); + } + } + firewallCounter = firewallCounter + 1; + }); + // + + + $scope.fetchSettings = function () { + + $scope.csfLoading = false; + + $('#testingMode').bootstrapToggle('off'); + $('#firewallStatus').bootstrapToggle('off'); + + url = "/firewall/fetchCSFSettings"; + + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.csfLoading = true; + + if (response.data.fetchStatus === 1) { + + new PNotify({ + title: 'Successfully fetched!', + text: 'CSF settings successfully fetched.', + type: 'success' + }); + + if (response.data.testingMode === 1) { + $('#testingMode').bootstrapToggle('on'); } - function cantLoadInitialDatas(response) { - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - - + if (response.data.firewallStatus === 1) { + $('#firewallStatus').bootstrapToggle('on'); } - } + $scope.tcpIN = response.data.tcpIN; + $scope.tcpOUT = response.data.tcpOUT; + $scope.udpIN = response.data.udpIN; + $scope.udpOUT = response.data.udpOUT; + } else { + new PNotify({ + title: 'Failed to load!', + text: response.data.error_message, + type: 'error' + }); - // After installation + } - var currentMain = "generalLI"; - var currentChild = "general"; + } - $scope.activateTab = function (newMain, newChild) { - $("#"+currentMain).removeClass("ui-tabs-active"); - $("#"+currentMain).removeClass("ui-state-active"); + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; - $("#"+newMain).addClass("ui-tabs-active"); - $("#"+newMain).addClass("ui-state-active"); + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } - $('#'+currentChild).hide(); - $('#'+newChild).show(); + }; + $scope.fetchSettings(); - currentMain = newMain; - currentChild = newChild; - }; + $scope.changeStatus = function (controller, status) { - $scope.removeCSF = function(){ + $scope.csfLoading = false; - $scope.csfLoading = false; + url = "/firewall/changeStatus"; - url = "/firewall/removeCSF"; - var data = {}; + var data = { + controller: controller, + status: status + }; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { - function ListInitialDatas(response) { + $scope.csfLoading = true; - $scope.csfLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Changes successfully applied.', + type: 'success' + }); + } else { - if(response.data.installStatus === 1){ + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); - new PNotify({ - title: 'Successfully removed!', - text: 'CSF successfully removed from server, refreshing page in 3 seconds..', - type:'success' - }); + } - $timeout(function() { $window.location.reload(); }, 3000); + } - } - else{ - new PNotify({ - title: 'Operation failed!', - text: response.data.error_message, - type:'error' - }); + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; - } + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } - } - function cantLoadInitialDatas(response) { + }; - new PNotify({ - title: 'Operation failed!', - text: 'Could not connect to server, please refresh this page.', - type:'error' - }); + $scope.modifyPorts = function (protocol) { + $scope.csfLoading = false; - } + var ports; - }; + if (protocol === 'TCP_IN') { + ports = $scope.tcpIN; + } else if (protocol === 'TCP_OUT') { + ports = $scope.tcpOUT; + } else if (protocol === 'UDP_IN') { + ports = $scope.udpIN; + } else if (protocol === 'UDP_OUT') { + ports = $scope.udpOUT; + } - //////// Fetch settings - // - var testingMode = false; - var testingCounter = 0; + url = "/firewall/modifyPorts"; - $('#testingMode').change(function() { - testingMode = $(this).prop('checked'); + var data = { + protocol: protocol, + ports: ports + }; - if(testingCounter !== 0) { + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - if (testingMode === true) { - $scope.changeStatus('testingMode', 'enable'); - } else { - $scope.changeStatus('testingMode', 'disable'); - } - } - testingCounter = testingCounter + 1; - }); - // - // - var firewallStatus = false; - var firewallCounter = 0; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $('#firewallStatus').change(function() { - firewallStatus = $(this).prop('checked'); + function ListInitialDatas(response) { - if(firewallCounter !== 0) { + $scope.csfLoading = true; - if (firewallStatus === true) { - $scope.changeStatus('csf', 'enable'); - } else { - $scope.changeStatus('csf', 'disable'); - } - } - firewallCounter = firewallCounter + 1; - }); - // + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Changes successfully applied.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); - $scope.fetchSettings = function(){ + } - $scope.csfLoading = false; + } - $('#testingMode').bootstrapToggle('off'); - $('#firewallStatus').bootstrapToggle('off'); + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; - url = "/firewall/fetchCSFSettings"; + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } + }; - var data = {}; + $scope.modifyIPs = function (mode) { - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.csfLoading = false; + var ipAddress; + if (mode === 'allowIP') { + ipAddress = $scope.allowIP; + } else if (mode === 'blockIP') { + ipAddress = $scope.blockIP; + } - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + url = "/firewall/modifyIPs"; - function ListInitialDatas(response) { - $scope.csfLoading = true; + var data = { + mode: mode, + ipAddress: ipAddress + }; - if(response.data.fetchStatus === 1){ + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - new PNotify({ - title: 'Successfully fetched!', - text: 'CSF settings successfully fetched.', - type:'success' - }); - if (response.data.testingMode === 1) { - $('#testingMode').bootstrapToggle('on'); - } - if (response.data.firewallStatus === 1) { - $('#firewallStatus').bootstrapToggle('on'); - } + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $scope.tcpIN = response.data.tcpIN; - $scope.tcpOUT = response.data.tcpOUT; - $scope.udpIN = response.data.udpIN; - $scope.udpOUT = response.data.udpOUT; - }else{ - new PNotify({ - title: 'Failed to load!', - text: response.data.error_message, - type:'error' - }); + function ListInitialDatas(response) { - } + $scope.csfLoading = true; - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; + if (response.data.status === 1) { - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } + new PNotify({ + title: 'Success!', + text: 'Changes successfully applied.', + type: 'success' + }); + } else { - }; - $scope.fetchSettings(); + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } - $scope.changeStatus = function(controller, status){ + } - $scope.csfLoading = false; + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } - - url = "/firewall/changeStatus"; - - - var data = { - controller: controller, - status : status - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.csfLoading = true; - - if(response.data.status === 1){ - - new PNotify({ - title: 'Success!', - text: 'Changes successfully applied.', - type:'success' - }); - }else{ - - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type:'error' - }); - - } - - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; - - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } - - }; - - $scope.modifyPorts = function(protocol){ - - $scope.csfLoading = false; - - var ports; - - if(protocol === 'TCP_IN'){ - ports = $scope.tcpIN; - }else if(protocol === 'TCP_OUT'){ - ports = $scope.tcpOUT; - }else if(protocol === 'UDP_IN'){ - ports = $scope.udpIN; - }else if(protocol === 'UDP_OUT'){ - ports = $scope.udpOUT; - } - - - - url = "/firewall/modifyPorts"; - - - var data = { - protocol: protocol, - ports : ports - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.csfLoading = true; - - if(response.data.status === 1){ - - new PNotify({ - title: 'Success!', - text: 'Changes successfully applied.', - type:'success' - }); - }else{ - - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type:'error' - }); - - } - - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; - - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } - - }; - - $scope.modifyIPs = function(mode){ - - $scope.csfLoading = false; - - var ipAddress; - - if(mode === 'allowIP'){ - ipAddress = $scope.allowIP; - }else if(mode === 'blockIP'){ - ipAddress = $scope.blockIP; - } - - - - url = "/firewall/modifyIPs"; - - - var data = { - mode: mode, - ipAddress : ipAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.csfLoading = true; - - if(response.data.status === 1){ - - new PNotify({ - title: 'Success!', - text: 'Changes successfully applied.', - type:'success' - }); - }else{ - - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type:'error' - }); - - } - - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; - - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } - - }; + }; }); \ No newline at end of file diff --git a/install/install.py b/install/install.py index 864b333ec..c187c6441 100644 --- a/install/install.py +++ b/install/install.py @@ -2390,14 +2390,16 @@ class preFlightsChecks: def removeUfw(self): try: preFlightsChecks.stdOut("Checking to see if ufw firewall is installed (will be removed)", 1) - status = subprocess.check_output(shlex.split('ufw status'), stderr=subprocess.STDOUT) + status = subprocess.check_output(shlex.split('ufw status')) preFlightsChecks.stdOut("ufw current status: " + status + "...will be removed") - except subprocess.CalledProcessError as err: + except BaseException, msg: preFlightsChecks.stdOut("Expected access to ufw not available, do not need to remove it", 1) return True - - preFlightsChecks.call('apt-get -y remove ufw', self.distro, '[remove_ufw]', 'Remove ufw firewall ' + - '(using firewalld)', 1, 1, os.EX_OSERR) + try: + preFlightsChecks.call('apt-get -y remove ufw', self.distro, '[remove_ufw]', 'Remove ufw firewall ' + + '(using firewalld)', 1, 0, os.EX_OSERR) + except: + pass return True def installFirewalld(self): @@ -3514,9 +3516,29 @@ def main(): logging.InstallLog.writeToFile("Starting CyberPanel installation..") preFlightsChecks.stdOut("Starting CyberPanel installation..") + if args.ent == None: + ent = 0 + preFlightsChecks.stdOut("OpenLiteSpeed web server will be installed.") + else: + if args.ent == 'ols': + ent = 0 + preFlightsChecks.stdOut("OpenLiteSpeed web server will be installed.") + else: + preFlightsChecks.stdOut("LiteSpeed Enterprise web server will be installed.") + ent = 1 + if args.serial != None: + serial = args.serial + preFlightsChecks.stdOut("LiteSpeed Enterprise Serial detected: " + serial) + else: + preFlightsChecks.stdOut("Installation failed, please specify LiteSpeed Enterprise key using --serial") + os._exit(0) + ## Writing public IP - os.mkdir("/etc/cyberpanel") + try: + os.mkdir("/etc/cyberpanel") + except: + pass machineIP = open("/etc/cyberpanel/machineIP", "w") machineIP.writelines(args.publicip) @@ -3537,20 +3559,6 @@ def main(): mysql = args.mysql preFlightsChecks.stdOut("Dobule MySQL instance version will be installed.") - if args.ent == None: - ent = 0 - else: - if args.ent == 'ols': - ent = 0 - else: - ent = 1 - if args.serial != None: - serial = args.serial - preFlightsChecks.stdOut("LiteSpeed Enterprise Serial detected: " + serial) - else: - preFlightsChecks.stdOut("Installation failed, please specify LiteSpeed Enterprise key using --serial") - os._exit(0) - checks.checkPythonVersion() checks.setup_account_cyberpanel() if distro == centos: diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index 02323129a..da5d9edd8 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -67,6 +67,21 @@ class InstallCyberPanel: try: count = 0 while (1): + try: + + command = 'groupadd nobody' + cmd = shlex.split(command) + subprocess.call(cmd) + + except: + pass + + try: + command = 'usermod -a -G nobody nobody' + cmd = shlex.split(command) + subprocess.call(cmd) + except: + pass command = 'wget https://www.litespeedtech.com/packages/5.0/lsws-5.3-ent-x86_64-linux.tar.gz' cmd = shlex.split(command) @@ -1301,7 +1316,7 @@ class InstallCyberPanel: -def Main(cwd, mysql, distro, ent): +def Main(cwd, mysql, distro, ent, serial = None): InstallCyberPanel.mysqlPassword = randomPassword.generate_pass() InstallCyberPanel.mysql_Root_password = randomPassword.generate_pass() @@ -1321,7 +1336,7 @@ def Main(cwd, mysql, distro, ent): else: InstallCyberPanel.mysqlPassword = InstallCyberPanel.mysql_Root_password - installer = InstallCyberPanel("/usr/local/lsws/",cwd, distro, ent) + installer = InstallCyberPanel("/usr/local/lsws/",cwd, distro, ent, serial) installer.installLiteSpeed() if ent == 0: diff --git a/mailServer/mailserverManager.py b/mailServer/mailserverManager.py index 5b04cc7e9..f450b6040 100644 --- a/mailServer/mailserverManager.py +++ b/mailServer/mailserverManager.py @@ -21,6 +21,8 @@ from dns.models import Records as dnsRecords from mailServer.models import Forwardings from plogical.acl import ACLManager import os +from plogical.dnsUtilities import DNS +from loginSystem.models import Administrator class MailServerManager: @@ -428,9 +430,16 @@ class MailServerManager: execPath = execPath + " generateKeys --domain " + domainName output = subprocess.check_output(shlex.split(execPath)) - if output.find("1,None") > -1: + admin = Administrator.objects.get(pk=userID) + DNS.dnsTemplate(domainName, admin) - zone = dnsDomains.objects.get(name=domainName) + if output.find("1,None") > -1: + import tldextract + + extractDomain = tldextract.extract(domainName) + topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix + + zone = dnsDomains.objects.get(name=topLevelDomain) zone.save() path = "/etc/opendkim/keys/" + domainName + "/default.txt" @@ -439,6 +448,8 @@ class MailServerManager: leftIndex = output.index('(') + 2 rightIndex = output.rindex(')') - 1 + DNS.createDKIMRecords(domainName) + record = dnsRecords(domainOwner=zone, domain_id=zone.id, name="default._domainkey." + domainName, diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index c7e776622..901fe128b 100644 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -146,8 +146,8 @@ class mailUtilities: import tldextract - extractDomain = tldextract.extract(virtualHostName) - virtualHostName = extractDomain.domain + '.' + extractDomain.suffix + #extractDomain = tldextract.extract(virtualHostName) + #virtualHostName = extractDomain.domain + '.' + extractDomain.suffix if os.path.exists("/etc/opendkim/keys/" + virtualHostName): return 1, "None" diff --git a/serverLogs/views.py b/serverLogs/views.py index 92d95ea00..bd314c6c7 100644 --- a/serverLogs/views.py +++ b/serverLogs/views.py @@ -134,20 +134,25 @@ def getLogsFromFile(request): fileName = "/var/log/messages" elif type == "modSec": fileName = "/usr/local/lsws/logs/auditmodsec.log" + elif type == "cyberpanel": + fileName = "/home/cyberpanel/error-logs.txt" - command = "sudo tail -50 " + fileName - - fewLinesOfLogFile = subprocess.check_output(shlex.split(command)) - - status = {"logstatus": 1, "logsdata": fewLinesOfLogFile} - final_json = json.dumps(status) - return HttpResponse(final_json) - + try: + command = "sudo tail -50 " + fileName + fewLinesOfLogFile = subprocess.check_output(shlex.split(command)) + status = {"status": 1, "logstatus": 1, "logsdata": fewLinesOfLogFile} + final_json = json.dumps(status) + return HttpResponse(final_json) + except: + status = {"status": 1, "logstatus": 1, "logsdata": 'Emtpy File.'} + final_json = json.dumps(status) + return HttpResponse(final_json) except KeyError, msg: - status = {"logstatus":0,"error":"Could not fetch data from log file, please see CyberCP main log file through command line."} + status = {"status": 0, "logstatus":0,"error":"Could not fetch data from log file, please see CyberCP main log file through command line."} logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[getLogsFromFile]") - return HttpResponse("Not Logged in as admin") + final_json = json.dumps(status) + return HttpResponse(final_json) def clearLogFile(request): try: diff --git a/static/firewall/firewall.js b/static/firewall/firewall.js index bb0e4a07f..441d0daf0 100644 --- a/static/firewall/firewall.js +++ b/static/firewall/firewall.js @@ -5,7 +5,92 @@ /* Java script code to ADD Firewall Rules */ -app.controller('firewallController', function($scope,$http) { +app.controller('firewallController', function ($scope, $http) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + $scope.rulesDetails = false; + + firewallStatus(); + + populateCurrentRecords(); + + $scope.addRule = function () { + + $scope.rulesLoading = false; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + + url = "/firewall/addRule"; + + + var ruleName = $scope.ruleName; + var ruleProtocol = $scope.ruleProtocol; + var rulePort = $scope.rulePort; + + + var data = { + ruleName: ruleName, + ruleProtocol: ruleProtocol, + rulePort: rulePort, + ruleIP: $scope.ruleIP, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.add_status == 1) { + + + populateCurrentRecords(); + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = false; + $scope.couldNotConnect = true; + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = false; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { $scope.rulesLoading = true; $scope.actionFailed = true; @@ -13,531 +98,410 @@ app.controller('firewallController', function($scope,$http) { $scope.canNotAddRule = true; $scope.ruleAdded = true; - $scope.couldNotConnect = true; - $scope.rulesDetails = false; + $scope.couldNotConnect = false; + } - firewallStatus(); + }; + + function populateCurrentRecords() { + + $scope.rulesLoading = false; + $scope.actionFailed = true; + $scope.actionSuccess = true; - populateCurrentRecords(); + url = "/firewall/getCurrentRules"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $scope.addRule = function(){ + function ListInitialDatas(response) { + if (response.data.fetchStatus === 1) { + $scope.rules = JSON.parse(response.data.data); + $scope.rulesLoading = true; + } + else { + $scope.rulesLoading = true; + $scope.errorMessage = response.data.error_message; + } + } - $scope.rulesLoading = false; - $scope.actionFailed = true; - $scope.actionSuccess = true; + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; + } + + }; + + $scope.deleteRule = function (id, proto, port, ruleIP) { + + $scope.rulesLoading = false; + + url = "/firewall/deleteRule"; + + var data = { + id: id, + proto: proto, + port: port, + ruleIP: ruleIP + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - url = "/firewall/addRule"; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - var ruleName = $scope.ruleName; - var ruleProtocol = $scope.ruleProtocol; - var rulePort = $scope.rulePort; + function ListInitialDatas(response) { - - var data = { - ruleName:ruleName, - ruleProtocol:ruleProtocol, - rulePort:rulePort, - ruleIP:$scope.ruleIP, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + if (response.data.delete_status === 1) { - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + populateCurrentRecords(); + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; - function ListInitialDatas(response) { + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = false; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = true; + $scope.errorMessage = response.data.error_message; - if(response.data.add_status == 1){ + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; - populateCurrentRecords(); - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = false; - $scope.couldNotConnect = true; + } - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = false; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; + }; - $scope.errorMessage = response.data.error_message; - } + $scope.reloadFireWall = function () { + + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = false; + + url = "/firewall/reloadFirewall"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.reload_status == 1) { + + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = false; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = false; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; + + + } + + + }; + + $scope.startFirewall = function () { + + + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = false; + + url = "/firewall/startFirewall"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.start_status == 1) { + + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = false; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesDetails = false; + + firewallStatus(); + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = false; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; + + + } + + + }; + + + $scope.stopFirewall = function () { + + + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesLoading = false; + + url = "/firewall/stopFirewall"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.stop_status == 1) { + + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = false; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.rulesDetails = true; + + firewallStatus(); + + + } + else { + + $scope.rulesLoading = true; + $scope.actionFailed = false; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.rulesLoading = true; + $scope.actionFailed = true; + $scope.actionSuccess = true; + + $scope.canNotAddRule = true; + $scope.ruleAdded = true; + $scope.couldNotConnect = false; + + + } + + + }; + + + function firewallStatus() { + + + url = "/firewall/firewallStatus"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.status == 1) { + + if (response.data.firewallStatus == 1) { + $scope.rulesDetails = false; + $scope.status = "ON"; } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - + else { + $scope.rulesDetails = true; + $scope.status = "OFF"; } + } + else { - }; + $scope.rulesDetails = true; + $scope.status = "OFF"; + } + } - function populateCurrentRecords(){ - - $scope.rulesLoading = false; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - - url = "/firewall/getCurrentRules"; - - var data = { - - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.fetchStatus == 1){ - - $scope.rules = JSON.parse(response.data.data); - $scope.rulesLoading = true; - - } - else{ - $scope.rulesLoading = true; - $scope.errorMessage = response.data.error_message; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - - } - - }; - - - - $scope.deleteRule = function(id,proto,port,ruleIP){ - - - - - $scope.rulesLoading = false; - - url = "/firewall/deleteRule"; - - var data = { - id:id, - proto:proto, - port:port, - ruleIP:ruleIP, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.delete_status == 1){ - - - populateCurrentRecords(); - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = false; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = true; - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - - } - - - }; - - - $scope.reloadFireWall = function(){ - - - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = false; - - url = "/firewall/reloadFirewall"; - - var data = { - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.reload_status == 1){ - - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = false; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = false; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - } - - - }; - - $scope.startFirewall = function(){ - - - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = false; - - url = "/firewall/startFirewall"; - - var data = { - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.start_status == 1){ - - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = false; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesDetails = false; - - firewallStatus(); - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = false; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - } - - - }; - - - $scope.stopFirewall = function(){ - - - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesLoading = false; - - url = "/firewall/stopFirewall"; - - var data = { - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.stop_status == 1){ - - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = false; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.rulesDetails = true; - - firewallStatus(); - - - - } - else{ - - $scope.rulesLoading = true; - $scope.actionFailed = false; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - - } - - } - function cantLoadInitialDatas(response) { - - $scope.rulesLoading = true; - $scope.actionFailed = true; - $scope.actionSuccess = true; - - $scope.canNotAddRule = true; - $scope.ruleAdded = true; - $scope.couldNotConnect = false; - - - } - - - }; - - - function firewallStatus(){ - - - - url = "/firewall/firewallStatus"; - - var data = { - - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.status == 1){ - - if(response.data.firewallStatus == 1){ - $scope.rulesDetails = false; - $scope.status = "ON"; - } - else{ - $scope.rulesDetails = true; - $scope.status = "OFF"; - } - } - else{ - - $scope.rulesDetails = true; - $scope.status = "OFF"; - } - - - } - function cantLoadInitialDatas(response) { - - $scope.couldNotConnect = false; - - - } - - }; + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + } + }; }); @@ -546,274 +510,272 @@ app.controller('firewallController', function($scope,$http) { /* Java script code to Secure SSH */ -app.controller('secureSSHCTRL', function($scope,$http) { +app.controller('secureSSHCTRL', function ($scope, $http) { - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - $scope.keyDeleted = true; - $scope.keyBox = true; - $scope.showKeyBox = false; - $scope.saveKeyBtn = true; + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + $scope.keyDeleted = true; + $scope.keyBox = true; + $scope.showKeyBox = false; + $scope.saveKeyBtn = true; - $scope.addKey = function(){ + $scope.addKey = function () { + $scope.saveKeyBtn = false; + $scope.showKeyBox = true; + $scope.keyBox = false; + }; + + + getSSHConfigs(); + populateCurrentKeys(); + + // Checking root login + + var rootLogin = false; + + $('#rootLogin').change(function () { + rootLogin = $(this).prop('checked'); + }); + + + function getSSHConfigs() { + + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = false; + + url = "/firewall/getSSHConfigs"; + + var data = { + type: "1", + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.sshPort = response.data.sshPort; + + if (response.data.permitRootLogin == 1) { + $('#rootLogin').bootstrapToggle('on'); + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + } + else { + $scope.errorMessage = response.data.error_message; + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + + } + + } + + $scope.saveChanges = function () { + + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = false; + + url = "/firewall/saveSSHConfigs"; + + var data = { + type: "1", + sshPort: $scope.sshPort, + rootLogin: rootLogin + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.saveStatus == 1) { + $scope.couldNotSave = true; + $scope.detailsSaved = false; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + } + else { + + $scope.couldNotSave = false; + $scope.detailsSaved = true; + $scope.couldNotConnect = true; + $scope.secureSSHLoading = true; + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotSave = true; + $scope.detailsSaved = true; + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + + } + }; + + + function populateCurrentKeys() { + + url = "/firewall/getSSHConfigs"; + + var data = { + type: "2" + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + $scope.records = JSON.parse(response.data.data); + } + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + } + + + } + + $scope.deleteKey = function (key) { + + $scope.secureSSHLoading = false; + + url = "/firewall/deleteSSHKey"; + + var data = { + key: key, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.delete_status === 1) { + $scope.secureSSHLoading = true; + $scope.keyDeleted = false; + populateCurrentKeys(); + } + else { + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + + } + + + } + + + $scope.saveKey = function (key) { + + $scope.secureSSHLoading = false; + + url = "/firewall/addSSHKey"; + + var data = { + key: $scope.keyData, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.add_status === 1) { + $scope.secureSSHLoading = true; + $scope.saveKeyBtn = true; + $scope.showKeyBox = false; + $scope.keyBox = true; + + + populateCurrentKeys(); + } + else { + $scope.secureSSHLoading = true; $scope.saveKeyBtn = false; $scope.showKeyBox = true; - $scope.keyBox = false; - }; + $scope.keyBox = true; + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; + } + } - getSSHConfigs(); - populateCurrentKeys(); + function cantLoadInitialDatas(response) { + $scope.secureSSHLoading = true; + $scope.saveKeyBtn = false; + $scope.showKeyBox = true; + $scope.keyBox = true; + $scope.couldNotConnect = false; + $scope.secureSSHLoading = true; - // Checking root login + } - var rootLogin = false; - $('#rootLogin').change(function() { - rootLogin = $(this).prop('checked'); - }); - - - function getSSHConfigs(){ - - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = false; - - url = "/firewall/getSSHConfigs"; - - var data = { - type:"1", - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.sshPort = response.data.sshPort; - - if(response.data.permitRootLogin == 1){ - $('#rootLogin').bootstrapToggle('on'); - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - } - else{ - $scope.errorMessage = response.data.error_message; - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - - } - - }; - - $scope.saveChanges = function () { - - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = false; - - url = "/firewall/saveSSHConfigs"; - - var data = { - type:"1", - sshPort:$scope.sshPort, - rootLogin:rootLogin, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.saveStatus == 1){ - $scope.couldNotSave = true; - $scope.detailsSaved = false; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - } - else{ - - $scope.couldNotSave = false; - $scope.detailsSaved = true; - $scope.couldNotConnect = true; - $scope.secureSSHLoading = true; - - $scope.errorMessage = response.data.error_message; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotSave = true; - $scope.detailsSaved = true; - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - - } - }; - - - function populateCurrentKeys(){ - - url = "/firewall/getSSHConfigs"; - - var data = { - type:"2", - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.status == 1){ - $scope.records = JSON.parse(response.data.data); - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - - } - - - } - - $scope.deleteKey = function(key){ - - $scope.secureSSHLoading = false; - - url = "/firewall/deleteSSHKey"; - - var data = { - key:key, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.delete_status === 1){ - $scope.secureSSHLoading = true; - $scope.keyDeleted = false; - populateCurrentKeys(); - } - else{ - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - - } - - - } - - - $scope.saveKey = function(key){ - - $scope.secureSSHLoading = false; - - url = "/firewall/addSSHKey"; - - var data = { - key:$scope.keyData, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if(response.data.add_status === 1){ - $scope.secureSSHLoading = true; - $scope.saveKeyBtn = true; - $scope.showKeyBox = false; - $scope.keyBox = true; - - - populateCurrentKeys(); - } - else{ - $scope.secureSSHLoading = true; - $scope.saveKeyBtn = false; - $scope.showKeyBox = true; - $scope.keyBox = true; - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.secureSSHLoading = true; - $scope.saveKeyBtn = false; - $scope.showKeyBox = true; - $scope.keyBox = true; - $scope.couldNotConnect = false; - $scope.secureSSHLoading = true; - - } - - - } + } }); @@ -821,736 +783,739 @@ app.controller('secureSSHCTRL', function($scope,$http) { /* Java script code for ModSec */ -app.controller('modSec', function($scope, $http, $timeout, $window) { +app.controller('modSec', function ($scope, $http, $timeout, $window) { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + $scope.installModSec = function () { - $scope.installModSec = function(){ + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + url = "/firewall/installModSec"; - url = "/firewall/installModSec"; + var data = {}; - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - if(response.data.installModSec === 1){ + if (response.data.installModSec === 1) { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - getRequestStatus(); + getRequestStatus(); + } + else { + $scope.errorMessage = response.data.error_message; + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = false; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + } + + } + + function cantLoadInitialDatas(response) { + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + } + + }; + + function getRequestStatus() { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + url = "/firewall/installStatusModSec"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.abort === 0) { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + $scope.requestData = response.data.requestStatus; + $timeout(getRequestStatus, 1000); + } + else { + // Notifications + $timeout.cancel(); + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + + $scope.requestData = response.data.requestStatus; + + if (response.data.installed === 0) { + $scope.installationFailed = false; + $scope.errorMessage = response.data.error_message; + } else { + $scope.modSecSuccessfullyInstalled = false; + $timeout(function () { + $window.location.reload(); + }, 3000); + } + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + + } + + } + + ///// ModSec configs + + var modsecurity_status = false; + var SecAuditEngine = false; + var SecRuleEngine = false; + + + $('#modsecurity_status').change(function () { + modsecurity_status = $(this).prop('checked'); + }); + + $('#SecAuditEngine').change(function () { + SecAuditEngine = $(this).prop('checked'); + }); + + + $('#SecRuleEngine').change(function () { + SecRuleEngine = $(this).prop('checked'); + }); + + fetchModSecSettings(); + function fetchModSecSettings() { + + $scope.modsecLoading = false; + + $('#modsecurity_status').bootstrapToggle('off'); + $('#SecAuditEngine').bootstrapToggle('off'); + $('#SecRuleEngine').bootstrapToggle('off'); + + url = "/firewall/fetchModSecSettings"; + + var phpSelection = $scope.phpSelection; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.modsecLoading = true; + + if (response.data.fetchStatus === 1) { + + if (response.data.installed === 1) { + + if (response.data.modsecurity === 1) { + $('#modsecurity_status').bootstrapToggle('on'); } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = false; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; + if (response.data.SecAuditEngine === 1) { + $('#SecAuditEngine').bootstrapToggle('on'); + } + if (response.data.SecRuleEngine === 1) { + $('#SecRuleEngine').bootstrapToggle('on'); } - } - function cantLoadInitialDatas(response) { - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - } - - }; - - function getRequestStatus(){ - - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - - url = "/firewall/installStatusModSec"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.abort === 0){ - - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - - $scope.requestData = response.data.requestStatus; - $timeout(getRequestStatus,1000); - } - else{ - // Notifications - $timeout.cancel(); - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - - $scope.requestData = response.data.requestStatus; - - if(response.data.installed === 0) { - $scope.installationFailed = false; - $scope.errorMessage = response.data.error_message; - }else{ - $scope.modSecSuccessfullyInstalled = false; - $timeout(function() { $window.location.reload(); }, 3000); - } - - } - - } - function cantLoadInitialDatas(response) { - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - + $scope.SecDebugLogLevel = response.data.SecDebugLogLevel; + $scope.SecAuditLogParts = response.data.SecAuditLogParts; + $scope.SecAuditLogRelevantStatus = response.data.SecAuditLogRelevantStatus; + $scope.SecAuditLogType = response.data.SecAuditLogType; } - } + } - ///// ModSec configs + } - var modsecurity_status = false; - var SecAuditEngine = false; - var SecRuleEngine = false; + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + } + + } - $('#modsecurity_status').change(function() { - modsecurity_status = $(this).prop('checked'); - }); + ///// - $('#SecAuditEngine').change(function() { - SecAuditEngine = $(this).prop('checked'); - }); + /// Save ModSec Changes + + $scope.failedToSave = true; + $scope.successfullySaved = true; + + $scope.saveModSecConfigurations = function () { + + $scope.failedToSave = true; + $scope.successfullySaved = true; + $scope.modsecLoading = false; + $scope.couldNotConnect = true; - $('#SecRuleEngine').change(function() { - SecRuleEngine = $(this).prop('checked'); - }); + url = "/firewall/saveModSecConfigurations"; - fetchModSecSettings(); - function fetchModSecSettings(){ + var data = { + modsecurity_status: modsecurity_status, + SecAuditEngine: SecAuditEngine, + SecRuleEngine: SecRuleEngine, + SecDebugLogLevel: $scope.SecDebugLogLevel, + SecAuditLogParts: $scope.SecAuditLogParts, + SecAuditLogRelevantStatus: $scope.SecAuditLogRelevantStatus, + SecAuditLogType: $scope.SecAuditLogType, + }; - $scope.modsecLoading = false; - - $('#modsecurity_status').bootstrapToggle('off'); - $('#SecAuditEngine').bootstrapToggle('off'); - $('#SecRuleEngine').bootstrapToggle('off'); - - url = "/firewall/fetchModSecSettings"; - - var phpSelection = $scope.phpSelection; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { - - $scope.modsecLoading = true; - - if(response.data.fetchStatus === 1){ - - if(response.data.installed === 1) { - - if (response.data.modsecurity === 1) { - $('#modsecurity_status').bootstrapToggle('on'); - } - if (response.data.SecAuditEngine === 1) { - $('#SecAuditEngine').bootstrapToggle('on'); - } - if (response.data.SecRuleEngine === 1) { - $('#SecRuleEngine').bootstrapToggle('on'); - } - - $scope.SecDebugLogLevel = response.data.SecDebugLogLevel; - $scope.SecAuditLogParts = response.data.SecAuditLogParts; - $scope.SecAuditLogRelevantStatus = response.data.SecAuditLogRelevantStatus; - $scope.SecAuditLogType = response.data.SecAuditLogType; - - } - - } - - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - } - - } + function ListInitialDatas(response) { - ///// + if (response.data.saveStatus === 1) { - /// Save ModSec Changes + $scope.failedToSave = true; + $scope.successfullySaved = false; + $scope.modsecLoading = true; + $scope.couldNotConnect = true; - $scope.failedToSave = true; - $scope.successfullySaved = true; + } + else { + $scope.errorMessage = response.data.error_message; - $scope.saveModSecConfigurations = function () { + $scope.failedToSave = false; + $scope.successfullySaved = true; + $scope.modsecLoading = true; + $scope.couldNotConnect = true; + } - $scope.failedToSave = true; - $scope.successfullySaved = true; - $scope.modsecLoading = false; - $scope.couldNotConnect = true; + } + + function cantLoadInitialDatas(response) { + $scope.failedToSave = true; + $scope.successfullySaved = false; + $scope.modsecLoading = true; + $scope.couldNotConnect = true; + } - url = "/firewall/saveModSecConfigurations"; - - var data = { - modsecurity_status:modsecurity_status, - SecAuditEngine:SecAuditEngine, - SecRuleEngine:SecRuleEngine, - SecDebugLogLevel:$scope.SecDebugLogLevel, - SecAuditLogParts:$scope.SecAuditLogParts, - SecAuditLogRelevantStatus:$scope.SecAuditLogRelevantStatus, - SecAuditLogType:$scope.SecAuditLogType, - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.saveStatus === 1){ - - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.modsecLoading = true; - $scope.couldNotConnect = true; - - } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.failedToSave = false; - $scope.successfullySaved = true; - $scope.modsecLoading = true; - $scope.couldNotConnect = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.modsecLoading = true; - $scope.couldNotConnect = true; - } - - - }; + }; }); -app.controller('modSecRules', function($scope, $http) { +app.controller('modSecRules', function ($scope, $http) { - $scope.modsecLoading = true; - $scope.rulesSaved = true; - $scope.couldNotConnect = true; - $scope.couldNotSave = true; + $scope.modsecLoading = true; + $scope.rulesSaved = true; + $scope.couldNotConnect = true; + $scope.couldNotSave = true; - fetchModSecRules(); - function fetchModSecRules(){ + fetchModSecRules(); + function fetchModSecRules() { - $scope.modsecLoading = false; - $scope.modsecLoading = true; - $scope.rulesSaved = true; - $scope.couldNotConnect = true; + $scope.modsecLoading = false; + $scope.modsecLoading = true; + $scope.rulesSaved = true; + $scope.couldNotConnect = true; - url = "/firewall/fetchModSecRules"; + url = "/firewall/fetchModSecRules"; - var data = {}; + var data = {}; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - $scope.modsecLoading = true; + $scope.modsecLoading = true; - if(response.data.modSecInstalled === 1){ + if (response.data.modSecInstalled === 1) { - $scope.currentModSecRules = response.data.currentModSecRules; + $scope.currentModSecRules = response.data.currentModSecRules; - } + } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - } + } - } + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + } - $scope.saveModSecRules = function(){ + } - $scope.modsecLoading = false; - $scope.rulesSaved = true; - $scope.couldNotConnect = true; - $scope.couldNotSave = true; + $scope.saveModSecRules = function () { + + $scope.modsecLoading = false; + $scope.rulesSaved = true; + $scope.couldNotConnect = true; + $scope.couldNotSave = true; - url = "/firewall/saveModSecRules"; + url = "/firewall/saveModSecRules"; - var data = { - modSecRules:$scope.currentModSecRules - }; + var data = { + modSecRules: $scope.currentModSecRules + }; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - $scope.modsecLoading = true; + $scope.modsecLoading = true; - if(response.data.saveStatus === 1){ + if (response.data.saveStatus === 1) { - $scope.rulesSaved = false; - $scope.couldNotConnect = true; - $scope.couldNotSave = true; + $scope.rulesSaved = false; + $scope.couldNotConnect = true; + $scope.couldNotSave = true; - }else{ - $scope.rulesSaved = true; - $scope.couldNotConnect = true; - $scope.couldNotSave = false; + } else { + $scope.rulesSaved = true; + $scope.couldNotConnect = true; + $scope.couldNotSave = false; - $scope.errorMessage = response.data.error_message; - } + $scope.errorMessage = response.data.error_message; + } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - $scope.rulesSaved = true; - $scope.couldNotConnect = false; - $scope.couldNotSave = true; - } - } + } + + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + $scope.rulesSaved = true; + $scope.couldNotConnect = false; + $scope.couldNotSave = true; + } + } }); /* Java script code for ModSec */ -app.controller('modSecRulesPack', function($scope, $http, $timeout, $window) { +app.controller('modSecRulesPack', function ($scope, $http, $timeout, $window) { - $scope.modsecLoading = true; - $scope.owaspDisable = true; - $scope.comodoDisable = true; + $scope.modsecLoading = true; + $scope.owaspDisable = true; + $scope.comodoDisable = true; - // + // - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = true; - $scope.ruleFiles = true; + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = true; + $scope.ruleFiles = true; - ///// + ///// - var owaspInstalled = false; - var comodoInstalled = false; - var counterOWASP = 0; - var counterComodo = 0; + var owaspInstalled = false; + var comodoInstalled = false; + var counterOWASP = 0; + var counterComodo = 0; - $('#owaspInstalled').change(function() { + $('#owaspInstalled').change(function () { - owaspInstalled = $(this).prop('checked'); - $scope.ruleFiles = true; + owaspInstalled = $(this).prop('checked'); + $scope.ruleFiles = true; - if(counterOWASP !== 0) { - if (owaspInstalled === true) { - installModSecRulesPack('installOWASP'); + if (counterOWASP !== 0) { + if (owaspInstalled === true) { + installModSecRulesPack('installOWASP'); + } else { + installModSecRulesPack('disableOWASP') + } + } + + counterOWASP = counterOWASP + 1; + }); + + $('#comodoInstalled').change(function () { + + $scope.ruleFiles = true; + comodoInstalled = $(this).prop('checked'); + + if (counterComodo !== 0) { + + if (comodoInstalled === true) { + installModSecRulesPack('installComodo'); + } else { + installModSecRulesPack('disableComodo') + } + } + + counterComodo = counterComodo + 1; + + }); + + + getOWASPAndComodoStatus(true); + function getOWASPAndComodoStatus(updateToggle) { + + $scope.modsecLoading = false; + + + url = "/firewall/getOWASPAndComodoStatus"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.modsecLoading = true; + + if (response.data.modSecInstalled === 1) { + + if (updateToggle === true) { + + if (response.data.owaspInstalled === 1) { + $('#owaspInstalled').bootstrapToggle('on'); + $scope.owaspDisable = false; } else { - installModSecRulesPack('disableOWASP') + $('#owaspInstalled').bootstrapToggle('off'); + $scope.owaspDisable = true; + } + if (response.data.comodoInstalled === 1) { + $('#comodoInstalled').bootstrapToggle('on'); + $scope.comodoDisable = false; + } else { + $('#comodoInstalled').bootstrapToggle('off'); + $scope.comodoDisable = true; + } + } else { + + if (response.data.owaspInstalled === 1) { + $scope.owaspDisable = false; + } else { + $scope.owaspDisable = true; + } + if (response.data.comodoInstalled === 1) { + $scope.comodoDisable = false; + } else { + $scope.comodoDisable = true; } } - counterOWASP = counterOWASP + 1; - }); + } - $('#comodoInstalled').change(function() { + } - $scope.ruleFiles = true; - comodoInstalled = $(this).prop('checked'); + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + } - if(counterComodo !== 0) { + } - if (comodoInstalled === true) { - installModSecRulesPack('installComodo'); - } else { - installModSecRulesPack('disableComodo') - } - } + ///// - counterComodo = counterComodo + 1; + function installModSecRulesPack(packName) { - }); + $scope.modsecLoading = false; + url = "/firewall/installModSecRulesPack"; - getOWASPAndComodoStatus(true); - function getOWASPAndComodoStatus(updateToggle){ + var data = { + packName: packName + }; - $scope.modsecLoading = false; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - url = "/firewall/getOWASPAndComodoStatus"; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - var data = {}; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + function ListInitialDatas(response) { + $scope.modsecLoading = true; + if (response.data.installStatus === 1) { - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $scope.modsecLoading = true; + // - function ListInitialDatas(response) { + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = false; - $scope.modsecLoading = true; + getOWASPAndComodoStatus(false); - if(response.data.modSecInstalled === 1){ + } else { + $scope.modsecLoading = true; - if (updateToggle === true){ + // - if (response.data.owaspInstalled === 1) { - $('#owaspInstalled').bootstrapToggle('on'); - $scope.owaspDisable = false; - } else { - $('#owaspInstalled').bootstrapToggle('off'); - $scope.owaspDisable = true; - } - if (response.data.comodoInstalled === 1) { - $('#comodoInstalled').bootstrapToggle('on'); - $scope.comodoDisable = false; - } else { - $('#comodoInstalled').bootstrapToggle('off'); - $scope.comodoDisable = true; - } - }else{ + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = false; + $scope.installationSuccess = true; - if (response.data.owaspInstalled === 1) { - $scope.owaspDisable = false; - } else { - $scope.owaspDisable = true; - } - if (response.data.comodoInstalled === 1) { - $scope.comodoDisable = false; - } else { - $scope.comodoDisable = true; - } - } + $scope.errorMessage = response.data.error_message; + } - } + } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - } + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; - } + // - ///// + $scope.installationQuote = true; + $scope.couldNotConnect = false; + $scope.installationFailed = true; + $scope.installationSuccess = true; + } - function installModSecRulesPack(packName) { - $scope.modsecLoading = false; + } - url = "/firewall/installModSecRulesPack"; + ///// - var data = { - packName:packName - }; + $scope.fetchRulesFile = function (packName) { - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.modsecLoading = false; + $scope.ruleFiles = false; + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = true; + url = "/firewall/getRulesFiles"; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + var data = { + packName: packName + }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - function ListInitialDatas(response) { - $scope.modsecLoading = true; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - if(response.data.installStatus === 1){ - $scope.modsecLoading = true; + function ListInitialDatas(response) { - // + $scope.modsecLoading = true; - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = false; + if (response.data.fetchStatus === 1) { + $scope.records = JSON.parse(response.data.data); + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = false; - getOWASPAndComodoStatus(false); + } + else { + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = false; + $scope.installationSuccess = true; + $scope.errorMessage = response.data.error_message; + } - }else{ - $scope.modsecLoading = true; + } - // + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; + $scope.installationQuote = true; + $scope.couldNotConnect = false; + $scope.installationFailed = true; + $scope.installationSuccess = true; + } - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = false; - $scope.installationSuccess = true; + }; - $scope.errorMessage = response.data.error_message; - } - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; + $scope.removeRuleFile = function (fileName, packName, status) { - // + $scope.modsecLoading = false; - $scope.installationQuote = true; - $scope.couldNotConnect = false; - $scope.installationFailed = true; - $scope.installationSuccess = true; - } + url = "/firewall/enableDisableRuleFile"; - } + var data = { + packName: packName, + fileName: fileName, + status: status + }; - ///// + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $scope.fetchRulesFile = function (packName) { - $scope.modsecLoading = false; - $scope.ruleFiles = false; - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = true; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - url = "/firewall/getRulesFiles"; - var data = { - packName:packName - }; + function ListInitialDatas(response) { - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.modsecLoading = true; + if (response.data.saveStatus === 1) { + $scope.modsecLoading = true; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + // + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = true; + $scope.installationSuccess = false; - function ListInitialDatas(response) { + $scope.fetchRulesFile(packName); - $scope.modsecLoading = true; + } else { + $scope.modsecLoading = true; - if(response.data.fetchStatus === 1){ - $scope.records = JSON.parse(response.data.data); - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = false; + // - } - else{ - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = false; - $scope.installationSuccess = true; - $scope.errorMessage = response.data.error_message; - } + $scope.installationQuote = true; + $scope.couldNotConnect = true; + $scope.installationFailed = false; + $scope.installationSuccess = true; - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - $scope.installationQuote = true; - $scope.couldNotConnect = false; - $scope.installationFailed = true; - $scope.installationSuccess = true; - } + $scope.errorMessage = response.data.error_message; + } - }; + } + function cantLoadInitialDatas(response) { + $scope.modsecLoading = true; - $scope.removeRuleFile = function (fileName, packName, status) { + // - $scope.modsecLoading = false; - - - - url = "/firewall/enableDisableRuleFile"; - - var data = { - packName:packName, - fileName:fileName, - status:status - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.modsecLoading = true; - - if(response.data.saveStatus === 1){ - - $scope.modsecLoading = true; - - // - - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = true; - $scope.installationSuccess = false; - - $scope.fetchRulesFile(packName); - - }else{ - $scope.modsecLoading = true; - - // - - $scope.installationQuote = true; - $scope.couldNotConnect = true; - $scope.installationFailed = false; - $scope.installationSuccess = true; - - $scope.errorMessage = response.data.error_message; - } - - } - function cantLoadInitialDatas(response) { - $scope.modsecLoading = true; - - // - - $scope.installationQuote = true; - $scope.couldNotConnect = false; - $scope.installationFailed = true; - $scope.installationSuccess = true; - } - - } + $scope.installationQuote = true; + $scope.couldNotConnect = false; + $scope.installationFailed = true; + $scope.installationSuccess = true; + } + } }); @@ -1561,551 +1526,550 @@ app.controller('modSecRulesPack', function($scope, $http, $timeout, $window) { /* Java script code for CSF */ -app.controller('csf', function($scope, $http, $timeout, $window) { +app.controller('csf', function ($scope, $http, $timeout, $window) { - $scope.csfLoading = true; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.csfLoading = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + $scope.installCSF = function () { - $scope.installCSF = function(){ + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + url = "/firewall/installCSF"; - url = "/firewall/installCSF"; + var data = {}; - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - if(response.data.installStatus === 1){ + if (response.data.installStatus === 1) { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; - getRequestStatus(); + getRequestStatus(); - } - else{ - $scope.errorMessage = response.data.error_message; + } + else { + $scope.errorMessage = response.data.error_message; - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = true; - $scope.modsecLoading = true; - $scope.failedToStartInallation = false; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - } + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = false; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + } - } - function cantLoadInitialDatas(response) { + } - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + function cantLoadInitialDatas(response) { + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + } + + }; + function getRequestStatus() { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + url = "/firewall/installStatusCSF"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.abort === 0) { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + $scope.requestData = response.data.requestStatus; + $timeout(getRequestStatus, 1000); + } + else { + // Notifications + $timeout.cancel(); + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + + $scope.requestData = response.data.requestStatus; + + if (response.data.installed === 0) { + $scope.installationFailed = false; + $scope.errorMessage = response.data.error_message; + } else { + $scope.modSecSuccessfullyInstalled = false; + $timeout(function () { + $window.location.reload(); + }, 3000); } - }; - function getRequestStatus(){ + } - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + } - url = "/firewall/installStatusCSF"; + function cantLoadInitialDatas(response) { - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + } - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + } - function ListInitialDatas(response) { + // After installation + + var currentMain = "generalLI"; + var currentChild = "general"; + + $scope.activateTab = function (newMain, newChild) { + $("#" + currentMain).removeClass("ui-tabs-active"); + $("#" + currentMain).removeClass("ui-state-active"); + + $("#" + newMain).addClass("ui-tabs-active"); + $("#" + newMain).addClass("ui-state-active"); + + $('#' + currentChild).hide(); + $('#' + newChild).show(); + + currentMain = newMain; + currentChild = newChild; + }; - if(response.data.abort === 0){ + $scope.removeCSF = function () { - $scope.modSecNotifyBox = true; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; + $scope.csfLoading = false; - $scope.requestData = response.data.requestStatus; - $timeout(getRequestStatus,1000); - } - else{ - // Notifications - $timeout.cancel(); - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.requestData = response.data.requestStatus; + url = "/firewall/removeCSF"; - if(response.data.installed === 0) { - $scope.installationFailed = false; - $scope.errorMessage = response.data.error_message; - }else{ - $scope.modSecSuccessfullyInstalled = false; - $timeout(function() { $window.location.reload(); }, 3000); - } + var data = {}; - } + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.csfLoading = true; + + + if (response.data.installStatus === 1) { + + new PNotify({ + title: 'Successfully removed!', + text: 'CSF successfully removed from server, refreshing page in 3 seconds..', + type: 'success' + }); + + $timeout(function () { + $window.location.reload(); + }, 3000); + + } + else { + new PNotify({ + title: 'Operation failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + + new PNotify({ + title: 'Operation failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } + + }; + + //////// Fetch settings + + // + var testingMode = false; + var testingCounter = 0; + + + $('#testingMode').change(function () { + testingMode = $(this).prop('checked'); + + if (testingCounter !== 0) { + + if (testingMode === true) { + $scope.changeStatus('testingMode', 'enable'); + } else { + $scope.changeStatus('testingMode', 'disable'); + } + } + testingCounter = testingCounter + 1; + }); + // + + // + var firewallStatus = false; + var firewallCounter = 0; + + + $('#firewallStatus').change(function () { + firewallStatus = $(this).prop('checked'); + + if (firewallCounter !== 0) { + + if (firewallStatus === true) { + $scope.changeStatus('csf', 'enable'); + } else { + $scope.changeStatus('csf', 'disable'); + } + } + firewallCounter = firewallCounter + 1; + }); + // + + + $scope.fetchSettings = function () { + + $scope.csfLoading = false; + + $('#testingMode').bootstrapToggle('off'); + $('#firewallStatus').bootstrapToggle('off'); + + url = "/firewall/fetchCSFSettings"; + + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.csfLoading = true; + + if (response.data.fetchStatus === 1) { + + new PNotify({ + title: 'Successfully fetched!', + text: 'CSF settings successfully fetched.', + type: 'success' + }); + + if (response.data.testingMode === 1) { + $('#testingMode').bootstrapToggle('on'); } - function cantLoadInitialDatas(response) { - - $scope.modSecNotifyBox = false; - $scope.modeSecInstallBox = false; - $scope.modsecLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.modSecSuccessfullyInstalled = true; - $scope.installationFailed = true; - - + if (response.data.firewallStatus === 1) { + $('#firewallStatus').bootstrapToggle('on'); } - } + $scope.tcpIN = response.data.tcpIN; + $scope.tcpOUT = response.data.tcpOUT; + $scope.udpIN = response.data.udpIN; + $scope.udpOUT = response.data.udpOUT; + } else { + new PNotify({ + title: 'Failed to load!', + text: response.data.error_message, + type: 'error' + }); - // After installation + } - var currentMain = "generalLI"; - var currentChild = "general"; + } - $scope.activateTab = function (newMain, newChild) { - $("#"+currentMain).removeClass("ui-tabs-active"); - $("#"+currentMain).removeClass("ui-state-active"); + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; - $("#"+newMain).addClass("ui-tabs-active"); - $("#"+newMain).addClass("ui-state-active"); + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } - $('#'+currentChild).hide(); - $('#'+newChild).show(); + }; + $scope.fetchSettings(); - currentMain = newMain; - currentChild = newChild; - }; + $scope.changeStatus = function (controller, status) { - $scope.removeCSF = function(){ + $scope.csfLoading = false; - $scope.csfLoading = false; + url = "/firewall/changeStatus"; - url = "/firewall/removeCSF"; - var data = {}; + var data = { + controller: controller, + status: status + }; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { - function ListInitialDatas(response) { + $scope.csfLoading = true; - $scope.csfLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Changes successfully applied.', + type: 'success' + }); + } else { - if(response.data.installStatus === 1){ + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); - new PNotify({ - title: 'Successfully removed!', - text: 'CSF successfully removed from server, refreshing page in 3 seconds..', - type:'success' - }); + } - $timeout(function() { $window.location.reload(); }, 3000); + } - } - else{ - new PNotify({ - title: 'Operation failed!', - text: response.data.error_message, - type:'error' - }); + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; - } + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } - } - function cantLoadInitialDatas(response) { + }; - new PNotify({ - title: 'Operation failed!', - text: 'Could not connect to server, please refresh this page.', - type:'error' - }); + $scope.modifyPorts = function (protocol) { + $scope.csfLoading = false; - } + var ports; - }; + if (protocol === 'TCP_IN') { + ports = $scope.tcpIN; + } else if (protocol === 'TCP_OUT') { + ports = $scope.tcpOUT; + } else if (protocol === 'UDP_IN') { + ports = $scope.udpIN; + } else if (protocol === 'UDP_OUT') { + ports = $scope.udpOUT; + } - //////// Fetch settings - // - var testingMode = false; - var testingCounter = 0; + url = "/firewall/modifyPorts"; - $('#testingMode').change(function() { - testingMode = $(this).prop('checked'); + var data = { + protocol: protocol, + ports: ports + }; - if(testingCounter !== 0) { + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - if (testingMode === true) { - $scope.changeStatus('testingMode', 'enable'); - } else { - $scope.changeStatus('testingMode', 'disable'); - } - } - testingCounter = testingCounter + 1; - }); - // - // - var firewallStatus = false; - var firewallCounter = 0; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $('#firewallStatus').change(function() { - firewallStatus = $(this).prop('checked'); + function ListInitialDatas(response) { - if(firewallCounter !== 0) { + $scope.csfLoading = true; - if (firewallStatus === true) { - $scope.changeStatus('csf', 'enable'); - } else { - $scope.changeStatus('csf', 'disable'); - } - } - firewallCounter = firewallCounter + 1; - }); - // + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Changes successfully applied.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); - $scope.fetchSettings = function(){ + } - $scope.csfLoading = false; + } - $('#testingMode').bootstrapToggle('off'); - $('#firewallStatus').bootstrapToggle('off'); + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; - url = "/firewall/fetchCSFSettings"; + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } + }; - var data = {}; + $scope.modifyIPs = function (mode) { - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.csfLoading = false; + var ipAddress; + if (mode === 'allowIP') { + ipAddress = $scope.allowIP; + } else if (mode === 'blockIP') { + ipAddress = $scope.blockIP; + } - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + url = "/firewall/modifyIPs"; - function ListInitialDatas(response) { - $scope.csfLoading = true; + var data = { + mode: mode, + ipAddress: ipAddress + }; - if(response.data.fetchStatus === 1){ + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - new PNotify({ - title: 'Successfully fetched!', - text: 'CSF settings successfully fetched.', - type:'success' - }); - if (response.data.testingMode === 1) { - $('#testingMode').bootstrapToggle('on'); - } - if (response.data.firewallStatus === 1) { - $('#firewallStatus').bootstrapToggle('on'); - } + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - $scope.tcpIN = response.data.tcpIN; - $scope.tcpOUT = response.data.tcpOUT; - $scope.udpIN = response.data.udpIN; - $scope.udpOUT = response.data.udpOUT; - }else{ - new PNotify({ - title: 'Failed to load!', - text: response.data.error_message, - type:'error' - }); + function ListInitialDatas(response) { - } + $scope.csfLoading = true; - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; + if (response.data.status === 1) { - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } + new PNotify({ + title: 'Success!', + text: 'Changes successfully applied.', + type: 'success' + }); + } else { - }; - $scope.fetchSettings(); + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } - $scope.changeStatus = function(controller, status){ + } - $scope.csfLoading = false; + function cantLoadInitialDatas(response) { + $scope.csfLoading = true; + new PNotify({ + title: 'Failed to load!', + text: 'Failed to fetch CSF settings.', + type: 'error' + }); + } - - url = "/firewall/changeStatus"; - - - var data = { - controller: controller, - status : status - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.csfLoading = true; - - if(response.data.status === 1){ - - new PNotify({ - title: 'Success!', - text: 'Changes successfully applied.', - type:'success' - }); - }else{ - - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type:'error' - }); - - } - - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; - - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } - - }; - - $scope.modifyPorts = function(protocol){ - - $scope.csfLoading = false; - - var ports; - - if(protocol === 'TCP_IN'){ - ports = $scope.tcpIN; - }else if(protocol === 'TCP_OUT'){ - ports = $scope.tcpOUT; - }else if(protocol === 'UDP_IN'){ - ports = $scope.udpIN; - }else if(protocol === 'UDP_OUT'){ - ports = $scope.udpOUT; - } - - - - url = "/firewall/modifyPorts"; - - - var data = { - protocol: protocol, - ports : ports - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.csfLoading = true; - - if(response.data.status === 1){ - - new PNotify({ - title: 'Success!', - text: 'Changes successfully applied.', - type:'success' - }); - }else{ - - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type:'error' - }); - - } - - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; - - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } - - }; - - $scope.modifyIPs = function(mode){ - - $scope.csfLoading = false; - - var ipAddress; - - if(mode === 'allowIP'){ - ipAddress = $scope.allowIP; - }else if(mode === 'blockIP'){ - ipAddress = $scope.blockIP; - } - - - - url = "/firewall/modifyIPs"; - - - var data = { - mode: mode, - ipAddress : ipAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.csfLoading = true; - - if(response.data.status === 1){ - - new PNotify({ - title: 'Success!', - text: 'Changes successfully applied.', - type:'success' - }); - }else{ - - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type:'error' - }); - - } - - } - function cantLoadInitialDatas(response) { - $scope.csfLoading = true; - - new PNotify({ - title: 'Failed to load!', - text: 'Failed to fetch CSF settings.', - type:'error' - }); - } - - }; + }; }); \ No newline at end of file