diff --git a/CyberCP/settings.py b/CyberCP/settings.py index 261522ba5..3849e4816 100644 --- a/CyberCP/settings.py +++ b/CyberCP/settings.py @@ -63,6 +63,7 @@ INSTALLED_APPS = [ 'emailPremium', 'emailMarketing', 'cloudAPI', + 'highAvailability' ] MIDDLEWARE = [ diff --git a/api/views.py b/api/views.py index beebbec53..db7969ba8 100644 --- a/api/views.py +++ b/api/views.py @@ -262,6 +262,7 @@ def fetchSSHkey(request): data = subprocess.check_output(shlex.split(execPath)) data_ret = { + 'status': 1, 'pubKeyStatus': 1, 'error_message': "None", 'pubKey':data @@ -270,6 +271,7 @@ def fetchSSHkey(request): return HttpResponse(json_data) else: data_ret = { + 'status' : 0, 'pubKeyStatus': 0, 'error_message': "Could not authorize access to API." } @@ -277,7 +279,7 @@ def fetchSSHkey(request): return HttpResponse(json_data) except BaseException, msg: - data = {'pubKeyStatus': 0,'error_message': str(msg)} + data = {'status' : 0, 'pubKeyStatus': 0,'error_message': str(msg)} json_data = json.dumps(data) return HttpResponse(json_data) diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index 42145f3b0..ea5b81083 100644 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -17,6 +17,11 @@ from packages.packagesManager import PackagesManager from plogical.processUtilities import ProcessUtilities from firewall.firewallManager import FirewallManager from serverLogs.views import getLogsFromFile +from random import randint +from highAvailability.haManager import HAManager +from plogical.httpProc import httpProc +from api.views import fetchSSHkey +import os class CloudManager: def __init__(self, data=None, admin = None): @@ -742,3 +747,86 @@ class CloudManager: return obtainMailServerSSL(request) except BaseException, msg: return self.ajaxPre(0, str(msg)) + + def setupManager(self, request): + try: + request.session['userID'] = self.admin.pk + tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + self.data['tempStatusPath'] = tempStatusPath + + ham = HAManager(request, self.data, 'setupNode') + ham.start() + + data = {} + data['tempStatusPath'] = tempStatusPath + + proc = httpProc(request, None) + return proc.ajax(1, None, data) + + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def fetchManagerTokens(self, request): + try: + request.session['userID'] = self.admin.pk + ham = HAManager(request, self.data, 'fetchManagerTokens') + return ham.fetchManagerTokens() + + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def addWorker(self, request): + try: + request.session['userID'] = self.admin.pk + ham = HAManager(request, self.data, 'fetchManagerTokens') + return ham.addWorker() + + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def fetchSSHKey(self, request): + try: + pubKey = os.path.join("/root", ".ssh", 'cyberpanel.pub') + execPath = "sudo cat " + pubKey + data = subprocess.check_output(shlex.split(execPath)) + + data_ret = { + 'status': 1, + 'error_message': "None", + 'pubKey': data + } + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def putSSHkeyFunc(self, request): + try: + fm = FirewallManager(request) + return fm.addSSHKey(self.admin.pk, self.data) + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def leaveSwarm(self, request): + try: + request.session['userID'] = self.admin.pk + ham = HAManager(request, self.data, 'leaveSwarm') + return ham.leaveSwarm() + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def setUpDataNode(self, request): + try: + request.session['userID'] = self.admin.pk + ham = HAManager(request, self.data, 'setUpDataNode') + return ham.setUpDataNode() + except BaseException, msg: + return self.ajaxPre(0, str(msg)) + + def submitEditCluster(self, request): + try: + request.session['userID'] = self.admin.pk + ham = HAManager(request, self.data, 'submitEditCluster') + return ham.submitEditCluster() + except BaseException, msg: + return self.ajaxPre(0, str(msg)) diff --git a/cloudAPI/views.py b/cloudAPI/views.py index c35156e42..88c175238 100644 --- a/cloudAPI/views.py +++ b/cloudAPI/views.py @@ -161,6 +161,22 @@ def router(request): return cm.getLogsFromFile(request) elif controller == 'serverSSL': return cm.serverSSL(request) + elif controller == 'setupNode': + return cm.setupManager(request) + elif controller == 'fetchManagerTokens': + return cm.fetchManagerTokens(request) + elif controller == 'addWorker': + return cm.addWorker(request) + elif controller == 'fetchSSHKey': + return cm.fetchSSHKey(request) + elif controller == 'putSSHkeyFunc': + return cm.putSSHkeyFunc(request) + elif controller == 'leaveSwarm': + return cm.leaveSwarm(request) + elif controller == 'setUpDataNode': + return cm.setUpDataNode(request) + elif controller == 'submitEditCluster': + return cm.submitEditCluster(request) else: return cm.ajaxPre(0, 'This function is not available in your version of CyberPanel.') diff --git a/emailPremium/models.py b/emailPremium/models.py index b40864678..60e4ca5b6 100644 --- a/emailPremium/models.py +++ b/emailPremium/models.py @@ -5,8 +5,6 @@ from django.db import models from mailServer.models import Domains, EUsers # Create your models here. - - class DomainLimits(models.Model): domain = models.ForeignKey(Domains, on_delete=models.CASCADE) limitStatus = models.IntegerField(default=0) diff --git a/firewall/firewallManager.py b/firewall/firewallManager.py index 2e611104d..2d6d951de 100644 --- a/firewall/firewallManager.py +++ b/firewall/firewallManager.py @@ -350,12 +350,17 @@ class FirewallManager: if items.find("ssh-rsa") > -1: keydata = items.split(" ") - key = "ssh-rsa " + keydata[1][:50] + " .. " + keydata[2] - try: - userName = keydata[2][:keydata[2].index("@")] + key = "ssh-rsa " + keydata[1][:50] + " .. " + keydata[2] + try: + userName = keydata[2][:keydata[2].index("@")] + except: + userName = keydata[2] except: - userName = keydata[2] + key = "ssh-rsa " + keydata[1][:50] + userName = '' + + dic = {'userName': userName, 'key': key, @@ -545,7 +550,7 @@ class FirewallManager: # temp change of permissions - command = 'sudo chown -R cyberpanel:cyberpanel /root' + command = 'sudo chown -R cyberpanel:cyberpanel /root' cmd = shlex.split(command) @@ -569,11 +574,22 @@ class FirewallManager: sshFile.writelines("#Created by CyberPanel\n") sshFile.close() - writeToFile = open(pathToSSH, 'a') - writeToFile.writelines("\n") - writeToFile.writelines(key) - writeToFile.writelines("\n") - writeToFile.close() + presenseCheck = 0 + try: + data = open(pathToSSH, "r").readlines() + for items in data: + if items.find(key) > -1: + presenseCheck = 1 + except: + pass + + if presenseCheck == 0: + writeToFile = open(pathToSSH, 'a') + writeToFile.writelines("#Added by CyberPanel\n") + writeToFile.writelines("\n") + writeToFile.writelines(key) + writeToFile.writelines("\n") + writeToFile.close() # change back permissions diff --git a/highAvailability/__init__.py b/highAvailability/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/highAvailability/admin.py b/highAvailability/admin.py new file mode 100644 index 000000000..13be29d96 --- /dev/null +++ b/highAvailability/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/highAvailability/apps.py b/highAvailability/apps.py new file mode 100644 index 000000000..1b1e13f4d --- /dev/null +++ b/highAvailability/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class HighavailabilityConfig(AppConfig): + name = 'highAvailability' diff --git a/highAvailability/haManager.py b/highAvailability/haManager.py new file mode 100644 index 000000000..e83acc336 --- /dev/null +++ b/highAvailability/haManager.py @@ -0,0 +1,245 @@ +#!/usr/local/CyberCP/bin/python2 +import os.path +import sys +import django +sys.path.append('/usr/local/CyberCP') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") +django.setup() +import subprocess, shlex +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging +from plogical.httpProc import httpProc +from plogical.processUtilities import ProcessUtilities +from plogical.acl import ACLManager +import threading as multi +import argparse +from plogical.firewallUtilities import FirewallUtilities +from firewall.models import FirewallRules + + +class HAManager(multi.Thread): + + def __init__(self, request = None, data = None, function = None): + multi.Thread.__init__(self) + self.request = request + self.data = data + self.function = function + + def run(self): + try: + if self.function == 'setupNode': + self.setupNode() + elif self.function == 'addManager': + self.setupNode() + except BaseException, msg: + logging.writeToFile( str(msg) + ' [HAManager.run]') + + def setupNode(self): + try: + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos: + mesg = 'Clusters are only supported on Ubuntu 18.04. [404]' + logging.statusWriter(self.data['tempStatusPath'], mesg) + return 0 + + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 0: + mesg = 'Only administrators can create clusters. [404]' + logging.statusWriter(self.data['tempStatusPath'], mesg) + return 0 + + logging.statusWriter(self.data['tempStatusPath'], 'Setting up node in progress..') + + commands = self.data['commands'] + + for command in commands: + try: + result = subprocess.call(command, shell=True) + if result != 0: + logging.writeToFile(command + ' Failed.') + except BaseException: + logging.statusWriter(self.data['tempStatusPath'], command + ' Failed. [404]') + return 0 + + try: + FirewallUtilities.addRule('tcp', '2377', "0.0.0.0/0") + fwRule = FirewallRules(name="Docker", port='2377', proto="tcp") + fwRule.save() + except: + pass + + mesg = 'Node successfully configured. [200]' + logging.statusWriter(self.data['tempStatusPath'], mesg) + + except BaseException, msg: + logging.writeToFile(str(msg)) + logging.statusWriter(self.data['tempStatusPath'], str(msg) + '. [404]') + + def fetchManagerTokens(self): + try: + + proc = httpProc(self.request, None, None) + + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 0: + return proc.ajax(0, 'Only administrators can create clusters.') + + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddress = ipData.split('\n', 1)[0] + + command = 'sudo docker swarm init --advertise-addr ' + ipAddress + ProcessUtilities.executioner(command) + + managerToken = '' + workerToken = '' + + command = "sudo docker swarm join-token manager" + output = subprocess.check_output(shlex.split(command)).splitlines() + + for items in output: + if items.find('--token') > -1: + managerToken = items.split(' ')[-2] + + command = "sudo docker swarm join-token worker" + output = subprocess.check_output(shlex.split(command)).splitlines() + + for items in output: + if items.find('--token') > -1: + workerToken = items.split(' ')[-2] + + data = {} + data['managerToken'] = managerToken + data['workerToken'] = workerToken + + return proc.ajax(1, None, data) + + except BaseException, msg: + proc = httpProc(self.request, None, None) + return proc.ajax(0, None, str(msg)) + + def addWorker(self): + try: + + proc = httpProc(self.request, None, None) + + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 0: + return proc.ajax(0, 'Only administrators can create clusters.') + + token = self.data['token'] + ipAddress = self.data['ipAddress'] + command = 'sudo docker swarm join --token ' + token + ' ' + ipAddress + ':2377' + + if ProcessUtilities.executioner(command) == 0: + return proc.ajax(0, 'Failed to join as worker.') + + return proc.ajax(1, None) + + except BaseException, msg: + proc = httpProc(self.request, None, None) + return proc.ajax(0, None, str(msg)) + + def leaveSwarm(self): + try: + + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + proc = httpProc(self.request, None, None) + + if currentACL['admin'] == 0: + return proc.ajax(0, 'Only administrators can create clusters.') + + commands = self.data['commands'] + + for command in commands: + try: + result = subprocess.call(command, shell=True) + if result != 0: + logging.writeToFile(command + ' Failed.') + except BaseException, msg: + logging.writeToFile(command + 'Failed.') + return 0 + + except BaseException, msg: + logging.writeToFile(str(msg)) + + def setUpDataNode(self): + try: + + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + proc = httpProc(self.request, None, None) + + if currentACL['admin'] == 0: + return proc.ajax(0, 'Only administrators can create clusters.') + + composePath = '/home/cyberpanel/composePath' + + if not os.path.exists(composePath): + os.mkdir(composePath) + + composeFile = composePath + '/docker-compose.yml' + + compose = open(composeFile, 'w') + for items in self.data['composeData']: + compose.writelines(items) + compose.close() + + return proc.ajax(1, None) + + except BaseException, msg: + logging.writeToFile(str(msg)) + proc = httpProc(self.request, None, None) + return proc.ajax(0, str(msg)) + + def submitEditCluster(self): + try: + + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + proc = httpProc(self.request, None, None) + + if currentACL['admin'] == 0: + return proc.ajax(0, 'Only administrators can create clusters.') + + composePath = '/home/cyberpanel/composePath' + composeFile = composePath + '/docker-compose.yml' + + data = open(composeFile, 'r').readlines() + compose = open(composeFile, 'w') + for items in data: + if items.find('replicas') > -1: + compose.writelines(' replicas: ' + str(self.data['containers']) + '\n') + elif items.find('memory') > -1: + compose.writelines(' memory: ' + self.data['containerRam'] + '\n') + elif items.find('cpus:') > -1: + compose.writelines(' cpus: "' + self.data['containerCPU'] + '"\n') + else: + compose.writelines(items) + compose.close() + + return proc.ajax(1, None) + + except BaseException, msg: + logging.writeToFile(str(msg)) + proc = httpProc(self.request, None, None) + return proc.ajax(0, str(msg)) + +def main(): + + parser = argparse.ArgumentParser(description='CyberPanel HA Manager') + parser.add_argument('function', help='Specific a function to call!') + parser.add_argument('--id', help='ID!') + parser.add_argument('--ipAddress', help='IP Address!') + + args = parser.parse_args() + +if __name__ == "__main__": + main() diff --git a/highAvailability/migrations/__init__.py b/highAvailability/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/highAvailability/models.py b/highAvailability/models.py new file mode 100644 index 000000000..1dfab7604 --- /dev/null +++ b/highAvailability/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/highAvailability/tests.py b/highAvailability/tests.py new file mode 100644 index 000000000..5982e6bcd --- /dev/null +++ b/highAvailability/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/highAvailability/urls.py b/highAvailability/urls.py new file mode 100644 index 000000000..e69de29bb diff --git a/highAvailability/views.py b/highAvailability/views.py new file mode 100644 index 000000000..e784a0bd2 --- /dev/null +++ b/highAvailability/views.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here. diff --git a/install/install.py b/install/install.py index c187c6441..a9ca19b2f 100644 --- a/install/install.py +++ b/install/install.py @@ -57,7 +57,7 @@ class preFlightsChecks: def resFailed(distro, res): if distro == ubuntu and res != 0: return True - elif distro == centos and res == 1: + elif distro == centos and res != 0: return True return False @@ -76,7 +76,7 @@ class preFlightsChecks: if do_exit: fatal_message = '. Fatal error, see /var/log/installLogs.txt for full details' - preFlightsChecks.stdOut("We are not able to " + message + ' return code: ' + str(res) + + preFlightsChecks.stdOut("[ERROR] We are not able to " + message + ' return code: ' + str(res) + fatal_message + " " + bracket, 1, do_exit, code) return False else: diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index 8f0fc36a8..bd03912f1 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -1,7 +1,6 @@ import shutil import subprocess import os -import pexpect from mysqlUtilities import mysqlUtilities import installLog as logging import shlex @@ -9,7 +8,6 @@ import randomPassword import errno import MySQLdb as mariadb import install -#import stat #distros centos=0 @@ -33,96 +31,77 @@ class InstallCyberPanel: def installLiteSpeed(self): if self.ent == 0: - try: - count = 0 - while (1): + if self.distro == ubuntu: + command = "apt-get -y install openlitespeed" + else: + command = 'yum install -y openlitespeed' - if self.distro == ubuntu: - command = "apt-get -y install openlitespeed" - else: - command = 'yum install -y openlitespeed' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to install OpenLiteSpeed, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to install OpenLiteSpeed, exiting installer! [installLiteSpeed]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("OpenLiteSpeed successfully installed!") - InstallCyberPanel.stdOut("OpenLiteSpeed successfully installed!") - break - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installLiteSpeed]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installLiteSpeed]") - return 0 - - return 1 + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'Install LiteSpeed.', + 1, 1, os.EX_OSERR) else: try: - count = 0 - while (1): - try: + try: + command = 'groupadd nobody' + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'groupadd nobody', + 1, 0, os.EX_OSERR) + except: + pass - command = 'groupadd nobody' - cmd = shlex.split(command) - subprocess.call(cmd) + try: + command = 'usermod -a -G nobody nobody' + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'groupadd nobody', + 1, 0, os.EX_OSERR) + except: + pass - except: - pass + command = 'wget https://www.litespeedtech.com/packages/5.0/lsws-5.3.4-ent-x86_64-linux.tar.gz' + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'Install LiteSpeed Webserver Enterprise.', + 1, 1, os.EX_OSERR) - try: - command = 'usermod -a -G nobody nobody' - cmd = shlex.split(command) - subprocess.call(cmd) - except: - pass + command = 'tar zxf lsws-5.3.4-ent-x86_64-linux.tar.gz' + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'Install LiteSpeed Webserver Enterprise.', + 1, 1, os.EX_OSERR) - command = 'wget https://www.litespeedtech.com/packages/5.0/lsws-5.3-ent-x86_64-linux.tar.gz' - cmd = shlex.split(command) - res = subprocess.call(cmd) + writeSerial = open('lsws-5.3.4/serial.no', 'w') + writeSerial.writelines(self.serial) + writeSerial.close() - command = 'tar zxf lsws-5.3-ent-x86_64-linux.tar.gz' - subprocess.call(shlex.split(command)) + shutil.copy('litespeed/install.sh', 'lsws-5.3.4/') + shutil.copy('litespeed/functions.sh', 'lsws-5.3.4/') - writeSerial = open('lsws-5.3/serial.no', 'w') - writeSerial.writelines(self.serial) - writeSerial.close() + os.chdir('lsws-5.3.4') - shutil.copy('litespeed/install.sh', 'lsws-5.3/') - shutil.copy('litespeed/functions.sh', 'lsws-5.3/') + command = 'chmod +x install.sh' + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'Install LiteSpeed Webserver Enterprise.', + 1, 1, os.EX_OSERR) - os.chdir('lsws-5.3') + command = 'chmod +x functions.sh' + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'Install LiteSpeed Webserver Enterprise.', + 1, 1, os.EX_OSERR) - command = 'chmod +x install.sh' - subprocess.call(shlex.split(command)) + command = './install.sh' + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'Install LiteSpeed Webserver Enterprise.', + 1, 1, os.EX_OSERR) - command = 'chmod +x functions.sh' - subprocess.call(shlex.split(command)) + os.chdir(self.cwd) + confPath = '/usr/local/lsws/conf/' + shutil.copy('litespeed/httpd_config.xml', confPath) + shutil.copy('litespeed/modsec.conf', confPath) + shutil.copy('litespeed/httpd.conf', confPath) - command = './install.sh' - res = subprocess.call(shlex.split(command)) + command = 'chown -R lsadm:lsadm ' + confPath + install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]', + 'Install LiteSpeed Webserver Enterprise.', + 1, 0, os.EX_OSERR) - if install.preFlightsChecks.resFailed(self.distro, res): - logging.InstallLog.writeToFile( - "Failed to install LiteSpeed Enterprise! [installLiteSpeed]") - InstallCyberPanel.stdOut("Failed to install LiteSpeed Enterprise!") - os._exit(0) - - os.chdir(self.cwd) - confPath = '/usr/local/lsws/conf/' - shutil.copy('litespeed/httpd_config.xml', confPath) - shutil.copy('litespeed/modsec.conf', confPath) - shutil.copy('litespeed/httpd.conf', confPath) - - command = 'chown -R lsadm:lsadm ' + confPath - subprocess.call(shlex.split(command)) - break except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [installLiteSpeed]") return 0 @@ -133,80 +112,15 @@ class InstallCyberPanel: return 1 def reStartLiteSpeed(self): - - try: - cmd = [] - count = 0 - - while(1): - cmd.append(self.server_root_path+"bin/lswsctrl") - cmd.append("restart") - - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to restart OpenLiteSpeed, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to restart OpenLiteSpeed, you can do this manually later using: systemctl restart lsws! [reStartLiteSpeed]") - break - else: - logging.InstallLog.writeToFile("OpenLiteSpeed successfully restarted!") - InstallCyberPanel.stdOut("OpenLiteSpeed successfully restarted!") - break - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [reStartLiteSpeed]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [reStartLiteSpeed]") - return 0 - return 1 + command = self.server_root_path+"bin/lswsctrl restart" + install.preFlightsChecks.call(command, self.distro, '[reStartLiteSpeed]', + 'Restart LiteSpeed WebServer', + 1, 0, os.EX_OSERR) def fix_ols_configs(self): try: - InstallCyberPanel.stdOut("Fixing OpenLiteSpeed configurations!") - logging.InstallLog.writeToFile("Fixing OpenLiteSpeed configurations!") - - ## cache module settings - cacheStart = "module cache {\n" - ls_enabled = "ls_enabled 1\n" - enableCache = "enableCache 0\n" - qsCache = "qsCache 1\n" - reqCookieCache = "reqCookieCache 1\n" - respCookieCache = "respCookieCache 1\n" - ignoreReqCacheCtrl = "ignoreReqCacheCtrl 1\n" - ignoreRespCacheCtrl = "ignoreRespCacheCtrl 0\n" - enablePrivateCache = "enablePrivateCache 0\n" - privateExpireInSeconds = "privateExpireInSeconds 1000\n" - expireInSeconds = "expireInSeconds 1000\n" - storagePath = "storagePath cachedata\n" - checkPrivateCache = "checkPrivateCache 1\n" - checkPublicCache = "checkPublicCache 1\n" - cacheEnd = "}\n" - - writeDataToFile = open(self.server_root_path+"conf/httpd_config.conf", 'a') - - writeDataToFile.writelines(cacheStart) - writeDataToFile.writelines(ls_enabled) - writeDataToFile.writelines(enableCache) - writeDataToFile.writelines(qsCache) - writeDataToFile.writelines(reqCookieCache) - writeDataToFile.writelines(respCookieCache) - writeDataToFile.writelines(ignoreReqCacheCtrl) - writeDataToFile.writelines(ignoreRespCacheCtrl) - writeDataToFile.writelines(enablePrivateCache) - writeDataToFile.writelines(privateExpireInSeconds) - writeDataToFile.writelines(expireInSeconds) - writeDataToFile.writelines(storagePath) - writeDataToFile.writelines(checkPrivateCache) - writeDataToFile.writelines(checkPublicCache) - writeDataToFile.writelines(cacheEnd) - writeDataToFile.writelines("\n") - writeDataToFile.writelines("\n") - - writeDataToFile.close() + InstallCyberPanel.stdOut("Fixing OpenLiteSpeed configurations!", 1) ## remove example virtual host @@ -222,10 +136,7 @@ class InstallCyberPanel: writeDataToFile.close() - InstallCyberPanel.stdOut("OpenLiteSpeed Configurations fixed!") - logging.InstallLog.writeToFile("OpenLiteSpeed Configurations fixed!") - - + InstallCyberPanel.stdOut("OpenLiteSpeed Configurations fixed!", 1) except IOError, msg: logging.InstallLog.writeToFile(str(msg) + " [fix_ols_configs]") return 0 @@ -234,8 +145,7 @@ class InstallCyberPanel: def changePortTo80(self): try: - InstallCyberPanel.stdOut("Changing default port to 80..") - logging.InstallLog.writeToFile("Changing default port to 80..") + InstallCyberPanel.stdOut("Changing default port to 80..", 1) data = open(self.server_root_path+"conf/httpd_config.conf").readlines() @@ -249,8 +159,7 @@ class InstallCyberPanel: writeDataToFile.close() - InstallCyberPanel.stdOut("Default port is now 80 for OpenLiteSpeed!") - logging.InstallLog.writeToFile("Default port is now 80 for OpenLiteSpeed!") + InstallCyberPanel.stdOut("Default port is now 80 for OpenLiteSpeed!", 1) except IOError, msg: logging.InstallLog.writeToFile(str(msg) + " [changePortTo80]") @@ -261,8 +170,7 @@ class InstallCyberPanel: def setupFileManager(self): if self.ent == 0: try: - logging.InstallLog.writeToFile("Setting up Filemanager files..") - InstallCyberPanel.stdOut("Setting up Filemanager files..") + InstallCyberPanel.stdOut("Setting up Filemanager files..", 1) os.chdir(self.cwd) @@ -279,21 +187,13 @@ class InstallCyberPanel: os.remove(fileManagerPath + "upload.html") os.remove(fileManagerPath + "upload.php") - logging.InstallLog.writeToFile("Filemanager files are set!") - InstallCyberPanel.stdOut("Filemanager files are set!") + InstallCyberPanel.stdOut("Filemanager files are set!", 1) - except OSError, msg: + except BaseException, msg: logging.InstallLog.writeToFile(str(msg) + " [setupFileManager]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [setupFileManager]") - return 0 - - return 1 else: try: - logging.InstallLog.writeToFile("Setting up Filemanager files..") - InstallCyberPanel.stdOut("Setting up Filemanager files..") + InstallCyberPanel.stdOut("Setting up Filemanager files..", 1) os.chdir(self.cwd) @@ -303,107 +203,49 @@ class InstallCyberPanel: ## remove unnecessary files command = 'chmod -R 777 ' + fileManagerPath - subprocess.call(shlex.split(command)) + install.preFlightsChecks.call(command, self.distro, '[setupFileManager]', + 'Change Filemanager permissions.', + 1, 0, os.EX_OSERR) - logging.InstallLog.writeToFile("Filemanager files are set!") - InstallCyberPanel.stdOut("Filemanager files are set!") + InstallCyberPanel.stdOut("Filemanager files are set!", 1) - except OSError, msg: + except BaseException, msg: logging.InstallLog.writeToFile(str(msg) + " [setupFileManager]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [setupFileManager]") - return 0 - - return 1 def installAllPHPVersions(self): - try: - count = 0 + if self.distro == ubuntu: + command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install ' \ + 'lsphp7? lsphp7?-common lsphp7?-curl lsphp7?-dev lsphp7?-imap lsphp7?-intl lsphp7?-json ' \ + 'lsphp7?-ldap lsphp7?-mysql lsphp7?-opcache lsphp7?-pspell lsphp7?-recode ' \ + 'lsphp7?-sqlite3 lsphp7?-tidy' + else: + command = 'yum -y groupinstall lsphp-all' - while (1): - failed = False - if self.distro == ubuntu: - command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install ' \ - 'lsphp7? lsphp7?-common lsphp7?-curl lsphp7?-dev lsphp7?-imap lsphp7?-intl lsphp7?-json ' \ - 'lsphp7?-ldap lsphp7?-mysql lsphp7?-opcache lsphp7?-pspell lsphp7?-recode ' \ - 'lsphp7?-sqlite3 lsphp7?-tidy' - res = os.system(command) - if res != 0: - failed = True - else: - command = 'yum -y groupinstall lsphp-all' - cmd = shlex.split(command) - res = subprocess.call(cmd) - if install.preFlightsChecks.resFailed(self.distro, res): - failed = True + install.preFlightsChecks.call(command, self.distro, '[installAllPHPVersions]', + 'Install PHP', + 1, 1, os.EX_OSERR) - if failed: - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to install LiteSpeed PHPs, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to install LiteSpeed PHPs, exiting installer! [installAllPHPVersions]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("LiteSpeed PHPs successfully installed!") - InstallCyberPanel.stdOut("LiteSpeed PHPs successfully installed!") + InstallCyberPanel.stdOut("LiteSpeed PHPs successfully installed!", 1) - ## only php 71 - if self.distro == centos: - count = 0 - while (1): - command = 'yum install lsphp71 lsphp71-json lsphp71-xmlrpc lsphp71-xml lsphp71-tidy lsphp71-soap lsphp71-snmp lsphp71-recode lsphp71-pspell lsphp71-process lsphp71-pgsql lsphp71-pear lsphp71-pdo lsphp71-opcache lsphp71-odbc lsphp71-mysqlnd lsphp71-mcrypt lsphp71-mbstring lsphp71-ldap lsphp71-intl lsphp71-imap lsphp71-gmp lsphp71-gd lsphp71-enchant lsphp71-dba lsphp71-common lsphp71-bcmath -y' - cmd = shlex.split(command) - res = subprocess.call(cmd) - if res == 1: - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to install LiteSpeed PHP 7.1, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to install LiteSpeed PHP 7.1, exiting installer! [installAllPHPVersions]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("LiteSpeed PHP 7.1 successfully installed!") - InstallCyberPanel.stdOut("LiteSpeed PHP 7.1 successfully installed!") - break + ## only php 71 + if self.distro == centos: - ## only php 72 - count = 0 - while (1): - command = 'yum install -y lsphp72 lsphp72-json lsphp72-xmlrpc lsphp72-xml lsphp72-tidy lsphp72-soap lsphp72-snmp lsphp72-recode lsphp72-pspell lsphp72-process lsphp72-pgsql lsphp72-pear lsphp72-pdo lsphp72-opcache lsphp72-odbc lsphp72-mysqlnd lsphp72-mcrypt lsphp72-mbstring lsphp72-ldap lsphp72-intl lsphp72-imap lsphp72-gmp lsphp72-gd lsphp72-enchant lsphp72-dba lsphp72-common lsphp72-bcmath' - cmd = shlex.split(command) - res = subprocess.call(cmd) - if res == 1: - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to install LiteSpeed PHP 7.1, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to install LiteSpeed PHP 7.1, exiting installer! [installAllPHPVersions]") - InstallCyberPanel.stdOut( - "Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("LiteSpeed PHP 7.1 successfully installed!") - InstallCyberPanel.stdOut("LiteSpeed PHP 7.1 successfully installed!") - break + command = 'yum install lsphp71 lsphp71-json lsphp71-xmlrpc lsphp71-xml lsphp71-tidy lsphp71-soap lsphp71-snmp ' \ + 'lsphp71-recode lsphp71-pspell lsphp71-process lsphp71-pgsql lsphp71-pear lsphp71-pdo lsphp71-opcache ' \ + 'lsphp71-odbc lsphp71-mysqlnd lsphp71-mcrypt lsphp71-mbstring lsphp71-ldap lsphp71-intl lsphp71-imap ' \ + 'lsphp71-gmp lsphp71-gd lsphp71-enchant lsphp71-dba lsphp71-common lsphp71-bcmath -y' + install.preFlightsChecks.call(command, self.distro, '[installAllPHPVersions]', + 'Install PHP', + 1, 1, os.EX_OSERR) + ## only php 72 + command = 'yum install -y lsphp72 lsphp72-json lsphp72-xmlrpc lsphp72-xml lsphp72-tidy lsphp72-soap lsphp72-snmp ' \ + 'lsphp72-recode lsphp72-pspell lsphp72-process lsphp72-pgsql lsphp72-pear lsphp72-pdo lsphp72-opcache ' \ + 'lsphp72-odbc lsphp72-mysqlnd lsphp72-mcrypt lsphp72-mbstring lsphp72-ldap lsphp72-intl lsphp72-imap ' \ + 'lsphp72-gmp lsphp72-gd lsphp72-enchant lsphp72-dba lsphp72-common lsphp72-bcmath' - ## break for outer loop - break - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installAllPHPVersion]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installAllPHPVersion]") - return 0 - - return 1 + install.preFlightsChecks.call(command, self.distro, '[installAllPHPVersions]', + 'Install PHP', + 1, 1, os.EX_OSERR) def setup_mariadb_repo(self): try: @@ -415,311 +257,137 @@ class InstallCyberPanel: # command = "add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main'" return - logging.InstallLog.writeToFile("Setting up MariaDB Repo..") - InstallCyberPanel.stdOut("Setting up MariaDB Repo..") + InstallCyberPanel.stdOut("Setting up MariaDB Repo..", 1) os.chdir(self.cwd) shutil.copy("mysql/MariaDB.repo","/etc/yum.repos.d/MariaDB.repo") - logging.InstallLog.writeToFile("MariaDB repo set!") - InstallCyberPanel.stdOut("MariaDB repo set!") + InstallCyberPanel.stdOut("MariaDB repo set!", 1) + - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [setup_mariadb_repo]") - return 0 except BaseException, msg: logging.InstallLog.writeToFile(str(msg) + " [setup_mariadb_repo]") return 0 def installMySQL(self, mysql): - try: - ############## Install mariadb ###################### + ############## Install mariadb ###################### + + if self.distro == ubuntu: + command = "apt-get -y install mariadb-server" + else: + command = 'yum -y install mariadb-server' + + install.preFlightsChecks.call(command, self.distro, '[installMySQL]', + 'Install MySQL', + 1, 1, os.EX_OSERR) + + ## Fix configurations if two MYSQL are used + + if mysql == 'Two': + logging.InstallLog.writeToFile("Setting up MariaDB configurations!") + InstallCyberPanel.stdOut("Setting up MariaDB configurations!") + + pathConf = "/etc/my.cnf" + pathServiceFile = "/etc/systemd/system/mysqld@.service" + + if os.path.exists(pathConf): + os.remove(pathConf) + + if os.path.exists(pathServiceFile): + os.remove(pathServiceFile) + + os.chdir(self.cwd) + + shutil.copy("mysql/my.cnf", pathConf) + shutil.copy("mysql/mysqld@.service", pathServiceFile) + + logging.InstallLog.writeToFile("MariaDB configurations set!") + InstallCyberPanel.stdOut("MariaDB configurations set!") + + ## count = 0 while (1): - if self.distro == ubuntu: - command = "apt-get -y install mariadb-server" - else: - command = 'yum -y install mariadb-server' - cmd = shlex.split(command) + command = "mysql_install_db --user=mysql --datadir=/var/lib/mysql1" + install.preFlightsChecks.call(command, self.distro, '[installMySQL]', + 'Install MySQL', + 1, 1, os.EX_OSERR) - res = subprocess.call(cmd) + ## + + count = 0 + + while (1): + command = "systemctl start mysqld@1" + res = subprocess.call(shlex.split(command)) if install.preFlightsChecks.resFailed(self.distro, res): count = count + 1 - InstallCyberPanel.stdOut("Trying to install MariaDB, trying again, try number: " + str(count)) + InstallCyberPanel.stdOut( + "Trying to start first MariaDB instance, trying again, try number: " + str(count)) if count == 3: - logging.InstallLog.writeToFile("Failed to install MariaDB, exiting installer! [installMySQL]") + logging.InstallLog.writeToFile( + "Failed to start first MariaDB instance, exiting installer! [installMySQL]") InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") os._exit(0) else: - logging.InstallLog.writeToFile("MariaDB successfully installed!") - InstallCyberPanel.stdOut("MariaDB successfully installed!") + logging.InstallLog.writeToFile("First MariaDB instance successfully started!") + InstallCyberPanel.stdOut("First MariaDB instance successfully started!") break - ## Fix configurations if two MYSQL are used + count = 0 - if mysql == 'Two': - logging.InstallLog.writeToFile("Setting up MariaDB configurations!") - InstallCyberPanel.stdOut("Setting up MariaDB configurations!") + while (1): + command = "systemctl enable mysqld@1" + res = subprocess.call(shlex.split(command)) - pathConf = "/etc/my.cnf" - pathServiceFile = "/etc/systemd/system/mysqld@.service" - - if os.path.exists(pathConf): - os.remove(pathConf) - - if os.path.exists(pathServiceFile): - os.remove(pathServiceFile) - - os.chdir(self.cwd) - - shutil.copy("mysql/my.cnf", pathConf) - shutil.copy("mysql/mysqld@.service", pathServiceFile) - - logging.InstallLog.writeToFile("MariaDB configurations set!") - InstallCyberPanel.stdOut("MariaDB configurations set!") - - ## - - count = 0 - - while (1): - command = "mysql_install_db --user=mysql --datadir=/var/lib/mysql1" - - res = subprocess.call(shlex.split(command)) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to create data directories for second MariaDB instance, trying again, try number: " + str( - count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to create data directories for second MariaDB instance, exiting installer! [installMySQL]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("Data directories created for second MariaDB instance!") - InstallCyberPanel.stdOut("Data directories created for second MariaDB instance!") - break - - ## - - count = 0 - - while (1): - command = "systemctl start mysqld@1" - res = subprocess.call(shlex.split(command)) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to start first MariaDB instance, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to start first MariaDB instance, exiting installer! [installMySQL]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("First MariaDB instance successfully started!") - InstallCyberPanel.stdOut("First MariaDB instance successfully started!") - break - - count = 0 - - while (1): - command = "systemctl enable mysqld@1" - res = subprocess.call(shlex.split(command)) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to enable first MariaDB instance to start and system restart, trying again, try number: " + str( - count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to enable first MariaDB instance to run at system restart, exiting installer! [installMySQL]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("First MariaDB instance successfully enabled at system restart!") - InstallCyberPanel.stdOut("First MariaDB instance successfully enabled at system restart!") - break - - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installMySQL]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installMySQL]") - return 0 + if install.preFlightsChecks.resFailed(self.distro, res): + count = count + 1 + InstallCyberPanel.stdOut( + "Trying to enable first MariaDB instance to start and system restart, trying again, try number: " + str( + count)) + if count == 3: + logging.InstallLog.writeToFile( + "Failed to enable first MariaDB instance to run at system restart, exiting installer! [installMySQL]") + InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") + os._exit(0) + else: + logging.InstallLog.writeToFile("First MariaDB instance successfully enabled at system restart!") + InstallCyberPanel.stdOut("First MariaDB instance successfully enabled at system restart!") + break ############## Start mariadb ###################### self.startMariaDB() - ############## Enable mariadb at system startup ###################### - - try: - - count = 0 - - while(1): - - if self.distro == ubuntu: - command = "systemctl enable mariadb" - else: - command = "systemctl enable mysql" - res = subprocess.call(shlex.split(command)) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to enable MariaDB instance to start and system restart, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to enable MariaDB instance to run at system restart, you can do this later using systemctl enable mysql! [installMySQL]") - break - else: - logging.InstallLog.writeToFile("MariaDB instance successfully enabled at system restart!") - InstallCyberPanel.stdOut("MariaDB instance successfully enabled at system restart!") - break - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " Could not add mariadb to startup [installMySQL]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " Could not add mariadb to startup [installMySQL]") - return 0 - - - return 1 - def changeMYSQLRootPassword(self): - try: - - logging.InstallLog.writeToFile("Changing MariaDB root password..") - InstallCyberPanel.stdOut("Changing MariaDB root password..") - - - expectation = "Enter password:" - securemysql = pexpect.spawn("mysql -u root -p", timeout=5) - securemysql.expect(expectation) - securemysql.sendline("") - - expectation = "clear the current input statement." - securemysql.expect(expectation) - securemysql.sendline("use mysql;") - - expectation = "Database changed" - securemysql.expect(expectation) - securemysql.sendline("update user set password=PASSWORD('"+InstallCyberPanel.mysql_Root_password+"') where User='root';") - - expectation = "Query OK" - securemysql.expect(expectation) - securemysql.sendline("flush privileges;") - - expectation = "Query OK" - securemysql.expect(expectation) - securemysql.sendline("quit") - - securemysql.wait() - - logging.InstallLog.writeToFile("MariaDB root password changed!") - InstallCyberPanel.stdOut("MariaDB root password changed!") - - - except pexpect.EOF, msg: - logging.InstallLog.writeToFile(str(msg) + " Exception EOF [changeMYSQLRootPassword]") - except pexpect.TIMEOUT, msg: - print securemysql.before - logging.InstallLog.writeToFile(str(msg) + " Exception EOF [changeMYSQLRootPassword]") - except BaseException, msg: - logging.InstallLog.writeToFile(str(msg) + "[changeMYSQLRootPassword]") - - return 0 - - def changeMYSQLRootPasswordCyberPanel(self, mysql): - try: - - logging.InstallLog.writeToFile("Changing CyberPanel MariaDB root password..") - InstallCyberPanel.stdOut("Changing CyberPanel MariaDB root password..") - - expectation = "Enter password:" - if mysql == 'Two': - securemysql = pexpect.spawn("mysql --host=127.0.0.1 --port=3307 -u root -p", timeout=5) - else: - securemysql = pexpect.spawn("mysql -u root -p", timeout=5) - - securemysql.expect(expectation) - securemysql.sendline("") - - expectation = "clear the current input statement." - securemysql.expect(expectation) - securemysql.sendline("use mysql;") - - expectation = "Database changed" - securemysql.expect(expectation) - securemysql.sendline("update user set password=PASSWORD('"+InstallCyberPanel.mysql_Root_password+"') where User='root';") - - expectation = "Query OK" - securemysql.expect(expectation) - securemysql.sendline("flush privileges;") - - expectation = "Query OK" - securemysql.expect(expectation) - securemysql.sendline("quit") - - securemysql.wait() - - logging.InstallLog.writeToFile("CyberPanel MariaDB root password changed!") - InstallCyberPanel.stdOut("CyberPanel MariaDB root password changed!") - - - except pexpect.EOF, msg: - logging.InstallLog.writeToFile(str(msg) + " Exception EOF [changeMYSQLRootPasswordCyberPanel]") - except pexpect.TIMEOUT, msg: - print securemysql.before - logging.InstallLog.writeToFile(str(msg) + " Exception EOF [changeMYSQLRootPasswordCyberPanel]") - except BaseException, msg: - logging.InstallLog.writeToFile(str(msg) + "[changeMYSQLRootPasswordCyberPanel]") - - return 0 + passwordCMD = "use mysql;update user set password=PASSWORD('" + InstallCyberPanel.mysql_Root_password + "') where User='root';flush privileges;" + command = 'mysql -u root -e "' + passwordCMD + '"' + install.preFlightsChecks.call(command, self.distro, '[changeMYSQLRootPassword]', 'MYSQL Root Password change.', + 1, 1, os.EX_OSERR) def startMariaDB(self): ############## Start mariadb ###################### - try: - count = 0 + command = "systemctl start mysql" + install.preFlightsChecks.call(command, self.distro, '[startMariaDB]', + 'Start MySQL', + 1, 1, os.EX_OSERR) - while(1): - command = "systemctl start mysql" - res = subprocess.call(shlex.split(command)) + ############## Enable mariadb at system startup ###################### - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to start MariaDB instance, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to start MariaDB instance, exiting installer! [startMariaDB]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("MariaDB instance successfully started!") - InstallCyberPanel.stdOut("MariaDB instance successfully started!") - break + if self.distro == ubuntu: + command = "systemctl enable mariadb" + else: + command = "systemctl enable mysql" - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [startMariaDB]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [startMariaDB]") - return 0 - - return 1 + install.preFlightsChecks.call(command, self.distro, '[installMySQL]', + 'Install MySQL', + 1, 1, os.EX_OSERR) def fixMariaDB(self): self.stdOut("Setup MariaDB so it can support Cyberpanel's needs") @@ -748,190 +416,60 @@ class InstallCyberPanel: self.stdOut("MariaDB is now setup so it can support Cyberpanel's needs") def installPureFTPD(self): - try: + if self.distro == ubuntu: + command = 'apt-get -y install ' + install.preFlightsChecks.pureFTPDServiceName(self.distro) + else: + command = "yum install -y pure-ftpd" - count = 0 - while (1): - if self.distro == ubuntu: - command = 'apt-get -y install ' + install.preFlightsChecks.pureFTPDServiceName(self.distro) - else: - command = "yum install -y pure-ftpd" + install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]', + 'Install FTP', + 1, 1, os.EX_OSERR) - res = subprocess.call(shlex.split(command)) + ####### Install pureftpd to system startup - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to install PureFTPD, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to install PureFTPD, exiting installer! [installPureFTPD]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("PureFTPD successfully installed!") - InstallCyberPanel.stdOut("PureFTPD successfully installed!") - break + command = "systemctl enable " + install.preFlightsChecks.pureFTPDServiceName(self.distro) + install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]', + 'Install FTP', + 1, 1, os.EX_OSERR) + ###### FTP Groups and user settings settings - ####### Install pureftpd to system startup - - count = 0 - - while(1): - - command = "systemctl enable " + install.preFlightsChecks.pureFTPDServiceName(self.distro) - res = subprocess.call(shlex.split(command)) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to enable PureFTPD to start and system restart, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to enable PureFTPD to run at system restart, exiting installer! [installPureFTPD]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("PureFTPD successfully enabled at system restart!") - InstallCyberPanel.stdOut("PureFTPD successfully enabled at system restart!") - break - - - - - ###### FTP Groups and user settings settings - - count = 0 - - while(1): - cmd = [] - cmd.append("groupadd") - cmd.append("-g") - cmd.append("2001") - cmd.append("ftpgroup") - - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to create group for FTP, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to create group for FTP, exiting installer! [installPureFTPD]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("System group for FTP successfully created!") - InstallCyberPanel.stdOut("System group for FTP successfully created!") - break - - count = 0 - - while(1): - - cmd = [] - - cmd.append("useradd") - cmd.append("-u") - cmd.append("2001") - cmd.append("-s") - cmd.append("/bin/false") - cmd.append("-d") - cmd.append("/bin/null") - cmd.append("-c") - cmd.append('"pureftpd user"') - cmd.append("-g") - cmd.append("ftpgroup") - cmd.append("ftpuser") - - - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to create user for FTP, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to create user for FTP, exiting installer! [installPureFTPD]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("System user for FTP successfully created!") - InstallCyberPanel.stdOut("System user for FTP successfully created!") - break - - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installPureFTPD]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installPureFTPD]") - return 0 - - return 1 + command = 'groupadd -g 2001 ftpgroup' + install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]', + 'Install FTP', + 1, 1, os.EX_OSERR) + command = 'useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftpgroup ftpuser' + install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]', + 'Install FTP', + 1, 1, os.EX_OSERR) def startPureFTPD(self): - ############## Start pureftpd ###################### - - try: - - count = 0 - - while(1): - if self.distro == ubuntu: - command = 'systemctl start pure-ftpd-mysql' - else: - command = 'systemctl start pure-ftpd' - res = subprocess.call(shlex.split(command)) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to start PureFTPD instance, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to start PureFTPD instance, you can do this manually later using systemctl start pure-ftpd [startPureFTPD]") - break - else: - logging.InstallLog.writeToFile("PureFTPD instance successfully started!") - InstallCyberPanel.stdOut("PureFTPD instance successfully started!") - break - - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [startPureFTPD]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [startPureFTPD]") - return 0 - - return 1 + if self.distro == ubuntu: + command = 'systemctl start pure-ftpd-mysql' + else: + command = 'systemctl start pure-ftpd' + install.preFlightsChecks.call(command, self.distro, '[startPureFTPD]', + 'Start FTP', + 1, 0, os.EX_OSERR) def installPureFTPDConfigurations(self, mysql): - try: ## setup ssl for ftp - logging.InstallLog.writeToFile("Configuring PureFTPD..") - InstallCyberPanel.stdOut("Configuring PureFTPD..") + InstallCyberPanel.stdOut("Configuring PureFTPD..", 1) try: os.mkdir("/etc/ssl/private") except: logging.InstallLog.writeToFile("Could not create directory for FTP SSL") - count = 0 - - while(1): - command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem' - res = subprocess.call(shlex.split(command)) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to create SSL for PureFTPD, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to create SSL for PureFTPD! [installPureFTPDConfigurations]") - break - else: - logging.InstallLog.writeToFile("SSL for PureFTPD successfully created!") - InstallCyberPanel.stdOut("SSL for PureFTPD successfully created!") - break + command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem' + install.preFlightsChecks.call(command, self.distro, '[installPureFTPDConfigurations]', + 'FTP Configurations', + 1, 0, os.EX_OSERR) os.chdir(self.cwd) ftpdPath = "/etc/pure-ftpd" @@ -967,18 +505,14 @@ class InstallCyberPanel: else: writeDataToFile.writelines(items) - #if self.distro == ubuntu: - # os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR) writeDataToFile.close() - #if self.distro == ubuntu: - # os.chmod(ftpdPath + '/pureftpd-ldap.conf', stat.S_IRUSR | stat.S_IWUSR) - # os.chmod(ftpdPath + '/pureftpd-pgsql.conf', stat.S_IRUSR | stat.S_IWUSR) - if self.distro == ubuntu: command = 'apt install pure-ftpd-mysql -y' - subprocess.call(shlex.split(command)) + install.preFlightsChecks.call(command, self.distro, '[installPureFTPDConfigurations]', + 'FTP Configurations', + 1, 1, os.EX_OSERR) if os.path.exists('/etc/pure-ftpd/db/mysql.conf'): os.remove('/etc/pure-ftpd/db/mysql.conf') @@ -990,17 +524,16 @@ class InstallCyberPanel: subprocess.call(command, shell=True) command = 'systemctl restart pure-ftpd-mysql.service' - subprocess.call(shlex.split(command)) + install.preFlightsChecks.call(command, self.distro, '[installPureFTPDConfigurations]', + 'FTP Configurations', + 1, 0, os.EX_OSERR) - logging.InstallLog.writeToFile("PureFTPD configured!") - InstallCyberPanel.stdOut("PureFTPD configured!") + InstallCyberPanel.stdOut("PureFTPD configured!", 1) except IOError, msg: logging.InstallLog.writeToFile(str(msg) + " [installPureFTPDConfigurations]") return 0 - return 1 - def installPowerDNS(self): try: count = 0 @@ -1038,86 +571,32 @@ class InstallCyberPanel: "/etc/resolv.conf'", 1, 1, os.EX_OSERR) if self.distro == centos: - while (1): - command = 'yum -y install epel-release yum-plugin-priorities' - cmd = shlex.split(command) - res = subprocess.call(cmd) + command = 'yum -y install epel-release yum-plugin-priorities' + install.preFlightsChecks.call(command, self.distro, '[installPowerDNS]', + 'Install PowerDNS', + 1, 1, os.EX_OSERR) - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to install PowerDNS Repositories, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to install PowerDNS Repositories, exiting installer! [installPowerDNS]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("PowerDNS Repositories successfully installed!") - InstallCyberPanel.stdOut("PowerDNS Repositories successfully installed!") - break + command = 'curl -o /etc/yum.repos.d/powerdns-auth-master.repo ' \ + 'https://repo.powerdns.com/repo-files/centos-auth-master.repo' + install.preFlightsChecks.call(command, self.distro, '[installPowerDNS]', + 'Install PowerDNS', + 1, 1, os.EX_OSERR) - count = 0 + if self.distro == ubuntu: + command = "DEBIAN_FRONTEND=noninteractive apt-get -y install pdns-server pdns-backend-mysql" + else: + command = 'yum -y install pdns pdns-backend-mysql' - while (1): - - command = 'curl -o /etc/yum.repos.d/powerdns-auth-master.repo ' \ - 'https://repo.powerdns.com/repo-files/centos-auth-master.repo' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut( - "Trying to install PowerDNS Repositories, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to install PowerDNS Repositories, exiting installer! [installPowerDNS]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("PowerDNS Repositories successfully installed!") - InstallCyberPanel.stdOut("PowerDNS Repositories successfully installed!") - break - - count = 1 - - while (1): - if self.distro == ubuntu: - command = "DEBIAN_FRONTEND=noninteractive apt-get -y install pdns-server pdns-backend-mysql" - res = os.system(command) - else: - command = 'yum -y install pdns pdns-backend-mysql' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to install PowerDNS, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to install PowerDNS, exiting installer! [installPowerDNS]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("PowerDNS successfully installed!") - InstallCyberPanel.stdOut("PowerDNS successfully installed!") - break - - except OSError, msg: + install.preFlightsChecks.call(command, self.distro, '[installPowerDNS]', + 'Install PowerDNS', + 1, 1, os.EX_OSERR) + except BaseException, msg: logging.InstallLog.writeToFile(str(msg) + " [powerDNS]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [powerDNS]") - return 0 - - return 1 def installPowerDNSConfigurations(self, mysqlPassword, mysql): try: - logging.InstallLog.writeToFile("Configuring PowerDNS..") - InstallCyberPanel.stdOut("Configuring PowerDNS..") + InstallCyberPanel.stdOut("Configuring PowerDNS..", 1) os.chdir(self.cwd) if self.distro == centos: @@ -1154,8 +633,7 @@ class InstallCyberPanel: writeDataToFile.close() - logging.InstallLog.writeToFile("PowerDNS configured!") - InstallCyberPanel.stdOut("PowerDNS configured!") + InstallCyberPanel.stdOut("PowerDNS configured!", 1) except IOError, msg: logging.InstallLog.writeToFile(str(msg) + " [installPowerDNSConfigurations]") @@ -1167,152 +645,55 @@ class InstallCyberPanel: ############## Start PowerDNS ###################### try: + command = 'systemctl enable pdns' + install.preFlightsChecks.call(command, self.distro, '[startPowerDNS]', + 'Start PowerDNS', + 1, 0, os.EX_OSERR) - count = 0 - - while(1): - - cmd = [] - - cmd.append("systemctl") - cmd.append("enable") - cmd.append("pdns") - - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to enable PowerDNS to start and system restart, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to enable PowerDNS to run at system restart, you can manually do this later using systemctl enable pdns! [startPowerDNS]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - break - else: - logging.InstallLog.writeToFile("PowerDNS successfully enabled at system restart!") - InstallCyberPanel.stdOut("PowerDNS successfully enabled at system restart!") - break - - count = 1 - - while(1): - command = 'systemctl start pdns' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to start PowerDNS instance, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to start PowerDNS instance, exiting installer! [startPowerDNS]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("PowerDNS instance successfully started!") - InstallCyberPanel.stdOut("PowerDNS instance successfully started!") - break - - - except OSError, msg: + command = 'systemctl start pdns' + install.preFlightsChecks.call(command, self.distro, '[startPowerDNS]', + 'Start PowerDNS', + 1, 0, os.EX_OSERR) + except BaseException, msg: logging.InstallLog.writeToFile(str(msg) + " [startPowerDNS]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [startPowerDNS]") - return 0 - - return 1 def installLSCPD(self): try: - logging.InstallLog.writeToFile("Starting LSCPD installation..") - InstallCyberPanel.stdOut("Starting LSCPD installation..") + InstallCyberPanel.stdOut("Starting LSCPD installation..", 1) os.chdir(self.cwd) - count = 0 + if self.distro == ubuntu: + command = "apt-get -y install gcc g++ make autoconf rcs" + else: + command = 'yum -y install gcc gcc-c++ make autoconf glibc rcs' - while (1): - if self.distro == ubuntu: - command = "apt-get -y install gcc g++ make autoconf rcs" - else: - command = 'yum -y install gcc gcc-c++ make autoconf glibc rcs' + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 1, os.EX_OSERR) - cmd = shlex.split(command) - res = subprocess.call(cmd) + if self.distro == ubuntu: + command = "apt-get -y install libpcre3 libpcre3-dev openssl libexpat1 libexpat1-dev libgeoip-dev" \ + " zlib1g zlib1g-dev libudns-dev whichman curl" + else: + command = 'yum -y install pcre-devel openssl-devel expat-devel geoip-devel zlib-devel udns-devel' \ + ' which curl' + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 1, os.EX_OSERR) - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to install LSCPD prerequisites, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to install LSCPD prerequisites, exiting installer! [installLSCPD]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("LSCPD prerequisites successfully installed!") - InstallCyberPanel.stdOut("LSCPD prerequisites successfully installed!") - break - count = 0 + command = 'tar zxf lscp.tar.gz -C /usr/local/' + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 1, os.EX_OSERR) - while(1): - if self.distro == ubuntu: - command = "apt-get -y install libpcre3 libpcre3-dev openssl libexpat1 libexpat1-dev libgeoip-dev" \ - " zlib1g zlib1g-dev libudns-dev whichman curl" - else: - command = 'yum -y install pcre-devel openssl-devel expat-devel geoip-devel zlib-devel udns-devel' \ - ' which curl' - cmd = shlex.split(command) - res = subprocess.call(cmd) - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to install LSCPD prerequisites, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to install LSCPD prerequisites, exiting installer! [installLSCPD]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("LSCPD prerequisites successfully installed!") - InstallCyberPanel.stdOut("LSCPD prerequisites successfully installed!") - break - - count = 0 - - while(1): - - command = 'tar zxf lscp.tar.gz -C /usr/local/' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to configure LSCPD, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to configure LSCPD, exiting installer! [installLSCPD]") - InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("LSCPD successfully configured!") - InstallCyberPanel.stdOut("LSCPD successfully extracted!") - break - - count = 0 - while(1): - - command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/key.pem -out /usr/local/lscp/cert.pem' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if install.preFlightsChecks.resFailed(self.distro, res): - count = count + 1 - InstallCyberPanel.stdOut("Trying to create SSL for LSCPD, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to create SSL for LSCPD! [installLSCPD]") - break - else: - logging.InstallLog.writeToFile("SSL for LSCPD successfully created!") - InstallCyberPanel.stdOut("SSL for LSCPD successfully created!") - break + command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/key.pem -out /usr/local/lscp/cert.pem' + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 1, os.EX_OSERR) try: os.remove("/usr/local/lscp/fcgi-bin/lsphp") @@ -1325,37 +706,33 @@ class InstallCyberPanel: else: command = 'useradd lscpd -M -d /usr/local/lscp' - cmd = shlex.split(command) - res = subprocess.call(cmd) + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 0, os.EX_OSERR) if self.distro == centos: command = 'groupadd lscpd' - cmd = shlex.split(command) - res = subprocess.call(cmd) + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 0, os.EX_OSERR) # Added group in useradd for Ubuntu command = 'usermod -a -G lscpd lscpd' - cmd = shlex.split(command) - res = subprocess.call(cmd) + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 0, os.EX_OSERR) command = 'usermod -a -G lsadm lscpd' - cmd = shlex.split(command) - res = subprocess.call(cmd) + install.preFlightsChecks.call(command, self.distro, '[installLSCPD]', + 'Install LSCPD', + 1, 0, os.EX_OSERR) os.mkdir('/usr/local/lscp/cyberpanel') - logging.InstallLog.writeToFile("LSCPD successfully installed!") - InstallCyberPanel.stdOut("LSCPD successfully installed!") - - except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installLSCPD]") - return 0 - except ValueError, msg: - logging.InstallLog.writeToFile(str(msg) + " [installLSCPD]") - return 0 - - return 1 + InstallCyberPanel.stdOut("LSCPD successfully installed!", 1) + except BaseException, msg: + logging.InstallLog.writeToFile(str(msg) + " [startPowerDNS]") def Main(cwd, mysql, distro, ent, serial = None): @@ -1392,12 +769,12 @@ def Main(cwd, mysql, distro, ent, serial = None): installer.setup_mariadb_repo() installer.installMySQL(mysql) installer.changeMYSQLRootPassword() - installer.changeMYSQLRootPasswordCyberPanel(mysql) + #installer.changeMYSQLRootPasswordCyberPanel(mysql) installer.startMariaDB() if distro == ubuntu: installer.fixMariaDB() - mysqlUtilities.createDatabaseCyberPanel("cyberpanel","cyberpanel",InstallCyberPanel.mysqlPassword, mysql) + mysqlUtilities.createDatabase("cyberpanel","cyberpanel",InstallCyberPanel.mysqlPassword) installer.installPureFTPD() installer.installPureFTPDConfigurations(mysql) diff --git a/install/lscp.tar.gz b/install/lscp.tar.gz index e8a29ff27..094067b80 100644 Binary files a/install/lscp.tar.gz and b/install/lscp.tar.gz differ diff --git a/install/mysqlUtilities.py b/install/mysqlUtilities.py index 17d89f1a0..bdab9c3d4 100644 --- a/install/mysqlUtilities.py +++ b/install/mysqlUtilities.py @@ -1,43 +1,11 @@ - import pexpect import installLog as logging +import subprocess, shlex class mysqlUtilities: @staticmethod - def SendQuery(user, password, dbname, query): - try: - expectation = "Enter password:" - securemysql = pexpect.spawn("mysql -u "+user+" -p") - securemysql.expect(expectation) - securemysql.sendline(password) - - expectation = ["Access denied for user", "Welcome to the MariaDB monitor"] - index = securemysql.expect(expectation) - if index == 0: - return "Wrong Password" - else: - - securemysql.sendline("USE "+dbname+";") - expectation = "Database changed" - securemysql.expect(expectation) - - expectation = "Query OK" - securemysql.sendline(query); - securemysql.expect(expectation) - - securemysql.sendline("exit"); - - securemysql.wait() - return 1 - except pexpect.EOF, msg: - logging.InstallLog.writeToFile(str(msg) + " Exception EOF [SendQuery]") - except BaseException, msg: - logging.InstallLog.writeToFile(str(msg) + "[SendQuery]") - - - @staticmethod - def createDatabase(dbname,dbuser,dbpassword): + def createDatabase(dbname, dbuser, dbpassword): try: @@ -47,98 +15,33 @@ class mysqlUtilities: data = f.read() password = data.split('\n', 1)[0] - expectation = "Enter password:" - securemysql = pexpect.spawn("mysql -u root -p") - securemysql.expect(expectation) - securemysql.sendline(password) + createDB = "CREATE DATABASE " + dbname - expectation = ["Access denied for user", "Welcome to the MariaDB monitor"] + command = 'mysql -u root -p' + password + ' -e "' + createDB + '"' + cmd = shlex.split(command) + res = subprocess.call(cmd) - index = securemysql.expect(expectation) + if res == 1: + return 0 - if index == 0: - return "Wrong root Password" + createUser = "CREATE USER '" + dbuser + "'@'localhost' IDENTIFIED BY '" + dbpassword + "'" + + command = 'mysql -u root -p' + password + ' -e "' + createUser + '"' + + cmd = shlex.split(command) + res = subprocess.call(cmd) + + if res == 1: + return 0 else: - securemysql.sendline("CREATE DATABASE "+dbname+";") + dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'" + command = 'mysql -u root -p' + password + ' -e "' + dropDB + '"' + cmd = shlex.split(command) + res = subprocess.call(cmd) - expectation = ["database exists","Query OK"] - index = securemysql.expect(expectation) + if res == 1: + return 0 - - if index == 0: - return "This database already exists, please choose another name." - elif index == 1: - securemysql.sendline("CREATE USER '" +dbuser+ "'@'localhost' IDENTIFIED BY '"+dbpassword+"';") - expectation = ["CREATE USER failed","Query OK"] - - index = securemysql.expect(expectation) - - if index == 0: - securemysql.sendline("DROP DATABASE IF EXISTS "+dbname+";") - return "This user already exists, please choose another user." - else: - securemysql.sendline("GRANT ALL PRIVILEGES ON " +dbname+ ".* TO '" +dbuser+ "'@'localhost';") - expectation = "Query OK" - securemysql.expect(expectation) - securemysql.sendline("exit") - securemysql.wait() return 1 - except pexpect.EOF, msg: - logging.InstallLog.writeToFile(str(msg) + " Exception EOF [createDatabase]") except BaseException, msg: - logging.InstallLog.writeToFile(str(msg) + "[createDatabase]") - - @staticmethod - def createDatabaseCyberPanel(dbname,dbuser,dbpassword, mysql): - - try: - - passFile = "/etc/cyberpanel/mysqlPassword" - - f = open(passFile) - data = f.read() - password = data.split('\n', 1)[0] - - expectation = "Enter password:" - if mysql == 'Two': - securemysql = pexpect.spawn("mysql --host=127.0.0.1 --port=3307 -u root -p") - else: - securemysql = pexpect.spawn("mysql -u root -p", timeout=5) - securemysql.expect(expectation) - securemysql.sendline(password) - - expectation = ["Access denied for user", "Welcome to the MariaDB monitor"] - - index = securemysql.expect(expectation) - - if index == 0: - return "Wrong root Password" - else: - securemysql.sendline("CREATE DATABASE "+dbname+";") - - expectation = ["database exists","Query OK"] - index = securemysql.expect(expectation) - - - if index == 0: - return "This database already exists, please choose another name." - elif index == 1: - securemysql.sendline("CREATE USER '" +dbuser+ "'@'localhost' IDENTIFIED BY '"+dbpassword+"';") - expectation = ["CREATE USER failed","Query OK"] - - index = securemysql.expect(expectation) - - if index == 0: - securemysql.sendline("DROP DATABASE IF EXISTS "+dbname+";") - return "This user already exists, please choose another user." - else: - securemysql.sendline("GRANT ALL PRIVILEGES ON " +dbname+ ".* TO '" +dbuser+ "'@'localhost';") - expectation = "Query OK" - securemysql.expect(expectation) - securemysql.sendline("exit") - securemysql.wait() - return 1 - except pexpect.EOF, msg: - logging.InstallLog.writeToFile(str(msg) + " Exception EOF [createDatabase]") - except BaseException, msg: - logging.InstallLog.writeToFile(str(msg) + "[createDatabase]") \ No newline at end of file + return 0 \ No newline at end of file diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 07459e13b..7845c9400 100644 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -436,7 +436,8 @@ class ApplicationInstaller(multi.Thread): if home == '0': path = self.extraArgs['path'] - finalURL = domainName + '/' + path + #finalURL = domainName + '/' + path + finalURL = domainName else: finalURL = domainName diff --git a/plogical/httpProc.py b/plogical/httpProc.py new file mode 100644 index 000000000..8d3ff115f --- /dev/null +++ b/plogical/httpProc.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +from django.shortcuts import render, HttpResponse +import json + +class httpProc: + def __init__(self, request, templateName, data = None): + self.request = request + self.templateName = templateName + self.data = data + + def renderPre(self): + if self.data == None: + return render(self.request, self.templateName) + else: + return render(self.request, self.templateName, self.data) + def ajaxPre(self, status, errorMessage, success = None): + final_dic = {'status': status, 'error_message': errorMessage, 'success': success} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def ajax(self, status, errorMessage, data = None): + if data == None: + finalDic = {'status': status, 'error_message': errorMessage} + finalJson = json.dumps(finalDic) + return HttpResponse(finalJson) + else: + finalDic = {} + finalDic['status'] = status + finalDic['error_message'] = errorMessage + + for key, value in data.iteritems(): + finalDic[key] = value + + finalJson = json.dumps(finalDic) + return HttpResponse(finalJson) + diff --git a/plogical/mysqlUtilities.py b/plogical/mysqlUtilities.py index 7a3021f1a..c73d4c9a2 100644 --- a/plogical/mysqlUtilities.py +++ b/plogical/mysqlUtilities.py @@ -8,90 +8,62 @@ import subprocess import shlex from websiteFunctions.models import Websites from databases.models import Databases +import MySQLdb as mysql class mysqlUtilities: - @staticmethod - def createDatabase(dbname,dbuser,dbpassword): - + def setupConnection(): try: - passFile = "/etc/cyberpanel/mysqlPassword" f = open(passFile) data = f.read() password = data.split('\n', 1)[0] - createDB = "CREATE DATABASE "+dbname + conn = mysql.connect(user='root', passwd=password) + cursor = conn.cursor() + return conn, cursor - command = 'sudo mysql -u root -p' + password + ' -e "' + createDB + '"' - cmd = shlex.split(command) - res = subprocess.call(cmd) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return 0, 0 - if res == 1: - logging.CyberCPLogFileWriter.writeToFile("Can not create Database: " +dbname) + + @staticmethod + def createDatabase(dbname,dbuser,dbpassword): + try: + + connection, cursor = mysqlUtilities.setupConnection() + + if connection == 0: return 0 - createUser = "CREATE USER '" +dbuser+ "'@'localhost' IDENTIFIED BY '"+dbpassword+"'" - - command = 'sudo mysql -u root -p' + password + ' -e "' + createUser + '"' - - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if res == 1: - logging.CyberCPLogFileWriter.writeToFile("Can not create Database User: " + dbuser) - ## reverting the db creation which was created earlier - mysqlUtilities.deleteDatabase(dbname,dbuser) - return 0 - else: - dropDB = "GRANT ALL PRIVILEGES ON " +dbname+ ".* TO '" +dbuser+ "'@'localhost'" - command = 'sudo mysql -u root -p' + password + ' -e "' + dropDB + '"' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if res == 1: - mysqlUtilities.deleteDatabase(dbname, dbuser) - logging.CyberCPLogFileWriter.writeToFile("Can not grant privileges to user: " + dbuser) - return 0 + cursor.execute("CREATE DATABASE " + dbname) + cursor.execute("CREATE USER '" +dbuser+ "'@'localhost' IDENTIFIED BY '"+dbpassword+"'") + cursor.execute("GRANT ALL PRIVILEGES ON " +dbname+ ".* TO '" +dbuser+ "'@'localhost'") + connection.close() return 1 except BaseException, msg: + mysqlUtilities.deleteDatabase(dbname, dbuser) logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabase]") return 0 @staticmethod def deleteDatabase(dbname, dbuser): - try: - passFile = "/etc/cyberpanel/mysqlPassword" + connection, cursor = mysqlUtilities.setupConnection() - f = open(passFile) - data = f.read() - password = data.split('\n', 1)[0] - - dropDB = "DROP DATABASE " + dbname - command = 'sudo mysql -u root -p' + password + ' -e "' + dropDB + '"' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - - if res == 1: - logging.CyberCPLogFileWriter.writeToFile("Can not delete Database: " + dbname) + if connection == 0: return 0 - else: - dropUser = "DROP USER '"+dbuser+"'@'localhost'" - command = 'sudo mysql -u root -p' + password + ' -e "' + dropUser + '"' - cmd = shlex.split(command) - res = subprocess.call(cmd) - if res == 1: - logging.CyberCPLogFileWriter.writeToFile("Can not delete Database User: " + dbuser) - return 0 + cursor.execute("DROP DATABASE " + dbname) + cursor.execute("DROP USER '"+dbuser+"'@'localhost'") + connection.close() return 1 @@ -121,7 +93,7 @@ class mysqlUtilities: return 1 except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabase]") + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabaseBackup]") return 0 @staticmethod @@ -146,21 +118,20 @@ class mysqlUtilities: logging.CyberCPLogFileWriter.writeToFile("Could not restore MYSQL database: " +databaseName +"! [restoreDatabaseBackup]") return 0 - passwordCMD = "use mysql;SET PASSWORD FOR '"+databaseName+"'@'localhost' = '"+dbPassword+"';FLUSH PRIVILEGES;" + connection, cursor = mysqlUtilities.setupConnection() - command = 'sudo mysql -u root -p'+password+' -e "'+passwordCMD+'"' - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if res == 1: - logging.CyberCPLogFileWriter.writeToFile("Could not change password for MYSQL user: " + databaseName + "! [restoreDatabaseBackup]") + if connection == 0: return 0 + passwordCMD = "use mysql;SET PASSWORD FOR '" + databaseName + "'@'localhost' = '" + dbPassword + "';FLUSH PRIVILEGES;" + + cursor.execute(passwordCMD) + connection.close() + return 1 except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[restoreDatabaseBackup]") - @staticmethod def submitDBCreation(dbName, dbUsername, dbPassword, databaseWebsite): try: diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 4090d2093..1a4d1b642 100644 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -72,10 +72,10 @@ class ProcessUtilities: def executioner(command): try: res = subprocess.call(shlex.split(command)) - if res == 1: - return 0 - else: + if res == 0: return 1 + else: + return 0 except BaseException, msg: return 0 diff --git a/plogical/vhost.py b/plogical/vhost.py index f627bb37b..dd6d24378 100644 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -54,9 +54,15 @@ class vhost: @staticmethod def createDirectories(path, virtualHostUser, pathHTML, pathLogs, confPath, completePathToConfigFile): try: - FNULL = open(os.devnull, 'w') + try: + command = 'chmod 711 /home' + cmd = shlex.split(command) + subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + except: + pass + try: os.makedirs(path) @@ -64,6 +70,10 @@ class vhost: cmd = shlex.split(command) subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + command = "chmod 711 " + path + cmd = shlex.split(command) + subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + except OSError, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + " [27 Not able create to directories for virtual host [createDirectories]]") @@ -606,7 +616,6 @@ class vhost: return 0 return 1 - @staticmethod def deleteCoreConf(virtualHostName, numberOfSites): if ProcessUtilities.decideServer() == ProcessUtilities.OLS: @@ -778,7 +787,6 @@ class vhost: print 0, str(msg) return [0, str(msg) + " [IO Error with per host config file [changePHP]]"] - @staticmethod def addRewriteRules(virtualHostName, fileName=None): try: diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 6b0420d7e..39fe7a842 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -1102,8 +1102,6 @@ def main(): parser.add_argument('--openBasedirValue', help='open_base dir protection value!') parser.add_argument('--tempStatusPath', help='Temporary Status file path.') - - args = parser.parse_args() if args.function == "createVirtualHost": diff --git a/plogical/website.py b/plogical/website.py index b819cc94a..c552e4d7b 100644 --- a/plogical/website.py +++ b/plogical/website.py @@ -145,7 +145,12 @@ class WebsiteManager: phpSelection = data['phpSelection'] packageName = data['package'] websiteOwner = data['websiteOwner'] - externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:7] + try: + HA = data['HA'] + externalApp = 'nobody' + except: + externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:7] + tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) ## Create Configurations diff --git a/websiteFunctions/templates/websiteFunctions/installPrestaShop.html b/websiteFunctions/templates/websiteFunctions/installPrestaShop.html index ef2a28091..92c4baf70 100644 --- a/websiteFunctions/templates/websiteFunctions/installPrestaShop.html +++ b/websiteFunctions/templates/websiteFunctions/installPrestaShop.html @@ -66,12 +66,12 @@ -
+