Initial ModSec integration and bug fix to UI.

This commit is contained in:
usmannasir 2018-03-19 22:15:02 +05:00
parent bf496020b2
commit af07a0fec5
18 changed files with 1037 additions and 28 deletions

View File

@ -102,7 +102,7 @@ DATABASES = {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.db.backends.mysql',
'NAME': 'cyberpanel', 'NAME': 'cyberpanel',
'USER': 'cyberpanel', 'USER': 'cyberpanel',
'PASSWORD': 'jFzZwX3fFyYrCo', 'PASSWORD': 'Bz9gF7Hr7X4RtD',
'HOST': '127.0.0.1', 'HOST': '127.0.0.1',
'PORT':'3307' 'PORT':'3307'
}, },
@ -110,10 +110,10 @@ DATABASES = {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.db.backends.mysql',
'NAME': 'mysql', 'NAME': 'mysql',
'USER': 'root', 'USER': 'root',
'PASSWORD': 'b1w3wHi5x0o8t9', 'PASSWORD': 'sXm5VlRaAsXkDd',
'HOST': 'localhost', 'HOST': 'localhost',
'PORT': '', 'PORT': '',
} },
} }
DATABASE_ROUTERS = ['backup.backupRouter.backupRouter'] DATABASE_ROUTERS = ['backup.backupRouter.backupRouter']
@ -174,4 +174,3 @@ LANGUAGES = (
('ru', _('Russian')), ('ru', _('Russian')),
('tr', _('Turkish')), ('tr', _('Turkish')),
) )

Binary file not shown.

View File

@ -57,7 +57,7 @@ def getAdminStatus(request):
logging.CyberCPLogFileWriter.writeToFile("Failed to read machine IP, error:" +str(msg)) logging.CyberCPLogFileWriter.writeToFile("Failed to read machine IP, error:" +str(msg))
serverIPAddress = "192.168.100.1" 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} adminData = {"admin_type":admin_type,"user_name":adminName,"serverIPAddress":serverIPAddress}

View File

@ -823,4 +823,407 @@ app.controller('secureSSHCTRL', function($scope,$http) {
}); });
/* Java script code to Secure SSH */ /* 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 */

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -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 %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "ModSecurity Configurations!" %} </h2>
<p>{% trans "On this page you can configure ModSecurity settings." %}</p>
</div>
<div ng-controller="modSec" class="example-box-wrapper">
<div style="border-radius: 25px;border-color:#3498db" class="content-box">
<h3 class="content-box-header bg-blue">
{% trans "ModSecurity" %} <img ng-hide="modsecLoading" src="/static/images/loading.gif">
</h3>
<div class="content-box-wrapper">
<div class="row">
{% if modSecInstalled == 0 %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h3>{% trans "ModSecurity is not installed " %}
<button ng-click="installModSec()" class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Install Now." %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button></h3>
</div>
<!------ ModeSec Install Log box ----------------->
<div ng-hide="modSecNotifyBox" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div ng-hide="failedToStartInallation" class="alert alert-danger">
<p>{% trans "Failed to start installation, Error message: " %} {$ errorMessage $}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect. Please refresh this page." %} </p>
</div>
<div ng-hide="installationFailed" class="alert alert-danger">
<p>{% trans "Installation failed." %} {$ errorMessage $}</p>
</div>
<div ng-hide="modSecSuccessfullyInstalled" class="alert alert-success">
<p>{% trans "ModSecurity successfully installed, refreshing page in 3 seconds.." %}</p>
</div>
</div>
</div>
<div ng-hide="modeSecInstallBox" class="col-md-12">
<form action="/" id="" class="form-horizontal bordered-row">
<div class="form-group">
<div class="col-sm-12 text-center">
<h3><img src="{% static 'firewall/icons/firewall.png' %}"> {% trans "Winter is coming, but so is ModSecurity." %} <img ng-hide="modsecLoading" src="/static/images/loading.gif"></h3>
</div>
<div style="margin-top: 2%;" class="col-sm-12">
<textarea ng-model="requestData" rows="15" class="form-control">{{ requestData }}</textarea>
</div>
</div>
</form>
</div>
<!----- ModeSec Install Log box ----------------->
{% else %}
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -18,10 +18,16 @@ urlpatterns = [
url(r'^secureSSH', views.secureSSH, name='secureSSH'), url(r'^secureSSH', views.secureSSH, name='secureSSH'),
url(r'^getSSHConfigs', views.getSSHConfigs, name='getSSHConfigs'), url(r'^getSSHConfigs', views.getSSHConfigs, name='getSSHConfigs'),
url(r'^saveSSHConfigs', views.saveSSHConfigs, name='saveSSHConfigs'), url(r'^saveSSHConfigs', views.saveSSHConfigs, name='saveSSHConfigs'),
url(r'^deleteSSHKey', views.deleteSSHKey, name='deleteSSHKey'), url(r'^deleteSSHKey', views.deleteSSHKey, name='deleteSSHKey'),
url(r'^addSSHKey', views.addSSHKey, name='addSSHKey'), 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'),
] ]

View File

