diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index b923418cb..fb7b12788 --- a/install.sh +++ b/install.sh @@ -1,4 +1,45 @@ #!/bin/bash +install-ubuntu() +{ + #!/bin/bash + #yum autoremove epel-release -y + #rm -f /etc/yum.repos.d/epel.repo + #rm -f /etc/yum.repos.d/epel.repo.rpmsave + #yum install epel-release -y + #some provider's centos7 template come with incorrect or misconfigured epel.repo + #if systemctl is-active named | grep -q 'active'; then + # systemctl stop named + # systemctl disable named + # echo "Disabling named to aviod powerdns conflicts..." + # else + # echo "named is not installed or active, to next step..." + #fi + # above if will check if server has named.service running that occupies port 53 which makes powerdns failed to start + apt-get clean all + apt-get update -y + apt-get install curl -y + #setenforce 0 + #sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config + #wget https://cyberpanel.net/install.tar.gz + #tar xzvf install.tar.gz + apt-get install python -y + apt-get install git -y + if [ ! -d cyberpanel ]; then + git clone https://github.com/rperper/cyberpanel.git + fi + cd cyberpanel + cd install + chmod +x install.py + server_ip="$(wget -qO- http://whatismyip.akamai.com/)" + python install.py $server_ip + exit $? +} + + +if [ -a /etc/lsb-release ]; then + install-ubuntu + exit $? +fi yum autoremove epel-release -y rm -f /etc/yum.repos.d/epel.repo rm -f /etc/yum.repos.d/epel.repo.rpmsave diff --git a/install/.idea/vcs.xml b/install/.idea/vcs.xml new file mode 100644 index 000000000..6c0b86358 --- /dev/null +++ b/install/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/install/composer-no-test.sh b/install/composer-no-test.sh new file mode 100644 index 000000000..4225b03c6 --- /dev/null +++ b/install/composer-no-test.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +#php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" +php composer-setup.php +php -r "unlink('composer-setup.php');" +cp composer.phar /usr/bin/composer diff --git a/install/install.py b/install/install.py old mode 100644 new mode 100755 index 7b8f514cb..a887ca9c5 --- a/install/install.py +++ b/install/install.py @@ -9,48 +9,42 @@ from firewallUtilities import FirewallUtilities import time import string import random +import socket +import errno +from os.path import * +from stat import * # There can not be peace without first a great suffering. -class preFlightsChecks: +#distros +centos=0 +ubuntu=1 + + +class preFlightsChecks: cyberPanelMirror = "mirror.cyberpanel.net/pip" - def __init__(self,rootPath,ip,path,cwd,cyberPanelPath): + def __init__(self, rootPath, ip, path, cwd, cyberPanelPath, distro): self.ipAddr = ip self.path = path self.cwd = cwd self.server_root_path = rootPath self.cyberPanelPath = cyberPanelPath + self.distro = distro @staticmethod - def stdOut(message): + def stdOut(message, log = 0, do_exit = 0, code = os.EX_OK): print("\n\n") print ("[" + time.strftime( "%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n") print("[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + message + "\n") print ("[" + time.strftime( "%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n") - - def checkIfSeLinuxDisabled(self): - try: - command = "sestatus" - output = subprocess.check_output(shlex.split(command)) - - if output.find("disabled") > -1 or output.find("permissive") > -1: - logging.InstallLog.writeToFile("SELinux Check OK. [checkIfSeLinuxDisabled]") - preFlightsChecks.stdOut("SELinux Check OK.") - return 1 - else: - logging.InstallLog.writeToFile("SELinux is enabled, please disable SELinux and restart the installation!") - preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - - except BaseException,msg: - logging.InstallLog.writeToFile(str(msg) + "[checkIfSeLinuxDisabled]") - logging.InstallLog.writeToFile("SELinux Check OK. [checkIfSeLinuxDisabled]") - preFlightsChecks.stdOut("SELinux Check OK.") - return 1 + if log: + logging.InstallLog.writeToFile(message) + if do_exit: + sys.exit(code) def checkPythonVersion(self): if sys.version_info[0] == 2 and sys.version_info[1] == 7: @@ -60,107 +54,129 @@ class preFlightsChecks: os._exit(0) def setup_account_cyberpanel(self): + self.stdOut("Setup Cyberpanel account") try: count = 0 - while (1): - command = "yum install sudo -y" - cmd = shlex.split(command) - res = subprocess.call(cmd) + if self.distro == centos: + while (1): + command = "yum install sudo -y" + cmd = shlex.split(command) + res = subprocess.call(cmd) - if res == 1: - count = count + 1 - preFlightsChecks.stdOut("SUDO install failed, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("We are not able to install SUDO, exiting the installer. [setup_account_cyberpanel]") - preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("SUDO successfully installed!") - preFlightsChecks.stdOut("SUDO successfully installed!") - break + if res == 1: + count = count + 1 + preFlightsChecks.stdOut("SUDO install failed, trying again, try number: " + str(count)) + if count == 3: + logging.InstallLog.writeToFile("We are not able to install SUDO, exiting the installer. [setup_account_cyberpanel]") + preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") + os._exit(0) + else: + logging.InstallLog.writeToFile("SUDO successfully installed!") + preFlightsChecks.stdOut("SUDO successfully installed!") + break ## count = 0 - while (1): - command = "adduser cyberpanel" + if self.distro == ubuntu: + self.stdOut("Fix sudoers") + try: + fileName = '/etc/sudoers' + data = open(fileName, 'r').readlines() + + writeDataToFile = open(fileName, 'w') + for line in data: + if line[:5] == '%sudo': + writeDataToFile.write('%sudo ALL=(ALL:ALL) NOPASSWD: ALL\n') + else: + writeDataToFile.write(line) + writeDataToFile.close() + except IOError as err: + self.stdOut("Error in fixing sudoers file: " + str(err), 1, 1, os.EX_OSERR) + + self.stdOut("Add Cyberpanel user") + command = "useradd cyberpanel -m -U -G sudo" cmd = shlex.split(command) res = subprocess.call(cmd) + if res != 0 and res != 9: + logging.InstallLog.writeToFile("Can not create cyberpanel user, error #" + str(res)) + preFlightsChecks.stdOut("Can not create cyberpanel user, error #" + str(res)) + os._exit(0) + if res == 0: + logging.InstallLog.writeToFile("CyberPanel user added") + preFlightsChecks.stdOut("CyberPanel user added") - if res == 1: - count = count + 1 - preFlightsChecks.stdOut("Not able to add user cyberpanel to system, trying again, try number: " + str(count) + "\n") - if count == 3: - logging.InstallLog.writeToFile("We are not able add user cyberpanel to system, exiting the installer. [setup_account_cyberpanel]") - preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("CyberPanel user added!") - preFlightsChecks.stdOut("CyberPanel user added!") - break + else: + while (1): + command = "adduser cyberpanel" + cmd = shlex.split(command) + res = subprocess.call(cmd) - ## + if res == 1: + count = count + 1 + preFlightsChecks.stdOut("Not able to add user cyberpanel to system, trying again, try number: " + str(count) + "\n") + if count == 3: + logging.InstallLog.writeToFile("We are not able add user cyberpanel to system, exiting the installer. [setup_account_cyberpanel]") + preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") + os._exit(0) + else: + logging.InstallLog.writeToFile("CyberPanel user added!") + preFlightsChecks.stdOut("CyberPanel user added!") + break + + ## + + count = 0 + + while (1): + + command = "usermod -aG wheel cyberpanel" + cmd = shlex.split(command) + res = subprocess.call(cmd) + + if res == 1: + count = count + 1 + preFlightsChecks.stdOut("We are trying to add CyberPanel user to SUDO group, trying again, try number: " + str(count) + "\n") + if count == 3: + logging.InstallLog.writeToFile("Not able to add user CyberPanel to SUDO group, exiting the installer. [setup_account_cyberpanel]") + preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") + os._exit(0) + else: + logging.InstallLog.writeToFile("CyberPanel user was successfully added to SUDO group!") + preFlightsChecks.stdOut("CyberPanel user was successfully added to SUDO group!") + break + + + ############################### + + path = "/etc/sudoers" + + data = open(path, 'r').readlines() + + writeToFile = open(path, 'w') + + for items in data: + if items.find("wheel ALL=(ALL) NOPASSWD: ALL") > -1: + writeToFile.writelines("%wheel ALL=(ALL) NOPASSWD: ALL") + else: + writeToFile.writelines(items) + + writeToFile.close() + + ############################### count = 0 - - while (1): - - command = "usermod -aG wheel cyberpanel" - cmd = shlex.split(command) - res = subprocess.call(cmd) - - if res == 1: - count = count + 1 - preFlightsChecks.stdOut("We are trying to add CyberPanel user to SUDO group, trying again, try number: " + str(count) + "\n") - if count == 3: - logging.InstallLog.writeToFile("Not able to add user CyberPanel to SUDO group, exiting the installer. [setup_account_cyberpanel]") - preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) + self.stdOut("Create /etc/letsencrypt directory") + try: + os.mkdir("/etc/letsencrypt") + except OSError as e: + if e.errno != errno.EEXIST: + self.stdOut("Error creating /etc/letsencrypt directory: " + str(e) + + " Installer can continue without this [setup_account_cyberpanel] ",1) else: - logging.InstallLog.writeToFile("CyberPanel user was successfully added to SUDO group!") - preFlightsChecks.stdOut("CyberPanel user was successfully added to SUDO group!") - break - - - ############################### - - path = "/etc/sudoers" - - data = open(path, 'r').readlines() - - writeToFile = open(path, 'w') - - for items in data: - if items.find("wheel ALL=(ALL) NOPASSWD: ALL") > -1: - writeToFile.writelines("%wheel ALL=(ALL) NOPASSWD: ALL") - else: - writeToFile.writelines(items) - - writeToFile.close() - - ############################### - - count = 0 - - while (1): - - command = "mkdir /etc/letsencrypt" - - cmd = shlex.split(command) - - res = subprocess.call(cmd) - - if res == 1: - count = count + 1 - preFlightsChecks.stdOut("We are trying to create Let's Encrypt directory to store SSLs, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile("Failed to create Let's Encrypt directory to store SSLs. Installer can continue without this.. [setup_account_cyberpanel]") - else: - logging.InstallLog.writeToFile("Successfully created Let's Encrypt directory!") - preFlightsChecks.stdOut("Successfully created Let's Encrypt directory!") - break + pass ## @@ -200,26 +216,66 @@ class preFlightsChecks: return 1 def installCyberPanelRepo(self): + self.stdOut("Install Cyberpanel repo") cmd = [] count = 0 - while(1): - cmd.append("rpm") - cmd.append("-ivh") - cmd.append("http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm") - res = subprocess.call(cmd) + if self.distro == ubuntu: + try: + filename = "enable_lst_debain_repo.sh" + command = "wget http://rpms.litespeedtech.com/debian/" + filename + cmd = shlex.split(command) + res = subprocess.call(cmd) + if res != 0: + logging.InstallLog.writeToFile("Unable to download Ubuntu CyberPanel installer! [installCyberPanelRepo]:" + " Error #" + str(res)) + preFlightsChecks.stdOut("Unable to download Ubuntu CyberPanel installer! [installCyberPanelRepo]:" + " Error #" + str(res)) + os._exit(os.EX_NOINPUT) + + os.chmod(filename, S_IRWXU | S_IRWXG) + + command = "./" + filename + cmd = shlex.split(command) + res = subprocess.call(cmd) + + if res != 0: + logging.InstallLog.writeToFile("Unable to install Ubuntu CyberPanel! [installCyberPanelRepo]:" + " Error #" + str(res)) + preFlightsChecks.stdOut("Unable to install Ubuntu CyberPanel! [installCyberPanelRepo]:" + " Error #" + str(res)) + os._exit(os.EX_NOINPUT) + + except OSError as err: + logging.InstallLog.writeToFile("Exception during CyberPanel install: " + str(err)) + preFlightsChecks.stdOut("Exception during CyberPanel install: " + str(err)) + os._exit(os.EX_OSERR) + + except: + logging.InstallLog.writeToFile("Exception during CyberPanel install") + preFlightsChecks.stdOut("Exception during CyberPanel install") + os._exit(os.EX_SOFTWARE) + + else: + while(1): + cmd.append("rpm") + cmd.append("-ivh") + cmd.append("http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm") + res = subprocess.call(cmd) + + if res == 1: + count = count + 1 + preFlightsChecks.stdOut("Unable to add CyberPanel official repository, trying again, try number: " + str(count) + "\n") + if count == 3: + logging.InstallLog.writeToFile("Unable to add CyberPanel official repository, exiting installer! [installCyberPanelRepo]") + preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") + os._exit(0) + else: + logging.InstallLog.writeToFile("CyberPanel Repo added!") + preFlightsChecks.stdOut("CyberPanel Repo added!") + break + return 0 - if res == 1: - count = count + 1 - preFlightsChecks.stdOut("Unable to add CyberPanel official repository, trying again, try number: " + str(count) + "\n") - if count == 3: - logging.InstallLog.writeToFile("Unable to add CyberPanel official repository, exiting installer! [installCyberPanelRepo]") - preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("CyberPanel Repo added!") - preFlightsChecks.stdOut("CyberPanel Repo added!") - break def enableEPELRepo(self): try: @@ -258,10 +314,15 @@ class preFlightsChecks: return 1 + def install_pip(self): + self.stdOut("Install pip") count = 0 while (1): - command = "yum -y install python-pip" + if self.distro == ubuntu: + command = "apt-get -y install python-pip" + else: + command = "yum -y install python-pip" res = subprocess.call(shlex.split(command)) if res == 1: @@ -276,10 +337,15 @@ class preFlightsChecks: preFlightsChecks.stdOut("PIP successfully installed!") break + def install_python_dev(self): + self.stdOut("Install python development environment") count = 0 while (1): - command = "yum -y install python-devel" + if self.distro == centos: + command = "yum -y install python-devel" + else: + command = "apt-get -y install python-dev" res = subprocess.call(shlex.split(command)) if res == 1: @@ -294,11 +360,16 @@ class preFlightsChecks: preFlightsChecks.stdOut("Python development tools successfully installed!") break + def install_gcc(self): + self.stdOut("Install gcc") count = 0 while (1): - command = "yum -y install gcc" + if self.distro == centos: + command = "yum -y install gcc" + else: + command = "apt-get -y install gcc" res = subprocess.call(shlex.split(command)) if res == 1: @@ -314,6 +385,7 @@ class preFlightsChecks: break def install_python_setup_tools(self): + self.stdOut("Install python setup tools") count = 0 while (1): command = "yum -y install python-setuptools" @@ -335,6 +407,7 @@ class preFlightsChecks: break def install_python_requests(self): + self.stdOut("Install python requests") try: import requests @@ -481,6 +554,7 @@ class preFlightsChecks: break def install_django(self): + self.stdOut("Install Django") count = 0 while (1): command = "pip install django==1.11" @@ -500,9 +574,13 @@ class preFlightsChecks: break def install_python_mysql_library(self): + self.stdOut("Install MySQL python library") count = 0 while (1): - command = "yum -y install MySQL-python" + if self.distro == centos: + command = "yum -y install MySQL-python" + else: + command = "apt-get -y install libmysqlclient-dev" res = subprocess.call(shlex.split(command)) if res == 1: count = count + 1 @@ -516,10 +594,25 @@ class preFlightsChecks: preFlightsChecks.stdOut("MySQL-python successfully installed!") break + if self.distro == ubuntu: + command = "pip install MySQL-python" + res = subprocess.call(shlex.split(command)) + if res != 0: + logging.InstallLog.writeToFile( + "Unable to install MySQL-python, exiting installer! [install_python_mysql_library] Error: " + str(res)) + preFlightsChecks.stdOut( + "Unable to install MySQL-python, exiting installer! [install_python_mysql_library] Error: " + str(res)) + os._exit(os.EX_OSERR) + + def install_gunicorn(self): + self.stdOut("Install GUnicorn") count = 0 while (1): - command = "easy_install gunicorn" + if self.distro == ubuntu: + command = "pip install gunicorn" + else: + command = "easy_install gunicorn" res = subprocess.call(shlex.split(command)) if res == 1: count = count + 1 @@ -533,6 +626,7 @@ class preFlightsChecks: preFlightsChecks.stdOut("GUNICORN successfully installed!") break + def setup_gunicorn(self): try: @@ -578,6 +672,7 @@ class preFlightsChecks: preFlightsChecks.stdOut("Not able to setup gunicorn, see install log.") def install_psutil(self): + self.stdOut("Install psutil") try: import psutil @@ -623,6 +718,9 @@ class preFlightsChecks: break def fix_selinux_issue(self): + if (self.distro == ubuntu): + return + try: cmd = [] @@ -641,9 +739,13 @@ class preFlightsChecks: logging.InstallLog.writeToFile("fix_selinux_issue problem") def install_psmisc(self): + self.stdOut("Install psmisc") count = 0 while (1): - command = "yum -y install psmisc" + if self.distro == centos: + command = "yum -y install psmisc" + else: + command = "apt-get -y install psmisc" res = subprocess.call(shlex.split(command)) if res == 1: count = count + 1 @@ -658,6 +760,7 @@ class preFlightsChecks: break def download_install_CyberPanel(self,mysqlPassword, mysql): + self.stdOut("Download and install Cyberpanel") try: ## On OpenVZ there is an issue with requests module, which needs to upgrade requests module @@ -779,7 +882,10 @@ class preFlightsChecks: ### Applying migrations - os.chdir("CyberCP") + try: + os.chdir("CyberCP") + except: + self.stdOut("Error changing to CyberCP directory - internal error!", 1, 1, os.EX_USAGE) count = 0 @@ -873,12 +979,16 @@ class preFlightsChecks: def install_unzip(self): + self.stdOut("Install unzip") try: count = 0 while (1): - command = 'yum -y install unzip' + if self.distro == centos: + command = 'yum -y install unzip' + else: + command = 'apt-get -y install unzip' cmd = shlex.split(command) res = subprocess.call(cmd) @@ -905,11 +1015,15 @@ class preFlightsChecks: return 1 def install_zip(self): + self.stdOut("Install zip") try: count = 0 while (1): - command = 'yum -y install zip' + if self.distro == centos: + command = 'yum -y install zip' + else: + command = 'apt-get -y install zip' cmd = shlex.split(command) @@ -938,8 +1052,15 @@ class preFlightsChecks: return 1 def download_install_phpmyadmin(self): + self.stdOut("Install PHP MyAdmin") try: - os.chdir("/usr/local/lscp/cyberpanel/") + directory = "/usr/local/lscp/cyberpanel/" + try: + os.chdir(directory) + except OSError as e: + msg = "Error changing to " + "/usr/local/lscp/cyberpanel/ :" + str(e) + " [download_install_phpmyadmin]" + self.stdOut(msg, 1, 1, os.EX_USAGE) + count = 0 while(1): @@ -1033,7 +1154,13 @@ class preFlightsChecks: writeToFile.close() - os.mkdir('/usr/local/lscp/cyberpanel/phpmyadmin/tmp') + try: + os.mkdir('/usr/local/lscp/cyberpanel/phpmyadmin/tmp') + except OSError as e: + if e.errno != errno.EEXIST: + self.stdOut("Error ceating: '/usr/local/lscp/cyberpanel/phpmyadmin/tmp' " + str(e), 1, 1, os.EX_CANTCREAT) + else: + pass command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/phpmyadmin' subprocess.call(shlex.split(command)) @@ -1052,14 +1179,32 @@ class preFlightsChecks: def install_postfix_davecot(self): + self.stdOut("Install dovecot - first remove postfix") try: + if self.distro == centos: + command = 'yum remove postfix -y' + else: + command = 'apt-get -y remove postfix' - command = 'yum remove postfix -y' subprocess.call(shlex.split(command)) + self.stdOut("Install dovecot - do the install") count = 0 while(1): - command = 'yum install -y http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//postfix3-3.2.4-1.gf.el7.x86_64.rpm' + if self.distro == centos: + command = 'yum install -y http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//postfix3-3.2.4-1.gf.el7.x86_64.rpm' + else: + command = 'apt-get -y debconf-utils' + subprocess.call(shlex.split(command)) + file_name = self.cwd + '/pf.unattend.text' + pf = open(file_name, 'w') + pf.write('postfix postfix/mailname string ' + str(socket.getfqdn() + '\n')) + pf.write('postfix postfix/main_mailer_type string "Internet Site"\n') + pf.close() + command = 'debconf-set-selections ' + file_name + subprocess.call(shlex.split(command)) + command = 'apt-get -y install postfix' + # os.remove(file_name) cmd = shlex.split(command) @@ -1079,7 +1224,10 @@ class preFlightsChecks: count = 0 while (1): - command = 'yum install -y http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//postfix3-mysql-3.2.4-1.gf.el7.x86_64.rpm' + if self.distro == centos: + command = 'yum install -y http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//postfix3-mysql-3.2.4-1.gf.el7.x86_64.rpm' + else: + command = 'apt-get -y install dovecot-imapd dovecot-pop3d postfix-mysql' cmd = shlex.split(command) @@ -1087,10 +1235,10 @@ class preFlightsChecks: if res == 1: count = count + 1 - preFlightsChecks.stdOut("Unable to install Postfix, trying again, try number: " + str(count)) + preFlightsChecks.stdOut("Unable to install Postfix agent, trying again, try number: " + str(count)) if count == 3: logging.InstallLog.writeToFile( - "Unable to install Postfix, you will not be able to send mails and rest should work fine! [install_postfix_davecot]") + "Unable to install Postfix agent, you will not be able to send mails and rest should work fine! [install_postfix_davecot]") break else: logging.InstallLog.writeToFile("Postfix successfully installed!") @@ -1101,7 +1249,10 @@ class preFlightsChecks: while(1): - command = 'yum -y install dovecot dovecot-mysql' + if self.distro == centos: + command = 'yum -y install dovecot dovecot-mysql' + else: + command = 'apt-get -y install dovecot-mysql' cmd = shlex.split(command) @@ -1131,6 +1282,7 @@ class preFlightsChecks: def setup_email_Passwords(self,mysqlPassword, mysql): + self.stdOut("Setup email passwords") try: logging.InstallLog.writeToFile("Setting up authentication for Postfix and Dovecot...") @@ -1246,12 +1398,12 @@ class preFlightsChecks: def setup_postfix_davecot_config(self, mysql): + self.stdOut("Configuring postfix and dovecot") try: logging.InstallLog.writeToFile("Configuring postfix and dovecot...") os.chdir(self.cwd) - mysql_virtual_domains = "/etc/postfix/mysql-virtual_domains.cf" mysql_virtual_forwardings = "/etc/postfix/mysql-virtual_forwardings.cf" mysql_virtual_mailboxes = "/etc/postfix/mysql-virtual_mailboxes.cf" @@ -1261,8 +1413,6 @@ class preFlightsChecks: davecot = "/etc/dovecot/dovecot.conf" davecotmysql = "/etc/dovecot/dovecot-sql.conf.ext" - - if os.path.exists(mysql_virtual_domains): os.remove(mysql_virtual_domains) @@ -1891,7 +2041,11 @@ class preFlightsChecks: ####### - os.chdir("/usr/local/lscp/cyberpanel") + try: + os.chdir("/usr/local/lscp/cyberpanel") + except OSError as e: + self.stdOut("Can't change to cyberpanel directory, fatal error at this point") + count = 1 @@ -2017,6 +2171,7 @@ class preFlightsChecks: def reStartLiteSpeed(self): + self.stdOut("Restarting Litespeed") try: count = 0 while(1): @@ -2048,6 +2203,9 @@ class preFlightsChecks: def installFirewalld(self): + if self.distro == ubuntu: + return 0 # Uses AppArmor + try: preFlightsChecks.stdOut("Enabling Firewall!") @@ -2206,6 +2364,16 @@ class preFlightsChecks: count = 0 + # In Ubuntu, the library that lscpd looks for is libpcre.so.1, but the one it installs is libpcre.so.3... + if self.distro == ubuntu: + command = 'ln -s /lib/x86_64-linux-gnu/libpcre.so.3 /lib/x86_64-linux-gnu/libpcre.so.1' + res = subprocess.call(shlex.split(command)) + if res == 0: + self.stdOut("Created ubuntu symbolic link to pcre") + else: + self.stdOut("Error creating symbolic link to pcre: " + str(res)) + + while(1): command = 'systemctl start lscpd' @@ -2238,18 +2406,22 @@ class preFlightsChecks: return 1 def setup_cron(self): + self.stdOut("Install and setup cron") try: ## first install crontab - file = open("installLogs.txt", 'a') + fd = open("installLogs.txt", 'a') count = 0 while(1): - command = 'yum install cronie -y' + if self.distro == centos: + command = 'yum install cronie -y' + else: + command = 'apt-get -y install cron' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = subprocess.call(cmd, stdout=fd) if res == 1: count = count + 1 @@ -2266,10 +2438,12 @@ class preFlightsChecks: count = 0 while(1): - - command = 'systemctl enable crond' + if self.distro == centos: + command = 'systemctl enable crond' + else: + command = 'systemctl enable cron' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = subprocess.call(cmd, stdout=fd) if res == 1: count = count + 1 @@ -2285,9 +2459,13 @@ class preFlightsChecks: count = 0 while(1): - command = 'systemctl start crond' + if self.distro == centos: + command = 'systemctl start crond' + else: + command = 'systemctl start cron' + cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = subprocess.call(cmd, stdout=fd) if res == 1: count = count + 1 @@ -2310,7 +2488,7 @@ class preFlightsChecks: command = 'chmod +x /usr/local/CyberCP/plogical/findBWUsage.py' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = subprocess.call(cmd, stdout=fd) if res == 1: logging.InstallLog.writeToFile("1427 [setup_cron]") @@ -2320,7 +2498,7 @@ class preFlightsChecks: command = 'chmod +x /usr/local/CyberCP/postfixSenderPolicy/client.py' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = subprocess.call(cmd, stdout=fd) if res == 1: logging.InstallLog.writeToFile("1428 [setup_cron]") @@ -2330,9 +2508,13 @@ class preFlightsChecks: count = 0 while(1): - command = 'systemctl restart crond.service' + if self.distro == centos: + command = 'systemctl restart crond.service' + else: + command = 'systemctl restart cron.service' + cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = subprocess.call(cmd, stdout=fd) if res == 1: count = count + 1 @@ -2345,8 +2527,7 @@ class preFlightsChecks: preFlightsChecks.stdOut("Crond successfully restarted!") break - file.close() - + fd.close() except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [setup_cron]") @@ -2358,6 +2539,7 @@ class preFlightsChecks: return 1 def install_default_keys(self): + self.stdOut("Installing default certificates") try: count = 0 @@ -2393,11 +2575,15 @@ class preFlightsChecks: return 1 def install_rsync(self): + self.stdOut("Installing rsync") try: count = 0 while (1): + if self.distro == centos: + command = 'yum -y install rsync' + else: + command = 'apt-get -y install rsync' - command = 'yum -y install rsync' cmd = shlex.split(command) res = subprocess.call(cmd) @@ -2423,6 +2609,7 @@ class preFlightsChecks: return 1 def test_Requests(self): + self.stdOut("Testing Requests...") try: import requests getVersion = requests.get('https://cyberpanel.net/version.txt') @@ -2488,7 +2675,8 @@ class preFlightsChecks: print(" Visit: https://" + self.ipAddr + ":8090 ") print(" Username: admin ") print(" Password: 1234567 ") - + print(" Database password in /etc/cyberpanel/mysqlPassword ") + print(" ") print("###################################################################") def installCertBot(self): @@ -2609,8 +2797,11 @@ class preFlightsChecks: try: count = 0 while (1): + if self.distro == centos: + command = 'yum -y install opendkim' + else: + command = 'apt-get -y install opendkim' - command = 'yum -y install opendkim' cmd = shlex.split(command) res = subprocess.call(cmd) @@ -2746,45 +2937,104 @@ milter_default_action = accept def setupPHPAndComposer(self): try: + if self.distro == ubuntu: + if not os.access('/usr/local/lsws/lsphp70/bin/php', os.R_OK): + if os.access('/usr/local/lsws/lsphp70/bin/php7.0', os.R_OK): + os.symlink('/usr/local/lsws/lsphp70/bin/php7.0', '/usr/local/lsws/lsphp70/bin/php') + if not os.access('/usr/local/lsws/lsphp71/bin/php', os.R_OK): + if os.access('/usr/local/lsws/lsphp71/bin/php7.1', os.R_OK): + os.symlink('/usr/local/lsws/lsphp71/bin/php7.1', '/usr/local/lsws/lsphp71/bin/php') + if not os.access('/usr/local/lsws/lsphp72/bin/php', os.R_OK): + if os.access('/usr/local/lsws/lsphp72/bin/php7.2', os.R_OK): + os.symlink('/usr/local/lsws/lsphp72/bin/php7.2', '/usr/local/lsws/lsphp72/bin/php') + command = "cp /usr/local/lsws/lsphp71/bin/php /usr/bin/" res = subprocess.call(shlex.split(command)) os.chdir(self.cwd) - command = "chmod +x composer.sh" + if self.distro == centos: + command = "chmod +x composer.sh" + else: + command = "chmod +x composer-no-test.sh" + res = subprocess.call(shlex.split(command)) - command = "./composer.sh" + if self.distro == centos: + command = "./composer.sh" + else: + command = "./composer-no-test.sh" + res = subprocess.call(shlex.split(command)) except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [setupPHPAndComposer]") + self.stdOut('Setup PHP error: ' + str(msg) + " [setupPHPAndComposer]", 1, 1, os.EX_OSERR) return 0 @staticmethod - def setupVirtualEnv(): + def installOne(package): + res = subprocess.call(shlex.split('apt-get -y install ' + package)) + if res != 0: + preFlightsChecks.stdOut("Error #" + str(res) + ' installing:' + package + '. This may not be an issue ' \ + 'but may affect installation of something later', 1) + return res #Though probably not used + + + @staticmethod + def setupVirtualEnv(distro): try: ## count = 0 - while (1): - command = "yum install -y libattr-devel xz-devel gpgme-devel mariadb-devel curl-devel" - res = subprocess.call(shlex.split(command)) + if distro == ubuntu: + # You can't install all at once! So install one at a time. + preFlightsChecks.stdOut("Installing python prerequisites", 1) + preFlightsChecks.installOne('libcurl4-gnutls-dev') + preFlightsChecks.installOne('libgnutls-dev') + preFlightsChecks.installOne('libgcrypt20-dev') + preFlightsChecks.installOne('libattr1') + preFlightsChecks.installOne('libattr1-dev') + preFlightsChecks.installOne('liblzma-dev') + preFlightsChecks.installOne('libgpgme-dev') + preFlightsChecks.installOne('libmariadbclient-dev') + preFlightsChecks.installOne('libcurl4-gnutls-dev') + preFlightsChecks.installOne('libssl-dev') + preFlightsChecks.installOne('nghttp2') + preFlightsChecks.installOne('libnghttp2-dev') + preFlightsChecks.installOne('idn2') + preFlightsChecks.installOne('libidn2-dev') + preFlightsChecks.installOne('libidn2-0-dev') + preFlightsChecks.installOne('librtmp-dev') + preFlightsChecks.installOne('libpsl-dev') + preFlightsChecks.installOne('nettle-dev') + preFlightsChecks.installOne('libgnutls28-dev') + preFlightsChecks.installOne('libldap2-dev') + preFlightsChecks.installOne('libgssapi-krb5-2') + preFlightsChecks.installOne('libk5crypto3') + preFlightsChecks.installOne('libkrb5-dev') + preFlightsChecks.installOne('libcomerr2') + preFlightsChecks.installOne('libldap2-dev') + preFlightsChecks.installOne('python-gpg') + preFlightsChecks.installOne('python-gpgme') + else: + while (1): + command = "yum install -y libattr-devel xz-devel gpgme-devel mariadb-devel curl-devel" + res = subprocess.call(shlex.split(command)) - if res == 1: - count = count + 1 - preFlightsChecks.stdOut( - "Trying to install project dependant modules, trying again, try number: " + str(count)) - if count == 3: - logging.InstallLog.writeToFile( - "Failed to install project dependant modules! [setupVirtualEnv]") - preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("Project dependant modules installed successfully!") - preFlightsChecks.stdOut("Project dependant modules installed successfully!!") - break + if res == 1: + count = count + 1 + preFlightsChecks.stdOut( + "Trying to install project dependant modules, trying again, try number: " + str(count)) + if count == 3: + logging.InstallLog.writeToFile( + "Failed to install project dependant modules! [setupVirtualEnv]") + preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") + os._exit(0) + else: + logging.InstallLog.writeToFile("Project dependant modules installed successfully!") + preFlightsChecks.stdOut("Project dependant modules installed successfully!!") + break ## @@ -2825,8 +3075,8 @@ milter_default_action = accept preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") os._exit(0) else: - logging.InstallLog.writeToFile("virtualenv setuped successfully!") - preFlightsChecks.stdOut("virtualenv setuped successfully!") + logging.InstallLog.writeToFile("virtualenv setup successfully!") + preFlightsChecks.stdOut("virtualenv setup successfully!") break ## @@ -2838,22 +3088,36 @@ milter_default_action = accept ## + install_file = '/usr/local/CyberCP/requirments.txt' + if distro == ubuntu and get_Ubuntu_release() < 18.04: + install_file_new = '/usr/local/CyberCP/requirements.txt' + fd = open(install_file,'r') + fd_new = open(install_file_new,'w') + lines = fd.readlines() + for line in lines: + if line[:6] != 'pycurl' and line[:7] != 'pygpgme': + fd_new.write(line) + fd.close() + fd_new.close() + preFlightsChecks.stdOut("Install updated " + install_file_new, 1) + install_file = install_file_new + count = 0 while (1): - command = "pip install --ignore-installed -r /usr/local/CyberCP/requirments.txt" + command = "pip install --ignore-installed -r " + install_file res = subprocess.call(shlex.split(command)) if res == 1: count = count + 1 preFlightsChecks.stdOut( - "Trying to install project dependant modules, trying again, try number: " + str(count)) + "Trying to install Python project dependant modules, trying again, try number: " + str(count)) if count == 3: logging.InstallLog.writeToFile( - "Failed to install project dependant modules! [setupVirtualEnv]") + "Failed to install Python project dependant modules! [setupVirtualEnv]") break else: - logging.InstallLog.writeToFile("Project dependant modules installed successfully!") - preFlightsChecks.stdOut("Project dependant modules installed successfully!!") + logging.InstallLog.writeToFile("Python project dependant modules installed successfully!") + preFlightsChecks.stdOut("Python project dependant modules installed successfully!!") break command = "systemctl restart gunicorn.socket" @@ -2891,7 +3155,7 @@ milter_default_action = accept writeToFile.close() except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [enableDisableDNS]") + preFlightsChecks.stdOut('Error disabling DNS: ' + str(msg) + " [enableDisableDNS]", 1, 0) return 0 @staticmethod @@ -2917,7 +3181,7 @@ milter_default_action = accept writeToFile.close() except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]") + preFlightsChecks.stdOut('Error disabling Email: ' + str(msg) + " [enableDisableEmail]", 1, 0) return 0 @staticmethod @@ -2943,11 +3207,56 @@ milter_default_action = accept writeToFile.close() except OSError, msg: - logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]") + preFlightsChecks.stdOut('Error disabling FTP: ' + str(msg) + " [enableDisableFTP]", 1, 0) return 0 +def get_distro(): + distro = -1 + distro_file = "" + if exists("/etc/lsb-release"): + distro_file = "/etc/lsb-release" + with open(distro_file) as f: + for line in f: + if line == "DISTRIB_ID=Ubuntu\n": + distro = ubuntu + elif exists("/etc/os-release"): + distro_file = "/etc/os-release" + distro = centos + + else: + logging.InstallLog.writeToFile("Can't find linux release file - fatal error") + preFlightsChecks.stdOut("Can't find linux release file - fatal error") + os._exit(os.EX_UNAVAILABLE) + + if distro == -1: + logging.InstallLog.writeToFile("Can't find distro name in " + distro_file + " - fatal error") + preFlightsChecks.stdOut("Can't find distro name in " + distro_file + " - fatal error") + os._exit(os.EX_UNAVAILABLE) + + return distro + + +def get_Ubuntu_release(): + release = -1 + if exists("/etc/lsb-release"): + distro_file = "/etc/lsb-release" + with open(distro_file) as f: + for line in f: + if line[:16] == "DISTRIB_RELEASE=": + release = float(line[16:]) + + if release == -1: + preFlightsChecks.stdOut("Can't find distro release name in " + distro_file + " - fatal error", 1, 1, + os.EX_UNAVAILABLE) + + else: + logging.InstallLog.writeToFile("Can't find linux release file - fatal error") + preFlightsChecks.stdOut("Can't find linux release file - fatal error") + os._exit(os.EX_UNAVAILABLE) + + return release def main(): @@ -2965,7 +3274,13 @@ def main(): ## Writing public IP - os.mkdir("/etc/cyberpanel") + try: + os.mkdir("/etc/cyberpanel") + except OSError as e: + if e.errno != errno.EEXIST: + preFlightsChecks.stdOut("Error creating /etc/cyberpanel directory: " + str(e), 1, 1, os.EX_CANTCREAT) + else: + pass machineIP = open("/etc/cyberpanel/machineIP", "w") machineIP.writelines(args.publicip) @@ -2973,25 +3288,32 @@ def main(): cwd = os.getcwd() - checks = preFlightsChecks("/usr/local/lsws/",args.publicip,"/usr/local",cwd,"/usr/local/CyberCP") + distro = get_distro() + checks = preFlightsChecks("/usr/local/lsws/", args.publicip, "/usr/local", cwd, "/usr/local/CyberCP", distro) + + if distro == ubuntu: + os.chdir("/etc/cyberpanel") if args.mysql == None: mysql = 'One' preFlightsChecks.stdOut("Single MySQL instance version will be installed.") else: mysql = args.mysql - preFlightsChecks.stdOut("Dobule MySQL instance version will be installed.") + preFlightsChecks.stdOut("Double MySQL instance version will be installed.") checks.checkPythonVersion() checks.setup_account_cyberpanel() - checks.yum_update() + if distro == centos: + checks.yum_update() checks.installCyberPanelRepo() - checks.enableEPELRepo() + if distro == centos: + checks.enableEPELRepo() checks.install_pip() checks.install_python_dev() checks.install_gcc() - checks.install_python_setup_tools() + if distro == centos: + checks.install_python_setup_tools() checks.install_django() checks.install_pexpect() checks.install_python_mysql_library() @@ -3001,21 +3323,19 @@ def main(): import installCyberPanel - installCyberPanel.Main(cwd, mysql) + installCyberPanel.Main(cwd, mysql, distro) checks.fix_selinux_issue() checks.install_psmisc() checks.install_postfix_davecot() checks.setup_email_Passwords(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql) checks.setup_postfix_davecot_config(mysql) - checks.install_unzip() checks.install_zip() checks.install_rsync() checks.downoad_and_install_raindloop() - checks.download_install_phpmyadmin() checks.installFirewalld() @@ -3039,7 +3359,7 @@ def main(): checks.configureOpenDKIM() checks.modSecPreReqs() - checks.setupVirtualEnv() + checks.setupVirtualEnv(distro) checks.setupPHPAndComposer() if args.postfix != None: @@ -3061,7 +3381,8 @@ def main(): checks.enableDisableFTP('On') logging.InstallLog.writeToFile("CyberPanel installation successfully completed!") - + checks.installation_successfull() if __name__ == "__main__": main() + diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index 82011d03a..17e3e8902 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -3,30 +3,34 @@ import subprocess import os import pexpect from mysqlUtilities import mysqlUtilities +import install import installLog as logging import shlex import randomPassword +import errno +import MySQLdb as mariadb +import re import time import sys +#distros +centos=0 +ubuntu=1 + class InstallCyberPanel: mysql_Root_password = "" mysqlPassword = "" - def __init__(self,rootPath,cwd): + def __init__(self,rootPath,cwd,distro): self.server_root_path = rootPath self.cwd = cwd + self.distro=distro @staticmethod - def stdOut(message): - print("\n\n") - print ("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n") - print("[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + message + "\n") - print ("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n") + def stdOut(message, log = 0, exit = 0, code = os.EX_OK): + install.preFlightsChecks.stdOut(message, log, exit, code) def installLiteSpeed(self): @@ -34,7 +38,10 @@ class InstallCyberPanel: count = 0 while (1): - 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) @@ -224,9 +231,14 @@ class InstallCyberPanel: while (1): - command = 'yum -y groupinstall lsphp-all' - cmd = shlex.split(command) - res = subprocess.call(cmd) + if self.distro == ubuntu: + command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install lsphp7*' + res = os.system(command) + + else: + command = 'yum -y groupinstall lsphp-all' + cmd = shlex.split(command) + res = subprocess.call(cmd) if res == 1: count = count + 1 @@ -240,42 +252,43 @@ class InstallCyberPanel: InstallCyberPanel.stdOut("LiteSpeed PHPs successfully installed!") ## only php 71 - 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 + 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 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 + ## 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 ## break for outer loop @@ -292,8 +305,14 @@ class InstallCyberPanel: def setup_mariadb_repo(self): - try: + if self.distro == ubuntu: + # Only needed if the repo is broken or we need the latest version. + #command = "apt-get -y install software-properties-common" + #command = "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8" + #command = "add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main'" + return + try: logging.InstallLog.writeToFile("Setting up MariaDB Repo..") InstallCyberPanel.stdOut("Setting up MariaDB Repo..") @@ -318,8 +337,10 @@ class InstallCyberPanel: count = 0 while (1): - - command = 'yum -y install mariadb-server' + if self.distro == ubuntu: + command = "apt-get -y install mariadb-server" + else: + command = 'yum -y install mariadb-server' cmd = shlex.split(command) res = subprocess.call(cmd) @@ -446,14 +467,19 @@ class InstallCyberPanel: while(1): - command = "systemctl enable mysql" + if self.distro == ubuntu: + command = "systemctl enable mariadb" + else: + command = "systemctl enable mysql" res = subprocess.call(shlex.split(command)) if res == 1: count = count + 1 - InstallCyberPanel.stdOut("Trying to enable MariaDB instance to start and system restart, trying again, try number: " + str(count)) + InstallCyberPanel.stdOut("Trying to enable MariaDB instance to start at 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]") + 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!") @@ -594,12 +620,42 @@ class InstallCyberPanel: return 1 + def fixMariaDB(self): + self.stdOut("Setup MariaDB so it can support Cyberpanel's needs") + + conn = mariadb.connect(user='root', passwd=self.mysql_Root_password) + cursor = conn.cursor() + cursor.execute('set global innodb_file_per_table = on;') + cursor.execute('set global innodb_file_format = Barracuda;') + cursor.execute('set global innodb_large_prefix = on;') + cursor.close() + conn.close() + + try: + fileName = '/etc/mysql/mariadb.conf.d/50-server.cnf' + data = open(fileName, 'r').readlines() + + writeDataToFile = open(fileName, 'w') + for line in data: + writeDataToFile.write(line.replace('utf8mb4','utf8')) + writeDataToFile.close() + except IOError as err: + self.stdOut("Error in setting: " + fileName + ": " + str(err), 1, 1, os.EX_OSERR) + + os.system('systemctl restart mysql') + + self.stdOut("MariaDB is now setup so it can support Cyberpanel's needs") + + def installPureFTPD(self): try: count = 0 while (1): - command = "yum install -y pure-ftpd" + if self.distro == ubuntu: + command = 'apt-get -y install pure-ftpd' + else: + command = "yum install -y pure-ftpd" res = subprocess.call(shlex.split(command)) if res == 1: @@ -713,9 +769,18 @@ class InstallCyberPanel: ############## Start pureftpd ###################### try: - + self.stdOut("Correct configuration with pure-ftpd") count = 0 + try: + os.mkdir("/etc/pure-ftpd/conf") + os.mkdir("/etc/pure-ftpd/auth") + except OSError as e: + pass + command = 'cp /etc/pure-ftpd/pure-ftpd.conf /etc/pure-ftpd/conf/pure-ftpd.conf' + res = subprocess.call(shlex.split(command)) + + self.stdOut("Start the pure-ftp service") while(1): cmd = [] @@ -729,7 +794,8 @@ class InstallCyberPanel: 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]") + 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!") @@ -762,7 +828,9 @@ class InstallCyberPanel: 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' + 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 res == 1: @@ -822,51 +890,89 @@ class InstallCyberPanel: count = 0 - while (1): - command = 'yum -y install epel-release yum-plugin-priorities' - cmd = shlex.split(command) - res = subprocess.call(cmd) + if self.distro == ubuntu: + command = 'systemctl stop systemd-resolved' + res = subprocess.call(shlex.split(command)) + if res != 0: + InstallCyberPanel.stdOut('Unable to stop systemd.resolved, prohits install of PowerDNS, error #' + + str(res), 1, 1, os.EX_OSERR) + command = 'systemctl disable systemd-resolved.service' + res = subprocess.call(shlex.split(command)) + if res != 0: + InstallCyberPanel.stdOut('Unable to disable systemd.resolved, prohits install of PowerDNS, error #' + + str(res), 1, 1, os.EX_OSERR) + try: + os.rename('/etc/resolv.conf', 'etc/resolved.conf') + except OSError as e: + if e.errno != errno.EEXIST and e.errno != errno.ENOENT: + InstallCyberPanel.stdOut("Unable to rename /etc/resolv.conf to install PowerDNS: " + + str(e), 1, 1, os.EX_OSERR) + try: + os.remove('/etc/resolv.conf') + except OSError as e1: + InstallCyberPanel.stdOut("Unable to remove existing /etc/resolv.conf to install PowerDNS: " + + str(e1), 1, 1, os.EX_OSERR) + try: + f = open('/etc/resolv.conf', 'w') + f.write('nameserver 8.8.8.8') + f.close() + except IOError as e: + InstallCyberPanel.stdOut("Unable to create /etc/resolv.conf: " + str(e) + + ". This may need to be fixed manually as 'echo \"nameserver 8.8.8.8\"> " + "/etc/resolv.conf'", 1, 1, os.EX_OSERR) - if res == 1: - 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 = 0 + if self.distro == centos: + while (1): + command = 'yum -y install epel-release yum-plugin-priorities' + cmd = shlex.split(command) + res = subprocess.call(cmd) - while(1): + if res == 1: + 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' - cmd = shlex.split(command) - res = subprocess.call(cmd) + count = 0 - if res == 1: - 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 + 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 res == 1: + 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): - command = 'yum -y install pdns pdns-backend-mysql' - cmd = shlex.split(command) - res = subprocess.call(cmd) + 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 res == 1: count = count + 1 @@ -896,7 +1002,10 @@ class InstallCyberPanel: InstallCyberPanel.stdOut("Configuring PowerDNS..") os.chdir(self.cwd) - dnsPath = "/etc/pdns/pdns.conf" + if self.distro == centos: + dnsPath = "/etc/pdns/pdns.conf" + else: + dnsPath = "/etc/powerdns/pdns.conf" if os.path.exists(dnsPath): os.remove(dnsPath) @@ -956,7 +1065,9 @@ class InstallCyberPanel: 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]") + 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: @@ -1004,7 +1115,10 @@ class InstallCyberPanel: count = 0 while(1): - command = 'yum -y install gcc gcc-c++ make autoconf glibc rcs' + 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' cmd = shlex.split(command) res = subprocess.call(cmd) @@ -1023,7 +1137,12 @@ class InstallCyberPanel: count = 0 while(1): - command = 'yum -y install pcre-devel openssl-devel expat-devel geoip-devel zlib-devel udns-devel which curl' + 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) @@ -1049,20 +1168,22 @@ class InstallCyberPanel: if res == 1: count = count + 1 - InstallCyberPanel.stdOut("Trying to configure LSCPD, trying again, try number: " + str(count)) + InstallCyberPanel.stdOut("Trying to extract LSCPD, trying again, try number: " + str(count)) if count == 3: - logging.InstallLog.writeToFile("Failed to configure LSCPD, exiting installer! [installLSCPD]") + logging.InstallLog.writeToFile("Failed to extract LSCPD, exiting installer! [installLSCPD]") InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt") os._exit(0) else: - logging.InstallLog.writeToFile("LSCPD successfully configured!") + logging.InstallLog.writeToFile("LSCPD successfully extracted!") 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' + 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) @@ -1083,13 +1204,19 @@ class InstallCyberPanel: except: pass - command = 'adduser lscpd -M -d /usr/local/lscp' + if self.distro == centos: + command = 'adduser lscpd -M -d /usr/local/lscp' + else: + command = 'useradd lscpd -M -d /usr/local/lscp' + cmd = shlex.split(command) res = subprocess.call(cmd) - command = 'groupadd lscpd' - cmd = shlex.split(command) - res = subprocess.call(cmd) + if self.distro == centos: + command = 'groupadd lscpd' + cmd = shlex.split(command) + res = subprocess.call(cmd) + # Added group in useradd for Ubuntu command = 'usermod -a -G lscpd lscpd' cmd = shlex.split(command) @@ -1115,17 +1242,25 @@ class InstallCyberPanel: -def Main(cwd, mysql): +def Main(cwd, mysql, distro): - InstallCyberPanel.mysqlPassword = randomPassword.generate_pass() InstallCyberPanel.mysql_Root_password = randomPassword.generate_pass() - - password = open("/etc/cyberpanel/mysqlPassword","w") - password.writelines(InstallCyberPanel.mysql_Root_password) + file_name = '/etc/cyberpanel/mysqlPassword' + if os.access(file_name, os.F_OK): + password = open(file_name, 'r') + InstallCyberPanel.mysql_Root_password = password.readline() + else: + password = open(file_name, "w") + password.writelines(InstallCyberPanel.mysql_Root_password) password.close() - installer = InstallCyberPanel("/usr/local/lsws/",cwd) + if distro == centos: + InstallCyberPanel.mysqlPassword = randomPassword.generate_pass() + else: + InstallCyberPanel.mysqlPassword = InstallCyberPanel.mysql_Root_password + + installer = InstallCyberPanel("/usr/local/lsws/", cwd, distro) installer.installLiteSpeed() installer.changePortTo80() @@ -1133,15 +1268,15 @@ def Main(cwd, mysql): installer.installAllPHPVersions() installer.fix_ols_configs() - installer.setup_mariadb_repo() installer.installMySQL(mysql) installer.changeMYSQLRootPassword() installer.changeMYSQLRootPasswordCyberPanel(mysql) installer.startMariaDB() + if distro == ubuntu: + installer.fixMariaDB() - mysqlUtilities.createDatabaseCyberPanel("cyberpanel","cyberpanel",InstallCyberPanel.mysqlPassword, mysql) - + mysqlUtilities.createDatabaseCyberPanel("cyberpanel", "cyberpanel", InstallCyberPanel.mysqlPassword, mysql) installer.installPureFTPD() installer.installPureFTPDConfigurations(mysql) diff --git a/install/unInstall.py b/install/unInstall.py index 5d14440c1..89294bad6 100644 --- a/install/unInstall.py +++ b/install/unInstall.py @@ -6,19 +6,41 @@ import argparse import os import shlex import socket +import install +#distros +centos=0 +ubuntu=1 +distro = install.get_distro() class unInstallCyberPanel: - def unInstallCyberPanelRepo(self): + def fixResolvConf(self): + if distro == centos: + return + + if os.access('/etc/resolv.conf', os.F_OK): + return try: - copyPath = "/etc/yum.repos.d/cyberpanel.repo" - os.remove(copyPath) + f = open('/etc/resolv.conf', 'w') + f.write('nameserver 8.8.8.8') + f.close() + except IOError as e: + print "Unable to create /etc/resolv.conf: " + str(e) + \ + ". This may need to be fixed manually as 'echo \"nameserver 8.8.8.8\"> " \ + "/etc/resolv.conf'" - except OSError,msg: - logging.InstallLog.writeToFile(str(msg)+ " [unInstallCyberPanelRepo]") + def unInstallCyberPanelRepo(self): + + if distro == centos: + try: + copyPath = "/etc/yum.repos.d/cyberpanel.repo" + os.remove(copyPath) + + except OSError,msg: + logging.InstallLog.writeToFile(str(msg)+ " [unInstallCyberPanelRepo]") def removeGunicorn(self): try: @@ -40,7 +62,10 @@ class unInstallCyberPanel: def removePostfixDovecot(self): try: - command = 'yum -y remove postfix' + if distro == centos: + command = 'yum -y remove postfix' + else: + command = 'apt-get -y remove postfix' cmd = shlex.split(command) @@ -62,7 +87,10 @@ class unInstallCyberPanel: def removeMysql(self): try: - command = 'yum -y remove mariadb mariadb-server' + if distro == centos: + command = 'yum -y remove mariadb mariadb-server' + else: + command = 'apt-get -y remove mariadb-server' cmd = shlex.split(command) @@ -84,13 +112,16 @@ class unInstallCyberPanel: def removeLiteSpeed(self): try: - command = 'yum -y remove openlitespeed' + if distro == centos: + command = 'yum -y remove openlitespeed' + else: + command = 'apt-get --purge -y remove openlitespeed' - cmd = shlex.split(command) + cmd = shlex.split(command) - res = subprocess.call(cmd) + res = subprocess.call(cmd) - shutil.rmtree("/usr/local/lsws") + shutil.rmtree("/usr/local/lsws") except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [removeLiteSpeed]") @@ -118,13 +149,16 @@ class unInstallCyberPanel: def removePureFTPD(self): try: - command = 'yum -y remove pure-ftpd' + if distro == centos: + command = 'yum -y remove pure-ftpd' + else: + command = 'apt-get -y remove pure-ftpd' - cmd = shlex.split(command) + cmd = shlex.split(command) - res = subprocess.call(cmd) + res = subprocess.call(cmd) - shutil.rmtree("/etc/pure-ftpd") + shutil.rmtree("/etc/pure-ftpd") except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [removePureFTPD]") @@ -136,14 +170,16 @@ class unInstallCyberPanel: def removePowerDNS(self): try: + if distro == centos: + command = 'yum -y remove pdns' + else: + command = 'apt-get -y remove pdns-server' - command = 'yum -y remove pdns' + cmd = shlex.split(command) - cmd = shlex.split(command) + res = subprocess.call(cmd) - res = subprocess.call(cmd) - - shutil.rmtree("/etc/pdns") + shutil.rmtree("/etc/pdns") except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [removePowerDNS]") @@ -156,13 +192,16 @@ class unInstallCyberPanel: def removePHP(self): try: - command = 'yum -y remove lsphp*' + if distro == centos: + command = 'yum -y remove lsphp*' + else: + command = 'apt-get -y remove lsphp*' - cmd = shlex.split(command) + cmd = shlex.split(command) - res = subprocess.call(cmd) + res = subprocess.call(cmd) - shutil.rmtree("/etc/pdns") + shutil.rmtree("/etc/pdns") except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [removePHP]") @@ -178,6 +217,7 @@ def Main(): remove = unInstallCyberPanel() + remove.fixResolvConf() remove.removeLiteSpeed() remove.removeMysql() remove.removePostfixDovecot()