diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 66202e555..297a2458c --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Web Hosting Control Panel that uses OpenLiteSpeed as the underlying Web Server. * PHP 8.2 (will reach end of life (EOL) on 31 Dec, 2026.) * PHP 8.1 (will reach end of life (EOL) on 31 Dec, 2025.) * PHP 8.0 (will reach end of life (EOL) on 26 Nov, 2023.) -* PHP 7.4 (Ubuntu 22.04 and up does not support php below this version.) (will reach end of life (EOL) on 28 Nov, 2022.) +* PHP 7.4 (Ubuntu 22.04 and Almalinux 9.x and up does not support php below this version.) (will reach end of life (EOL) on 28 Nov 2022.) * PHP 7.3 (will reach end of life (EOL) on 6 Dec, 2021.) * PHP 7.2 (will reach end of life (EOL) on 30 Nov, 2020.) * PHP 7.1 (Almalinux 8.x and up does not support php below this version.),(will reach end of life (EOL) on 1 Dec, 2019.) @@ -34,22 +34,22 @@ Web Hosting Control Panel that uses OpenLiteSpeed as the underlying Web Server. # Supported OS Versions * CyberPanel is supported on x86_64 based -* Ubuntu 18.04 (will reach end of life (EOL) on 31 May, 2023.) -* Ubuntu 20.04 (will reach end of life (EOL) on April, 2025.) -* Ubuntu 20.10 (will reach end of life (EOL) on 22 July, 2021.) -* Ubuntu 22.04 (will reach end of life (EOL) on Apr 2022 - Apr 2027.) -* CentOS 7 (will reach end of life (EOL) on 30 June, 2024.) -* CentOS 8 (will reach end of life (EOL) on 31 December, 2021.) -* CentOS 9 (will reach end of life (EOL) on 31 May, 2027.) -* RHEL 8 (will reach end of life (EOL) on 31 May, 2029.) -* RHEL 9 (will reach end of life (EOL) on 31 May, 2032.) -* AlmaLinux 8 (will reach end of life (EOL) on 01 May, 2024).) -* AlmaLinux 9 (will reach end of life (EOL) on 31 May, 2027.) -* RockyLinux 8 (will reach end of life (EOL) on 31 May, 2029.) -* CloudLinux 7 (will reach end of life (EOL) on 01 July, 2024.) -* CloudLinux 8 (will reach end of life (EOL) on 31 May, 2029.) -* openEuler 20.03 (will reach end of life (EOL) on April, 2022.) -* openEuler 22.03 (will reach end of life (EOL) on March, 2024.) +* RHEL 9 (will reach the end of life (EOL) on 31 May 2032) +* RHEL 8 (will reach the end of life (EOL) on 31 May 2029) +* RockyLinux 8 (will reach the end of life (EOL) on 31 May 2029) +* CloudLinux 8 (will reach the end of life (EOL) on 31 May 2029) +* Ubuntu 22.04 (will reach the end of life (EOL) on Apr 2027) +* CentOS 9 (will reach the end of life (EOL) on 31 May 2027) +* AlmaLinux 9 (will reach the end of life (EOL) on 31 May 2027) +* Ubuntu 20.04 (will reach the end of life (EOL) on Apr 2025) +* CentOS 7 (will reach the end of life (EOL) on 30 Jun 2024) +* AlmaLinux 8 (will reach the end of life (EOL) on 1 May 2024) +* CloudLinux 7 (will reach the end of life (EOL) on 1 Jul 2024) +* openEuler 22.03 (will reach the end of life (EOL) on Mar 2024) +* Ubuntu 18.04 (will reach the end of life (EOL) on 31 May 2023) +* openEuler 20.03 (will reach the end of life (EOL) on Apr 2022) +* CentOS 8 (will reach the end of life (EOL) on 31 Dec 2021) +* Ubuntu 20.10 (will reach the end of life (EOL) on 22 Jul 2021) # Installation Instructions @@ -72,4 +72,4 @@ sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgr * [Forums.](https://community.cyberpanel.net) * [Discord.](https://discord.gg/g8k8Db3) * [Facebook Group.](https://www.facebook.com/groups/cyberpanel) -* [YouTube Channel.](https://www.youtube.com/@Cyber-Panel) \ No newline at end of file +* [YouTube Channel.](https://www.youtube.com/@Cyber-Panel) diff --git a/install/filesPermsUtilities.py.bak b/install/filesPermsUtilities.py.bak deleted file mode 100644 index 07261326b..000000000 --- a/install/filesPermsUtilities.py.bak +++ /dev/null @@ -1,190 +0,0 @@ -import os -import shutil -import pathlib -import stat - - -def mkdir_p(path, exist_ok=True): - """ - Creates the directory and paths leading up to it like unix mkdir -p . - Defaults to exist_ok so if it exists were not throwing fatal errors - https://docs.python.org/3.7/library/os.html#os.makedirs - """ - if not os.path.exists(path): - print('creating directory: ' + path) - os.makedirs(path, exist_ok) - - -def chmod_digit(file_path, perms): - """ - Helper function to chmod like you would in unix without having to preface 0o or converting to octal yourself. - Credits: https://stackoverflow.com/a/60052847/1621381 - """ - try: - os.chmod(file_path, int(str(perms), base=8)) - except: - print(f'Could not chmod : {file_path} to {perms}') - pass - - -def touch(filepath: str, exist_ok=True): - """ - Touches a file like unix `touch somefile` would. - """ - try: - pathlib.Path(filepath).touch(exist_ok) - except FileExistsError: - print('Could touch : ' + filepath) - pass - - -def symlink(src, dst): - """ - Symlink a path to another if the src exists. - """ - try: - if os.access(src, os.R_OK): - os.symlink(src, dst) - except: - print(f'Could not symlink Source: {src} > Destination: {dst}') - pass - - -def chown(path, user, group=-1): - """ - Chown file/path to user/group provided. Passing -1 to user or group will leave it unchanged. - Useful if just changing user or group vs both. - """ - try: - shutil.chown(path, user, group) - except PermissionError: - print(f'Could not change permissions for: {path} to {user}:{group}') - pass - - -def recursive_chown(path, owner, group=-1): - """ - Recursively chown a path and contents to owner. - https://docs.python.org/3/library/shutil.html - """ - for dirpath, dirnames, filenames in os.walk(path): - try: - shutil.chown(dirpath, owner, group) - except PermissionError: - print('Could not change permissions for: ' + dirpath + ' to: ' + owner) - pass - for filename in filenames: - try: - shutil.chown(os.path.join(dirpath, filename), owner, group) - except PermissionError: - print('Could not change permissions for: ' + os.path.join(dirpath, filename) + ' to: ' + owner) - pass - - -def recursive_permissions(path, dir_mode=755, file_mode=644, topdir=True): - """ - Recursively chmod a path and contents to mode. - Defaults to chmod top level directory but can be optionally - toggled off when you want to chmod only contents of like a user's homedir vs homedir itself - https://docs.python.org/3.6/library/os.html#os.walk - """ - - # Here we are converting the integers to string and then to octal. - # so this function doesn't need to be called with 0o prefixed for the file and dir mode - dir_mode = int(str(dir_mode), base=8) - file_mode = int(str(file_mode), base=8) - - if topdir: - # Set chmod on top level path - try: - os.chmod(path, dir_mode) - except: - print('Could not chmod :' + path + ' to ' + str(dir_mode)) - for root, dirs, files in os.walk(path): - for d in dirs: - try: - os.chmod(os.path.join(root, d), dir_mode) - except: - print('Could not chmod :' + os.path.join(root, d) + ' to ' + str(dir_mode)) - pass - for f in files: - try: - os.chmod(os.path.join(root, f), file_mode) - except: - print('Could not chmod :' + path + ' to ' + str(file_mode)) - pass - - -# Left intentionally here for reference. -# Set recursive chown for a path -# recursive_chown(my_path, 'root', 'root') -# for changing group recursively without affecting user -# recursive_chown('/usr/local/lscp/cyberpanel/rainloop/data', -1, 'lscpd') - -# explicitly set permissions for directories/folders to 0755 and files to 0644 -# recursive_permissions(my_path, 755, 644) - -# Fix permissions and use default values -# recursive_permissions(my_path) -# ========================================================= -# Below is a helper class for getting and working with permissions -# Original credits to : https://github.com/keysemble/perfm - -def perm_octal_digit(rwx): - digit = 0 - if rwx[0] == 'r': - digit += 4 - if rwx[1] == 'w': - digit += 2 - if rwx[2] == 'x': - digit += 1 - return digit - - -class FilePerm: - def __init__(self, filepath): - filemode = stat.filemode(os.stat(filepath).st_mode) - permissions = [filemode[-9:][i:i + 3] for i in range(0, len(filemode[-9:]), 3)] - self.filepath = filepath - self.access_dict = dict(zip(['user', 'group', 'other'], [list(perm) for perm in permissions])) - - def mode(self): - mode = 0 - for shift, digit in enumerate(self.octal()[::-1]): - mode += digit << (shift * 3) - return mode - - def digits(self): - """Get the octal chmod equivalent value 755 in single string""" - return "".join(map(str, self.octal())) - - def octal(self): - """Get the octal value in a list [7, 5, 5]""" - return [perm_octal_digit(p) for p in self.access_dict.values()] - - def access_bits(self, access): - if access in self.access_dict.keys(): - r, w, x = self.access_dict[access] - return [r == 'r', w == 'w', x == 'x'] - - def update_bitwise(self, settings): - def perm_list(read=False, write=False, execute=False): - pl = ['-', '-', '-'] - if read: - pl[0] = 'r' - if write: - pl[1] = 'w' - if execute: - pl[2] = 'x' - return pl - - self.access_dict = dict( - [(access, perm_list(read=r, write=w, execute=x)) for access, [r, w, x] in settings.items()]) - os.chmod(self.filepath, self.mode()) - -# project_directory = os.path.abspath(os.path.dirname(sys.argv[0])) -# home_directory = os.path.expanduser('~') -# print(f'Path: {home_directory} Mode: {FilePerm(home_directory).mode()} Octal: {FilePerm(home_directory).octal()} ' -# f'Digits: {FilePerm(home_directory).digits()}') -# Example: Output -# Path: /home/cooluser Mode: 493 Octal: [7, 5, 5] Digits: 755 diff --git a/install/install.py.bak b/install/install.py.bak deleted file mode 100644 index 5f3f0e5fc..000000000 --- a/install/install.py.bak +++ /dev/null @@ -1,2383 +0,0 @@ -import sys -import subprocess -import shutil -import installLog as logging -import argparse -import os -import shlex -from firewallUtilities import FirewallUtilities -import time -import string -import random -import socket -from os.path import * -from stat import * -import stat - -VERSION = '2.3' -BUILD = 1 - -char_set = {'small': 'abcdefghijklmnopqrstuvwxyz', 'nums': '0123456789', 'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'} - - -def generate_pass(length=14): - chars = string.ascii_uppercase + string.ascii_lowercase + string.digits - size = length - return ''.join(random.choice(chars) for x in range(size)) - - -# There can not be peace without first a great suffering. - -# distros - -centos = 0 -ubuntu = 1 -cent8 = 2 - - -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 - - data = open('/etc/redhat-release', 'r').read() - - if data.find('CentOS Linux release 8') > -1: - return cent8 - if data.find('AlmaLinux release 8') > -1: - return cent8 - if data.find('Rocky Linux release 8') > -1 or data.find('Rocky Linux 8') > -1 or data.find('rocky:8') > -1: - return cent8 - - 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 - - -class preFlightsChecks: - debug = 1 - cyberPanelMirror = "mirror.cyberpanel.net/pip" - cdn = 'cyberpanel.sh' - - def __init__(self, rootPath, ip, path, cwd, cyberPanelPath, distro, remotemysql=None, mysqlhost=None, mysqldb=None, - mysqluser=None, mysqlpassword=None, mysqlport=None): - self.ipAddr = ip - self.path = path - self.cwd = cwd - self.server_root_path = rootPath - self.cyberPanelPath = cyberPanelPath - self.distro = distro - self.remotemysql = remotemysql - self.mysqlhost = mysqlhost - self.mysqluser = mysqluser - self.mysqlpassword = mysqlpassword - self.mysqlport = mysqlport - self.mysqldb = mysqldb - - @staticmethod - def stdOut(message, log=0, do_exit=0, code=os.EX_OK): - print("\n\n") - print(("[" + time.strftime( - "%m.%d.%Y_%H-%M-%S") + "] #########################################################################\n")) - print(("[" + time.strftime("%m.%d.%Y_%H-%M-%S") + "] " + message + "\n")) - print(("[" + time.strftime( - "%m.%d.%Y_%H-%M-%S") + "] #########################################################################\n")) - - if log: - logging.InstallLog.writeToFile(message) - if do_exit: - logging.InstallLog.writeToFile(message) - sys.exit(code) - - def mountTemp(self): - try: - ## On OpenVZ there is an issue using .tempdisk for /tmp as it breaks network on container after reboot. - - if subprocess.check_output('systemd-detect-virt').decode("utf-8").find("openvz") > -1: - - varTmp = "/var/tmp /tmp none bind 0 0\n" - - fstab = "/etc/fstab" - writeToFile = open(fstab, "a") - writeToFile.writelines(varTmp) - writeToFile.close() - - else: - - command = "dd if=/dev/zero of=/usr/.tempdisk bs=100M count=15" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - command = "mkfs.ext4 -F /usr/.tempdisk" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - command = "mkdir -p /usr/.tmpbak/" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - command = "cp -pr /tmp/* /usr/.tmpbak/" - subprocess.call(command, shell=True) - - command = "mount -o loop,rw,nodev,nosuid,noexec,nofail /usr/.tempdisk /tmp" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - command = "chmod 1777 /tmp" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - command = "cp -pr /usr/.tmpbak/* /tmp/" - subprocess.call(command, shell=True) - - command = "rm -rf /usr/.tmpbak" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - command = "mount --bind /tmp /var/tmp" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - tmp = "/usr/.tempdisk /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0\n" - varTmp = "/tmp /var/tmp none bind 0 0\n" - - fstab = "/etc/fstab" - writeToFile = open(fstab, "a") - writeToFile.writelines(tmp) - writeToFile.writelines(varTmp) - writeToFile.close() - - except BaseException as msg: - preFlightsChecks.stdOut('[ERROR] ' + str(msg)) - return 0 - - @staticmethod - def pureFTPDServiceName(distro): - if distro == ubuntu: - return 'pure-ftpd-mysql' - return 'pure-ftpd' - - @staticmethod - def resFailed(distro, res): - if distro == ubuntu and res != 0: - return True - elif distro == centos and res != 0: - return True - return False - - @staticmethod - def call(command, distro, bracket, message, log=0, do_exit=0, code=os.EX_OK): - finalMessage = 'Running: %s' % (message) - preFlightsChecks.stdOut(finalMessage, log) - count = 0 - while True: - res = subprocess.call(shlex.split(command)) - - if preFlightsChecks.resFailed(distro, res): - count = count + 1 - finalMessage = 'Running %s failed. Running again, try number %s' % (message, str(count)) - preFlightsChecks.stdOut(finalMessage) - if count == 3: - fatal_message = '' - if do_exit: - fatal_message = '. Fatal error, see /var/log/installLogs.txt for full details' - - preFlightsChecks.stdOut("[ERROR] We are not able to run " + message + ' return code: ' + str(res) + - fatal_message + ".", 1, do_exit, code) - return False - else: - preFlightsChecks.stdOut('Successfully ran: %s.' % (message), log) - break - - return True - - def checkIfSeLinuxDisabled(self): - try: - command = "sestatus" - output = subprocess.check_output(shlex.split(command)).decode("utf-8") - - 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 as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + "[checkIfSeLinuxDisabled]") - logging.InstallLog.writeToFile('[ERROR] ' + "SELinux Check OK. [checkIfSeLinuxDisabled]") - preFlightsChecks.stdOut('[ERROR] ' + "SELinux Check OK.") - return 1 - - def checkPythonVersion(self): - if sys.version_info[0] == 3: - return 1 - else: - preFlightsChecks.stdOut("You are running Unsupported python version, please install python 3.x") - os._exit(0) - - def setup_account_cyberpanel(self): - try: - - if self.distro == centos or self.distro == cent8: - command = "yum install sudo -y" - preFlightsChecks.call(command, self.distro, command, - command, - 1, 0, os.EX_OSERR) - - ## - - if self.distro == ubuntu: - self.stdOut("Add Cyberpanel user") - command = 'adduser --disabled-login --gecos "" cyberpanel' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - else: - command = "useradd -s /bin/false cyberpanel" - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - ############################### - - ### Docker User/group - - if self.distro == ubuntu: - command = 'adduser --disabled-login --gecos "" docker' - else: - command = "adduser docker" - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'groupadd docker' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'usermod -aG docker docker' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'usermod -aG docker cyberpanel' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ### - - command = "mkdir -p /etc/letsencrypt/live/" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except BaseException as msg: - logging.InstallLog.writeToFile("[ERROR] setup_account_cyberpanel. " + str(msg)) - - def installCyberPanelRepo(self): - self.stdOut("Install Cyberpanel repo") - - if self.distro == ubuntu: - try: - filename = "enable_lst_debain_repo.sh" - command = "wget http://rpms.litespeedtech.com/debian/" + filename - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - os.chmod(filename, S_IRWXU | S_IRWXG) - - command = "./" + filename - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - except: - logging.InstallLog.writeToFile("[ERROR] Exception during CyberPanel install") - preFlightsChecks.stdOut("[ERROR] Exception during CyberPanel install") - os._exit(os.EX_SOFTWARE) - - elif self.distro == centos: - command = 'rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.2-1.el7.noarch.rpm' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - elif self.distro == cent8: - command = 'rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el8.noarch.rpm' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - def fix_selinux_issue(self): - try: - cmd = [] - - cmd.append("setsebool") - cmd.append("-P") - cmd.append("httpd_can_network_connect") - cmd.append("1") - - res = subprocess.call(cmd) - - if preFlightsChecks.resFailed(self.distro, res): - logging.InstallLog.writeToFile("fix_selinux_issue problem") - else: - pass - except: - logging.InstallLog.writeToFile("[ERROR] fix_selinux_issue problem") - - def install_psmisc(self): - self.stdOut("Install psmisc") - - if self.distro == centos or self.distro == cent8: - command = "yum -y install psmisc" - else: - command = "apt-get -y install psmisc" - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - def download_install_CyberPanel(self, mysqlPassword, mysql): - ## - - os.chdir(self.path) - - os.chdir('/usr/local') - - command = "git clone https://github.com/usmannasir/cyberpanel" - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - shutil.move('cyberpanel', 'CyberCP') - - ## - - ### update password: - - if self.remotemysql == 'OFF': - passFile = "/etc/cyberpanel/mysqlPassword" - - f = open(passFile) - data = f.read() - password = data.split('\n', 1)[0] - else: - password = self.mysqlpassword - - ### Put correct mysql passwords in settings file! - - # This allows root/sudo users to be able to work with MySQL/MariaDB without hunting down the password like - # all the other control panels allow - # reference: https://oracle-base.com/articles/mysql/mysql-password-less-logins-using-option-files - mysql_my_root_cnf = '/root/.my.cnf' - mysql_root_cnf_content = """ -[client] -user=root -password="%s" -""" % password - - with open(mysql_my_root_cnf, 'w') as f: - f.write(mysql_root_cnf_content) - os.chmod(mysql_my_root_cnf, 0o600) - command = 'chown root:root %s' % mysql_my_root_cnf - subprocess.call(shlex.split(command)) - - logging.InstallLog.writeToFile("Updating /root/.my.cnf!") - - logging.InstallLog.writeToFile("Updating settings.py!") - - path = self.cyberPanelPath + "/CyberCP/settings.py" - - data = open(path, "r").readlines() - - writeDataToFile = open(path, "w") - - counter = 0 - - for items in data: - if items.find('SECRET_KEY') > -1: - SK = "SECRET_KEY = '%s'\n" % (generate_pass(50)) - writeDataToFile.writelines(SK) - continue - - if mysql == 'Two': - if items.find("'PASSWORD':") > -1: - if counter == 0: - writeDataToFile.writelines(" 'PASSWORD': '" + mysqlPassword + "'," + "\n") - counter = counter + 1 - else: - writeDataToFile.writelines(" 'PASSWORD': '" + password + "'," + "\n") - - else: - writeDataToFile.writelines(items) - else: - if items.find("'PASSWORD':") > -1: - if counter == 0: - writeDataToFile.writelines(" 'PASSWORD': '" + mysqlPassword + "'," + "\n") - counter = counter + 1 - else: - writeDataToFile.writelines(" 'PASSWORD': '" + password + "'," + "\n") - elif items.find('127.0.0.1') > -1: - writeDataToFile.writelines(" 'HOST': 'localhost',\n") - elif items.find("'PORT':'3307'") > -1: - writeDataToFile.writelines(" 'PORT': '',\n") - else: - writeDataToFile.writelines(items) - - if self.distro == ubuntu: - os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR) - - writeDataToFile.close() - - if self.remotemysql == 'ON': - command = "sed -i 's|localhost|%s|g' %s" % (self.mysqlhost, path) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - # command = "sed -i 's|'mysql'|'%s'|g' %s" % (self.mysqldb, path) - # preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = "sed -i 's|root|%s|g' %s" % (self.mysqluser, path) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = "sed -i \"s|'PORT': ''|'PORT':'%s'|g\" %s" % (self.mysqlport, path) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - logging.InstallLog.writeToFile("settings.py updated!") - - # self.setupVirtualEnv(self.distro) - - ### Applying migrations - - os.chdir("/usr/local/CyberCP") - - command = "/usr/local/CyberPanel/bin/python manage.py makemigrations" - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - ## - - command = "/usr/local/CyberPanel/bin/python manage.py migrate" - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - if not os.path.exists("/usr/local/CyberCP/public"): - os.mkdir("/usr/local/CyberCP/public") - - ## Moving static content to lscpd location - command = 'mv static /usr/local/CyberCP/public/' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - try: - path = "/usr/local/CyberCP/version.txt" - writeToFile = open(path, 'w') - writeToFile.writelines('%s\n' % (VERSION)) - writeToFile.writelines(str(BUILD)) - writeToFile.close() - except: - pass - - def fixCyberPanelPermissions(self): - - ###### fix Core CyberPanel permissions - - command = "usermod -G lscpd,lsadm,nobody lscpd" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "usermod -G lscpd,lsadm,nogroup lscpd" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "find /usr/local/CyberCP -type d -exec chmod 0755 {} \;" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "find /usr/local/CyberCP -type f -exec chmod 0644 {} \;" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod -R 755 /usr/local/CyberCP/bin" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## change owner - - command = "chown -R root:root /usr/local/CyberCP" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ########### Fix LSCPD - - command = "find /usr/local/lscp -type d -exec chmod 0755 {} \;" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "find /usr/local/lscp -type f -exec chmod 0644 {} \;" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod -R 755 /usr/local/lscp/bin" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod -R 755 /usr/local/lscp/fcgi-bin" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin/tmp" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## change owner - - command = "chown -R root:root /usr/local/lscp" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod 700 /usr/local/CyberCP/cli/cyberPanel.py" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod 700 /usr/local/CyberCP/plogical/upgradeCritical.py" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod 755 /usr/local/CyberCP/postfixSenderPolicy/client.py" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod 640 /usr/local/CyberCP/CyberCP/settings.py" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chown root:cyberpanel /usr/local/CyberCP/CyberCP/settings.py" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - files = ['/etc/yum.repos.d/MariaDB.repo', '/etc/pdns/pdns.conf', '/etc/systemd/system/lscpd.service', - '/etc/pure-ftpd/pure-ftpd.conf', '/etc/pure-ftpd/pureftpd-pgsql.conf', - '/etc/pure-ftpd/pureftpd-mysql.conf', '/etc/pure-ftpd/pureftpd-ldap.conf', - '/etc/dovecot/dovecot.conf', '/usr/local/lsws/conf/httpd_config.xml', - '/usr/local/lsws/conf/modsec.conf', '/usr/local/lsws/conf/httpd.conf'] - - for items in files: - command = 'chmod 644 %s' % (items) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - impFile = ['/etc/pure-ftpd/pure-ftpd.conf', '/etc/pure-ftpd/pureftpd-pgsql.conf', - '/etc/pure-ftpd/pureftpd-mysql.conf', '/etc/pure-ftpd/pureftpd-ldap.conf', - '/etc/dovecot/dovecot.conf', '/etc/pdns/pdns.conf', '/etc/pure-ftpd/db/mysql.conf', - '/etc/powerdns/pdns.conf'] - - for items in impFile: - command = 'chmod 600 %s' % (items) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'chmod 640 /etc/postfix/*.cf' - subprocess.call(command, shell=True) - - command = 'chmod 644 /etc/postfix/main.cf' - subprocess.call(command, shell=True) - - command = 'chmod 640 /etc/dovecot/*.conf' - subprocess.call(command, shell=True) - - command = 'chmod 644 /etc/dovecot/dovecot.conf' - subprocess.call(command, shell=True) - - command = 'chmod 640 /etc/dovecot/dovecot-sql.conf.ext' - subprocess.call(command, shell=True) - - command = 'chmod 644 /etc/postfix/dynamicmaps.cf' - subprocess.call(command, shell=True) - - fileM = ['/usr/local/lsws/FileManager/', '/usr/local/CyberCP/install/FileManager', - '/usr/local/CyberCP/serverStatus/litespeed/FileManager', '/usr/local/lsws/Example/html/FileManager'] - - for items in fileM: - try: - shutil.rmtree(items) - except: - pass - - command = 'chmod 755 /etc/pure-ftpd/' - subprocess.call(command, shell=True) - - command = 'chmod +x /usr/local/CyberCP/plogical/renew.py' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'chmod +x /usr/local/CyberCP/CLManager/CLPackages.py' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - clScripts = ['/usr/local/CyberCP/CLScript/panel_info.py', '/usr/local/CyberCP/CLScript/CloudLinuxPackages.py', - '/usr/local/CyberCP/CLScript/CloudLinuxUsers.py', - '/usr/local/CyberCP/CLScript/CloudLinuxDomains.py', - '/usr/local/CyberCP/CLScript/CloudLinuxResellers.py', '/usr/local/CyberCP/CLScript/CloudLinuxAdmins.py', - '/usr/local/CyberCP/CLScript/CloudLinuxDB.py', '/usr/local/CyberCP/CLScript/UserInfo.py'] - - for items in clScripts: - command = 'chmod +x %s' % (items) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'chmod 600 /usr/local/CyberCP/plogical/adminPass.py' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'chmod 600 /etc/cagefs/exclude/cyberpanelexclude' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "find /usr/local/CyberCP/ -name '*.pyc' -delete" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.distro == cent8 or self.distro == centos: - command = 'chown root:pdns /etc/pdns/pdns.conf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'chmod 640 /etc/pdns/pdns.conf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'chmod 640 /usr/local/lscp/cyberpanel/logs/access.log' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'mkdir -p/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/configs/' - - rainloopinipath = '/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/configs/application.ini' - - command = 'chmod 600 /usr/local/CyberCP/public/rainloop.php' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ### - - WriteToFile = open('/etc/fstab', 'a') - WriteToFile.write('proc /proc proc defaults,hidepid=2 0 0\n') - WriteToFile.close() - - command = 'mount -o remount,rw,hidepid=2 /proc' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## symlink protection - - writeToFile = open('/usr/lib/sysctl.d/50-default.conf', 'a') - writeToFile.writelines('fs.protected_hardlinks = 1\n') - writeToFile.writelines('fs.protected_symlinks = 1\n') - writeToFile.close() - - command = 'sysctl --system' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'chmod 700 %s' % ('/home/cyberpanel') - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - destPrivKey = "/usr/local/lscp/conf/key.pem" - - command = 'chmod 600 %s' % (destPrivKey) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ### - - def install_unzip(self): - self.stdOut("Install unzip") - try: - if self.distro == centos or self.distro == cent8: - command = 'yum -y install unzip' - else: - command = 'apt-get -y install unzip' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_unzip]") - - def install_zip(self): - self.stdOut("Install zip") - try: - if self.distro == centos or self.distro == cent8: - command = 'yum -y install zip' - else: - command = 'apt-get -y install zip' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_zip]") - - def download_install_phpmyadmin(self): - try: - - if not os.path.exists("/usr/local/CyberCP/public"): - os.mkdir("/usr/local/CyberCP/public") - - command = 'wget -O /usr/local/CyberCP/public/phpmyadmin.zip https://github.com/usmannasir/cyberpanel/raw/stable/phpmyadmin.zip' - - preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]', - command, 1, 0, os.EX_OSERR) - - command = 'unzip /usr/local/CyberCP/public/phpmyadmin.zip -d /usr/local/CyberCP/public/' - preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]', - command, 1, 0, os.EX_OSERR) - - command = 'mv /usr/local/CyberCP/public/phpMyAdmin-*-all-languages /usr/local/CyberCP/public/phpmyadmin' - subprocess.call(command, shell=True) - - command = 'rm -f /usr/local/CyberCP/public/phpmyadmin.zip' - preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]', - command, 1, 0, os.EX_OSERR) - - ## Write secret phrase - - rString = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)]) - - data = open('/usr/local/CyberCP/public/phpmyadmin/config.sample.inc.php', 'r').readlines() - - writeToFile = open('/usr/local/CyberCP/public/phpmyadmin/config.inc.php', 'w') - - writeE = 1 - - phpMyAdminContent = """ -$cfg['Servers'][$i]['AllowNoPassword'] = false; -$cfg['Servers'][$i]['auth_type'] = 'signon'; -$cfg['Servers'][$i]['SignonSession'] = 'SignonSession'; -$cfg['Servers'][$i]['SignonURL'] = 'phpmyadminsignin.php'; -$cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout'; -""" - - for items in data: - if items.find('blowfish_secret') > -1: - writeToFile.writelines( - "$cfg['blowfish_secret'] = '" + rString + "'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */\n") - elif items.find('/* Authentication type */') > -1: - writeToFile.writelines(items) - writeToFile.write(phpMyAdminContent) - writeE = 0 - elif items.find("$cfg['Servers'][$i]['AllowNoPassword']") > -1: - writeE = 1 - else: - if writeE: - writeToFile.writelines(items) - - writeToFile.writelines("$cfg['TempDir'] = '/usr/local/CyberCP/public/phpmyadmin/tmp';\n") - - writeToFile.close() - - os.mkdir('/usr/local/CyberCP/public/phpmyadmin/tmp') - - command = 'chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin' - preFlightsChecks.call(command, self.distro, '[chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin]', - 'chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin', 1, 0, os.EX_OSERR) - - if self.remotemysql == 'ON': - command = "sed -i 's|'localhost'|'%s'|g' %s" % ( - self.mysqlhost, '/usr/local/CyberCP/public/phpmyadmin/config.inc.php') - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'cp /usr/local/CyberCP/plogical/phpmyadminsignin.php /usr/local/CyberCP/public/phpmyadmin/phpmyadminsignin.php' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.remotemysql == 'ON': - command = "sed -i 's|localhost|%s|g' /usr/local/CyberCP/public/phpmyadmin/phpmyadminsignin.php" % ( - self.mysqlhost) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [download_install_phpmyadmin]") - return 0 - - ###################################################### Email setup - - def install_postfix_dovecot(self): - self.stdOut("Install dovecot - first remove postfix") - - try: - if self.distro == centos: - command = 'yum remove postfix -y' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - elif self.distro == ubuntu: - command = 'apt-get -y remove postfix' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - self.stdOut("Install dovecot - do the install") - - if self.distro == centos: - command = 'yum install --enablerepo=gf-plus -y postfix3 postfix3-ldap postfix3-mysql postfix3-pcre' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - elif self.distro == cent8: - - command = 'dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el8.noarch.rpm' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'dnf install --enablerepo=gf-plus postfix3 postfix3-mysql -y' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - else: - command = 'apt-get -y install debconf-utils' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - 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 - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'apt-get -y install postfix postfix-mysql' - # os.remove(file_name) - - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - ## - - if self.distro == centos: - command = 'yum --enablerepo=gf-plus -y install dovecot23 dovecot23-mysql' - elif self.distro == cent8: - command = 'dnf install --enablerepo=gf-plus dovecot23 dovecot23-mysql -y' - else: - command = 'apt-get -y install dovecot-mysql dovecot-imapd dovecot-pop3d' - - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_postfix_dovecot]") - return 0 - - return 1 - - def setup_email_Passwords(self, mysqlPassword, mysql): - try: - - logging.InstallLog.writeToFile("Setting up authentication for Postfix and Dovecot...") - - os.chdir(self.cwd) - - mysql_virtual_domains = "email-configs-one/mysql-virtual_domains.cf" - mysql_virtual_forwardings = "email-configs-one/mysql-virtual_forwardings.cf" - mysql_virtual_mailboxes = "email-configs-one/mysql-virtual_mailboxes.cf" - mysql_virtual_email2email = "email-configs-one/mysql-virtual_email2email.cf" - dovecotmysql = "email-configs-one/dovecot-sql.conf.ext" - - ### update password: - - data = open(dovecotmysql, "r").readlines() - - writeDataToFile = open(dovecotmysql, "w") - - if mysql == 'Two': - dataWritten = "connect = host=127.0.0.1 dbname=cyberpanel user=cyberpanel password=" + mysqlPassword + " port=3307\n" - else: - dataWritten = "connect = host=localhost dbname=cyberpanel user=cyberpanel password=" + mysqlPassword + " port=3306\n" - - for items in data: - if items.find("connect") > -1: - writeDataToFile.writelines(dataWritten) - else: - writeDataToFile.writelines(items) - - writeDataToFile.close() - - ### update password: - - data = open(mysql_virtual_domains, "r").readlines() - - writeDataToFile = open(mysql_virtual_domains, "w") - - dataWritten = "password = " + mysqlPassword + "\n" - - for items in data: - if items.find("password") > -1: - writeDataToFile.writelines(dataWritten) - else: - writeDataToFile.writelines(items) - - writeDataToFile.close() - - ### update password: - - data = open(mysql_virtual_forwardings, "r").readlines() - - writeDataToFile = open(mysql_virtual_forwardings, "w") - - dataWritten = "password = " + mysqlPassword + "\n" - - for items in data: - if items.find("password") > -1: - writeDataToFile.writelines(dataWritten) - else: - writeDataToFile.writelines(items) - - writeDataToFile.close() - - ### update password: - - data = open(mysql_virtual_mailboxes, "r").readlines() - - writeDataToFile = open(mysql_virtual_mailboxes, "w") - - dataWritten = "password = " + mysqlPassword + "\n" - - for items in data: - if items.find("password") > -1: - writeDataToFile.writelines(dataWritten) - else: - writeDataToFile.writelines(items) - - writeDataToFile.close() - - ### update password: - - data = open(mysql_virtual_email2email, "r").readlines() - - writeDataToFile = open(mysql_virtual_email2email, "w") - - dataWritten = "password = " + mysqlPassword + "\n" - - for items in data: - if items.find("password") > -1: - writeDataToFile.writelines(dataWritten) - else: - writeDataToFile.writelines(items) - - writeDataToFile.close() - - if self.remotemysql == 'ON': - command = "sed -i 's|host=localhost|host=%s|g' %s" % (self.mysqlhost, dovecotmysql) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = "sed -i 's|port=3306|port=%s|g' %s" % (self.mysqlport, dovecotmysql) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - ## - - command = "sed -i 's|localhost|%s:%s|g' %s" % (self.mysqlhost, self.mysqlport, mysql_virtual_domains) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = "sed -i 's|localhost|%s:%s|g' %s" % ( - self.mysqlhost, self.mysqlport, mysql_virtual_forwardings) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = "sed -i 's|localhost|%s:%s|g' %s" % ( - self.mysqlhost, self.mysqlport, mysql_virtual_mailboxes) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = "sed -i 's|localhost|%s:%s|g' %s" % ( - self.mysqlhost, self.mysqlport, mysql_virtual_email2email) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - logging.InstallLog.writeToFile("Authentication for Postfix and Dovecot set.") - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR]' + str(msg) + " [setup_email_Passwords]") - return 0 - - return 1 - - def centos_lib_dir_to_ubuntu(self, filename, old, new): - try: - fd = open(filename, 'r') - lines = fd.readlines() - fd.close() - fd = open(filename, 'w') - centos_prefix = old - ubuntu_prefix = new - for line in lines: - index = line.find(centos_prefix) - if index != -1: - line = line[:index] + ubuntu_prefix + line[index + len(centos_prefix):] - fd.write(line) - fd.close() - except IOError as err: - self.stdOut( - "[ERROR] Error converting: " + filename + " from centos defaults to ubuntu defaults: " + str(err), 1, - 1, os.EX_OSERR) - - def setup_postfix_dovecot_config(self, mysql): - 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" - mysql_virtual_email2email = "/etc/postfix/mysql-virtual_email2email.cf" - main = "/etc/postfix/main.cf" - master = "/etc/postfix/master.cf" - dovecot = "/etc/dovecot/dovecot.conf" - dovecotmysql = "/etc/dovecot/dovecot-sql.conf.ext" - - if os.path.exists(mysql_virtual_domains): - os.remove(mysql_virtual_domains) - - if os.path.exists(mysql_virtual_forwardings): - os.remove(mysql_virtual_forwardings) - - if os.path.exists(mysql_virtual_mailboxes): - os.remove(mysql_virtual_mailboxes) - - if os.path.exists(mysql_virtual_email2email): - os.remove(mysql_virtual_email2email) - - if os.path.exists(main): - os.remove(main) - - if os.path.exists(master): - os.remove(master) - - if os.path.exists(dovecot): - os.remove(dovecot) - - if os.path.exists(dovecotmysql): - os.remove(dovecotmysql) - - ###############Getting SSL - - command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/postfix/key.pem -out /etc/postfix/cert.pem' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/dovecot/key.pem -out /etc/dovecot/cert.pem' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - # Cleanup config files for ubuntu - if self.distro == ubuntu: - preFlightsChecks.stdOut("Cleanup postfix/dovecot config files", 1) - - self.centos_lib_dir_to_ubuntu("email-configs-one/master.cf", "/usr/libexec/", "/usr/lib/") - self.centos_lib_dir_to_ubuntu("email-configs-one/main.cf", "/usr/libexec/postfix", - "/usr/lib/postfix/sbin") - - ########### Copy config files - - shutil.copy("email-configs-one/mysql-virtual_domains.cf", "/etc/postfix/mysql-virtual_domains.cf") - shutil.copy("email-configs-one/mysql-virtual_forwardings.cf", - "/etc/postfix/mysql-virtual_forwardings.cf") - shutil.copy("email-configs-one/mysql-virtual_mailboxes.cf", "/etc/postfix/mysql-virtual_mailboxes.cf") - shutil.copy("email-configs-one/mysql-virtual_email2email.cf", - "/etc/postfix/mysql-virtual_email2email.cf") - shutil.copy("email-configs-one/main.cf", main) - shutil.copy("email-configs-one/master.cf", master) - shutil.copy("email-configs-one/dovecot.conf", dovecot) - shutil.copy("email-configs-one/dovecot-sql.conf.ext", dovecotmysql) - - ########### Set custom settings - - # We are going to leverage postconfig -e to edit the settings for hostname - command = "postconf -e 'myhostname = %s'" % (str(socket.getfqdn())) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - # We are explicitly going to use sed to set the hostname default from "myhostname = server.example.com" - # to the fqdn from socket if the default is still found - command = "sed -i 's|server.example.com|%s|g' %s" % (str(socket.getfqdn()), main) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ######################################## Permissions - - command = 'chmod o= /etc/postfix/mysql-virtual_domains.cf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chmod o= /etc/postfix/mysql-virtual_forwardings.cf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chmod o= /etc/postfix/mysql-virtual_mailboxes.cf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chmod o= /etc/postfix/mysql-virtual_email2email.cf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chmod o= ' + main - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chmod o= ' + master - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ####################################### - - command = 'chgrp postfix /etc/postfix/mysql-virtual_domains.cf' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chgrp postfix /etc/postfix/mysql-virtual_forwardings.cf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - ## - - command = 'chgrp postfix /etc/postfix/mysql-virtual_mailboxes.cf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chgrp postfix /etc/postfix/mysql-virtual_email2email.cf' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chgrp postfix ' + main - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chgrp postfix ' + master - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ######################################## users and groups - - command = 'groupadd -g 5000 vmail' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'useradd -g vmail -u 5000 vmail -d /home/vmail -m' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ######################################## Further configurations - - # hostname = socket.gethostname() - - ################################### Restart postix - - command = 'systemctl enable postfix.service' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'systemctl start postfix.service' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ######################################## Permissions - - command = 'chgrp dovecot /etc/dovecot/dovecot-sql.conf.ext' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'chmod o= /etc/dovecot/dovecot-sql.conf.ext' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ################################### Restart dovecot - - command = 'systemctl enable dovecot.service' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'systemctl start dovecot.service' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'systemctl restart postfix.service' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## chaging permissions for main.cf - - command = "chmod 755 " + main - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.distro == ubuntu: - command = "mkdir -p /etc/pki/dovecot/private/" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "mkdir -p /etc/pki/dovecot/certs/" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "mkdir -p /etc/opendkim/keys/" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "sed -i 's/auth_mechanisms = plain/#auth_mechanisms = plain/g' /etc/dovecot/conf.d/10-auth.conf" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## Ubuntu 18.10 ssl_dh for dovecot 2.3.2.1 - - if get_Ubuntu_release() == 18.10: - dovecotConf = '/etc/dovecot/dovecot.conf' - - data = open(dovecotConf, 'r').readlines() - writeToFile = open(dovecotConf, 'w') - for items in data: - if items.find('ssl_key = -1: - writeToFile.writelines(items) - writeToFile.writelines('ssl_dh = -1: - writeToFile.writelines( - " $sCustomDataPath = '/usr/local/lscp/cyberpanel/rainloop/data';\n") - else: - writeToFile.writelines(items) - - writeToFile.close() - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [downoad_and_install_rainloop]") - return 0 - - return 1 - - ###################################################### Email setup ends! - - def reStartLiteSpeed(self): - command = '%sbin/lswsctrl restart' % (self.server_root_path) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - def removeUfw(self): - try: - preFlightsChecks.stdOut("Checking to see if ufw firewall is installed (will be removed)", 1) - status = subprocess.check_output(shlex.split('ufw status')).decode("utf-8") - preFlightsChecks.stdOut("ufw current status: " + status + "...will be removed") - except BaseException as msg: - preFlightsChecks.stdOut("[ERROR] Expected access to ufw not available, do not need to remove it", 1) - return True - try: - preFlightsChecks.call('apt-get -y remove ufw', self.distro, '[remove_ufw]', 'Remove ufw firewall ' + - '(using firewalld)', 1, 0, os.EX_OSERR) - except: - pass - return True - - def installFirewalld(self): - - if self.distro == ubuntu: - self.removeUfw() - - try: - preFlightsChecks.stdOut("Enabling Firewall!") - - if self.distro == ubuntu: - command = 'apt-get -y install firewalld' - else: - command = 'yum -y install firewalld' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ###### - if self.distro == centos: - # Not available in ubuntu - command = 'systemctl restart dbus' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'systemctl restart systemd-logind' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'systemctl start firewalld' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ########## - - command = 'systemctl enable firewalld' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - FirewallUtilities.addRule("tcp", "8090") - FirewallUtilities.addRule("tcp", "7080") - FirewallUtilities.addRule("tcp", "80") - FirewallUtilities.addRule("tcp", "443") - FirewallUtilities.addRule("tcp", "21") - FirewallUtilities.addRule("tcp", "25") - FirewallUtilities.addRule("tcp", "587") - FirewallUtilities.addRule("tcp", "465") - FirewallUtilities.addRule("tcp", "110") - FirewallUtilities.addRule("tcp", "143") - FirewallUtilities.addRule("tcp", "993") - FirewallUtilities.addRule("tcp", "995") - FirewallUtilities.addRule("udp", "53") - FirewallUtilities.addRule("tcp", "53") - FirewallUtilities.addRule("udp", "443") - FirewallUtilities.addRule("tcp", "40110-40210") - - logging.InstallLog.writeToFile("FirewallD installed and configured!") - preFlightsChecks.stdOut("FirewallD installed and configured!") - - except OSError as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installFirewalld]") - return 0 - except ValueError as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installFirewalld]") - return 0 - - return 1 - - ## from here - - def installLSCPD(self): - try: - - logging.InstallLog.writeToFile("Starting LSCPD installation..") - - os.chdir(self.cwd) - - 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' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - 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' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'tar zxf lscp.tar.gz -C /usr/local/' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - ### - - lscpdPath = '/usr/local/lscp/bin/lscpd' - - command = 'cp -f /usr/local/CyberCP/lscpd-0.3.1 /usr/local/lscp/bin/lscpd-0.3.1' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = 'rm -f /usr/local/lscp/bin/lscpd' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = 'mv /usr/local/lscp/bin/lscpd-0.3.1 /usr/local/lscp/bin/lscpd' - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - command = 'chmod 755 %s' % (lscpdPath) - preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - - ## - - 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/conf/key.pem -out /usr/local/lscp/conf/cert.pem' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - try: - os.remove("/usr/local/lscp/fcgi-bin/lsphp") - shutil.copy("/usr/local/lsws/lsphp73/bin/lsphp", "/usr/local/lscp/fcgi-bin/lsphp") - except: - pass - - if self.distro == centos or self.distro == cent8: - command = 'adduser lscpd -M -d /usr/local/lscp' - else: - command = 'useradd lscpd -M -d /usr/local/lscp' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.distro == centos or self.distro == cent8: - command = 'groupadd lscpd' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - # Added group in useradd for Ubuntu - - command = 'usermod -a -G lscpd lscpd' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'usermod -a -G lsadm lscpd' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - try: - os.mkdir('/usr/local/lscp/cyberpanel') - except: - pass - try: - os.mkdir('/usr/local/lscp/cyberpanel/logs') - except: - pass - - # self.setupComodoRules() - - logging.InstallLog.writeToFile("LSCPD successfully installed!") - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installLSCPD]") - - def setupComodoRules(self): - try: - os.chdir(self.cwd) - - extractLocation = "/usr/local/lscp/modsec" - - command = "mkdir -p /usr/local/lscp/modsec" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - try: - if os.path.exists('comodo.tar.gz'): - os.remove('comodo.tar.gz') - except: - pass - - command = "wget https://cyberpanel.net/modsec/comodo.tar.gz" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "tar -zxf comodo.tar.gz -C /usr/local/lscp/modsec" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ### - - modsecConfPath = "/usr/local/lscp/conf/modsec.conf" - - modsecConfig = """ - module mod_security { - ls_enabled 0 - modsecurity on - modsecurity_rules ` - SecDebugLogLevel 0 - SecDebugLog /usr/local/lscp/logs/modsec.log - SecAuditEngine on - SecAuditLogRelevantStatus "^(?:5|4(?!04))" - SecAuditLogParts AFH - SecAuditLogType Serial - SecAuditLog /usr/local/lscp/logs/auditmodsec.log - SecRuleEngine Off - ` - modsecurity_rules_file /usr/local/lscp/modsec/comodo/modsecurity.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/00_Init_Initialization.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/01_Init_AppsInitialization.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/02_Global_Generic.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/03_Global_Agents.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/04_Global_Domains.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/05_Global_Backdoor.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/06_XSS_XSS.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/07_Global_Other.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/08_Bruteforce_Bruteforce.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/09_HTTP_HTTP.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/10_HTTP_HTTPDoS.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/11_HTTP_Protocol.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/12_HTTP_Request.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/13_Outgoing_FilterGen.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/14_Outgoing_FilterASP.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/15_Outgoing_FilterPHP.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/16_Outgoing_FilterSQL.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/17_Outgoing_FilterOther.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/18_Outgoing_FilterInFrame.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/19_Outgoing_FiltersEnd.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/20_PHP_PHPGen.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/21_SQL_SQLi.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/22_Apps_Joomla.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/23_Apps_JComponent.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/24_Apps_WordPress.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/25_Apps_WPPlugin.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/26_Apps_WHMCS.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/27_Apps_Drupal.conf - modsecurity_rules_file /usr/local/lscp/modsec/comodo/28_Apps_OtherApps.conf - } - """ - - writeToFile = open(modsecConfPath, 'w') - writeToFile.write(modsecConfig) - writeToFile.close() - - ### - - command = "chown -R lscpd:lscpd /usr/local/lscp/modsec" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - return 1 - - except BaseException as msg: - logging.InstallLog.writeToFile("[ERROR]" + str(msg)) - return 0 - - def setupPort(self): - try: - ### - bindConfPath = "/usr/local/lscp/conf/bind.conf" - - writeToFile = open(bindConfPath, 'w') - writeToFile.write("*:" + self.port) - writeToFile.close() - - except: - return 0 - - def setupPythonWSGI(self): - try: - - command = "wget http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.6.tgz" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "tar xf wsgi-lsapi-1.6.tgz" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - os.chdir("wsgi-lsapi-1.6") - - command = "/usr/local/CyberPanel/bin/python ./configure.py" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "make" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if not os.path.exists('/usr/local/CyberCP/bin/'): - os.mkdir('/usr/local/CyberCP/bin/') - - command = "cp lswsgi /usr/local/CyberCP/bin/" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - os.chdir(self.cwd) - - except: - return 0 - - def setupLSCPDDaemon(self): - try: - - preFlightsChecks.stdOut("Trying to setup LSCPD Daemon!") - logging.InstallLog.writeToFile("Trying to setup LSCPD Daemon!") - - os.chdir(self.cwd) - - shutil.copy("lscpd/lscpd.service", "/etc/systemd/system/lscpd.service") - shutil.copy("lscpd/lscpdctrl", "/usr/local/lscp/bin/lscpdctrl") - - ## - - command = 'chmod +x /usr/local/lscp/bin/lscpdctrl' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - path = "/usr/local/lscpd/admin/" - - command = "mkdir -p " + path - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - path = "/usr/local/CyberCP/conf/" - command = "mkdir -p " + path - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - path = "/usr/local/CyberCP/conf/token_env" - writeToFile = open(path, "w") - writeToFile.write("abc\n") - writeToFile.close() - - command = "chmod 600 " + path - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - command = 'systemctl enable lscpd.service' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - 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' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = 'systemctl start lscpd' - # preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - preFlightsChecks.stdOut("LSCPD Daemon Set!") - - logging.InstallLog.writeToFile("LSCPD Daemon Set!") - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setupLSCPDDaemon]") - return 0 - - return 1 - - def setup_cron(self): - - try: - ## first install crontab - - if self.distro == centos or self.distro == cent8: - command = 'yum install cronie -y' - else: - command = 'apt-get -y install cron' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.distro == centos or self.distro == cent8: - command = 'systemctl enable crond' - else: - command = 'systemctl enable cron' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.distro == centos or self.distro == cent8: - command = 'systemctl start crond' - else: - command = 'systemctl start cron' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - CentOSPath = '/etc/redhat-release' - - if os.path.exists(CentOSPath): - cronPath = '/var/spool/cron/root' - else: - cronPath = '/var/spool/cron/crontabs/root' - - cronFile = open(cronPath, "w") - - content = """ -0 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/findBWUsage.py >/dev/null 2>&1 -0 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/postfixSenderPolicy/client.py hourlyCleanup >/dev/null 2>&1 -0 0 1 * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/postfixSenderPolicy/client.py monthlyCleanup >/dev/null 2>&1 -0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/upgradeCritical.py >/dev/null 2>&1 -0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/renew.py >/dev/null 2>&1 -7 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null -0 0 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Daily -0 0 * * 0 /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Weekly -*/3 * * * * if ! find /home/*/public_html/ -maxdepth 2 -type f -newer /usr/local/lsws/cgid -name '.htaccess' -exec false {} +; then /usr/local/lsws/bin/lswsctrl restart; fi -""" - - cronFile.write(content) - cronFile.close() - - ### Check and remove OLS restart if lsws ent detected - - if not os.path.exists('/usr/local/lsws/bin/openlitespeed'): - - data = open(cronPath, 'r').readlines() - - writeToFile = open(cronPath, 'w') - - for items in data: - if items.find('-maxdepth 2 -type f -newer') > -1: - pass - else: - writeToFile.writelines(items) - - writeToFile.close() - - if not os.path.exists(CentOSPath): - command = 'chmod 600 %s' % (cronPath) - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.distro == centos or self.distro == cent8: - command = 'systemctl restart crond.service' - else: - command = 'systemctl restart cron.service' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setup_cron]") - return 0 - - def install_default_keys(self): - try: - path = "/root/.ssh" - - if not os.path.exists(path): - os.mkdir(path) - - command = "ssh-keygen -f /root/.ssh/cyberpanel -t rsa -N ''" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_default_keys]") - return 0 - - def install_rsync(self): - try: - if self.distro == centos or self.distro == cent8: - command = 'yum -y install rsync' - else: - command = 'apt-get -y install rsync' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_rsync]") - return 0 - - def test_Requests(self): - try: - import requests - getVersion = requests.get('https://cyberpanel.net/version.txt') - latest = getVersion.json() - except BaseException as msg: - - command = "pip uninstall --yes urllib3" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "pip uninstall --yes requests" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "pip install http://mirror.cyberpanel.net/urllib3-1.22.tar.gz" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "pip install http://mirror.cyberpanel.net/requests-2.18.4.tar.gz" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - def installation_successfull(self): - print("###################################################################") - print(" CyberPanel Successfully Installed ") - print(" ") - - print(" ") - print(" ") - - print((" Visit: https://" + self.ipAddr + ":8090 ")) - print(" Username: admin ") - print(" Password: 1234567 ") - - print("###################################################################") - - def modSecPreReqs(self): - try: - - pathToRemoveGarbageFile = os.path.join(self.server_root_path, "modules/mod_security.so") - os.remove(pathToRemoveGarbageFile) - - except OSError as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [modSecPreReqs]") - return 0 - - def installOpenDKIM(self): - try: - if self.distro == centos: - command = 'yum -y install opendkim' - elif self.distro == cent8: - command = 'dnf install opendkim -y' - else: - command = 'apt-get -y install opendkim' - - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - if self.distro == ubuntu: - command = 'apt install opendkim-tools -y' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'mkdir -p /etc/opendkim/keys/' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installOpenDKIM]") - return 0 - - return 1 - - def configureOpenDKIM(self): - try: - - ## Configure OpenDKIM specific settings - - openDKIMConfigurePath = "/etc/opendkim.conf" - - configData = """ -Mode sv -Canonicalization relaxed/simple -KeyTable refile:/etc/opendkim/KeyTable -SigningTable refile:/etc/opendkim/SigningTable -ExternalIgnoreList refile:/etc/opendkim/TrustedHosts -InternalHosts refile:/etc/opendkim/TrustedHosts -""" - - writeToFile = open(openDKIMConfigurePath, 'a') - writeToFile.write(configData) - writeToFile.close() - - ## Configure postfix specific settings - - postfixFilePath = "/etc/postfix/main.cf" - - configData = """ -smtpd_milters = inet:127.0.0.1:8891 -non_smtpd_milters = $smtpd_milters -milter_default_action = accept -""" - - writeToFile = open(postfixFilePath, 'a') - writeToFile.write(configData) - writeToFile.close() - - if self.distro == ubuntu: - data = open(openDKIMConfigurePath, 'r').readlines() - writeToFile = open(openDKIMConfigurePath, 'w') - for items in data: - if items.find('Socket') > -1 and items.find('local:') and items[0] != '#': - writeToFile.writelines('Socket inet:8891@localhost\n') - else: - writeToFile.writelines(items) - writeToFile.close() - - #### Restarting Postfix and OpenDKIM - - command = "systemctl start opendkim" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "systemctl enable opendkim" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## - - command = "systemctl start postfix" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except BaseException as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [configureOpenDKIM]") - return 0 - - return 1 - - def setupCLI(self): - command = "ln -s /usr/local/CyberCP/cli/cyberPanel.py /usr/bin/cyberpanel" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "chmod +x /usr/local/CyberCP/cli/cyberPanel.py" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - 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/" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - os.chdir(self.cwd) - - command = "chmod +x composer.sh" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = "./composer.sh" - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except OSError as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setupPHPAndComposer]") - return 0 - - @staticmethod - 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 enableDisableDNS(state): - try: - servicePath = '/home/cyberpanel/powerdns' - - if state == 'off': - - command = 'sudo systemctl stop pdns' - subprocess.call(shlex.split(command)) - - command = 'sudo systemctl disable pdns' - subprocess.call(shlex.split(command)) - - try: - os.remove(servicePath) - except: - pass - - else: - writeToFile = open(servicePath, 'w+') - writeToFile.close() - - except OSError as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableDNS]") - return 0 - - @staticmethod - def enableDisableEmail(state): - try: - servicePath = '/home/cyberpanel/postfix' - - if state == 'off': - - command = 'sudo systemctl stop postfix' - subprocess.call(shlex.split(command)) - - command = 'sudo systemctl disable postfix' - subprocess.call(shlex.split(command)) - - try: - os.remove(servicePath) - except: - pass - - else: - writeToFile = open(servicePath, 'w+') - writeToFile.close() - - except OSError as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]") - return 0 - - @staticmethod - def enableDisableFTP(state, distro): - try: - servicePath = '/home/cyberpanel/pureftpd' - - if state == 'off': - - command = 'sudo systemctl stop ' + preFlightsChecks.pureFTPDServiceName(distro) - subprocess.call(shlex.split(command)) - - command = 'sudo systemctl disable ' + preFlightsChecks.pureFTPDServiceName(distro) - subprocess.call(shlex.split(command)) - - try: - os.remove(servicePath) - except: - pass - - else: - writeToFile = open(servicePath, 'w+') - writeToFile.close() - - except OSError as msg: - logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]") - return 0 - - @staticmethod - def setUpFirstAccount(): - try: - command = 'python /usr/local/CyberCP/plogical/adminPass.py --password 1234567' - subprocess.call(shlex.split(command)) - except: - pass - - def installRestic(self): - try: - - CentOSPath = '/etc/redhat-release' - - if os.path.exists(CentOSPath): - command = 'yum install -y yum-plugin-copr' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - command = 'yum copr enable -y copart/restic' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - command = 'yum install -y restic' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - else: - command = 'apt-get update -y' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'apt-get install restic -y' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - except: - pass - - def installCLScripts(self): - try: - - CentOSPath = '/etc/redhat-release' - - if os.path.exists(CentOSPath): - command = 'mkdir -p /opt/cpvendor/etc/' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - content = """[integration_scripts] - -panel_info = /usr/local/CyberCP/CLScript/panel_info.py -packages = /usr/local/CyberCP/CLScript/CloudLinuxPackages.py -users = /usr/local/CyberCP/CLScript/CloudLinuxUsers.py -domains = /usr/local/CyberCP/CLScript/CloudLinuxDomains.py -resellers = /usr/local/CyberCP/CLScript/CloudLinuxResellers.py -admins = /usr/local/CyberCP/CLScript/CloudLinuxAdmins.py -db_info = /usr/local/CyberCP/CLScript/CloudLinuxDB.py - -[lvemanager_config] -ui_user_info =/usr/local/CyberCP/CLScript/UserInfo.py -base_path = /usr/local/lvemanager -run_service = 1 -service_port = 9000 -""" - - writeToFile = open('/opt/cpvendor/etc/integration.ini', 'w') - writeToFile.write(content) - writeToFile.close() - - command = 'mkdir -p /etc/cagefs/exclude' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - content = """cyberpanel -docker -ftpuser -lscpd -opendkim -pdns -vmail -""" - - writeToFile = open('/etc/cagefs/exclude/cyberpanelexclude', 'w') - writeToFile.write(content) - writeToFile.close() - - except: - pass - - def installAcme(self): - command = 'wget -O - https://get.acme.sh | sh' - subprocess.call(command, shell=True) - - command = '/root/.acme.sh/acme.sh --upgrade --auto-upgrade' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - def installRedis(self): - if self.distro == ubuntu: - command = 'apt install redis-server -y' - elif self.distro == centos: - command = 'yum install redis -y' - else: - command = 'dnf install redis -y' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - ## install redis conf - - redisConf = '/usr/local/lsws/conf/dvhost_redis.conf' - - writeToFile = open(redisConf, 'w') - writeToFile.write('127.0.0.1,6379,\n') - writeToFile.close() - - ## - - os.chdir(self.cwd) - - confPath = '/usr/local/lsws/conf/' - - if os.path.exists('%shttpd.conf' % (confPath)): - os.remove('%shttpd.conf' % (confPath)) - - shutil.copy('litespeed/httpd-redis.conf', '%shttpd.conf' % (confPath)) - - ## start and enable - - command = 'systemctl start redis' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - command = 'systemctl enable redis' - preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - - def disablePackegeUpdates(self): - if self.distro == centos: - mainConfFile = '/etc/yum.conf' - content = 'exclude=MariaDB-client MariaDB-common MariaDB-devel MariaDB-server MariaDB-shared ' \ - 'pdns pdns-backend-mysql dovecot dovecot-mysql postfix3 postfix3-ldap postfix3-mysql ' \ - 'postfix3-pcre restic opendkim libopendkim pure-ftpd ftp\n' - - writeToFile = open(mainConfFile, 'a') - writeToFile.write(content) - writeToFile.close() - - -def main(): - parser = argparse.ArgumentParser(description='CyberPanel Installer') - parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.') - parser.add_argument('--mysql', help='Specify number of MySQL instances to be used.') - parser.add_argument('--postfix', help='Enable or disable Email Service.') - parser.add_argument('--powerdns', help='Enable or disable DNS Service.') - parser.add_argument('--ftp', help='Enable or disable ftp Service.') - parser.add_argument('--ent', help='Install LS Ent or OpenLiteSpeed') - parser.add_argument('--serial', help='Install LS Ent or OpenLiteSpeed') - parser.add_argument('--port', help='LSCPD Port') - parser.add_argument('--redis', help='vHosts on Redis - Requires LiteSpeed Enterprise') - parser.add_argument('--remotemysql', help='Opt to choose local or remote MySQL') - parser.add_argument('--mysqlhost', help='MySQL host if remote is chosen.') - parser.add_argument('--mysqldb', help='MySQL DB if remote is chosen.') - parser.add_argument('--mysqluser', help='MySQL user if remote is chosen.') - parser.add_argument('--mysqlpassword', help='MySQL password if remote is chosen.') - parser.add_argument('--mysqlport', help='MySQL port if remote is chosen.') - - args = parser.parse_args() - - logging.InstallLog.ServerIP = args.publicip - logging.InstallLog.writeToFile("Starting CyberPanel installation..,10") - preFlightsChecks.stdOut("Starting CyberPanel installation..") - - if args.ent is None: - ent = 0 - preFlightsChecks.stdOut("OpenLiteSpeed web server will be installed.") - else: - if args.ent == 'ols': - ent = 0 - preFlightsChecks.stdOut("OpenLiteSpeed web server will be installed.") - else: - preFlightsChecks.stdOut("LiteSpeed Enterprise web server will be installed.") - ent = 1 - if args.serial is not None: - serial = args.serial - preFlightsChecks.stdOut("LiteSpeed Enterprise Serial detected: " + serial) - else: - preFlightsChecks.stdOut("Installation failed, please specify LiteSpeed Enterprise key using --serial") - os._exit(0) - - ## Writing public IP - - try: - os.mkdir("/etc/cyberpanel") - except: - pass - - machineIP = open("/etc/cyberpanel/machineIP", "w") - machineIP.writelines(args.publicip) - machineIP.close() - - cwd = os.getcwd() - - if args.remotemysql == 'ON': - remotemysql = args.remotemysql - mysqlhost = args.mysqlhost - mysqluser = args.mysqluser - mysqlpassword = args.mysqlpassword - mysqlport = args.mysqlport - mysqldb = args.mysqldb - - if preFlightsChecks.debug: - print('mysqlhost: %s, mysqldb: %s, mysqluser: %s, mysqlpassword: %s, mysqlport: %s' % ( - mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport)) - time.sleep(10) - - else: - remotemysql = args.remotemysql - mysqlhost = '' - mysqluser = '' - mysqlpassword = '' - mysqlport = '' - mysqldb = '' - - distro = get_distro() - checks = preFlightsChecks("/usr/local/lsws/", args.publicip, "/usr/local", cwd, "/usr/local/CyberCP", distro, - remotemysql, mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport) - checks.mountTemp() - - if args.port is None: - port = "8090" - else: - port = args.port - - if args.mysql is 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.") - - checks.checkPythonVersion() - checks.setup_account_cyberpanel() - checks.installCyberPanelRepo() - - import installCyberPanel - - if ent == 0: - installCyberPanel.Main(cwd, mysql, distro, ent, None, port, args.ftp, args.powerdns, args.publicip, remotemysql, - mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport) - else: - installCyberPanel.Main(cwd, mysql, distro, ent, serial, port, args.ftp, args.powerdns, args.publicip, - remotemysql, mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport) - - checks.setupPHPAndComposer() - checks.fix_selinux_issue() - checks.install_psmisc() - - if args.postfix is None: - checks.install_postfix_dovecot() - checks.setup_email_Passwords(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql) - checks.setup_postfix_dovecot_config(mysql) - else: - if args.postfix == 'ON': - checks.install_postfix_dovecot() - checks.setup_email_Passwords(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql) - checks.setup_postfix_dovecot_config(mysql) - - checks.install_unzip() - checks.install_zip() - checks.install_rsync() - - checks.installFirewalld() - checks.install_default_keys() - - checks.download_install_CyberPanel(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql) - checks.downoad_and_install_raindloop() - checks.download_install_phpmyadmin() - checks.setupCLI() - checks.setup_cron() - checks.installRestic() - checks.installAcme() - - ## Install and Configure OpenDKIM. - - if args.postfix is None: - checks.installOpenDKIM() - checks.configureOpenDKIM() - else: - if args.postfix == 'ON': - checks.installOpenDKIM() - checks.configureOpenDKIM() - - checks.modSecPreReqs() - checks.installLSCPD() - checks.setupPort() - checks.setupPythonWSGI() - checks.setupLSCPDDaemon() - - if args.redis is not None: - checks.installRedis() - - if args.postfix is not None: - checks.enableDisableEmail(args.postfix.lower()) - else: - preFlightsChecks.stdOut("Postfix will be installed and enabled.") - checks.enableDisableEmail('on') - - if args.powerdns is not None: - checks.enableDisableDNS(args.powerdns.lower()) - else: - preFlightsChecks.stdOut("PowerDNS will be installed and enabled.") - checks.enableDisableDNS('on') - - if args.ftp is not None: - checks.enableDisableFTP(args.ftp.lower(), distro) - else: - preFlightsChecks.stdOut("Pure-FTPD will be installed and enabled.") - checks.enableDisableFTP('on', distro) - - checks.installCLScripts() - # checks.disablePackegeUpdates() - - try: - # command = 'mkdir -p /usr/local/lscp/cyberpanel/rainloop/data/data/default/configs/' - # subprocess.call(shlex.split(command)) - - writeToFile = open('/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/configs/application.ini', 'a') - - writeToFile.write(""" -[security] -admin_login = "admin" -admin_password = "12345" -""") - writeToFile.close() - - import randomPassword - - content = """SetPassword('%s'); -echo $oConfig->Save() ? 'Done' : 'Error'; - -?>""" % (randomPassword.generate_pass()) - - writeToFile = open('/usr/local/CyberCP/public/rainloop.php', 'w') - writeToFile.write(content) - writeToFile.close() - - command = '/usr/local/lsws/lsphp72/bin/php /usr/local/CyberCP/public/rainloop.php' - subprocess.call(shlex.split(command)) - - command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data" - subprocess.call(shlex.split(command)) - except: - pass - - checks.fixCyberPanelPermissions() - - logging.InstallLog.writeToFile("CyberPanel installation successfully completed!,80") - - -if __name__ == "__main__": - main() diff --git a/install/venvsetup.sh.bak b/install/venvsetup.sh.bak deleted file mode 100644 index 959d69ab0..000000000 --- a/install/venvsetup.sh.bak +++ /dev/null @@ -1,1290 +0,0 @@ -#!/bin/bash - -#CyberPanel installer script for Ubuntu 18.04 and CentOS 7.X -DEV="OFF" -BRANCH="stable" -POSTFIX_VARIABLE="ON" -POWERDNS_VARIABLE="ON" -PUREFTPD_VARIABLE="ON" -PROVIDER="undefined" -SERIAL_NO="" -DIR=$(pwd) -TEMP=$(curl --silent https://cyberpanel.net/version.txt) -CP_VER1=${TEMP:12:3} -CP_VER2=${TEMP:25:1} -SERVER_OS="CentOS" -VERSION="OLS" -LICENSE_KEY="" -KEY_SIZE="" -ADMIN_PASS="1234567" -MEMCACHED="ON" -REDIS="ON" -TOTAL_RAM=$(free -m | awk '/Mem\:/ { print $2 }') - -license_validation() { -CURRENT_DIR=$(pwd) - -if [ -f /root/cyberpanel-tmp ] ; then -rm -rf /root/cyberpanel-tmp -fi - -mkdir /root/cyberpanel-tmp -cd /root/cyberpanel-tmp -wget -q https://$DOWNLOAD_SERVER/litespeed/lsws-$LSWS_STABLE_VER-ent-x86_64-linux.tar.gz -tar xzvf lsws-$LSWS_STABLE_VER-ent-x86_64-linux.tar.gz > /dev/null -cd /root/cyberpanel-tmp/lsws-$LSWS_STABLE_VER/conf -if [[ $LICENSE_KEY == "TRIAL" ]] ; then -wget -q http://license.litespeedtech.com/reseller/trial.key -sed -i "s|writeSerial = open('lsws-5.4.2/serial.no', 'w')|command = 'wget -q --output-document=./lsws-$LSWS_STABLE_VER/trial.key http://license.litespeedtech.com/reseller/trial.key'|g" $CURRENT_DIR/installCyberPanel.py -sed -i 's|writeSerial.writelines(self.serial)|subprocess.call(command, shell=True)|g' $CURRENT_DIR/installCyberPanel.py -sed -i 's|writeSerial.close()||g' $CURRENT_DIR/installCyberPanel.py -else -echo $LICENSE_KEY > serial.no -fi - -cd /root/cyberpanel-tmp/lsws-$LSWS_STABLE_VER/bin - -if [[ $LICENSE_KEY == "TRIAL" ]] ; then - if ./lshttpd -V |& grep "ERROR" ; then - echo -e "\n\nIt apeears to have some issue with license , please check above result..." - exit - fi - LICENSE_KEY="1111-2222-3333-4444" -else - if ./lshttpd -r |& grep "ERROR" ; then - ./lshttpd -r - echo -e "\n\nIt apeears to have some issue with license , please check above result..." - exit - fi -fi -echo -e "License seems valid..." -cd /root/cyberpanel-tmp -rm -rf lsws-$LSWS_STABLE_VER* -cd $CURRENT_DIR -rm -rf /root/cyberpanel-tmp -} - -special_change(){ -sed -i 's|cyberpanel.sh|'$DOWNLOAD_SERVER'|g' install.py -sed -i 's|mirror.cyberpanel.net|'$DOWNLOAD_SERVER'|g' install.py -sed -i 's|git clone https://github.com/usmannasir/cyberpanel|echo downloaded|g' install.py -#change to CDN first, regardless country -sed -i 's|http://|https://|g' install.py - -LATEST_URL="https://update.litespeedtech.com/ws/latest.php" -#LATEST_URL="https://cyberpanel.sh/latest.php" -curl --silent -o /tmp/lsws_latest $LATEST_URL 2>/dev/null -LSWS_STABLE_LINE=`cat /tmp/lsws_latest | grep LSWS_STABLE` -LSWS_STABLE_VER=`expr "$LSWS_STABLE_LINE" : '.*LSWS_STABLE=\(.*\) BUILD .*'` - -if [[ $SERVER_COUNTRY == "CN" ]] ; then -#line1="$(grep -n "github.com/usmannasir/cyberpanel" install.py | head -n 1 | cut -d: -f1)" -#line2=$((line1 - 1)) -#sed -i "${line2}i\ \ \ \ \ \ \ \ subprocess.call(command, shell=True)" install.py -#sed -i "${line2}i\ \ \ \ \ \ \ \ command = 'tar xzvf cyberpanel-git.tar.gz'" install.py -#sed -i "${line2}i\ \ \ \ \ \ \ \ subprocess.call(command, shell=True)" install.py -#sed -i "${line2}i\ \ \ \ \ \ \ \ command = 'wget cyberpanel.sh/cyberpanel-git.tar.gz'" install.py -sed -i 's|wget https://rpms.litespeedtech.com/debian/|wget --no-check-certificate https://rpms.litespeedtech.com/debian/|g' install.py -sed -i 's|https://repo.powerdns.com/repo-files/centos-auth-42.repo|https://'$DOWNLOAD_SERVER'/powerdns/powerdns.repo|g' installCyberPanel.py -sed -i 's|https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip|https://'$DOWNLOAD_SERVER'/misc/rainloop-community-latest.zip|g' install.py - -sed -i 's|rpm -ivh https://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm|curl -o /etc/yum.repos.d/litespeed.repo https://'$DOWNLOAD_SERVER'/litespeed/litespeed.repo|g' install.py - - -sed -i 's|https://copr.fedorainfracloud.org/coprs/copart/restic/repo/epel-7/copart-restic-epel-7.repo|https://'$DOWNLOAD_SERVER'/restic/restic.repo|g' install.py - -sed -i 's|yum -y install https://cyberpanel.sh/gf-release-latest.gf.el7.noarch.rpm|wget -O /etc/yum.repos.d/gf.repo https://'$DOWNLOAD_SERVER'/gf-plus/gf.repo|g' install.py -sed -i 's|dovecot-2.3-latest|dovecot-2.3-latest-mirror|g' install.py -sed -i 's|git clone https://github.com/usmannasir/cyberpanel|wget https://cyberpanel.sh/cyberpanel-git.tar.gz \&\& tar xzvf cyberpanel-git.tar.gz|g' install.py -sed -i 's|https://repo.dovecot.org/ce-2.3-latest/centos/$releasever/RPMS/$basearch|https://'$DOWNLOAD_SERVER'/dovecot/|g' install.py -sed -i 's|'$DOWNLOAD_SERVER'|cyberpanel.sh|g' install.py -sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.4.2-ent-x86_64-linux.tar.gz|https://'$DOWNLOAD_SERVER'/litespeed/lsws-'$LSWS_STABLE_VER'-ent-x86_64-linux.tar.gz|g' installCyberPanel.py -# global change for CN , regardless provider and system - - if [[ $SERVER_OS == "CentOS" ]] ; then - DIR=$(pwd) - cd $DIR/mysql - echo "[mariadb-tsinghua] -name = MariaDB -baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.1/centos7-amd64 -gpgkey = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum//RPM-GPG-KEY-MariaDB -gpgcheck = 1" > MariaDB.repo -#above to set mariadb db to Tsinghua repo - cd $DIR - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|https://cyberpanel.sh/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|g' installCyberPanel.py - mkdir /root/.pip - cat << EOF > /root/.pip/pip.conf -[global] -index-url = https://mirrors.aliyun.com/pypi/simple/ -EOF - echo -e "\nSet to Aliyun pip repo..." - cat << EOF > composer.sh -#!/usr/bin/env bash -php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -php composer-setup.php -php -r "unlink('composer-setup.php');" -mv composer.phar /usr/bin/composer - -if [ ! -d /root/.config ]; then -mkdir /root/.config -fi - -if [ ! -d /root/.config/composer ]; then -mkdir /root/.config/composer -fi - -echo '{ - "bitbucket-oauth": {}, - "github-oauth": {}, - "gitlab-oauth": {}, - "gitlab-token": {}, - "http-basic": {} -} -' > /root/.config/composer/auth.json - -echo '{ - "config": {}, - "repositories": { - "packagist": { - "type": "composer", - "url": "https://mirrors.aliyun.com/composer/" - } - } -} -' > /root/.config/composer/config.json -composer clear-cache -EOF - fi - - - if [[ $SERVER_OS == "Ubuntu" ]] ; then - echo $'\n89.208.248.38 rpms.litespeedtech.com\n' >> /etc/hosts - echo -e "Mirror server set..." - pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ - cat << EOF > /root/.pip/pip.conf -[global] -index-url = https://mirrors.aliyun.com/pypi/simple/ -EOF - echo -e "\nSet to Aliyun pip repo..." - if [[ $PROVIDER == "Tencent Cloud" ]] ; then - #tencent cloud and ubuntu system - echo -e "\n Tencent Cloud detected ... bypass default repository" - cp /etc/apt/sources.list /etc/apt/sources.list-backup - #backup original sources list - cat << 'EOF' > /etc/apt/sources.list -deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse -EOF - DEBIAN_FRONTEND=noninteractive apt update -y - pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ - cat << EOF > composer.sh -#!/usr/bin/env bash -php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -php composer-setup.php -php -r "unlink('composer-setup.php');" -mv composer.phar /usr/bin/composer - -if [ ! -d /root/.config ]; then -mkdir /root/.config -fi - -if [ ! -d /root/.config/composer ]; then -mkdir /root/.config/composer -fi - -echo '{ - "bitbucket-oauth": {}, - "github-oauth": {}, - "gitlab-oauth": {}, - "gitlab-token": {}, - "http-basic": {} -} -' > /root/.config/composer/auth.json - -echo '{ - "config": {}, - "repositories": { - "packagist": { - "type": "composer", - "url": "https://mirrors.cloud.tencent.com/composer/" - } - } -} -' > /root/.config/composer/config.json -composer clear-cache -EOF - else - cat << EOF > composer.sh -#!/usr/bin/env bash -php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -php composer-setup.php -php -r "unlink('composer-setup.php');" -mv composer.phar /usr/bin/composer - -if [ ! -d /root/.config ]; then -mkdir /root/.config -fi - -if [ ! -d /root/.config/composer ]; then -mkdir /root/.config/composer -fi - -echo '{ - "bitbucket-oauth": {}, - "github-oauth": {}, - "gitlab-oauth": {}, - "gitlab-token": {}, - "http-basic": {} -} -' > /root/.config/composer/auth.json - -echo '{ - "config": {}, - "repositories": { - "packagist": { - "type": "composer", - "url": "https://packagist.phpcomposer.com" - } - } -} -' > /root/.config/composer/config.json -composer clear-cache -EOF - fi - fi -fi -} - - -system_tweak() { -if [[ $SERVER_OS == "CentOS" ]] ; then - setenforce 0 - sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config -fi - -if ! grep -q "pid_max" /etc/rc.local; then - if [[ $SERVER_OS == "CentOS" ]] ; then - echo "echo 1000000 > /proc/sys/kernel/pid_max -echo 1 > /sys/kernel/mm/ksm/run" >> /etc/rc.d/rc.local - chmod +x /etc/rc.d/rc.local - else - echo "echo 1000000 > /proc/sys/kernel/pid_max -echo 1 > /sys/kernel/mm/ksm/run" >> /etc/rc.local - chmod +x /etc/rc.local - fi - echo "fs.file-max = 65535" >> /etc/sysctl.conf - sysctl -p > /dev/null - echo "* soft nofile 65535 -* hard nofile 65535 -root soft nofile 65535 -root hard nofile 65535 -* soft nproc 65535 -* hard nproc 65535 -root soft nproc 65535 -root hard nproc 65535" >> /etc/security/limits.conf -fi - -#sed -i 's|#DefaultLimitNOFILE=|DefaultLimitNOFILE=65535|g' /etc/systemd/system.conf - - -TOTAL_SWAP=$(free -m | awk '/^Swap:/ { print $2 }') -SET_SWAP=$((TOTAL_RAM - TOTAL_SWAP)) -SWAP_FILE=/cyberpanel.swap - -if [ ! -f $SWAP_FILE ] ; then - if [[ $TOTAL_SWAP -gt $TOTAL_RAM ]] || [[ $TOTAL_SWAP -eq $TOTAL_RAM ]] ; then - echo "SWAP check..." - else - if [[ $SET_SWAP -gt "2049" ]] ; then - SET_SWAP="2048" - else - echo "Checking SWAP..." - fi - fallocate --length ${SET_SWAP}MiB $SWAP_FILE - chmod 600 $SWAP_FILE - mkswap $SWAP_FILE - swapon $SWAP_FILE - echo "${SWAP_FILE} swap swap sw 0 0" | sudo tee -a /etc/fstab - sysctl vm.swappiness=10 - echo "vm.swappiness = 10" >> /etc/sysctl.conf - echo "SWAP set..." - fi -fi -} - - -install_required() { -echo -e "\nInstalling necessary components..." -if [[ $SERVER_OS == "CentOS" ]] ; then - rpm --import https://$DOWNLOAD_SERVER/mariadb/RPM-GPG-KEY-MariaDB - rpm --import https://$DOWNLOAD_SERVER/litespeed/RPM-GPG-KEY-litespeed - rpm --import https://$DOWNLOAD_SERVER/powerdns/FD380FBB-pub.asc - rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 - rpm --import https://$DOWNLOAD_SERVER/gf-plus/RPM-GPG-KEY-gf.el7 - rpm --import https://repo.dovecot.org/DOVECOT-REPO-GPG - rpm --import https://copr-be.cloud.fedoraproject.org/results/copart/restic/pubkey.gpg - yum autoremove epel-release -y - rm -f /etc/yum.repos.d/epel.repo - rm -f /etc/yum.repos.d/epel.repo.rpmsave - yum clean all - yum update -y - yum install epel-release -y - yum install -y wget strace htop net-tools telnet curl which bc telnet htop libevent-devel gcc python-devel libattr-devel xz-devel gpgme-devel mariadb-devel curl-devel python-pip git - if [[ $DEV == "ON" ]] ; then - yum -y install yum-utils - yum -y groupinstall development - yum -y install https://centos7.iuscommunity.org/ius-release.rpm - yum -y install python36u python36u-pip python36u-devel - fi -fi - -if [[ $SERVER_OS == "Ubuntu" ]] ; then - apt update -y - DEBIAN_FRONTEND=noninteractive apt upgrade -y - DEBIAN_FRONTEND=noninteractive apt install -y htop telnet python-mysqldb python-dev libcurl4-gnutls-dev libgnutls28-dev libgcrypt20-dev libattr1 libattr1-dev liblzma-dev libgpgme-dev libmariadbclient-dev libcurl4-gnutls-dev libssl-dev nghttp2 libnghttp2-dev idn2 libidn2-dev libidn2-0-dev librtmp-dev libpsl-dev nettle-dev libgnutls28-dev libldap2-dev libgssapi-krb5-2 libk5crypto3 libkrb5-dev libcomerr2 libldap2-dev python-gpg python python-minimal python-setuptools virtualenv python-dev python-pip git - if [[ $DEV == "ON" ]] ; then - DEBIAN_FRONTEND=noninteractive apt install -y python3-pip - DEBIAN_FRONTEND=noninteractive apt install -y build-essential libssl-dev libffi-dev python3-dev - DEBIAN_FRONTEND=noninteractive apt install -y python3-venv - fi -fi -} - -memcached_installation() { -if [[ $SERVER_OS == "CentOS" ]] ; then - yum install -y lsphp73-memcached lsphp72-memcached lsphp71-memcached lsphp70-memcached lsphp56-pecl-memcached lsphp55-pecl-memcached lsphp54-pecl-memcached - if [[ $TOTAL_RAM -eq "2048" ]] || [[ $TOTAL_RAM -gt "2048" ]] ; then - yum groupinstall "Development Tools" -y - yum install autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl* -y - wget https://$DOWNLOAD_SERVER/litespeed/lsmcd.tar.gz - tar xzvf lsmcd.tar.gz - DIR=$(pwd) - cd $DIR/lsmcd - ./fixtimestamp.sh - ./configure CFLAGS=" -O3" CXXFLAGS=" -O3" - make - make install - systemctl enable lsmcd - systemctl start lsmcd - cd $DIR - else - yum install -y memcached - sed -i 's|OPTIONS=""|OPTIONS="-l 127.0.0.1 -U 0"|g' /etc/sysconfig/memcached - systemctl enable memcached - systemctl start memcached - fi -fi -if [[ $SERVER_OS == "Ubuntu" ]] ; then - DEBIAN_FRONTEND=noninteractive apt install -y lsphp73-memcached lsphp72-memcached lsphp71-memcached lsphp70-memcached - if [[ $TOTAL_RAM -eq "2048" ]] || [[ $TOTAL_RAM -gt "2048" ]] ; then - DEBIAN_FRONTEND=noninteractive apt install build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev git -y - wget https://$DOWNLOAD/litespeed/lsmcd.tar.gz - tar xzvf lsmcd.tar.gz - DIR=$(pwd) - cd $DIR/lsmcd - ./fixtimestamp.sh - ./configure CFLAGS=" -O3" CXXFLAGS=" -O3" - make - make install - cd $DIR - systemctl enable lsmcd - systemctl start lsmcd - else - DEBIAN_FRONTEND=noninteractive apt install -y memcached - systemctl enable memcached - systemctl start memcached - fi -fi - -if ps -aux | grep "lsmcd" | grep -v grep ; then - echo -e "\n\nLiteSpeed Memcached installed and running..." -fi - -if ps -aux | grep "memcached" | grep -v grep ; then - echo -e "\n\nMemcached installed and running..." -fi - -} - -redis_installation() { -if [[ $SERVER_OS == "CentOS" ]] ; then - yum install -y lsphp73-redis lsphp72-redis lsphp71-redis lsphp70-redis lsphp56-redis lsphp55-redis lsphp54-redis redis -fi -if [[ $SERVER_OS == "Ubuntu" ]] ; then - DEBIAN_FRONTEND=noninteractive apt install -y lsphp73-redis lsphp72-redis lsphp71-redis lsphp70-redis redis -fi - -if ifconfig -a | grep inet6 ; then - echo -e "\n IPv6 detected..." -else - sed -i 's|bind 127.0.0.1 ::1|bind 127.0.0.1|g' /etc/redis/redis.conf - echo -e "\n no IPv6 detected..." -fi - -if [[ $SERVER_OS == "CentOS" ]] ; then - systemctl enable redis - systemctl start redis -fi - -if [[ $SERVER_OS == "Ubuntu" ]] ; then - systemctl enable redis-server - systemctl start redis-server -fi - -if ps -aux | grep "redis" | grep -v grep ; then - echo -e "\n\nRedis installed and running..." -fi -} - -check_provider() { - -if hash dmidecode > /dev/null 2>&1 ; then - if [ "$(dmidecode -s bios-vendor)" = 'Google' ] ; then - PROVIDER='Google Cloud Platform' - elif [ "$(dmidecode -s bios-vendor)" = 'DigitalOcean' ] ; then - PROVIDER='Digital Ocean' - elif [ "$(dmidecode -s system-product-name | cut -c 1-7)" = 'Alibaba' ] ; then - PROVIDER='Alibaba Cloud' - elif [ "$(dmidecode -s system-manufacturer)" = 'Microsoft Corporation' ] ; then - PROVIDER='Microsoft Azure' - elif [ -d /usr/local/qcloud ] ; then - PROVIDER='Tencent Cloud' - else - PROVIDER='undefined' - fi -else - PROVIDER='undefined' -fi - -if [ "$(cat /sys/devices/virtual/dmi/id/product_uuid | cut -c 1-3)" = 'EC2' ] && [ -d /home/ubuntu ]; then - PROVIDER='Amazon Web Service' -fi - -} - - -check_OS() { -echo -e "\nChecking OS..." -OUTPUT=$(cat /etc/*release) -if echo $OUTPUT | grep -q "CentOS Linux 7" ; then - echo -e "\nDetecting CentOS 7.X...\n" - SERVER_OS="CentOS" -elif echo $OUTPUT | grep -q "CloudLinux 7" ; then - echo -e "\nDetecting CloudLinux 7.X...\n" - SERVER_OS="CentOS" -elif echo $OUTPUT | grep -q "Ubuntu 18.04" ; then - echo -e "\nDetecting Ubuntu 18.04...\n" - SERVER_OS="Ubuntu" -else - cat /etc/*release - echo -e "\nUnable to detect your OS...\n" - echo -e "\nCyberPanel is supported on Ubuntu 18.04, CentOS 7.x and CloudLinux 7.x...\n" - exit 1 -fi -} - -check_root() { -echo -e "Checking root privileges...\n" -if [[ $(id -u) != 0 ]] > /dev/null; then - echo -e "You must use root account to do this" - echo -e "or run following command: (do NOT miss the quotes)" - echo -e "\e[31msudo su -c \"sh <(curl https://cyberpanel.sh || wget -O - https://cyberpanel.sh)\"\e[39m" - exit 1 -else - echo -e "You are runing as root...\n" -fi -} - -check_panel() { -if [ -d /usr/local/cpanel ]; then - echo -e "\ncPanel detected...exit...\n" - exit 1 -fi -if [ -d /opt/plesk ]; then - echo -e "\nPlesk detected...exit...\n" - exit 1 -fi -} - -check_process() { -if systemctl is-active --quiet httpd; then - systemctl disable httpd - systemctl stop httpd - echo -e "\nhttpd process detected, disabling...\n" -fi -if systemctl is-active --quiet apache2; then - systemctl disable apache2 - systemctl stop apache2 - echo -e "\napache2 process detected, disabling...\n" -fi -if systemctl is-active --quiet named; then - systemctl stop named - systemctl disable named - echo -e "\nnamed process detected, disabling...\n" -fi -if systemctl is-active --quiet exim; then - systemctl stop exim - systemctl disable exim - echo -e "\nexim process detected, disabling...\n" -fi -} - -show_help() { -echo -e "\nCyberPanel Installer Script Help\n" -echo -e "\nUsage: wget https://cyberpanel.sh/cyberpanel.sh" -echo -e "\nchmod +x cyberpanel.sh" -echo -e "\n./cyberpanel.sh -v ols/SERIAL_NUMBER -c 1 -a 1" -echo -e "\n -v or --version: choose to install CyberPanel OpenLiteSpeed or CyberPanel Enterprise, available options are \e[31mols\e[39m and \e[31mSERIAL_NUMBER\e[39m, default ols" -echo -e "\n Please be aware, this serial number must be obtained from LiteSpeed Store." -echo -e "\n And if this serial number has been used before, it must be released/migrated in Store first, otherwise it will fail to start." -echo -e "\n -a or --addons: install addons: memcached, redis, PHP extension for memcached and redis, 1 for install addons, 0 for not to install, default 0, only applicable for CentOS system." -echo -e "\n -p or --password: set password of new installation, empty for default 1234567, [r] or [random] for randomly generated 16 digital password, any other value besdies [d] and [r(andom)] will be accept as password, default use 1234567." -#echo -e "\n -m: set to minimal mode which will not install PowerDNS, Pure-FTPd and Postfix" -echo -e "\n Example:" -echo -e "\n ./cyberpanel.sh -v ols -p r or ./cyberpanel.sh --version ols --password random" -echo -e "\n This will install CyberPanel OpenLiteSpeed and randomly generate the password." -echo -e "\n ./cyberpanel.sh default" -echo -e "\n This will install everything default , which is OpenLiteSpeed and nothing more.\n" - -} - -license_input() { -VERSION="ENT" -echo -e "\nPlease note that your server has \e[31m$TOTAL_RAM\e[39m RAM" -echo -e "If you are using \e[31mFree Start\e[39m license, It will not start due to \e[31m2GB RAM limit\e[39m.\n" -echo -e "If you do not have any license, you can also use trial license (if server has not used trial license before), type \e[31mTRIAL\e[39m\n" - -printf "%s" "Please input your serial number for LiteSpeed WebServer Enterprise:" -read LICENSE_KEY -if [ -z "$LICENSE_KEY" ] ; then - echo -e "\nPlease provide license key\n" - exit -fi - -echo -e "The serial number you input is: \e[31m$LICENSE_KEY\e[39m" -printf "%s" "Please verify it is correct. [y/N]" -read TMP_YN -if [ -z "$TMP_YN" ] ; then - echo -e "\nPlease type \e[31my\e[39m\n" - exit -fi - -KEY_SIZE=${#LICENSE_KEY} -TMP=$(echo $LICENSE_KEY | cut -c5) -TMP2=$(echo $LICENSE_KEY | cut -c10) -TMP3=$(echo $LICENSE_KEY | cut -c15) - -if [[ $TMP == "-" ]] && [[ $TMP2 == "-" ]] && [[ $TMP3 == "-" ]] && [[ $KEY_SIZE == "19" ]] ; then - echo -e "\nLicense key set..." -elif [[ $LICENSE_KEY == "trial" ]] || [[ $LICENSE_KEY == "TRIAL" ]] || [[ $LICENSE_KEY == "Trial" ]] ; then - echo -e "\nTrial license set..." - LICENSE_KEY="TRIAL" -else - echo -e "\nLicense key seems incorrect, please verify\n" - echo -e "\nIf you are copying/pasting, please make sure you didn't paste blank space...\n" - exit -fi -} - -interactive_mode() { -echo -e " CyberPanel Installer v$CP_VER1$CP_VER2 - - 1. Install CyberPanel. - - 2. Addons and Miscellaneous - - 3. Exit. - - " -read -p " Please enter the number[1-3]: " num -echo "" -case "$num" in - 1) - interactive_install - ;; - 2) - interactive_others - ;; - 3) - exit - ;; - *) - echo -e " Please enter the right number [1-3]\n" - exit - ;; -esac -} - -interactive_others() { -if [ ! -e "/etc/cyberpanel/machineIP" ]; then -echo -e "\nYou don't have CyberPanel installed...\n" -exit -fi - -echo -e " CyberPanel Addons v$CP_VER1$CP_VER2 - - 1. Install Memcached extension and backend - - 2. Install Redis extension and backend - - 3. Return to main page. - - 4. Exit - " - -echo && read -p "Please enter the number[1-4]: " num -case "$num" in - 1) - memcached_installation - exit - ;; - 2) - redis_installation - exit - ;; - 3) - interactive_mode - ;; - 4) - exit - ;; - *) - echo -e "${Error} please enter the right number [1-4]" - ;; -esac -} - -interactive_install() { -RAM=$(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') -DISK=$(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}') -#clear -echo -e " CyberPanel Installer v$CP_VER1$CP_VER2 - - RAM check : $RAM - - Disk check : $DISK (Minimal \e[31m10GB\e[39m free space) - - 1. Install CyberPanel with \e[31mOpenLiteSpeed\e[39m. - - 2. Install Cyberpanel with \e[31mLiteSpeed Enterprise\e[39m. - - 3. Exit. - - " -read -p " Please enter the number[1-3]: " num -echo "" -case "$num" in - 1) - VERSION="OLS" - ;; - 2) - license_input - ;; - 3) - exit - ;; - *) - echo -e " Please enter the right number [1-3]\n" - exit - ;; -esac - -< /dev/null; then - echo -e "\nCyberPanel installation sucessfully completed..." -else - echo -e "Oops, something went wrong..." - exit -fi - -if [[ $MEMCACHED == "ON" ]] ; then - memcached_installation -fi -if [[ $REDIS == "ON" ]] ; then - redis_installation -fi - after_install -fi -} - -pip_virtualenv() { -if [[ $DEV == "OFF" ]] ; then -if [[ $SERVER_COUNTRY == "CN" ]] ; then - mkdir /root/.pip -cat << EOF > /root/.pip/pip.conf -[global] -index-url = https://mirrors.aliyun.com/pypi/simple/ -EOF -fi - -if [[ $PROVIDER == "Alibaba Cloud" ]] ; then - pip install --upgrade pip - pip install setuptools==40.8.0 -fi - -pip install virtualenv -virtualenv --system-site-packages /usr/local/CyberPanel -source /usr/local/CyberPanel/bin/activate -rm -rf requirements.txt -wget -O requirements.txt https://raw.githubusercontent.com/usmannasir/cyberpanel/1.8.0/requirments.txt -pip install --ignore-installed -r requirements.txt -virtualenv --system-site-packages /usr/local/CyberPanel -fi - -if [[ $DEV == "ON" ]] ; then - #install dev branch - #wget https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/requirments.txt - cd /usr/local/ - python3.6 -m venv CyberPanel - source /usr/local/CyberPanel/bin/activate - wget -O requirements.txt https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/requirments.txt - pip3.6 install --ignore-installed -r requirements.txt -fi - -if [ -f requirements.txt ] && [ -d cyberpanel ] ; then - rm -rf cyberpanel - rm -f requirements.txt -fi - -if [[ $SERVER_COUNTRY == "CN" ]] ; then - wget https://cyberpanel.sh/cyberpanel-git.tar.gz - tar xzvf cyberpanel-git.tar.gz > /dev/null - cp -r cyberpanel /usr/local/cyberpanel - cd cyberpanel/install -else - if [[ $DEV == "ON" ]] ; then - git clone https://github.com/usmannasir/cyberpanel - cd cyberpanel - git checkout $BRANCH_NAME - cd - - cd cyberpanel/install - else - git clone https://github.com/usmannasir/cyberpanel - cd cyberpanel/install - fi -fi -curl https://cyberpanel.sh/?version -} - -after_install() { -if [ ! -d "/var/lib/php" ]; then - mkdir /var/lib/php -fi - -if [ ! -d "/var/lib/php/session" ]; then - mkdir /var/lib/php/session -fi - -chmod 1733 /var/lib/php/session - -if grep "\[ERROR\] We are not able to run ./install.sh return code: 1. Fatal error, see /var/log/installLogs.txt for full details" /var/log/installLogs.txt > /dev/null; then - cd ${DIR}/cyberpanel/install/lsws-* - ./install.sh - echo -e "\n\n\nIt seems LiteSpeed Enterprise has failed to install, please check your license key is valid" - echo -e "\nIf this license key has been used before, you may need to go to store to release it first." - exit -fi - - -if grep "CyberPanel installation successfully completed" /var/log/installLogs.txt > /dev/null; then - -if [[ $DEV == "ON" ]] ; then -python3.6 -m venv /usr/local/CyberCP -source /usr/local/CyberCP/bin/activate -wget -O requirements.txt https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/requirments.txt -pip3.6 install --ignore-installed -r requirements.txt -systemctl restart lscpd -fi - -for version in $(ls /usr/local/lsws | grep lsphp); - do - php_ini=$(find /usr/local/lsws/$version/ -name php.ini) - version2=${version:5:2} - version2=$(awk "BEGIN { print "${version2}/10" }") - if [[ $version2 = "7" ]] ; then - version2="7.0" - fi - if [[ $SERVER_OS == "CentOS" ]] ; then - yum remove -y $version-mysql - yum install -y $version-mysqlnd - yum install -y $version-devel make gcc glibc-devel libmemcached-devel zlib-devel - if [[ ! -d /usr/local/lsws/$version/tmp ]] ; then - mkdir /usr/local/lsws/$version/tmp - fi - /usr/local/lsws/${version}/bin/pecl channel-update pecl.php.net; - /usr/local/lsws/${version}/bin/pear config-set temp_dir /usr/local/lsws/${version}/tmp - /usr/local/lsws/${version}/bin/pecl install timezonedb - echo "extension=timezonedb.so" > /usr/local/lsws/${version}/etc/php.d/20-timezone.ini - sed -i 's|expose_php = On|expose_php = Off|g' $php_ini - sed -i 's|mail.add_x_header = On|mail.add_x_header = Off|g' $php_ini - sed -i 's|;session.save_path = "/tmp"|session.save_path = "/var/lib/php/session"|g' $php_ini - fi - - if [[ $SERVER_OS == "Ubuntu" ]] ; then - if [[ ! -d /usr/local/lsws/cyberpanel-tmp ]] ; then - echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone - systemctl restart pure-ftpd-mysql - DEBIAN_FRONTEND=noninteractive apt install libmagickwand-dev pkg-config build-essential -y - mkdir /usr/local/lsws/cyberpanel-tmp - cd /usr/local/lsws/cyberpanel-tmp - wget https://pecl.php.net/get/timezonedb-2019.3.tgz - tar xzvf timezonedb-2019.3.tgz - cd timezonedb-2019.3 - fi - /usr/local/lsws/${version}/bin/phpize - ./configure --with-php-config=/usr/local/lsws/${version}/bin/php-config${version2} - make - make install - echo "extension=timezonedb.so" > /usr/local/lsws/${version}/etc/php/${version2}/mods-available/20-timezone.ini - make clean - fi -done - -rm -rf /etc/profile.d/cyberpanel* -curl --silent -o /etc/profile.d/cyberpanel.sh https://cyberpanel.sh/?banner 2>/dev/null -chmod +x /etc/profile.d/cyberpanel.sh -RAM2=$(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') -DISK2=$(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}') -ELAPSED="$(($SECONDS / 3600)) hrs $((($SECONDS / 60) % 60)) min $(($SECONDS % 60)) sec" -MYSQLPASSWD=$(cat /etc/cyberpanel/mysqlPassword) -echo "$ADMIN_PASS" > /etc/cyberpanel/adminPass -/usr/local/CyberPanel/bin/python2 /usr/local/CyberCP/plogical/adminPass.py --password $ADMIN_PASS -systemctl restart lscpd -systemctl restart lsws -echo "/usr/local/CyberPanel/bin/python2 /usr/local/CyberCP/plogical/adminPass.py --password \$@" > /usr/bin/adminPass -echo "systemctl restart lscpd" >> /usr/bin/adminPass -chmod +x /usr/bin/adminPass -if [[ $VERSION = "OLS" ]] ; then - WORD="OpenLiteSpeed" -# sed -i 's|maxConnections 10000|maxConnections 100000|g' /usr/local/lsws/conf/httpd_config.conf -# OLS_LATEST=$(curl https://openlitespeed.org/packages/release) -# wget https://openlitespeed.org/packages/openlitespeed-$OLS_LATEST.tgz -# tar xzvf openlitespeed-$OLS_LATEST.tgz -# cd openlitespeed -# ./install.sh - /usr/local/lsws/bin/lswsctrl stop - /usr/local/lsws/bin/lswsctrl start -# rm -f openlitespeed-$OLS_LATEST.tgz -# rm -rf openlitespeed -# cd .. -fi -if [[ $VERSION = "ENT" ]] ; then - WORD="LiteSpeed Enterprise" - if [[ $SERVER_COUNTRY != "CN" ]] ; then - /usr/local/lsws/admin/misc/lsup.sh -f -v $LSWS_STABLE_VER - fi -fi - -systemctl status lsws 2>&1>/dev/null -if [[ $? == "0" ]] ; then - echo "LSWS service is running..." -else - systemctl stop lsws - systemctl start lsws -fi - -clear -echo "###################################################################" -echo " CyberPanel Successfully Installed " -echo " " -echo " Current Disk usage : $DISK2 " -echo " " -echo " Current RAM usage : $RAM2 " -echo " " -echo " Installation time : $ELAPSED " -echo " " -echo " Visit: https://$SERVER_IP:8090 " -echo " Panel username: admin " -echo " Panel password: $ADMIN_PASS " -#echo " Mysql username: root " -#echo " Mysql password: $MYSQLPASSWD " -echo " " -echo " Please change your default admin password " -echo " If you need to reset your panel password, please run: " -echo " adminPass YOUR_NEW_PASSWORD " -echo " " -echo " If you change mysql password, please modify file in " -echo -e " \e[31m/etc/cyberpanel/mysqlPassword\e[39m with new password as well " -echo " " -echo " Website : https://www.cyberpanel.net " -echo " Forums : https://forums.cyberpanel.net " -echo " Wikipage: https://docs.cyberpanel.net " -echo " " -echo -e " Enjoy your accelerated Internet by " -echo -e " CyberPanel & $WORD " -echo "###################################################################" -if [[ $PROVIDER != "undefined" ]] ; then - echo -e "\033[0;32m$PROVIDER\033[39m detected..." - echo -e "This provider has a \e[31mnetwork-level firewall\033[39m" -else - echo -e "If your provider has a \e[31mnetwork-level firewall\033[39m" -fi - echo -e "Please make sure you have opened following port for both in/out:" - echo -e "\033[0;32mTCP: 8090\033[39m for CyberPanel" - echo -e "\033[0;32mTCP: 80\033[39m, \033[0;32mTCP: 443\033[39m and \033[0;32mUDP: 443\033[39m for webserver" - echo -e "\033[0;32mTCP: 21\033[39m and \033[0;32mTCP: 40110-40210\033[39m for FTP" - echo -e "\033[0;32mTCP: 25\033[39m, \033[0;32mTCP: 587\033[39m, \033[0;32mTCP: 465\033[39m, \033[0;32mTCP: 110\033[39m, \033[0;32mTCP: 143\033[39m and \033[0;32mTCP: 993\033[39m for mail service" - echo -e "\033[0;32mTCP: 53\033[39m and \033[0;32mUDP: 53\033[39m for DNS service" -if [[ $SERVER_COUNTRY = CN ]] ; then - if [[ $PROVIDER == "Tencent Cloud" ]] ; then - if [[ $SERVER_OS == "Ubuntu" ]] ; then - rm -f /etc/apt/sources.list - mv /etc/apt/sources.list-backup /etc/apt/sources.list -echo > "nameserver 127.0.0.53 -options edns0" /run/systemd/resolve/stub-resolv.conf -echo > "nameserver 127.0.0.53 -options edns0" /etc/resolv.conf - apt update -#revert the previous change on tencent cloud repo. - fi - fi - if [[ $VERSION = "ENT" ]] ; then - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|https://cyberpanel.sh/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|g' /usr/local/CyberCP/install/installCyberPanel.py - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.8-ent-x86_64-linux.tar.gz|https://cyberpanel.sh/packages/5.0/lsws-5.3.8-ent-x86_64-linux.tar.gz|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.8-ent-x86_64-linux.tar.gz|https://'$DOWNLOAD_SERVER'/litespeed/lsws-'$LSWS_STABLE_VER'-ent-x86_64-linux.tar.gz|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - echo -e "If you have install LiteSpeed Enterprise, please run \e[31m/usr/local/lsws/admin/misc/lsup.sh\033[39m to update it to latest." - fi -fi - -sed -i 's|lsws-5.3.8|lsws-'$LSWS_STABLE_VER'|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py -sed -i 's|lsws-5.4.2|lsws-'$LSWS_STABLE_VER'|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py -sed -i 's|lsws-5.3.5|lsws-'$LSWS_STABLE_VER'|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - -if [[ $SILENT != "ON" ]] ; then -printf "%s" "Would you like to restart your server now? [y/N]: " -read TMP_YN - -if [[ "$TMP_YN" = "N" ]] || [[ "$TMP_YN" = "n" ]] || [[ -z "$TMP_YN" ]]; then -: -else -reboot -exit -fi - -exit -fi -#replace URL for CN - - - -else -echo "something went wrong..." -exit -fi -} - -argument_mode() { -KEY_SIZE=${#VERSION} -TMP=$(echo $VERSION | cut -c5) -TMP2=$(echo $VERSION | cut -c10) -TMP3=$(echo $VERSION | cut -c15) -if [[ $VERSION == "OLS" || $VERSION == "ols" ]] ; then - VERSION="OLS" - echo -e "\nSet to OpenLiteSpeed..." -elif [[ $VERSION == "Trial" ]] || [[ $VERSION == "TRIAL" ]] || [[ $VERSION == "trial" ]] ; then - VERSION="ENT" - LICENSE_KEY="TRIAL" - echo -e "\nLiteSpeed Enterprise trial license set..." -elif [[ $TMP == "-" ]] && [[ $TMP2 == "-" ]] && [[ $TMP3 == "-" ]] && [[ $KEY_SIZE == "19" ]] ; then - LICENSE_KEY=$VERSION - VERSION="ENT" - echo -e "\nLiteSpeed Enterprise license key set..." -else - echo -e "\nCan not recognize the input value \e[31m$VERSION\e[39m " - echo -e "\nPlease verify the input value..." - echo -e "\nPlease run with \e[31m-h\e[39m or \e[31m--help\e[39m for more detail." - exit -fi - -if [[ $ADMIN_PASS == "d" ]] ; then - ADMIN_PASS="1234567" - echo -e "\nSet to default password..." - echo -e "\nAdmin password will be set to \e[31m$ADMIN_PASS\e[39m" -elif [[ $ADMIN_PASS == "r" ]] ; then - ADMIN_PASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ; echo '') - echo -e "\nSet to random-generated password..." - echo -e "\nAdmin password will be set to \e[31m$ADMIN_PASS\e[39m" - echo $ADMIN_PASS -else - echo -e "\nAdmin password will be set to \e[31m$ADMIN_PASS\e[39m" -fi -} - -if [ $# -eq 0 ] ; then - echo -e "\nInitializing...\n" -else - if [[ $1 == "help" ]] ; then - show_help - exit - elif [[ $1 == "dev" ]] ; then - DEV="ON" - DEV_ARG="ON" - SILENT="OFF" - elif [[ $1 == "default" ]] ; then - echo -e "\nThis will start default installation...\n" - SILENT="ON" - POSTFIX_VARIABLE="ON" - POWERDNS_VARIABLE="ON" - PUREFTPD_VARIABLE="ON" - VERSION="OLS" - ADMIN_PASS="1234567" - MEMCACHED="ON" - REDIS="ON" - else - while [ ! -z "${1}" ]; do - case $1 in - -v | --version) shift - if [ "${1}" = '' ]; then - show_help - exit - else - VERSION="${1}" - SILENT="ON" - fi - ;; - -p | --password) shift - if [[ "${1}" == '' ]]; then - ADMIN_PASS="1234567" - elif [[ "${1}" == 'r' ]] || [[ $1 == 'random' ]] ; then - ADMIN_PASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ; echo '') - else - if [ ${1} -lt 8 ] ; then - echo -e "\nPassword lenth less than 8 digital, please choose a more complicated password.\n" - exit - fi - ADMIN_PASS="${1}" - fi - ;; - -a | --addons) - MEMCACHED="ON" - REDIS="ON" - ;; - -m | --minimal) - echo "minimal installation is still work in progress..." - exit - ;; - -h | --help) - show_help - exit - ;; - *) - echo "unknown argument..." - show_help - exit - ;; - esac - shift - done - fi -fi - - - -SERVER_IP=$(curl --silent --max-time 10 -4 https://cyberpanel.sh/?ip) -if [[ $SERVER_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo -e "Valid IP detected..." -else - echo -e "Can not detect IP, exit..." - exit -fi -SERVER_COUNTRY="unknow" -SERVER_COUNTRY=$(curl --silent --max-time 5 https://cyberpanel.sh/?country) -if [[ ${#SERVER_COUNTRY} == "2" ]] || [[ ${#SERVER_COUNTRY} == "6" ]] ; then - echo -e "\nChecking server..." - else - echo -e "\nChecking server..." - SERVER_COUNTRY="unknow" -fi -#SERVER_COUNTRY="CN" -#test string -if [[ $SERVER_COUNTRY == "CN" ]] ; then -DOWNLOAD_SERVER="cyberpanel.sh" -else -DOWNLOAD_SERVER="cdn.cyberpanel.sh" -fi - -check_OS -check_root -check_panel -check_process -check_provider - - - - - -if [[ $SILENT = "ON" ]] ; then -argument_mode -else -interactive_mode -fi - -SECONDS=0 -install_required - -pip_virtualenv - -system_tweak - -main_install \ No newline at end of file