refactor installation

This commit is contained in:
Usman Nasir
2019-11-13 16:13:52 +05:00
parent d5f7918de2
commit aa327d0e4d
2 changed files with 293 additions and 1528 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -39,36 +39,26 @@ class InstallCyberPanel:
else:
command = 'yum install -y openlitespeed'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'Install LiteSpeed.',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
else:
try:
try:
command = 'groupadd nobody'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'groupadd nobody',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except:
pass
try:
command = 'usermod -a -G nobody nobody'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'groupadd nobody',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except:
pass
command = 'wget https://www.litespeedtech.com/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'Install LiteSpeed Webserver Enterprise.',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = 'tar zxf lsws-5.3.5-ent-x86_64-linux.tar.gz'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'Install LiteSpeed Webserver Enterprise.',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
writeSerial = open('lsws-5.3.5/serial.no', 'w')
writeSerial.writelines(self.serial)
@@ -80,19 +70,13 @@ class InstallCyberPanel:
os.chdir('lsws-5.3.5')
command = 'chmod +x install.sh'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'Install LiteSpeed Webserver Enterprise.',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = 'chmod +x functions.sh'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'Install LiteSpeed Webserver Enterprise.',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = './install.sh'
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'Install LiteSpeed Webserver Enterprise.',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
os.chdir(self.cwd)
confPath = '/usr/local/lsws/conf/'
@@ -101,9 +85,7 @@ class InstallCyberPanel:
shutil.copy('litespeed/httpd.conf', confPath)
command = 'chown -R lsadm:lsadm ' + confPath
install.preFlightsChecks.call(command, self.distro, '[installLiteSpeed]',
'Install LiteSpeed Webserver Enterprise.',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installLiteSpeed]")
@@ -116,9 +98,7 @@ class InstallCyberPanel:
def reStartLiteSpeed(self):
command = self.server_root_path+"bin/lswsctrl restart"
install.preFlightsChecks.call(command, self.distro, '[reStartLiteSpeed]',
'Restart LiteSpeed WebServer',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def fix_ols_configs(self):
try:
@@ -170,51 +150,6 @@ class InstallCyberPanel:
return self.reStartLiteSpeed()
def setupFileManager(self):
if self.ent == 0:
try:
InstallCyberPanel.stdOut("Setting up Filemanager files..", 1)
os.chdir(self.cwd)
fileManagerPath = self.server_root_path+"Example/html/FileManager"
shutil.copytree("FileManager",fileManagerPath)
## remove unnecessary files
fileManagerPath = self.server_root_path + "Example/html/"
shutil.rmtree(fileManagerPath+"protected")
shutil.rmtree(fileManagerPath+"blocked")
os.remove(fileManagerPath+"phpinfo.php")
os.remove(fileManagerPath + "upload.html")
os.remove(fileManagerPath + "upload.php")
InstallCyberPanel.stdOut("Filemanager files are set!", 1)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [setupFileManager]")
else:
try:
InstallCyberPanel.stdOut("Setting up Filemanager files..", 1)
os.chdir(self.cwd)
fileManagerPath = self.server_root_path + "/FileManager"
shutil.copytree("FileManager", fileManagerPath)
## remove unnecessary files
command = 'chmod -R 777 ' + fileManagerPath
install.preFlightsChecks.call(command, self.distro, '[setupFileManager]',
'Change Filemanager permissions.',
1, 0, os.EX_OSERR)
InstallCyberPanel.stdOut("Filemanager files are set!", 1)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [setupFileManager]")
def installAllPHPVersions(self):
if self.distro == ubuntu:
@@ -230,9 +165,7 @@ class InstallCyberPanel:
else:
command = 'yum -y groupinstall lsphp-all'
install.preFlightsChecks.call(command, self.distro, '[installAllPHPVersions]',
'Install PHP ALL',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
InstallCyberPanel.stdOut("LiteSpeed PHPs successfully installed!", 1)
@@ -243,18 +176,15 @@ class InstallCyberPanel:
'lsphp71-recode lsphp71-pspell lsphp71-process lsphp71-pgsql lsphp71-pear lsphp71-pdo lsphp71-opcache ' \
'lsphp71-odbc lsphp71-mysqlnd lsphp71-mcrypt lsphp71-mbstring lsphp71-ldap lsphp71-intl lsphp71-imap ' \
'lsphp71-gmp lsphp71-gd lsphp71-enchant lsphp71-dba lsphp71-common lsphp71-bcmath -y'
install.preFlightsChecks.call(command, self.distro, '[installAllPHPVersions]',
'Install PHP 71',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
## only php 72
command = 'yum install -y lsphp72 lsphp72-json lsphp72-xmlrpc lsphp72-xml lsphp72-tidy lsphp72-soap lsphp72-snmp ' \
'lsphp72-recode lsphp72-pspell lsphp72-process lsphp72-pgsql lsphp72-pear lsphp72-pdo lsphp72-opcache ' \
'lsphp72-odbc lsphp72-mysqlnd lsphp72-mcrypt lsphp72-mbstring lsphp72-ldap lsphp72-intl lsphp72-imap ' \
'lsphp72-gmp lsphp72-gd lsphp72-enchant lsphp72-dba lsphp72-common lsphp72-bcmath'
install.preFlightsChecks.call(command, self.distro, '[installAllPHPVersions]',
'Install PHP 72',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
## only php 72
command = 'yum install -y lsphp73 lsphp73-json lsphp73-xmlrpc lsphp73-xml lsphp73-tidy lsphp73-soap lsphp73-snmp ' \
@@ -262,9 +192,7 @@ class InstallCyberPanel:
'lsphp73-odbc lsphp73-mysqlnd lsphp73-mcrypt lsphp73-mbstring lsphp73-ldap lsphp73-intl lsphp73-imap ' \
'lsphp73-gmp lsphp73-gd lsphp73-enchant lsphp73-dba lsphp73-common lsphp73-bcmath'
install.preFlightsChecks.call(command, self.distro, '[installAllPHPVersions]',
'Install PHP 73',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def setup_mariadb_repo(self):
try:
@@ -297,9 +225,7 @@ class InstallCyberPanel:
else:
command = 'yum -y install mariadb-server'
install.preFlightsChecks.call(command, self.distro, '[installMySQL]',
'Install MySQL',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
## Fix configurations if two MYSQL are used
@@ -326,56 +252,22 @@ class InstallCyberPanel:
##
count = 0
command = "mysql_install_db --user=mysql --datadir=/var/lib/mysql1"
install.preFlightsChecks.call(command, self.distro, '[installMySQL]',
'Install MySQL',
1, 1, os.EX_OSERR)
while (1):
command = "mysql_install_db --user=mysql --datadir=/var/lib/mysql1"
install.preFlightsChecks.call(command, self.distro, '[installMySQL]',
'Install MySQL',
1, 1, os.EX_OSERR)
##
count = 0
command = "systemctl start mysqld@1"
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
while (1):
command = "systemctl start mysqld@1"
res = subprocess.call(shlex.split(command))
##
if install.preFlightsChecks.resFailed(self.distro, res):
count = count + 1
InstallCyberPanel.stdOut(
"Trying to start first MariaDB instance, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Failed to start first MariaDB instance, exiting installer! [installMySQL]")
InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("First MariaDB instance successfully started!")
InstallCyberPanel.stdOut("First MariaDB instance successfully started!")
break
command = "systemctl enable mysqld@1"
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
count = 0
while (1):
command = "systemctl enable mysqld@1"
res = subprocess.call(shlex.split(command))
if install.preFlightsChecks.resFailed(self.distro, res):
count = count + 1
InstallCyberPanel.stdOut(
"Trying to enable first MariaDB instance to start and system restart, trying again, try number: " + str(
count))
if count == 3:
logging.InstallLog.writeToFile(
"Failed to enable first MariaDB instance to run at system restart, exiting installer! [installMySQL]")
InstallCyberPanel.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("First MariaDB instance successfully enabled at system restart!")
InstallCyberPanel.stdOut("First MariaDB instance successfully enabled at system restart!")
break
############## Start mariadb ######################
@@ -389,17 +281,15 @@ class InstallCyberPanel:
passwordCMD = "use mysql;update user set password=PASSWORD('" + InstallCyberPanel.mysql_Root_password + "') where User='root';flush privileges;"
command = 'mysql -u root -e "' + passwordCMD + '"'
install.preFlightsChecks.call(command, self.distro, '[changeMYSQLRootPassword]', 'MYSQL Root Password change.',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
def startMariaDB(self):
############## Start mariadb ######################
command = "systemctl start mysql"
install.preFlightsChecks.call(command, self.distro, '[startMariaDB]',
'Start MySQL',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
############## Enable mariadb at system startup ######################
@@ -413,9 +303,7 @@ class InstallCyberPanel:
else:
command = "systemctl enable mariadb"
install.preFlightsChecks.call(command, self.distro, '[installMySQL]',
'Enable MySQL',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
def fixMariaDB(self):
self.stdOut("Setup MariaDB so it can support Cyberpanel's needs")
@@ -449,28 +337,20 @@ class InstallCyberPanel:
else:
command = "yum install -y pure-ftpd"
install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]',
'Install FTP',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
####### Install pureftpd to system startup
command = "systemctl enable " + install.preFlightsChecks.pureFTPDServiceName(self.distro)
install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]',
'Install FTP',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
###### FTP Groups and user settings settings
command = 'groupadd -g 2001 ftpgroup'
install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]',
'Install FTP',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = 'useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftpgroup ftpuser'
install.preFlightsChecks.call(command, self.distro, '[installPureFTPD]',
'Install FTP',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
def startPureFTPD(self):
############## Start pureftpd ######################
@@ -478,9 +358,7 @@ class InstallCyberPanel:
command = 'systemctl start pure-ftpd-mysql'
else:
command = 'systemctl start pure-ftpd'
install.preFlightsChecks.call(command, self.distro, '[startPureFTPD]',
'Start FTP',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
def installPureFTPDConfigurations(self, mysql):
try:
@@ -495,9 +373,7 @@ class InstallCyberPanel:
command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem'
install.preFlightsChecks.call(command, self.distro, '[installPureFTPDConfigurations]',
'FTP Configurations',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
os.chdir(self.cwd)
ftpdPath = "/etc/pure-ftpd"
@@ -538,9 +414,7 @@ class InstallCyberPanel:
if self.distro == ubuntu:
command = 'apt install pure-ftpd-mysql -y'
install.preFlightsChecks.call(command, self.distro, '[installPureFTPDConfigurations]',
'FTP Configurations',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
if os.path.exists('/etc/pure-ftpd/db/mysql.conf'):
os.remove('/etc/pure-ftpd/db/mysql.conf')
@@ -552,9 +426,7 @@ class InstallCyberPanel:
subprocess.call(command, shell=True)
command = 'systemctl restart pure-ftpd-mysql.service'
install.preFlightsChecks.call(command, self.distro, '[installPureFTPDConfigurations]',
'FTP Configurations',
1, 0, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
InstallCyberPanel.stdOut("PureFTPD configured!", 1)
@@ -564,20 +436,14 @@ class InstallCyberPanel:
def installPowerDNS(self):
try:
count = 0
if self.distro == ubuntu:
command = 'systemctl stop systemd-resolved'
res = subprocess.call(shlex.split(command))
if res != 0:
InstallCyberPanel.stdOut('Unable to stop systemd.resolved, prohits install of PowerDNS, error #' +
str(res), 1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'systemctl disable systemd-resolved.service'
res = subprocess.call(shlex.split(command))
if res != 0:
InstallCyberPanel.stdOut(
'Unable to disable systemd.resolved, prohits install of PowerDNS, error #' +
str(res), 1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
try:
os.rename('/etc/resolv.conf', 'etc/resolved.conf')
except OSError as e:
@@ -588,7 +454,10 @@ class InstallCyberPanel:
os.remove('/etc/resolv.conf')
except OSError as e1:
InstallCyberPanel.stdOut("Unable to remove existing /etc/resolv.conf to install PowerDNS: " +
str(e1), 1, 1, os.EX_OSERR)
str(e1), 1, 1, os.EX_OSERR)+
try:
f = open('/etc/resolv.conf', 'w')
f.write('nameserver 8.8.8.8')
@@ -600,15 +469,11 @@ class InstallCyberPanel:
if self.distro == centos:
command = 'yum -y install epel-release'
install.preFlightsChecks.call(command, self.distro, '[installPowerDNS]',
'Install PowerDNS',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = 'curl -o /etc/yum.repos.d/powerdns-auth-42.repo ' \
'https://repo.powerdns.com/repo-files/centos-auth-42.repo'
install.preFlightsChecks.call(command, self.distro, '[installPowerDNS]',
'Install PowerDNS',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
if self.distro == ubuntu:
command = "DEBIAN_FRONTEND=noninteractive apt-get -y install pdns-server pdns-backend-mysql"
@@ -617,9 +482,8 @@ class InstallCyberPanel:
else:
command = 'yum -y install pdns pdns-backend-mysql'
install.preFlightsChecks.call(command, self.distro, '[installPowerDNS]',
'Install PowerDNS',
1, 1, os.EX_OSERR)
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [powerDNS]")
@@ -674,18 +538,11 @@ class InstallCyberPanel:
############## Start PowerDNS ######################
try:
command = 'systemctl enable pdns'
install.preFlightsChecks.call(command, self.distro, '[startPowerDNS]',
'Start PowerDNS',
1, 0, os.EX_OSERR)
command = 'systemctl enable pdns'
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'systemctl start pdns'
install.preFlightsChecks.call(command, self.distro, '[startPowerDNS]',
'Start PowerDNS',
1, 0, os.EX_OSERR)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [startPowerDNS]")
command = 'systemctl start pdns'
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns = None):
@@ -727,7 +584,6 @@ def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns
installer.installLiteSpeed()
if ent == 0:
installer.changePortTo80()
installer.setupFileManager()
installer.installAllPHPVersions()
if ent == 0:
installer.fix_ols_configs()