diff --git a/CyberCP/settings.py b/CyberCP/settings.py index 4348eed51..9dff2056a 100644 --- a/CyberCP/settings.py +++ b/CyberCP/settings.py @@ -102,7 +102,7 @@ DATABASES = { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'cyberpanel', 'USER': 'cyberpanel', - 'PASSWORD': 'jFzZwX3fFyYrCo', + 'PASSWORD': 'Bz9gF7Hr7X4RtD', 'HOST': '127.0.0.1', 'PORT':'3307' }, @@ -110,10 +110,10 @@ DATABASES = { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mysql', 'USER': 'root', - 'PASSWORD': 'b1w3wHi5x0o8t9', + 'PASSWORD': 'sXm5VlRaAsXkDd', 'HOST': 'localhost', 'PORT': '', - } + }, } DATABASE_ROUTERS = ['backup.backupRouter.backupRouter'] @@ -174,4 +174,3 @@ LANGUAGES = ( ('ru', _('Russian')), ('tr', _('Turkish')), ) - diff --git a/CyberCP/settings.pyc b/CyberCP/settings.pyc index 25b0de830..60e4a8795 100644 Binary files a/CyberCP/settings.pyc and b/CyberCP/settings.pyc differ diff --git a/baseTemplate/views.py b/baseTemplate/views.py index e61320243..ef9da75e8 100644 --- a/baseTemplate/views.py +++ b/baseTemplate/views.py @@ -57,7 +57,7 @@ def getAdminStatus(request): logging.CyberCPLogFileWriter.writeToFile("Failed to read machine IP, error:" +str(msg)) serverIPAddress = "192.168.100.1" - adminName = administrator.firstName + " " + administrator.lastName + adminName = administrator.firstName + " " + administrator.lastName[0] adminData = {"admin_type":admin_type,"user_name":adminName,"serverIPAddress":serverIPAddress} diff --git a/firewall/static/firewall/firewall.js b/firewall/static/firewall/firewall.js index fd35d3d32..07da99851 100644 --- a/firewall/static/firewall/firewall.js +++ b/firewall/static/firewall/firewall.js @@ -823,4 +823,407 @@ app.controller('secureSSHCTRL', function($scope,$http) { }); -/* Java script code to Secure SSH */ \ No newline at end of file +/* Java script code to Secure SSH */ + +/* Java script code for ModSec */ + +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.installModSec = function(){ + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + url = "/firewall/installModSec"; + + var data = {}; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + 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; + + 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; + + + } + + } + + + + 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; + + } + + + } + +}); + +/* Java script code for ModSec */ \ No newline at end of file diff --git a/firewall/static/firewall/icons/firewall.png b/firewall/static/firewall/icons/firewall.png new file mode 100644 index 000000000..667796450 Binary files /dev/null and b/firewall/static/firewall/icons/firewall.png differ diff --git a/firewall/templates/firewall/modSecurity.html b/firewall/templates/firewall/modSecurity.html new file mode 100644 index 000000000..9e22a514f --- /dev/null +++ b/firewall/templates/firewall/modSecurity.html @@ -0,0 +1,90 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "ModSecurity - CyberPanel" %}{% endblock %} +{% block content %} + +{% load static %} +{% get_current_language as LANGUAGE_CODE %} + + + +
+
+

{% trans "ModSecurity Configurations!" %}

+

{% trans "On this page you can configure ModSecurity settings." %}

+
+ +
+
+

+ {% trans "ModSecurity" %} +

+ +
+
+ + {% if modSecInstalled == 0 %} + +
+

{% trans "ModSecurity is not installed " %} +

+
+ + +
+ +
+
+

{% trans "Failed to start installation, Error message: " %} {$ errorMessage $}

+
+ +
+

{% trans "Could not connect. Please refresh this page." %}

+
+ +
+

{% trans "Installation failed." %} {$ errorMessage $}

+
+ +
+

{% trans "ModSecurity successfully installed, refreshing page in 3 seconds.." %}

+
+
+
+ + +
+ +
+
+
+

{% trans "Winter is coming, but so is ModSecurity." %}

+
+
+ +
+
+
+
+ + + + + {% else %} + {% endif %} + + + +
+
+
+
+ + +
+ + +{% endblock %} \ No newline at end of file diff --git a/firewall/urls.py b/firewall/urls.py index 4d45f790e..f729ba18d 100644 --- a/firewall/urls.py +++ b/firewall/urls.py @@ -18,10 +18,16 @@ urlpatterns = [ url(r'^secureSSH', views.secureSSH, name='secureSSH'), url(r'^getSSHConfigs', views.getSSHConfigs, name='getSSHConfigs'), - url(r'^saveSSHConfigs', views.saveSSHConfigs, name='saveSSHConfigs'), - url(r'^deleteSSHKey', views.deleteSSHKey, name='deleteSSHKey'), - url(r'^addSSHKey', views.addSSHKey, name='addSSHKey'), + + + ## ModSecurity + + url(r'^modSecurity', views.loadModSecurityHome, name='modSecurity'), + url(r'^installModSec', views.installModSec, name='installModSec'), + url(r'^installStatusModSec', views.installStatusModSec, name='installStatusModSec'), + + ] \ No newline at end of file diff --git a/firewall/views.py b/firewall/views.py index 7c5492875..fc1cb739d 100644 --- a/firewall/views.py +++ b/firewall/views.py @@ -1,8 +1,6 @@ from django.shortcuts import render,redirect -from .models import FirewallRules from django.http import HttpResponse import json -from plogical.firewallUtilities import FirewallUtilities import shlex import subprocess from loginSystem.views import loadLoginPage @@ -11,6 +9,10 @@ from .models import FirewallRules import os from loginSystem.models import Administrator import plogical.CyberCPLogFileWriter as logging +from plogical.virtualHostUtilities import virtualHostUtilities +import thread +from plogical.modSec import modSec +from plogical.installUtilities import installUtilities # Create your views here. @@ -628,3 +630,85 @@ def addSSHKey(request): final_dic = {'add_status': 0} final_json = json.dumps(final_dic) return HttpResponse(final_json) + +def loadModSecurityHome(request): + try: + userID = request.session['userID'] + + admin = Administrator.objects.get(pk=userID) + + if admin.type == 3: + return HttpResponse("You don't have enough privileges to access this page.") + + modSecPath = os.path.join(virtualHostUtilities.Server_root,'modules','mod_security.so') + + modSecInstalled = 0 + + if os.path.exists(modSecPath): + modSecInstalled = 1 + + return render(request,'firewall/modSecurity.html', {'modSecInstalled': modSecInstalled}) + except KeyError: + return redirect(loadLoginPage) + +def installModSec(request): + try: + val = request.session['userID'] + try: + thread.start_new_thread(modSec.installModSec, ('Install','modSec')) + final_json = json.dumps({'installModSec': 1, 'error_message': "None"}) + return HttpResponse(final_json) + + except BaseException,msg: + final_dic = {'installModSec': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + except KeyError: + final_dic = {'installModSec': 0, 'error_message': "Not Logged In, please refresh the page or login again."} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +def installStatusModSec(request): + try: + val = request.session['userID'] + try: + if request.method == 'POST': + + installStatus = unicode(open(modSec.installLogPath, "r").read()) + + if installStatus.find("[200]")>-1: + + final_json = json.dumps({ + 'error_message': "None", + 'requestStatus': installStatus, + 'abort':1, + 'installed': 1, + }) + return HttpResponse(final_json) + elif installStatus.find("[404]") > -1: + + final_json = json.dumps({ + 'abort':1, + 'installed':0, + 'error_message': "None", + 'requestStatus': installStatus, + }) + return HttpResponse(final_json) + + else: + final_json = json.dumps({ + 'abort':0, + 'error_message': "None", + 'requestStatus': installStatus, + }) + return HttpResponse(final_json) + + + except BaseException,msg: + final_dic = {'abort':1,'installed':0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + except KeyError: + final_dic = {'abort':1,'installed':0, 'error_message': "Not Logged In, please refresh the page or login again."} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) diff --git a/managePHP/templates/managePHP/installExtensions.html b/managePHP/templates/managePHP/installExtensions.html index 392fc1e42..e415e9dbb 100644 --- a/managePHP/templates/managePHP/installExtensions.html +++ b/managePHP/templates/managePHP/installExtensions.html @@ -114,10 +114,7 @@

{% trans "Could not connect. Please refresh this page." %}

- - - - + diff --git a/managePHP/views.py b/managePHP/views.py index ef68ded21..366af0ad4 100644 --- a/managePHP/views.py +++ b/managePHP/views.py @@ -1828,7 +1828,6 @@ def getExtensionsInformation(request): def submitExtensionRequest(request): - try: val = request.session['userID'] try: diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index c2522ae9c..e820e65ac 100644 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -1,4 +1,3 @@ -import thread import pexpect import CyberCPLogFileWriter as logging import subprocess diff --git a/plogical/modSec.py b/plogical/modSec.py new file mode 100644 index 000000000..126ae8e28 --- /dev/null +++ b/plogical/modSec.py @@ -0,0 +1,32 @@ +import CyberCPLogFileWriter as logging +import subprocess +import shlex + +class modSec: + installLogPath = "/home/cyberpanel/modSecInstallLog" + + @staticmethod + def installModSec(install, modSecInstall): + try: + + command = 'sudo yum install ols-modsecurity -y' + + cmd = shlex.split(command) + + with open(modSec.installLogPath, 'w') as f: + res = subprocess.call(cmd, stdout=f) + + if res == 1: + writeToFile = open(modSec.installLogPath, 'a') + writeToFile.writelines("Can not be installed.[404]\n") + writeToFile.close() + logging.CyberCPLogFileWriter.writeToFile("[Could not Install]") + return 0 + else: + writeToFile = open(modSec.installLogPath, 'a') + writeToFile.writelines("ModSecurity Installed.[200]\n") + writeToFile.close() + + return 1 + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installModSec]") \ No newline at end of file diff --git a/plogical/sslUtilities.py b/plogical/sslUtilities.py index 5e21700d4..2220b0532 100644 --- a/plogical/sslUtilities.py +++ b/plogical/sslUtilities.py @@ -33,7 +33,7 @@ class sslUtilities: keyFile = " keyFile " + pathToStoreSSL + "/privkey.pem" + "\n" certFile = " certFile " + pathToStoreSSL + "/fullchain.pem" + "\n" certChain = " certChain 1" + "\n" - sslProtocol = " sslProtocol 31" + "\n" + sslProtocol = " sslProtocol 30" + "\n" map = " map " + virtualHostName + " " + virtualHostName + "\n" final = "}" + "\n" + "\n" @@ -87,7 +87,7 @@ class sslUtilities: keyFile = " keyFile " + pathToStoreSSL + "/privkey.pem" + "\n" certFile = " certFile " + pathToStoreSSL + "/fullchain.pem" + "\n" certChain = " certChain 1" + "\n" - sslProtocol = " sslProtocol 31" + "\n" + sslProtocol = " sslProtocol 30" + "\n" final = "}" writeSSLConfig.writelines("\n") @@ -146,7 +146,7 @@ class sslUtilities: else: command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName logging.CyberCPLogFileWriter.writeToFile( - "SSL is issued without 'www' due to DNS error! for domain :" + virtualHostName) + "SSL is issued without 'www' due to DNS error! for domain : " + virtualHostName) except: command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName @@ -349,7 +349,7 @@ def issueSSLForDomain(domain,adminEmail,sslpath): if sslUtilities.installSSLForDomain(domain) == 1: return [1, "None"] else: - [0, "327 Failed to install SSL for domain. [issueSSLForDomain]"] + return [0, "352 Failed to install SSL for domain. [issueSSLForDomain]"] else: return [0,"347 Failed to obtain SSL [issueSSLForDomain]"] except BaseException,msg: diff --git a/static/firewall/firewall.js b/static/firewall/firewall.js index fd35d3d32..07da99851 100644 --- a/static/firewall/firewall.js +++ b/static/firewall/firewall.js @@ -823,4 +823,407 @@ app.controller('secureSSHCTRL', function($scope,$http) { }); -/* Java script code to Secure SSH */ \ No newline at end of file +/* Java script code to Secure SSH */ + +/* Java script code for ModSec */ + +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.installModSec = function(){ + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + url = "/firewall/installModSec"; + + var data = {}; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + 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; + + 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; + + + } + + } + + + + 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; + + } + + + } + +}); + +/* Java script code for ModSec */ \ No newline at end of file diff --git a/static/firewall/icons/firewall.png b/static/firewall/icons/firewall.png new file mode 100644 index 000000000..667796450 Binary files /dev/null and b/static/firewall/icons/firewall.png differ diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index 159e19277..fef3fe37a 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -13,7 +13,7 @@ app.controller('createWebsite', function($scope,$http) { $scope.createWebsite = function(){ - if ($scope.sslCheck == true){ + if ($scope.sslCheck === true){ var ssl = 1; } else{ diff --git a/userManagment/templates/userManagment/modifyUser.html b/userManagment/templates/userManagment/modifyUser.html index 4d0f491bf..dfa8999b8 100644 --- a/userManagment/templates/userManagment/modifyUser.html +++ b/userManagment/templates/userManagment/modifyUser.html @@ -69,8 +69,8 @@
diff --git a/websiteFunctions/templates/websiteFunctions/createWebsite.html b/websiteFunctions/templates/websiteFunctions/createWebsite.html index e97204c67..dda107468 100644 --- a/websiteFunctions/templates/websiteFunctions/createWebsite.html +++ b/websiteFunctions/templates/websiteFunctions/createWebsite.html @@ -118,9 +118,6 @@

{% trans "Website with domain" %} {$ websiteDomain $}{% trans " is Successfully Created" %}

- - -