mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
complete imunify integration
This commit is contained in:
@@ -114,16 +114,75 @@ class CageFS:
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
|
||||
|
||||
@staticmethod
|
||||
def submitinstallImunify(key):
|
||||
try:
|
||||
|
||||
mailUtilities.checkHome()
|
||||
|
||||
statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
"Starting Imunify Installation..\n", 1)
|
||||
|
||||
##
|
||||
|
||||
command = 'mkdir -p /etc/sysconfig/imunify360/generic'
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
command = 'touch /etc/sysconfig/imunify360/generic/modsec.conf'
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
integrationFile = '/etc/sysconfig/imunify360/integration.conf'
|
||||
|
||||
content = """[paths]
|
||||
ui_path =/usr/local/CyberCP/public/imunify
|
||||
[web_server]
|
||||
server_type = litespeed
|
||||
graceful_restart_script = /usr/local/lsws/bin/lswsctrl restart
|
||||
modsec_audit_log = /usr/local/lsws/logs/auditmodsec.log
|
||||
modsec_audit_logdir = /usr/local/lsws/logs/
|
||||
|
||||
[malware]
|
||||
basedir = /home
|
||||
pattern_to_watch = ^/home/.+?/(public_html|public_ftp|private_html)(/.*)?$
|
||||
"""
|
||||
|
||||
writeToFile = open(integrationFile, 'w')
|
||||
writeToFile.write(content)
|
||||
writeToFile.close()
|
||||
|
||||
##
|
||||
|
||||
if not os.path.exists('i360deploy.sh'):
|
||||
command = 'wget https://repo.imunify360.cloudlinux.com/defence360/i360deploy.sh'
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
command = 'bash i360deploy.sh --key %s --beta' % (key)
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
"Imunify reinstalled..\n", 1)
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
"Packages successfully installed.[200]\n", 1)
|
||||
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description='CyberPanel CageFS Manager')
|
||||
parser.add_argument('--function', help='Function')
|
||||
parser.add_argument('--key', help='Imunify Key')
|
||||
|
||||
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
if args["function"] == "submitCageFSInstall":
|
||||
CageFS.submitCageFSInstall()
|
||||
elif args["function"] == "submitinstallImunify":
|
||||
CageFS.submitinstallImunify(args["key"])
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,9 +19,13 @@ from firewall.models import FirewallRules
|
||||
from plogical.modSec import modSec
|
||||
from plogical.csf import CSF
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
from serverStatus.serverStatusUtil import ServerStatusUtil
|
||||
|
||||
class FirewallManager:
|
||||
|
||||
imunifyPath = '/usr/bin/imunify360-agent'
|
||||
CLPath = '/etc/sysconfig/cloudlinux'
|
||||
|
||||
def __init__(self, request = None):
|
||||
self.request = request
|
||||
|
||||
@@ -1560,6 +1564,49 @@ class FirewallManager:
|
||||
data = {}
|
||||
data['ipAddress'] = ipAddress
|
||||
|
||||
if os.path.exists(FirewallManager.CLPath):
|
||||
data['CL'] = 1
|
||||
else:
|
||||
data['CL'] = 0
|
||||
|
||||
if os.path.exists(FirewallManager.imunifyPath):
|
||||
data['imunify'] = 0
|
||||
else:
|
||||
data['imunify'] = 0
|
||||
|
||||
if data['CL'] == 0:
|
||||
return render(self.request, 'firewall/notAvailable.html', data)
|
||||
elif data['imunify'] == 0:
|
||||
return render(self.request, 'firewall/notAvailable.html', data)
|
||||
else:
|
||||
return render(self.request, 'firewall/imunify.html', data)
|
||||
|
||||
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def submitinstallImunify(self):
|
||||
try:
|
||||
userID = self.request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
'Not authorized to install container packages. [404].',
|
||||
1)
|
||||
return 0
|
||||
|
||||
data = json.loads(self.request.body)
|
||||
|
||||
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/CLManager/CageFS.py"
|
||||
execPath = execPath + " --function submitinstallImunify --key %s" % (data['key'])
|
||||
ProcessUtilities.popenExecutioner(execPath)
|
||||
|
||||
data_ret = {'status': 1, 'error_message': 'None'}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
|
||||
|
||||
@@ -2073,3 +2073,107 @@ app.controller('csf', function ($scope, $http, $timeout, $window) {
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* Imunify */
|
||||
|
||||
app.controller('installImunify', function ($scope, $http, $timeout, $window) {
|
||||
|
||||
$scope.installDockerStatus = true;
|
||||
$scope.installBoxGen = true;
|
||||
$scope.dockerInstallBTN = false;
|
||||
|
||||
$scope.submitinstallImunify = function () {
|
||||
|
||||
$scope.installDockerStatus = false;
|
||||
$scope.installBoxGen = true;
|
||||
$scope.dockerInstallBTN = true;
|
||||
|
||||
url = "/firewall/submitinstallImunify";
|
||||
|
||||
var data = {
|
||||
key: $scope.key
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
$scope.installBoxGen = false;
|
||||
getRequestStatus();
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function getRequestStatus() {
|
||||
$scope.installDockerStatus = false;
|
||||
|
||||
url = "/serverstatus/switchTOLSWSStatus";
|
||||
|
||||
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.requestData = response.data.requestStatus;
|
||||
$timeout(getRequestStatus, 1000);
|
||||
} else {
|
||||
// Notifications
|
||||
$scope.installDockerStatus = true;
|
||||
$timeout.cancel();
|
||||
$scope.requestData = response.data.requestStatus;
|
||||
if (response.data.installed === 1) {
|
||||
$timeout(function () {
|
||||
$window.location.reload();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.installDockerStatus = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
{% else %}
|
||||
|
||||
<div ng-controller="installCageFS" class="panel">
|
||||
<div ng-controller="installImunify" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Activate Now" %} <img ng-hide="installDockerStatus"
|
||||
@@ -36,12 +36,13 @@
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
<p>{% trans "CloudLinux is installed, but not activated." %}</p>
|
||||
<p>{% trans "Imunify is not installed, click to install now." %}</p>
|
||||
<!------ LSWS Switch box ----------------->
|
||||
|
||||
<div style="margin-top: 2%" ng-hide="installBoxGen" class="col-md-12">
|
||||
|
||||
<form action="/" id="" class="form-horizontal bordered-row">
|
||||
|
||||
<div class="form-group">
|
||||
<div style="margin-top: 2%;" class="col-sm-12">
|
||||
<textarea ng-model="requestData" rows="15"
|
||||
@@ -54,7 +55,27 @@
|
||||
|
||||
<!----- LSWS Switch box ----------------->
|
||||
<br>
|
||||
<button ng-hide="dockerInstallBTN" class="btn btn-primary" ng-click="submitCageFSInstall()">Activate Now</button>
|
||||
|
||||
<form action="/" id="" class="form-horizontal bordered-row">
|
||||
|
||||
<div ng-hide="dockerInstallBTN" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Imunify Key" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="key" type="text" class="form-control" ng-model="key" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="dockerInstallBTN" ng-hide="installationDetailsForm" class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-6">
|
||||
<button type="button" class="btn btn-primary"
|
||||
ng-click="submitinstallImunify()">
|
||||
Install Now
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -54,6 +54,7 @@ urlpatterns = [
|
||||
## Imunify
|
||||
|
||||
url(r'^imunify$', views.imunify, name='imunify'),
|
||||
url(r'^submitinstallImunify$', views.submitinstallImunify, name='submitinstallImunify'),
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -553,10 +553,18 @@ def modifyIPs(request):
|
||||
|
||||
def imunify(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
fm = FirewallManager(request)
|
||||
return fm.imunify()
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitinstallImunify(request):
|
||||
try:
|
||||
|
||||
fm = FirewallManager(request)
|
||||
return fm.submitinstallImunify()
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
104
static/firewall/firewall.js
Executable file → Normal file
104
static/firewall/firewall.js
Executable file → Normal file
@@ -2073,3 +2073,107 @@ app.controller('csf', function ($scope, $http, $timeout, $window) {
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* Imunify */
|
||||
|
||||
app.controller('installImunify', function ($scope, $http, $timeout, $window) {
|
||||
|
||||
$scope.installDockerStatus = true;
|
||||
$scope.installBoxGen = true;
|
||||
$scope.dockerInstallBTN = false;
|
||||
|
||||
$scope.submitinstallImunify = function () {
|
||||
|
||||
$scope.installDockerStatus = false;
|
||||
$scope.installBoxGen = true;
|
||||
$scope.dockerInstallBTN = true;
|
||||
|
||||
url = "/firewall/submitinstallImunify";
|
||||
|
||||
var data = {
|
||||
key: $scope.key
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
$scope.installBoxGen = false;
|
||||
getRequestStatus();
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function getRequestStatus() {
|
||||
$scope.installDockerStatus = false;
|
||||
|
||||
url = "/serverstatus/switchTOLSWSStatus";
|
||||
|
||||
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.requestData = response.data.requestStatus;
|
||||
$timeout(getRequestStatus, 1000);
|
||||
} else {
|
||||
// Notifications
|
||||
$scope.installDockerStatus = true;
|
||||
$timeout.cancel();
|
||||
$scope.requestData = response.data.requestStatus;
|
||||
if (response.data.installed === 1) {
|
||||
$timeout(function () {
|
||||
$window.location.reload();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.installDockerStatus = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user