@ -1,8 +1,6 @@
from django.shortcuts import render,redirect from django.shortcuts import render,redirect
from .models import FirewallRules
from django.http import HttpResponse from django.http import HttpResponse
import json import json
from plogical.firewallUtilities import FirewallUtilities
import shlex import shlex
import subprocess import subprocess
from loginSystem.views import loadLoginPage from loginSystem.views import loadLoginPage
@ -11,6 +9,10 @@ from .models import FirewallRules
import os import os
from loginSystem.models import Administrator from loginSystem.models import Administrator
import plogical.CyberCPLogFileWriter as logging 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. # Create your views here.
@ -628,3 +630,85 @@ def addSSHKey(request):
final_dic = {'add_status': 0} final_dic = {'add_status': 0}
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) 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)

View File

@ -114,10 +114,7 @@
<p>{% trans "Could not connect. Please refresh this page." %}</p> <p>{% trans "Could not connect. Please refresh this page." %}</p>
</div> </div>
</div> </div>
</div>
</div>

View File

@ -1828,7 +1828,6 @@ def getExtensionsInformation(request):
def submitExtensionRequest(request): def submitExtensionRequest(request):
try: try:
val = request.session['userID'] val = request.session['userID']
try: try:

View File

@ -1,4 +1,3 @@
import thread
import pexpect import pexpect
import CyberCPLogFileWriter as logging import CyberCPLogFileWriter as logging
import subprocess import subprocess

32
plogical/modSec.py Normal file
View File

@ -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]")

View File

@ -33,7 +33,7 @@ class sslUtilities:
keyFile = " keyFile " + pathToStoreSSL + "/privkey.pem" + "\n" keyFile = " keyFile " + pathToStoreSSL + "/privkey.pem" + "\n"
certFile = " certFile " + pathToStoreSSL + "/fullchain.pem" + "\n" certFile = " certFile " + pathToStoreSSL + "/fullchain.pem" + "\n"
certChain = " certChain 1" + "\n" certChain = " certChain 1" + "\n"
sslProtocol = " sslProtocol 31" + "\n" sslProtocol = " sslProtocol 30" + "\n"
map = " map " + virtualHostName + " " + virtualHostName + "\n" map = " map " + virtualHostName + " " + virtualHostName + "\n"
final = "}" + "\n" + "\n" final = "}" + "\n" + "\n"
@ -87,7 +87,7 @@ class sslUtilities:
keyFile = " keyFile " + pathToStoreSSL + "/privkey.pem" + "\n" keyFile = " keyFile " + pathToStoreSSL + "/privkey.pem" + "\n"
certFile = " certFile " + pathToStoreSSL + "/fullchain.pem" + "\n" certFile = " certFile " + pathToStoreSSL + "/fullchain.pem" + "\n"
certChain = " certChain 1" + "\n" certChain = " certChain 1" + "\n"
sslProtocol = " sslProtocol 31" + "\n" sslProtocol = " sslProtocol 30" + "\n"
final = "}" final = "}"
writeSSLConfig.writelines("\n") writeSSLConfig.writelines("\n")
@ -146,7 +146,7 @@ class sslUtilities:
else: else:
command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName
logging.CyberCPLogFileWriter.writeToFile( 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: except:
command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName 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: if sslUtilities.installSSLForDomain(domain) == 1:
return [1, "None"] return [1, "None"]
else: else:
[0, "327 Failed to install SSL for domain. [issueSSLForDomain]"] return [0, "352 Failed to install SSL for domain. [issueSSLForDomain]"]
else: else:
return [0,"347 Failed to obtain SSL [issueSSLForDomain]"] return [0,"347 Failed to obtain SSL [issueSSLForDomain]"]
except BaseException,msg: except BaseException,msg:

View File

@ -823,4 +823,407 @@ app.controller('secureSSHCTRL', function($scope,$http) {
}); });
/* Java script code to Secure SSH */ /* 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 */

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -13,7 +13,7 @@ app.controller('createWebsite', function($scope,$http) {
$scope.createWebsite = function(){ $scope.createWebsite = function(){
if ($scope.sslCheck == true){ if ($scope.sslCheck === true){
var ssl = 1; var ssl = 1;
} }
else{ else{

View File

@ -69,8 +69,8 @@
<label class="col-sm-3 control-label">{% trans "Account Type" %}</label> <label class="col-sm-3 control-label">{% trans "Account Type" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">
<select ng-change="showLimitsBox()" ng-model="accountType" class="form-control"> <select ng-change="showLimitsBox()" ng-model="accountType" class="form-control">
<option>{% trans "Admin" %}</option> <option>Admin</option>
<option>{% trans "Normal User" %}</option> <option>Normal User</option>
</select> </select>
</div> </div>

View File

@ -118,9 +118,6 @@
<p>{% trans "Website with domain" %} <strong>{$ websiteDomain $}</strong>{% trans " is Successfully Created" %}</p> <p>{% trans "Website with domain" %} <strong>{$ websiteDomain $}</strong>{% trans " is Successfully Created" %}</p>
</div> </div>
</div> </div>
</div> </div>