Files
CyberPanel/install/installCyberPanel.py

671 lines
29 KiB
Python
Raw Permalink Normal View History

2017-10-24 19:16:36 +05:00
import shutil
import subprocess
import os
2019-12-12 13:51:35 +05:00
from mysqlUtilities import mysqlUtilities
import installLog as logging
import randomPassword
import errno
2018-10-31 11:06:24 -04:00
import MySQLdb as mariadb
2019-12-12 13:51:35 +05:00
import install
2020-05-11 01:03:51 +05:00
from os.path import exists
2020-07-05 13:26:46 +05:00
import time
2025-06-28 16:52:23 +05:00
from installHelpers import PackageManager, ServiceManager, ConfigFileHandler, CommandExecutor, PHPInstaller, FileSystemHelper
2017-10-24 19:16:36 +05:00
2021-08-25 14:37:37 +05:00
# distros
centos = 0
ubuntu = 1
cent8 = 2
openeuler = 3
2021-08-25 14:37:37 +05:00
2018-10-26 14:24:28 -04:00
2020-05-11 01:03:51 +05:00
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:
print("Can't find distro release name in " + distro_file + " - fatal error")
else:
logging.InstallLog.writeToFile("Can't find linux release file - fatal error")
print("Can't find linux release file - fatal error")
os._exit(os.EX_UNAVAILABLE)
return release
2017-10-24 19:16:36 +05:00
def FetchCloudLinuxAlmaVersionVersion():
if os.path.exists('/etc/os-release'):
data = open('/etc/os-release', 'r').read()
2024-06-04 00:01:48 +04:00
if (data.find('CloudLinux') > -1 or data.find('cloudlinux') > -1) and (data.find('8.9') > -1 or data.find('Anatoly Levchenko') > -1 or data.find('VERSION="8.') > -1):
return 'cl-89'
elif (data.find('CloudLinux') > -1 or data.find('cloudlinux') > -1) and (data.find('8.8') > -1 or data.find('Anatoly Filipchenko') > -1):
return 'cl-88'
2024-06-04 00:01:48 +04:00
elif (data.find('CloudLinux') > -1 or data.find('cloudlinux') > -1) and (data.find('9.4') > -1 or data.find('VERSION="9.') > -1):
return 'cl-88'
elif (data.find('AlmaLinux') > -1 or data.find('almalinux') > -1) and (data.find('8.9') > -1 or data.find('Midnight Oncilla') > -1 or data.find('VERSION="8.') > -1):
return 'al-88'
elif (data.find('AlmaLinux') > -1 or data.find('almalinux') > -1) and (data.find('8.7') > -1 or data.find('Stone Smilodon') > -1):
return 'al-87'
2024-06-04 00:01:48 +04:00
elif (data.find('AlmaLinux') > -1 or data.find('almalinux') > -1) and (data.find('9.4') > -1 or data.find('9.3') > -1 or data.find('Shamrock Pampas') > -1 or data.find('Seafoam Ocelot') > -1 or data.find('VERSION="9.') > -1):
2024-05-09 12:12:10 +04:00
return 'al-93'
else:
return -1
2021-08-25 14:37:37 +05:00
class InstallCyberPanel:
2017-10-24 19:16:36 +05:00
mysql_Root_password = ""
mysqlPassword = ""
2023-09-19 10:47:27 +05:00
CloudLinux8 = 0
@staticmethod
def ISARM():
try:
command = 'uname -a'
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if 'aarch64' in result.stdout:
return True
else:
return False
except:
return False
2023-09-19 10:47:27 +05:00
@staticmethod
def OSFlags():
if os.path.exists("/etc/redhat-release"):
data = open('/etc/redhat-release', 'r').read()
if data.find('CloudLinux 8') > -1 or data.find('cloudlinux 8') > -1:
InstallCyberPanel.CloudLinux8 = 1
2017-10-24 19:16:36 +05:00
2021-08-25 14:37:37 +05:00
def __init__(self, rootPath, cwd, distro, ent, serial=None, port=None, ftp=None, dns=None, publicip=None,
remotemysql=None, mysqlhost=None, mysqldb=None, mysqluser=None, mysqlpassword=None, mysqlport=None):
2017-10-24 19:16:36 +05:00
self.server_root_path = rootPath
self.cwd = cwd
2018-11-06 00:19:58 +05:00
self.distro = distro
2018-11-10 16:05:40 +05:00
self.ent = ent
self.serial = serial
2019-03-26 16:19:03 +05:00
self.port = port
2019-06-26 03:57:16 +05:00
self.ftp = None
self.dns = dns
2020-02-03 11:45:34 +05:00
self.publicip = publicip
2020-06-26 18:22:20 +05:00
self.remotemysql = remotemysql
self.mysqlhost = mysqlhost
self.mysqluser = mysqluser
self.mysqlpassword = mysqlpassword
self.mysqlport = mysqlport
2020-07-05 14:39:57 +05:00
self.mysqldb = mysqldb
2017-10-24 19:16:36 +05:00
2023-09-19 10:47:27 +05:00
## TURN ON OS FLAGS FOR SPECIFIC NEEDS LATER
InstallCyberPanel.OSFlags()
@staticmethod
2018-11-06 00:19:58 +05:00
def stdOut(message, log=0, exit=0, code=os.EX_OK):
install.preFlightsChecks.stdOut(message, log, exit, code)
2017-10-24 19:16:36 +05:00
def installLiteSpeed(self):
2018-11-10 16:05:40 +05:00
if self.ent == 0:
2025-06-28 16:52:23 +05:00
PackageManager.install_packages('openlitespeed', self.distro, ubuntu, centos, cent8, openeuler,
use_shell=(self.distro == ubuntu))
2019-12-17 21:50:22 +05:00
2018-11-10 16:05:40 +05:00
else:
try:
try:
2025-06-28 16:52:23 +05:00
CommandExecutor.execute('groupadd nobody', self.distro, exit_on_error=False)
except:
pass
2018-11-10 16:05:40 +05:00
try:
2025-06-28 16:52:23 +05:00
CommandExecutor.execute('usermod -a -G nobody nobody', self.distro, exit_on_error=False)
except:
pass
if InstallCyberPanel.ISARM():
command = 'wget https://www.litespeedtech.com/packages/6.0/lsws-6.2-ent-aarch64-linux.tar.gz'
else:
command = 'wget https://www.litespeedtech.com/packages/6.0/lsws-6.2-ent-x86_64-linux.tar.gz'
2025-06-28 16:52:23 +05:00
CommandExecutor.execute(command, self.distro)
if InstallCyberPanel.ISARM():
command = 'tar zxf lsws-6.2-ent-aarch64-linux.tar.gz'
else:
command = 'tar zxf lsws-6.2-ent-x86_64-linux.tar.gz'
2025-06-28 16:52:23 +05:00
CommandExecutor.execute(command, self.distro)
2021-05-22 15:54:12 +05:00
if str.lower(self.serial) == 'trial':
command = 'wget -q --output-document=lsws-6.2/trial.key http://license.litespeedtech.com/reseller/trial.key'
2021-05-22 17:52:11 +05:00
if self.serial == '1111-2222-3333-4444':
command = 'wget -q --output-document=/root/cyberpanel/install/lsws-6.2/trial.key http://license.litespeedtech.com/reseller/trial.key'
2025-06-28 16:52:23 +05:00
CommandExecutor.execute(command, self.distro)
2021-05-22 15:54:12 +05:00
else:
writeSerial = open('lsws-6.2/serial.no', 'w')
2021-05-22 15:54:12 +05:00
writeSerial.writelines(self.serial)
writeSerial.close()
shutil.copy('litespeed/install.sh', 'lsws-6.2/')
shutil.copy('litespeed/functions.sh', 'lsws-6.2/')
os.chdir('lsws-6.2')
2025-06-28 16:52:23 +05:00
CommandExecutor.execute('chmod +x install.sh', self.distro)
CommandExecutor.execute('chmod +x functions.sh', self.distro)
CommandExecutor.execute('./install.sh', self.distro)
2018-11-10 16:05:40 +05:00
os.chdir(self.cwd)
confPath = '/usr/local/lsws/conf/'
shutil.copy('litespeed/httpd_config.xml', confPath)
shutil.copy('litespeed/modsec.conf', confPath)
shutil.copy('litespeed/httpd.conf', confPath)
2017-10-24 19:16:36 +05:00
2025-06-28 16:52:23 +05:00
CommandExecutor.execute('chown -R lsadm:lsadm ' + confPath, self.distro, exit_on_error=False)
2017-10-24 19:16:36 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installLiteSpeed]")
2018-11-10 16:05:40 +05:00
return 0
return 1
2017-10-24 19:16:36 +05:00
def reStartLiteSpeed(self):
2021-08-25 14:37:37 +05:00
command = self.server_root_path + "bin/lswsctrl restart"
2025-06-28 16:52:23 +05:00
CommandExecutor.execute(command, self.distro, exit_on_error=False)
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
def fix_ols_configs(self):
try:
InstallCyberPanel.stdOut("Fixing OpenLiteSpeed configurations!", 1)
2017-12-09 22:30:10 +05:00
## remove example virtual host
2025-06-28 16:52:23 +05:00
config_path = self.server_root_path + "conf/httpd_config.conf"
data = open(config_path, 'r').readlines()
2017-12-09 22:30:10 +05:00
2025-06-28 16:52:23 +05:00
with open(config_path, 'w') as writeDataToFile:
for items in data:
if not (items.find("map") > -1 and items.find("Example") > -1):
writeDataToFile.writelines(items)
2017-12-09 22:30:10 +05:00
InstallCyberPanel.stdOut("OpenLiteSpeed Configurations fixed!", 1)
2019-12-10 15:09:10 +05:00
except IOError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [fix_ols_configs]")
2017-12-09 22:30:10 +05:00
return 0
return self.reStartLiteSpeed()
2017-10-24 19:16:36 +05:00
def changePortTo80(self):
try:
InstallCyberPanel.stdOut("Changing default port to 80..", 1)
2025-06-28 16:52:23 +05:00
config_path = self.server_root_path + "conf/httpd_config.conf"
replacements = [("*:8088", "*:80")]
# Use sed for simple replacement
ConfigFileHandler.sed_replace(config_path, "*:8088", "*:80", self.distro)
2017-10-24 19:16:36 +05:00
InstallCyberPanel.stdOut("Default port is now 80 for OpenLiteSpeed!", 1)
2019-12-10 15:09:10 +05:00
except IOError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [changePortTo80]")
2017-10-24 19:16:36 +05:00
return 0
return self.reStartLiteSpeed()
def installAllPHPVersions(self):
if self.distro == ubuntu:
2025-06-28 16:52:23 +05:00
PHPInstaller.install_php_ubuntu()
else:
PHPInstaller.install_php_centos(self.distro, centos, cent8, openeuler)
2025-06-28 16:52:23 +05:00
InstallCyberPanel.stdOut("LiteSpeed PHPs successfully installed!", 1)
2020-04-13 08:46:08 +05:00
def installMySQL(self, mysql):
2017-10-24 19:16:36 +05:00
2020-07-05 18:47:36 +05:00
############## Install mariadb ######################
2017-10-24 19:16:36 +05:00
2020-07-05 18:47:36 +05:00
if self.distro == ubuntu:
2025-06-28 16:52:23 +05:00
PackageManager.install_packages('software-properties-common', self.distro, ubuntu, centos, cent8, openeuler, use_shell=True)
PackageManager.install_packages('apt-transport-https curl', self.distro, ubuntu, centos, cent8, openeuler, use_shell=True)
FileSystemHelper.create_directory('/etc/apt/keyrings')
CommandExecutor.execute("curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'", self.distro)
RepoPath = '/etc/apt/sources.list.d/mariadb.sources'
2025-06-28 16:52:23 +05:00
# Determine the Ubuntu codename for MariaDB repo
ubuntu_version = get_Ubuntu_release()
if ubuntu_version >= 24.04:
suite = 'noble' # Ubuntu 24.04 LTS
elif ubuntu_version >= 22.04:
suite = 'jammy' # Ubuntu 22.04 LTS
else:
suite = 'focal' # Ubuntu 20.04 LTS and earlier
RepoContent = f"""
# MariaDB 10.11 repository list - created 2023-12-11 07:53 UTC
# https://mariadb.org/download/
X-Repolib-Name: MariaDB
Types: deb
# deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# URIs: https://deb.mariadb.org/10.11/ubuntu
URIs: https://mirrors.gigenet.com/mariadb/repo/10.11/ubuntu
2025-06-28 16:52:23 +05:00
Suites: {suite}
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
"""
if get_Ubuntu_release() > 21.00:
2025-06-28 16:52:23 +05:00
# Use the MariaDB repository setup script which automatically handles different Ubuntu versions
2024-02-07 21:14:22 +05:00
command = 'curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.11'
2025-06-28 16:52:23 +05:00
CommandExecutor.execute(command, self.distro, exit_code=os.EX_OSERR)
2024-02-07 21:14:22 +05:00
# WriteToFile = open(RepoPath, 'w')
# WriteToFile.write(RepoContent)
# WriteToFile.close()
command = 'DEBIAN_FRONTEND=noninteractive apt-get update -y'
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR, True)
command = "DEBIAN_FRONTEND=noninteractive apt-get install mariadb-server -y"
2020-07-05 18:47:36 +05:00
elif self.distro == centos:
RepoPath = '/etc/yum.repos.d/mariadb.repo'
RepoContent = f"""
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.11/rhel8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
"""
WriteToFile = open(RepoPath, 'w')
WriteToFile.write(RepoContent)
WriteToFile.close()
command = 'dnf install mariadb-server -y'
elif self.distro == cent8 or self.distro == openeuler:
clAPVersion = FetchCloudLinuxAlmaVersionVersion()
type = clAPVersion.split('-')[0]
version = int(clAPVersion.split('-')[1])
if type == 'cl' and version >= 88:
2025-06-28 16:52:23 +05:00
CommandExecutor.execute('yum remove db-governor db-governor-mysql -y', self.distro)
PackageManager.install_packages('governor-mysql', self.distro, ubuntu, centos, cent8, openeuler)
CommandExecutor.execute('/usr/share/lve/dbgovernor/mysqlgovernor.py --mysql-version=mariadb106', self.distro)
command = '/usr/share/lve/dbgovernor/mysqlgovernor.py --install --yes'
else:
2025-06-28 16:52:23 +05:00
CommandExecutor.execute('curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.11', self.distro)
CommandExecutor.execute('yum remove mariadb* -y', self.distro)
CommandExecutor.execute('sudo dnf -qy module disable mariadb', self.distro)
CommandExecutor.execute('sudo dnf module reset mariadb -y', self.distro)
command = 'dnf install MariaDB-server MariaDB-client MariaDB-backup -y'
2019-11-13 16:13:52 +05:00
2022-11-12 16:00:41 +05:00
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR, True)
2019-11-13 16:13:52 +05:00
2020-07-05 18:47:36 +05:00
############## Start mariadb ######################
2017-10-24 19:16:36 +05:00
2020-07-05 18:47:36 +05:00
self.startMariaDB()
2017-10-24 19:16:36 +05:00
def changeMYSQLRootPassword(self):
2020-06-26 18:22:20 +05:00
if self.remotemysql == 'OFF':
if self.distro == ubuntu:
2021-08-25 14:37:37 +05:00
passwordCMD = "use mysql;DROP DATABASE IF EXISTS test;DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%%';GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '%s';UPDATE user SET plugin='' WHERE User='root';flush privileges;" % (
InstallCyberPanel.mysql_Root_password)
2020-06-26 18:22:20 +05:00
else:
2021-08-25 14:37:37 +05:00
passwordCMD = "use mysql;DROP DATABASE IF EXISTS test;DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%%';GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '%s';flush privileges;" % (
InstallCyberPanel.mysql_Root_password)
2018-12-13 04:23:08 +05:00
command = 'mariadb -u root -e "' + passwordCMD + '"'
2019-11-13 16:13:52 +05:00
2020-06-26 18:22:20 +05:00
install.preFlightsChecks.call(command, self.distro, command, command, 0, 0, os.EX_OSERR)
def startMariaDB(self):
2020-07-05 16:15:08 +05:00
if self.remotemysql == 'OFF':
############## Start mariadb ######################
2025-06-28 16:52:23 +05:00
ServiceManager.start_service('mariadb', self.distro)
2020-07-05 16:15:08 +05:00
############## Enable mariadb at system startup ######################
if os.path.exists('/etc/systemd/system/mysqld.service'):
os.remove('/etc/systemd/system/mysqld.service')
if os.path.exists('/etc/systemd/system/mariadb.service'):
os.remove('/etc/systemd/system/mariadb.service')
2018-12-17 18:46:34 +05:00
2025-06-28 16:52:23 +05:00
ServiceManager.enable_service('mariadb', self.distro)
2017-10-24 19:16:36 +05:00
2018-10-31 11:06:24 -04:00
def fixMariaDB(self):
self.stdOut("Setup MariaDB so it can support Cyberpanel's needs")
2018-10-31 11:37:42 -04:00
conn = mariadb.connect(user='root', passwd=self.mysql_Root_password)
cursor = conn.cursor()
cursor.execute('set global innodb_file_per_table = on;')
2020-05-11 13:56:51 +05:00
try:
cursor.execute('set global innodb_file_format = Barracuda;')
cursor.execute('set global innodb_large_prefix = on;')
except BaseException as msg:
self.stdOut('%s. [ERROR:335]' % (str(msg)))
2018-10-31 11:37:42 -04:00
cursor.close()
conn.close()
2018-10-31 11:06:24 -04:00
try:
fileName = '/etc/mysql/mariadb.conf.d/50-server.cnf'
2025-06-28 16:52:23 +05:00
ConfigFileHandler.sed_replace(fileName, 'utf8mb4', 'utf8', self.distro)
2018-10-31 11:06:24 -04:00
except IOError as err:
self.stdOut("[ERROR] Error in setting: " + fileName + ": " + str(err), 1, 1, os.EX_OSERR)
2018-10-31 11:06:24 -04:00
2025-06-28 16:52:23 +05:00
ServiceManager.restart_service('mariadb', self.distro)
2018-10-31 11:06:24 -04:00
self.stdOut("MariaDB is now setup so it can support Cyberpanel's needs")
2017-10-24 19:16:36 +05:00
def installPureFTPD(self):
if self.distro == ubuntu:
2020-04-17 23:08:14 +05:00
command = 'DEBIAN_FRONTEND=noninteractive apt install pure-ftpd-mysql -y'
os.system(command)
2020-05-11 01:03:51 +05:00
if get_Ubuntu_release() == 18.10:
2025-06-28 16:52:23 +05:00
urls = [
'https://rep.cyberpanel.net/pure-ftpd-common_1.0.47-3_all.deb',
'https://rep.cyberpanel.net/pure-ftpd-mysql_1.0.47-3_amd64.deb'
]
packages = [
'pure-ftpd-common_1.0.47-3_all.deb',
'pure-ftpd-mysql_1.0.47-3_amd64.deb'
]
for url in urls:
CommandExecutor.execute(f'wget {url}', self.distro)
for package in packages:
CommandExecutor.execute(f'dpkg --install --force-confold {package}', self.distro)
else:
PackageManager.install_packages('pure-ftpd', self.distro, ubuntu, centos, cent8, openeuler)
2020-04-17 05:53:06 +05:00
####### Install pureftpd to system startup
2025-06-28 16:52:23 +05:00
service_name = install.preFlightsChecks.pureFTPDServiceName(self.distro)
ServiceManager.enable_service(service_name, self.distro)
2017-10-24 19:16:36 +05:00
###### FTP Groups and user settings settings
2025-06-28 16:52:23 +05:00
FileSystemHelper.create_user_and_group('ftpuser', 'ftpgroup', 2001, 2001,
shell='/bin/false', home='/bin/null', distro=self.distro)
2021-08-25 14:37:37 +05:00
2017-10-24 19:16:36 +05:00
def startPureFTPD(self):
############## Start pureftpd ######################
2025-06-28 16:52:23 +05:00
service_name = 'pure-ftpd-mysql' if self.distro == ubuntu else 'pure-ftpd'
ServiceManager.start_service(service_name, self.distro)
2017-10-24 19:16:36 +05:00
def installPureFTPDConfigurations(self, mysql):
2017-10-24 19:16:36 +05:00
try:
2017-12-09 22:30:10 +05:00
## setup ssl for ftp
InstallCyberPanel.stdOut("Configuring PureFTPD..", 1)
2025-06-28 16:52:23 +05:00
FileSystemHelper.create_directory("/etc/ssl/private")
2017-12-09 22:30:10 +05:00
if (self.distro == centos or self.distro == cent8 or self.distro == openeuler) or (
2021-08-25 14:37:37 +05:00
self.distro == ubuntu and get_Ubuntu_release() == 18.14):
2020-05-13 21:42:16 +05:00
command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem'
else:
2024-05-10 16:43:15 +04:00
command = 'openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -subj "/C=US/ST=Denial/L=Sprinal-ield/O=Dis/CN=www.example.com" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem'
2017-12-09 22:30:10 +05:00
2025-06-28 16:52:23 +05:00
CommandExecutor.execute(command, self.distro, exit_on_error=False)
2017-12-09 22:30:10 +05:00
2017-10-24 19:16:36 +05:00
os.chdir(self.cwd)
ftpdPath = "/etc/pure-ftpd"
if os.path.exists(ftpdPath):
shutil.rmtree(ftpdPath)
if mysql == 'Two':
shutil.copytree("pure-ftpd", ftpdPath)
else:
shutil.copytree("pure-ftpd-one", ftpdPath)
2017-10-24 19:16:36 +05:00
else:
if mysql == 'Two':
2021-08-25 14:37:37 +05:00
shutil.copytree("pure-ftpd", ftpdPath)
else:
shutil.copytree("pure-ftpd-one", ftpdPath)
2017-10-24 19:16:36 +05:00
if self.distro == ubuntu:
2025-06-28 16:52:23 +05:00
for dir_path in ['/etc/pure-ftpd/conf', '/etc/pure-ftpd/auth', '/etc/pure-ftpd/db']:
FileSystemHelper.create_directory(dir_path)
2017-10-24 19:16:36 +05:00
2025-06-28 16:52:23 +05:00
# Update MySQL password in pureftpd config
pureftpd_config = ftpdPath + "/pureftpd-mysql.conf"
replacements = [("MYSQLPassword", "MYSQLPassword " + InstallCyberPanel.mysqlPassword)]
ConfigFileHandler.replace_in_file(pureftpd_config, replacements)
2017-10-24 19:16:36 +05:00
2020-07-06 11:28:41 +05:00
ftpConfPath = '/etc/pure-ftpd/pureftpd-mysql.conf'
if self.remotemysql == 'ON':
2025-06-28 16:52:23 +05:00
ConfigFileHandler.sed_replace(ftpConfPath, 'localhost', self.mysqlhost, self.distro)
ConfigFileHandler.sed_replace(ftpConfPath, '3306', self.mysqlport, self.distro)
ConfigFileHandler.sed_replace(ftpConfPath, 'MYSQLSocket /var/lib/mysql/mysql.sock', '', self.distro)
2020-07-06 11:28:41 +05:00
2018-11-08 12:11:42 +05:00
if self.distro == ubuntu:
2020-04-16 18:56:13 +05:00
2018-11-08 12:11:42 +05:00
if os.path.exists('/etc/pure-ftpd/db/mysql.conf'):
os.remove('/etc/pure-ftpd/db/mysql.conf')
2021-08-25 14:37:37 +05:00
shutil.copy(ftpdPath + "/pureftpd-mysql.conf", '/etc/pure-ftpd/db/mysql.conf')
2018-11-08 12:11:42 +05:00
else:
shutil.copy(ftpdPath + "/pureftpd-mysql.conf", '/etc/pure-ftpd/db/mysql.conf')
2025-06-28 16:52:23 +05:00
# Write configuration values to files
config_values = [
('1', '/etc/pure-ftpd/conf/TLS'),
(str(self.publicip), '/etc/pure-ftpd/conf/ForcePassiveIP'),
('40110 40210', '/etc/pure-ftpd/conf/PassivePortRange'),
('no', '/etc/pure-ftpd/conf/UnixAuthentication'),
('/etc/pure-ftpd/db/mysql.conf', '/etc/pure-ftpd/conf/MySQLConfigFile')
]
for value, filepath in config_values:
with open(filepath, 'w') as f:
f.write(value)
2018-11-08 12:11:42 +05:00
2025-06-28 16:52:23 +05:00
CommandExecutor.execute('ln -s /etc/pure-ftpd/conf/MySQLConfigFile /etc/pure-ftpd/auth/30mysql', self.distro)
CommandExecutor.execute('ln -s /etc/pure-ftpd/conf/UnixAuthentication /etc/pure-ftpd/auth/65unix', self.distro)
ServiceManager.restart_service('pure-ftpd-mysql.service', self.distro)
2023-04-15 14:42:35 +05:00
2023-04-15 14:42:35 +05:00
2025-06-28 16:52:23 +05:00
ubuntu_version = get_Ubuntu_release()
if ubuntu_version > 21.00:
### change mysql md5 to crypt for Ubuntu 22.04+ including 24.04
ConfigFileHandler.sed_replace('/etc/pure-ftpd/db/mysql.conf', 'MYSQLCrypt md5', 'MYSQLCrypt crypt', self.distro)
ServiceManager.restart_service('pure-ftpd-mysql.service', self.distro)
else:
try:
clAPVersion = FetchCloudLinuxAlmaVersionVersion()
type = clAPVersion.split('-')[0]
version = int(clAPVersion.split('-')[1])
if type == 'al' and version >= 90:
2025-06-28 16:52:23 +05:00
ConfigFileHandler.sed_replace('/etc/pure-ftpd/pureftpd-mysql.conf', 'MYSQLCrypt md5', 'MYSQLCrypt crypt', self.distro)
except:
pass
2023-04-15 14:44:42 +05:00
2023-04-15 14:42:35 +05:00
InstallCyberPanel.stdOut("PureFTPD configured!", 1)
2019-12-10 15:09:10 +05:00
except IOError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installPureFTPDConfigurations]")
2017-10-24 19:16:36 +05:00
return 0
def installPowerDNS(self):
try:
if self.distro == ubuntu or self.distro == cent8 or self.distro == openeuler:
2025-06-28 16:52:23 +05:00
ServiceManager.stop_service('systemd-resolved', self.distro, exit_on_error=False)
ServiceManager.disable_service('systemd-resolved.service', self.distro, exit_on_error=False)
2019-11-13 16:13:52 +05:00
try:
os.rename('/etc/resolv.conf', 'etc/resolved.conf')
except OSError as e:
if e.errno != errno.EEXIST and e.errno != errno.ENOENT:
InstallCyberPanel.stdOut("[ERROR] Unable to rename /etc/resolv.conf to install PowerDNS: " +
str(e), 1, 1, os.EX_OSERR)
try:
os.remove('/etc/resolv.conf')
except OSError as e1:
2021-08-25 14:37:37 +05:00
InstallCyberPanel.stdOut(
"[ERROR] Unable to remove existing /etc/resolv.conf to install PowerDNS: " +
str(e1), 1, 1, os.EX_OSERR)
2019-11-13 16:13:52 +05:00
# try:
# f = open('/etc/resolv.conf', 'a')
# f.write('nameserver 8.8.8.8')
# f.close()
# except IOError as e:
# InstallCyberPanel.stdOut("[ERROR] Unable to create /etc/resolv.conf: " + str(e) +
# ". This may need to be fixed manually as 'echo \"nameserver 8.8.8.8\"> "
# "/etc/resolv.conf'", 1, 1, os.EX_OSERR)
if self.distro == ubuntu:
command = "DEBIAN_FRONTEND=noninteractive apt-get -y install pdns-server pdns-backend-mysql"
2018-12-20 16:18:16 +05:00
os.system(command)
return 1
else:
2025-06-28 16:52:23 +05:00
PackageManager.install_packages('pdns pdns-backend-mysql', self.distro, ubuntu, centos, cent8, openeuler)
2019-11-13 16:13:52 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [powerDNS]")
2017-10-24 19:16:36 +05:00
2018-11-06 00:19:58 +05:00
def installPowerDNSConfigurations(self, mysqlPassword, mysql):
2017-10-24 19:16:36 +05:00
try:
InstallCyberPanel.stdOut("Configuring PowerDNS..", 1)
2017-10-24 19:16:36 +05:00
os.chdir(self.cwd)
if self.distro == centos or self.distro == cent8 or self.distro == openeuler:
dnsPath = "/etc/pdns/pdns.conf"
else:
dnsPath = "/etc/powerdns/pdns.conf"
2017-10-24 19:16:36 +05:00
if os.path.exists(dnsPath):
os.remove(dnsPath)
if mysql == 'Two':
shutil.copy("dns/pdns.conf", dnsPath)
else:
shutil.copy("dns-one/pdns.conf", dnsPath)
2017-10-24 19:16:36 +05:00
else:
if mysql == 'Two':
shutil.copy("dns/pdns.conf", dnsPath)
else:
shutil.copy("dns-one/pdns.conf", dnsPath)
2017-10-24 19:16:36 +05:00
2025-06-28 16:52:23 +05:00
# Update MySQL password in PowerDNS config
replacements = [("gmysql-password", "gmysql-password=" + mysqlPassword)]
ConfigFileHandler.replace_in_file(dnsPath, replacements)
2017-10-24 19:16:36 +05:00
2020-07-06 11:28:41 +05:00
if self.remotemysql == 'ON':
2025-06-28 16:52:23 +05:00
ConfigFileHandler.sed_replace(dnsPath, 'gmysql-host=localhost', f'gmysql-host={self.mysqlhost}', self.distro)
ConfigFileHandler.sed_replace(dnsPath, 'gmysql-port=3306', f'gmysql-port={self.mysqlport}', self.distro)
2020-07-06 11:28:41 +05:00
InstallCyberPanel.stdOut("PowerDNS configured!", 1)
2019-12-10 15:09:10 +05:00
except IOError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installPowerDNSConfigurations]")
2017-10-24 19:16:36 +05:00
return 0
return 1
def startPowerDNS(self):
############## Start PowerDNS ######################
2025-06-28 16:52:23 +05:00
ServiceManager.enable_service('pdns', self.distro)
ServiceManager.start_service('pdns', self.distro)
2017-10-24 19:16:36 +05:00
2021-08-25 14:37:37 +05:00
def Main(cwd, mysql, distro, ent, serial=None, port="8090", ftp=None, dns=None, publicip=None, remotemysql=None,
mysqlhost=None, mysqldb=None, mysqluser=None, mysqlpassword=None, mysqlport=None):
2018-11-06 00:19:58 +05:00
InstallCyberPanel.mysqlPassword = randomPassword.generate_pass()
2017-10-24 19:16:36 +05:00
InstallCyberPanel.mysql_Root_password = randomPassword.generate_pass()
2018-10-30 15:51:22 -04:00
file_name = '/etc/cyberpanel/mysqlPassword'
2020-06-26 18:22:20 +05:00
if remotemysql == 'OFF':
if os.access(file_name, os.F_OK):
password = open(file_name, 'r')
InstallCyberPanel.mysql_Root_password = password.readline()
password.close()
else:
password = open(file_name, "w")
password.writelines(InstallCyberPanel.mysql_Root_password)
password.close()
else:
2021-08-25 14:37:37 +05:00
mysqlData = {'remotemysql': remotemysql, 'mysqlhost': mysqlhost, 'mysqldb': mysqldb, 'mysqluser': mysqluser,
'mysqlpassword': mysqlpassword, 'mysqlport': mysqlport}
2020-06-26 18:22:20 +05:00
from json import dumps
writeToFile = open(file_name, 'w')
writeToFile.write(dumps(mysqlData))
writeToFile.close()
2020-07-05 13:26:46 +05:00
if install.preFlightsChecks.debug:
print(open(file_name, 'r').read())
time.sleep(10)
2020-06-26 18:22:20 +05:00
try:
2025-06-28 16:52:23 +05:00
CommandExecutor.execute(f'chmod 640 {file_name}', distro, '[chmod]', exit_on_error=False)
CommandExecutor.execute(f'chown root:cyberpanel {file_name}', distro, '[chmod]', exit_on_error=False)
2020-06-26 18:22:20 +05:00
except:
pass
2017-10-24 19:16:36 +05:00
2018-10-30 15:51:22 -04:00
if distro == centos:
InstallCyberPanel.mysqlPassword = randomPassword.generate_pass()
else:
InstallCyberPanel.mysqlPassword = InstallCyberPanel.mysql_Root_password
2021-08-25 14:37:37 +05:00
installer = InstallCyberPanel("/usr/local/lsws/", cwd, distro, ent, serial, port, ftp, dns, publicip, remotemysql,
mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport)
2017-10-24 19:16:36 +05:00
2021-01-19 15:24:51 +05:00
logging.InstallLog.writeToFile('Installing LiteSpeed Web server,40')
2017-10-24 19:16:36 +05:00
installer.installLiteSpeed()
2018-11-10 16:05:40 +05:00
if ent == 0:
installer.changePortTo80()
2021-01-19 15:24:51 +05:00
logging.InstallLog.writeToFile('Installing Optimized PHPs..,50')
2017-10-24 19:16:36 +05:00
installer.installAllPHPVersions()
2018-11-10 16:05:40 +05:00
if ent == 0:
installer.fix_ols_configs()
2017-12-09 22:30:10 +05:00
2021-01-19 15:24:51 +05:00
logging.InstallLog.writeToFile('Installing MySQL,60')
installer.installMySQL(mysql)
2018-10-31 11:53:03 -04:00
installer.changeMYSQLRootPassword()
2020-06-26 12:32:02 +05:00
2017-10-24 19:16:36 +05:00
installer.startMariaDB()
2020-06-26 18:22:20 +05:00
if remotemysql == 'OFF':
if distro == ubuntu:
installer.fixMariaDB()
2017-10-24 19:16:36 +05:00
2021-08-25 14:37:37 +05:00
mysqlUtilities.createDatabase("cyberpanel", "cyberpanel", InstallCyberPanel.mysqlPassword, publicip)
2018-11-06 00:19:58 +05:00
2021-10-16 00:28:44 +06:00
if ftp is None:
2019-06-26 03:57:16 +05:00
installer.installPureFTPD()
installer.installPureFTPDConfigurations(mysql)
installer.startPureFTPD()
else:
2020-01-03 14:45:37 +05:00
if ftp == 'ON':
2019-06-26 03:57:16 +05:00
installer.installPureFTPD()
installer.installPureFTPDConfigurations(mysql)
installer.startPureFTPD()
2021-10-16 00:28:44 +06:00
if dns is None:
2019-06-26 03:57:16 +05:00
installer.installPowerDNS()
installer.installPowerDNSConfigurations(InstallCyberPanel.mysqlPassword, mysql)
installer.startPowerDNS()
else:
2020-01-03 14:45:37 +05:00
if dns == 'ON':
2019-06-26 03:57:16 +05:00
installer.installPowerDNS()
installer.installPowerDNSConfigurations(InstallCyberPanel.mysqlPassword, mysql)
2021-10-16 00:28:44 +06:00
installer.startPowerDNS()