diff --git a/CLManager/CageFS.py b/CLManager/CageFS.py index 81fce624c..ca419d988 100644 --- a/CLManager/CageFS.py +++ b/CLManager/CageFS.py @@ -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"]) diff --git a/firewall/firewallManager.py b/firewall/firewallManager.py index 90dbc481d..c04eeaff4 100755 --- a/firewall/firewallManager.py +++ b/firewall/firewallManager.py @@ -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 - return render(self.request, 'firewall/imunify.html', data) + 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) diff --git a/firewall/static/firewall/firewall.js b/firewall/static/firewall/firewall.js index 441d0daf0..a0acd1f53 100755 --- a/firewall/static/firewall/firewall.js +++ b/firewall/static/firewall/firewall.js @@ -2072,4 +2072,108 @@ 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' + }); + + + } + + } }); \ No newline at end of file diff --git a/firewall/templates/firewall/notAvailable.html b/firewall/templates/firewall/notAvailable.html index 1519e6feb..3802dd3c5 100755 --- a/firewall/templates/firewall/notAvailable.html +++ b/firewall/templates/firewall/notAvailable.html @@ -20,7 +20,7 @@

{% trans "CloudLinux is not installed on your server." %} Click + href="https://go.cyberpanel.net/CLConvert">Click Here {% trans " for conversion details." %}

@@ -28,20 +28,21 @@ {% else %} -
-
-

- {% trans "Activate Now" %} -

-
+
+
+

+ {% trans "Activate Now" %} +

+
-

{% trans "CloudLinux is installed, but not activated." %}

+

{% trans "Imunify is not installed, click to install now." %}

+