From 1a95b0d30d876a13786747260150f7c73b4f0fc7 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Wed, 1 Jan 2020 11:57:13 +0500 Subject: [PATCH] final CloudLinux --- CLManager/CLManagerMain.py | 18 ++-- CLManager/CageFS.py | 87 +++++++++++++++++-- CLManager/static/CLManager/CLManager.js | 6 +- CLManager/templates/CLManager/cloudLinux.html | 37 ++++++++ .../templates/CLManager/notAvailable.html | 8 +- CLManager/views.py | 1 - plogical/virtualHostUtilities.py | 31 ------- 7 files changed, 136 insertions(+), 52 deletions(-) create mode 100755 CLManager/templates/CLManager/cloudLinux.html diff --git a/CLManager/CLManagerMain.py b/CLManager/CLManagerMain.py index 1772b58cf..2a02fd91c 100644 --- a/CLManager/CLManagerMain.py +++ b/CLManager/CLManagerMain.py @@ -41,24 +41,30 @@ class CLManagerMain(multi.Thread): else: return ACLManager.loadError() + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddress = ipData.split('\n', 1)[0] + data = {} data['CL'] = 0 - data['CAGEFS'] = 0 + data['activatedPath'] = 0 + data['ipAddress'] = ipAddress CLPath = '/etc/sysconfig/cloudlinux' - CageFSPath = '/usr/sbin/cagefsctl' + activatedPath = '/home/cyberpanel/cloudlinux' if os.path.exists(CLPath): data['CL'] = 1 - if os.path.exists(CageFSPath): - data['CAGEFS'] = 1 + if os.path.exists(activatedPath): + data['activatedPath'] = 1 if data['CL'] == 0: return render(self.request, 'CLManager/notAvailable.html', data) - elif data['CAGEFS'] == 0: + elif data['activatedPath'] == 0: return render(self.request, 'CLManager/notAvailable.html', data) else: - return render(self.request, self.templateName, self.data) + return render(self.request, 'CLManager/cloudLinux.html', data) def submitCageFSInstall(self): try: diff --git a/CLManager/CageFS.py b/CLManager/CageFS.py index a0d5d1c05..4a88a37be 100644 --- a/CLManager/CageFS.py +++ b/CLManager/CageFS.py @@ -1,9 +1,18 @@ #!/usr/local/CyberCP/bin/python import sys +import os +import django sys.path.append('/usr/local/CyberCP') + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") + +django.setup() import plogical.CyberCPLogFileWriter as logging import argparse from plogical.mailUtilities import mailUtilities +from plogical.processUtilities import ProcessUtilities +from plogical.firewallUtilities import FirewallUtilities +from firewall.models import FirewallRules from serverStatus.serverStatusUtil import ServerStatusUtil @@ -11,6 +20,37 @@ class CageFS: packages = ['talksho'] users = ['5001'] + @staticmethod + def EnableCloudLinux(): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + confPath = '/usr/local/lsws/conf/httpd_config.conf' + data = open(confPath, 'r').readlines() + + writeToFile = open(confPath, 'w') + + for items in data: + if items.find('priority') > -1: + writeToFile.writelines(items) + writeToFile.writelines('enableLVE 2\n') + else: + writeToFile.writelines(items) + + writeToFile.close() + else: + confPath = '/usr/local/lsws/conf/httpd_config.xml' + data = open(confPath, 'r').readlines() + + writeToFile = open(confPath, 'w') + + for items in data: + if items.find('') > -1: + writeToFile.writelines(items) + writeToFile.writelines(' 2\n') + else: + writeToFile.writelines(items) + + writeToFile.close() + @staticmethod def submitCageFSInstall(): try: @@ -20,19 +60,52 @@ class CageFS: statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w') logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, - "Starting Packages Installation..\n", 1) + "Checking if LVE Kernel is loaded ..\n", 1) - command = 'sudo yum install cagefs -y' + if ProcessUtilities.outputExecutioner('uname -a').find('lve') == -1: + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "CloudLinux is installed but kernel is not loaded, please reboot your server to load appropriate kernel. [404]\n", 1) + return 0 + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "CloudLinux Kernel detected..\n", 1) + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "Enabling CloudLinux in web server ..\n", 1) + + CageFS.EnableCloudLinux() + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "CloudLinux enabled in server ..\n", 1) + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "Adding LVEManager port ..\n", 1) + try: + FirewallUtilities.addRule('tcp', '9000', '0.0.0.0/0') + + newFWRule = FirewallRules(name='lvemanager', proto='tcp', port='9000', ipAddress='0.0.0.0/0') + newFWRule.save() + except: + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "LVEManager port added ..\n", 1) + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "Reinstalling important components ..\n", 1) + + command = 'yum install -y lvemanager' ServerStatusUtil.executioner(command, statusFile) - command = 'sudo /usr/sbin/cagefsctl --init' + command = 'yum reinstall -y lvemanager lve-utils cagefs alt-python27-cllib' ServerStatusUtil.executioner(command, statusFile) - command = 'sudo /usr/sbin/cagefsctl --update-etc' - ServerStatusUtil.executioner(command, statusFile) + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "Important components reinstalled..\n", 1) - command = 'sudo /usr/sbin/cagefsctl --force-update' - ServerStatusUtil.executioner(command, statusFile) + activatedPath = '/home/cyberpanel/cloudlinux' + + writeToFile = open(activatedPath, 'a') + writeToFile.write('CLInstalled') + writeToFile.close() logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, "Packages successfully installed.[200]\n", 1) diff --git a/CLManager/static/CLManager/CLManager.js b/CLManager/static/CLManager/CLManager.js index 547a407d5..ae17f696c 100644 --- a/CLManager/static/CLManager/CLManager.js +++ b/CLManager/static/CLManager/CLManager.js @@ -50,7 +50,7 @@ app.controller('installCageFS', function ($scope, $http, $timeout, $window) { }; function getRequestStatus() { - $scope.cyberPanelLoading = false; + $scope.installDockerStatus = false; url = "/serverstatus/switchTOLSWSStatus"; @@ -72,7 +72,7 @@ app.controller('installCageFS', function ($scope, $http, $timeout, $window) { $timeout(getRequestStatus, 1000); } else { // Notifications - $scope.cyberPanelLoading = true; + $scope.installDockerStatus = true; $timeout.cancel(); $scope.requestData = response.data.requestStatus; if (response.data.installed === 1) { @@ -85,7 +85,7 @@ app.controller('installCageFS', function ($scope, $http, $timeout, $window) { } function cantLoadInitialDatas(response) { - $scope.cyberPanelLoading = true; + $scope.installDockerStatus = true; new PNotify({ title: 'Operation Failed!', text: 'Could not connect to server, please refresh this page', diff --git a/CLManager/templates/CLManager/cloudLinux.html b/CLManager/templates/CLManager/cloudLinux.html new file mode 100755 index 000000000..b1316daeb --- /dev/null +++ b/CLManager/templates/CLManager/cloudLinux.html @@ -0,0 +1,37 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "CloudLinux - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + +
+
+

