CSF Installation

This commit is contained in:
usmannasir
2018-08-06 02:01:09 +05:00
parent d8da9d1321
commit 3fbe0a0dfa
6 changed files with 738 additions and 4 deletions

View File

@@ -1563,4 +1563,165 @@ app.controller('modSecRulesPack', function($scope, $http, $timeout, $window) {
}); });
/* Java script code for ModSec */ /* Java script code for ModSec */
/* Java script code for CSF */
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.installCSF = function(){
$scope.modSecNotifyBox = true;
$scope.modeSecInstallBox = true;
$scope.modsecLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.modSecSuccessfullyInstalled = true;
$scope.installationFailed = true;
url = "/firewall/installCSF";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
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;
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/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 cantLoadInitialDatas(response) {
$scope.modSecNotifyBox = false;
$scope.modeSecInstallBox = false;
$scope.modsecLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.modSecSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
}
});

View File

@@ -0,0 +1,200 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "CSF (ConfigServer Security and Firewall) - 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 "CSF (ConfigServer Security and Firewall)!" %}</h2>
<p>{% trans "On this page you can configure CSF (ConfigServer Security and Firewall) settings." %}</p>
</div>
<div ng-controller="csf" class="example-box-wrapper">
<div style="border-radius: 25px;border-color:#3498db" class="content-box">
<h3 class="content-box-header bg-blue">
{% trans "CSF" %} <img ng-hide="csfLoading" src="/static/images/loading.gif">
</h3>
<div class="content-box-wrapper">
<div class="row">
{% if csfInstalled == 0 %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h3>{% trans "CSF is not installed " %}
<button ng-click="installCSF()" 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 "CSF 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 "In winter we must protect each other.." %} <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 %}
<div style="padding: 2%" class="col-md-12">
<form action="/" id="createPackages" class="form-horizontal bordered-row">
<div ng-hide="phpDetailsBox" class="form-group">
<label class="col-sm-4 control-label">ModSecurity Status</label>
<div class="col-sm-6">
<input type="checkbox" id="modsecurity_status" data-toggle="toggle">
</div>
</div>
<div ng-hide="phpDetailsBox" class="form-group">
<label class="col-sm-4 control-label">SecAuditEngine</label>
<div class="col-sm-6">
<input type="checkbox" id="SecAuditEngine" data-toggle="toggle">
</div>
</div>
<div ng-hide="phpDetailsBox" class="form-group">
<label class="col-sm-4 control-label">SecRuleEngine</label>
<div class="col-sm-6">
<input type="checkbox" id="SecRuleEngine" data-toggle="toggle">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">SecDebugLogLevel</label>
<div class="col-sm-6">
<div class="selector" style="width: 79px;"><span style="width: 57px; -moz-user-select: none;">{$ SecDebugLogLevel $}</span><select ng-model="SecDebugLogLevel" class="custom-select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select><i class="glyph-icon icon-caret-down"></i></div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">SecAuditLogParts</label>
<div class="col-sm-6">
<div class="selector" style="width: 79px;"><span style="width: 57px; -moz-user-select: none;">{$ SecAuditLogParts $}</span><select ng-model="SecAuditLogParts" class="custom-select">
<option>A</option>
<option>AB</option>
<option>ABI</option>
<option>ABIJ</option>
<option>ABIJD</option>
<option>ABIJDE</option>
<option>ABIJDEF</option>
<option>ABIJDEFH</option>
<option>ABIJDEFHZ</option>
</select><i class="glyph-icon icon-caret-down"></i></div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">SecAuditLogRelevantStatus</label>
<div class="col-sm-6">
<input type="text" class="form-control" ng-model="SecAuditLogRelevantStatus" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">SecAuditLogType</label>
<div class="col-sm-6">
<input type="text" class="form-control" ng-model="SecAuditLogType" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="saveModSecConfigurations()" class="btn btn-primary btn-lg btn-block">{% trans "Save changes." %}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div ng-hide="failedToSave" class="alert alert-danger">
<p>{% trans "Failed to save ModSecurity configurations. Error message: " %} {$ errorMessage $}</p>
</div>
<div ng-hide="successfullySaved" class="alert alert-success">
<p>{% trans "ModSecurity configurations successfully saved." %}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect. Please refresh this page." %} </p>
</div>
</div>
</div>
</form>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -39,6 +39,12 @@ urlpatterns = [
url(r'^getRulesFiles', views.getRulesFiles, name='getRulesFiles'), url(r'^getRulesFiles', views.getRulesFiles, name='getRulesFiles'),
url(r'^enableDisableRuleFile', views.enableDisableRuleFile, name='enableDisableRuleFile'), url(r'^enableDisableRuleFile', views.enableDisableRuleFile, name='enableDisableRuleFile'),
## CSF
url(r'^csf$', views.csf, name='csf'),
url(r'^installCSF$', views.installCSF, name='installModSec'),
url(r'^installStatusCSF$', views.installStatusCSF, name='installStatusCSF'),
] ]

View File

@@ -14,6 +14,7 @@ import thread
from plogical.modSec import modSec from plogical.modSec import modSec
from plogical.installUtilities import installUtilities from plogical.installUtilities import installUtilities
from random import randint from random import randint
from plogical.csf import CSF
# Create your views here. # Create your views here.
@@ -803,7 +804,6 @@ def installStatusModSec(request):
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
def fetchModSecSettings(request): def fetchModSecSettings(request):
try: try:
val = request.session['userID'] val = request.session['userID']
@@ -1018,7 +1018,6 @@ def modSecRules(request):
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)
def fetchModSecRules(request): def fetchModSecRules(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
@@ -1358,3 +1357,101 @@ def enableDisableRuleFile(request):
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
def csf(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(pk=userID)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
csfInstalled = 1
try:
command = 'sudo csf -h'
res = subprocess.call(shlex.split(command))
if res == 1:
csfInstalled = 0
except subprocess.CalledProcessError:
csfInstalled = 0
return render(request,'firewall/csf.html', {'csfInstalled' : csfInstalled})
except KeyError:
return redirect(loadLoginPage)
def installCSF(request):
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
try:
if admin.type != 1:
final_dic = {'installStatus': 0, 'error_message': 'Not enough privileges.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
thread.start_new_thread(CSF.installCSF, ('Install','csf'))
final_json = json.dumps({'installStatus': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException,msg:
final_dic = {'installStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError:
final_dic = {'installStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def installStatusCSF(request):
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
try:
if request.method == 'POST':
if admin.type != 1:
final_dic = {'abort': 1, 'installed': 0, 'error_message': 'Not enough privileges.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
installStatus = unicode(open(CSF.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)

109
plogical/csf.py Normal file
View File

@@ -0,0 +1,109 @@
import CyberCPLogFileWriter as logging
import subprocess
import shlex
import argparse
from virtualHostUtilities import virtualHostUtilities
import os
import tarfile
import shutil
from mailUtilities import mailUtilities
class CSF:
installLogPath = "/home/cyberpanel/csfInstallLog"
csfURL = 'https://download.configserver.com/csf.tgz'
@staticmethod
def installCSF(install, csfInstall):
try:
mailUtilities.checkHome()
##
command = 'sudo wget ' + CSF.csfURL
cmd = shlex.split(command)
with open(CSF.installLogPath, 'w') as f:
res = subprocess.call(cmd, stdout=f)
##
command = 'sudo tar -xzf csf.tgz'
cmd = shlex.split(command)
with open(CSF.installLogPath, 'w') as f:
res = subprocess.call(cmd, stdout=f)
##
os.chdir('csf')
command = 'sudo ./install.sh'
cmd = shlex.split(command)
with open(CSF.installLogPath, 'w') as f:
res = subprocess.call(cmd, stdout=f)
os.chdir('/usr/local/CyberCP')
writeToFile = open(CSF.installLogPath, 'a')
writeToFile.writelines("CSF successfully Installed.[200]\n")
writeToFile.close()
command = 'sudo rm -rf csf'
cmd = shlex.split(command)
res = subprocess.call(cmd)
command = 'sudo rm -f csf.tgz'
cmd = shlex.split(command)
res = subprocess.call(cmd)
return 1
except BaseException, msg:
command = 'sudo rm -rf csf'
cmd = shlex.split(command)
res = subprocess.call(cmd)
command = 'sudo rm -f csf.tgz'
cmd = shlex.split(command)
res = subprocess.call(cmd)
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installModSec]")
def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer')
parser.add_argument('function', help='Specific a function to call!')
parser.add_argument('--tempConfigPath', help='Temporary path to configurations data!')
parser.add_argument('--packName', help='ModSecurity supplier name!')
parser.add_argument('--fileName', help='Filename to enable or disable!')
args = parser.parse_args()
if args.function == "installModSecConfigs":
modSec.installModSecConfigs()
elif args.function == "saveModSecConfigs":
modSec.saveModSecConfigs(args.tempConfigPath)
elif args.function == "saveModSecRules":
modSec.saveModSecRules()
elif args.function == "setupOWASPRules":
modSec.setupOWASPRules()
elif args.function == "installOWASP":
modSec.installOWASP()
elif args.function == "disableOWASP":
modSec.disableOWASP()
elif args.function == "setupComodoRules":
modSec.setupComodoRules()
elif args.function == "installComodo":
modSec.installComodo()
elif args.function == "disableComodo":
modSec.disableComodo()
elif args.function == "disableRuleFile":
modSec.disableRuleFile(args.fileName, args.packName)
elif args.function == "enableRuleFile":
modSec.enableRuleFile(args.fileName, args.packName)
if __name__ == "__main__":
main()

View File

@@ -1563,4 +1563,165 @@ app.controller('modSecRulesPack', function($scope, $http, $timeout, $window) {
}); });
/* Java script code for ModSec */ /* Java script code for ModSec */
/* Java script code for CSF */
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.installCSF = function(){
$scope.modSecNotifyBox = true;
$scope.modeSecInstallBox = true;
$scope.modsecLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.modSecSuccessfullyInstalled = true;
$scope.installationFailed = true;
url = "/firewall/installCSF";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
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;
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/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 cantLoadInitialDatas(response) {
$scope.modSecNotifyBox = false;
$scope.modeSecInstallBox = false;
$scope.modsecLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.modSecSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
}
});