{% trans "CloudLinux" %}

+

{% trans "Access LVEManager" %}

+
+ +
+
+

+ {% trans "CloudLinux" %} +

+
+ +

{% trans "CloudLinux is now integrated via their new API. You can manage CageFS and Package limits directly from LVEManager by clicking below. You can use your server root credentials to access LVEManager." %}

+
+ + + + +
+
+
+ +
+{% endblock %} + diff --git a/CLManager/templates/CLManager/notAvailable.html b/CLManager/templates/CLManager/notAvailable.html index c597c3827..1c5bcbd0a 100755 --- a/CLManager/templates/CLManager/notAvailable.html +++ b/CLManager/templates/CLManager/notAvailable.html @@ -19,7 +19,7 @@
-

{% trans "CageFS is only available with CloudLinux OS. " %} {% trans "CloudLinux is not installed on your server." %} Click Here {% trans " for conversion details." %}

@@ -31,12 +31,12 @@

- {% trans "Install Packages" %}

-

{% trans "CageFS is not installed on this server. Please proceed to installation." %}

+

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

@@ -54,7 +54,7 @@
- +
diff --git a/CLManager/views.py b/CLManager/views.py index 455e9c170..9c96ab45d 100644 --- a/CLManager/views.py +++ b/CLManager/views.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- - from django.shortcuts import redirect, HttpResponse from loginSystem.views import loadLoginPage from plogical.acl import ACLManager diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 4a5aca988..2dfd6c8af 100755 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -50,37 +50,6 @@ class virtualHostUtilities: ols = 2 lsws = 3 - @staticmethod - def EnableCloudLinux(): - if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - confPath = '/usr/local/lsws/conf/httpd_config.conf' - data = open(confPath, 'r').readlines() - - writeToFile = open(confPath, 'w') - - for items in data: - if items.find('priority') > -1: - writeToFile.writelines(items) - writeToFile.writelines('enableLVE 2\n') - else: - writeToFile.writelines(items) - - writeToFile.close() - else: - confPath = '/usr/local/lsws/conf/httpd_config.xml' - data = open(confPath, 'r').readlines() - - writeToFile = open(confPath, 'w') - - for items in data: - if items.find('') > -1: - writeToFile.writelines(items) - writeToFile.writelines(' 2\n') - else: - writeToFile.writelines(items) - - writeToFile.close() - Server_root = "/usr/local/lsws" cyberPanel = "/usr/local/CyberCP"