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
2018-10-29 10:17:57 -04:00
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
2017-10-24 19:16:36 +05:00
2018-10-26 14:24:28 -04:00
#distros
centos = 0
ubuntu = 1
2019-12-17 21:50:22 +05:00
cent8 = 2
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
class InstallCyberPanel :
mysql_Root_password = " "
mysqlPassword = " "
2020-07-05 14:39:57 +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
2018-02-04 21:15:30 +05:00
@staticmethod
2018-11-06 00:19:58 +05:00
def stdOut ( message , log = 0 , exit = 0 , code = os . EX_OK ) :
2018-10-29 09:04:11 -04:00
install . preFlightsChecks . stdOut ( message , log , exit , code )
2018-02-04 21:15:30 +05:00
2017-10-24 19:16:36 +05:00
def installLiteSpeed ( self ) :
2018-11-10 16:05:40 +05:00
if self . ent == 0 :
2018-12-06 15:03:43 +05:00
if self . distro == ubuntu :
command = " apt-get -y install openlitespeed "
2019-12-17 21:50:22 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
elif self . distro == centos :
2018-12-06 15:03:43 +05:00
command = ' yum install -y openlitespeed '
2019-12-17 21:50:22 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
else :
2019-12-18 13:39:32 +05:00
command = ' yum install -y openlitespeed '
2019-12-17 21:50:22 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-11-10 16:05:40 +05:00
else :
try :
2018-12-06 15:03:43 +05:00
try :
command = ' groupadd nobody '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
except :
pass
2018-11-10 16:05:40 +05:00
2018-12-06 15:03:43 +05:00
try :
command = ' usermod -a -G nobody nobody '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
except :
pass
2019-11-19 11:04:06 +05:00
command = ' wget https://www.litespeedtech.com/packages/5.0/lsws-5.4.2-ent-x86_64-linux.tar.gz '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
2019-11-19 11:04:06 +05:00
command = ' tar zxf lsws-5.4.2-ent-x86_64-linux.tar.gz '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
2019-11-19 11:04:06 +05:00
writeSerial = open ( ' lsws-5.4.2/serial.no ' , ' w ' )
2018-12-06 15:03:43 +05:00
writeSerial . writelines ( self . serial )
writeSerial . close ( )
2019-01-12 17:52:45 +05:00
shutil . copy ( ' litespeed/install.sh ' , ' lsws-5.3.5/ ' )
shutil . copy ( ' litespeed/functions.sh ' , ' lsws-5.3.5/ ' )
2018-12-06 15:03:43 +05:00
2019-01-12 17:52:45 +05:00
os . chdir ( ' lsws-5.3.5 ' )
2018-12-06 15:03:43 +05:00
command = ' chmod +x install.sh '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
command = ' chmod +x functions.sh '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
command = ' ./install.sh '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-11-10 16:05:40 +05:00
2018-12-06 15:03:43 +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
2018-12-06 15:03:43 +05:00
command = ' chown -R lsadm:lsadm ' + confPath
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2019-11-13 18:51:57 +05:00
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 ) :
2018-12-06 15:03:43 +05:00
command = self . server_root_path + " bin/lswsctrl restart "
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
def fix_ols_configs ( self ) :
try :
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " Fixing OpenLiteSpeed configurations! " , 1 )
2017-12-09 22:30:10 +05:00
## remove example virtual host
data = open ( self . server_root_path + " conf/httpd_config.conf " , ' r ' ) . readlines ( )
writeDataToFile = open ( self . server_root_path + " conf/httpd_config.conf " , ' w ' )
for items in data :
if items . find ( " map " ) > - 1 and items . find ( " Example " ) > - 1 :
continue
else :
writeDataToFile . writelines ( items )
writeDataToFile . close ( )
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " OpenLiteSpeed Configurations fixed! " , 1 )
2019-12-10 15:09:10 +05:00
except IOError as msg :
2019-11-13 18:51:57 +05:00
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 :
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " Changing default port to 80.. " , 1 )
2018-02-04 21:15:30 +05:00
2017-10-24 19:16:36 +05:00
data = open ( self . server_root_path + " conf/httpd_config.conf " ) . readlines ( )
writeDataToFile = open ( self . server_root_path + " conf/httpd_config.conf " , ' w ' )
for items in data :
if ( items . find ( " *:8088 " ) > - 1 ) :
writeDataToFile . writelines ( items . replace ( " *:8088 " , " *:80 " ) )
else :
writeDataToFile . writelines ( items )
writeDataToFile . close ( )
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " Default port is now 80 for OpenLiteSpeed! " , 1 )
2018-02-04 21:15:30 +05:00
2019-12-10 15:09:10 +05:00
except IOError as msg :
2019-11-13 18:51:57 +05:00
logging . InstallLog . writeToFile ( ' [ERROR] ' + str ( msg ) + " [changePortTo80] " )
2017-10-24 19:16:36 +05:00
return 0
return self . reStartLiteSpeed ( )
def installAllPHPVersions ( self ) :
2018-12-13 04:23:08 +05:00
2018-12-06 15:03:43 +05:00
if self . distro == ubuntu :
command = ' DEBIAN_FRONTEND=noninteractive apt-get -y install ' \
' lsphp7? lsphp7?-common lsphp7?-curl lsphp7?-dev lsphp7?-imap lsphp7?-intl lsphp7?-json ' \
' lsphp7?-ldap lsphp7?-mysql lsphp7?-opcache lsphp7?-pspell lsphp7?-recode ' \
' lsphp7?-sqlite3 lsphp7?-tidy '
2018-12-14 00:43:28 +05:00
res = os . system ( command )
if res != 0 :
InstallCyberPanel . stdOut ( " Failed to install PHP on Ubuntu. " , 1 , 1 )
2020-04-13 08:46:08 +05:00
elif self . distro == centos :
2018-12-06 15:03:43 +05:00
command = ' yum -y groupinstall lsphp-all '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " LiteSpeed PHPs successfully installed! " , 1 )
## only php 71
2020-04-13 08:46:08 +05:00
if self . distro == centos :
2018-12-06 15:03:43 +05:00
2019-12-18 15:34:33 +05:00
command = ' yum install lsphp71 lsphp71-json lsphp71-xmlrpc lsphp71-xml lsphp71-soap lsphp71-snmp ' \
2018-12-06 15:03:43 +05:00
' 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 '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
## only php 72
2019-12-18 15:34:33 +05:00
command = ' yum install -y lsphp72 lsphp72-json lsphp72-xmlrpc lsphp72-xml lsphp72-soap lsphp72-snmp ' \
2018-12-06 15:03:43 +05:00
' 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 '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2018-12-17 18:46:34 +05:00
2019-12-26 16:18:27 +05:00
2019-12-26 15:52:55 +05:00
## only php 73
2018-12-17 18:46:34 +05:00
command = ' yum install -y lsphp73 lsphp73-json lsphp73-xmlrpc lsphp73-xml lsphp73-tidy lsphp73-soap lsphp73-snmp ' \
' lsphp73-recode lsphp73-pspell lsphp73-process lsphp73-pgsql lsphp73-pear lsphp73-pdo lsphp73-opcache ' \
' 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 '
2019-12-29 23:12:36 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2019-12-26 15:52:55 +05:00
## only php 74
command = ' yum install -y lsphp74 lsphp74-json lsphp74-xmlrpc lsphp74-xml lsphp74-tidy lsphp74-soap lsphp74-snmp ' \
' lsphp74-recode lsphp74-pspell lsphp74-process lsphp74-pgsql lsphp74-pear lsphp74-pdo lsphp74-opcache ' \
' lsphp74-odbc lsphp74-mysqlnd lsphp74-mcrypt lsphp74-mbstring lsphp74-ldap lsphp74-intl lsphp74-imap ' \
' lsphp74-gmp lsphp74-gd lsphp74-enchant lsphp74-dba lsphp74-common lsphp74-bcmath '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2020-04-13 08:46:08 +05:00
if self . distro == cent8 :
command = ' dnf install lsphp71* lsphp72* lsphp73* lsphp74* --exclude lsphp73-pecl-zip -y '
subprocess . call ( command , shell = True )
2018-05-29 20:20:05 +05:00
def installMySQL ( self , mysql ) :
2020-06-26 18:22:20 +05:00
if self . remotemysql == ' OFF ' :
############## Install mariadb ######################
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
if self . distro == ubuntu :
command = " apt-get -y install mariadb-server "
elif self . distro == centos :
command = ' yum --enablerepo=CyberPanel -y install mariadb-server '
elif self . distro == cent8 :
command = ' dnf -y install mariadb-server '
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-11-06 00:19:58 +05:00
2020-06-26 18:22:20 +05:00
## Fix configurations if two MYSQL are used
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
if mysql == ' Two ' :
logging . InstallLog . writeToFile ( " Setting up MariaDB configurations! " )
InstallCyberPanel . stdOut ( " Setting up MariaDB configurations! " )
2018-02-04 21:15:30 +05:00
2020-06-26 18:22:20 +05:00
pathConf = " /etc/my.cnf "
pathServiceFile = " /etc/systemd/system/mysqld@.service "
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
if os . path . exists ( pathConf ) :
os . remove ( pathConf )
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
if os . path . exists ( pathServiceFile ) :
os . remove ( pathServiceFile )
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
os . chdir ( self . cwd )
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
shutil . copy ( " mysql/my.cnf " , pathConf )
shutil . copy ( " mysql/mysqld@.service " , pathServiceFile )
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
logging . InstallLog . writeToFile ( " MariaDB configurations set! " )
InstallCyberPanel . stdOut ( " MariaDB configurations set! " )
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
##
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
command = " mysql_install_db --user=mysql --datadir=/var/lib/mysql1 "
install . preFlightsChecks . call ( command , self . distro , ' [installMySQL] ' ,
' Install MySQL ' ,
1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
##
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
command = " systemctl start mysqld@1 "
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2019-11-13 16:13:52 +05:00
2020-06-26 18:22:20 +05:00
##
2019-11-13 16:13:52 +05:00
2020-06-26 18:22:20 +05:00
command = " systemctl enable mysqld@1 "
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2019-11-13 16:13:52 +05:00
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
############## Start mariadb ######################
2017-10-24 19:16:36 +05:00
2020-06-26 18:22:20 +05:00
self . startMariaDB ( )
2018-12-06 15:03:43 +05:00
def changeMYSQLRootPassword ( self ) :
2020-06-26 18:22:20 +05:00
if self . remotemysql == ' OFF ' :
if self . distro == ubuntu :
passwordCMD = " use mysql;update user set password=PASSWORD( ' " + InstallCyberPanel . mysql_Root_password + " ' ) where User= ' root ' ;UPDATE user SET plugin= ' ' WHERE User= ' root ' ;flush privileges; "
else :
passwordCMD = " use mysql;update user set password=PASSWORD( ' " + InstallCyberPanel . mysql_Root_password + " ' ) where User= ' root ' ;flush privileges; "
2018-12-13 04:23:08 +05:00
2020-06-26 18:22:20 +05:00
command = ' mysql -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 )
2018-12-06 15:03:43 +05:00
def startMariaDB ( self ) :
############## Start mariadb ######################
2019-12-18 15:34:33 +05:00
if self . distro == cent8 or self . distro == ubuntu :
command = ' systemctl start mariadb '
else :
command = " systemctl start mysql "
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
############## Enable mariadb at system startup ######################
2018-12-17 18:46:34 +05:00
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-06 15:03:43 +05:00
if self . distro == ubuntu :
command = " systemctl enable mariadb "
else :
2018-12-17 18:46:34 +05:00
command = " systemctl enable mariadb "
2018-12-06 15:03:43 +05:00
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
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 '
data = open ( fileName , ' r ' ) . readlines ( )
writeDataToFile = open ( fileName , ' w ' )
for line in data :
2018-11-06 00:19:58 +05:00
writeDataToFile . write ( line . replace ( ' utf8mb4 ' , ' utf8 ' ) )
2018-10-31 11:06:24 -04:00
writeDataToFile . close ( )
except IOError as err :
2019-11-13 18:51:57 +05:00
self . stdOut ( " [ERROR] Error in setting: " + fileName + " : " + str ( err ) , 1 , 1 , os . EX_OSERR )
2018-10-31 11:06:24 -04:00
os . system ( ' systemctl restart mysql ' )
self . stdOut ( " MariaDB is now setup so it can support Cyberpanel ' s needs " )
2017-10-24 19:16:36 +05:00
def installPureFTPD ( self ) :
2018-12-06 15:03:43 +05:00
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 :
command = ' wget https://rep.cyberpanel.net/pure-ftpd-common_1.0.47-3_all.deb '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2020-04-17 23:04:01 +05:00
2020-05-11 01:03:51 +05:00
command = ' wget https://rep.cyberpanel.net/pure-ftpd-mysql_1.0.47-3_amd64.deb '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2020-04-17 23:04:01 +05:00
2020-05-11 01:03:51 +05:00
command = ' dpkg --install --force-confold pure-ftpd-common_1.0.47-3_all.deb '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2020-04-17 23:04:01 +05:00
2020-05-11 01:03:51 +05:00
command = ' dpkg --install --force-confold pure-ftpd-mysql_1.0.47-3_amd64.deb '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2020-04-17 23:04:01 +05:00
2020-04-13 00:58:56 +05:00
elif self . distro == centos :
2018-12-06 15:03:43 +05:00
command = " yum install -y pure-ftpd "
2020-04-17 05:53:06 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2020-04-13 00:58:56 +05:00
elif self . distro == cent8 :
2020-06-08 00:11:14 +05:00
command = ' dnf install pure-ftpd -y '
2020-04-17 05:53:06 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-12-06 15:03:43 +05:00
####### Install pureftpd to system startup
2017-10-24 19:16:36 +05:00
2018-12-06 15:03:43 +05:00
command = " systemctl enable " + install . preFlightsChecks . pureFTPDServiceName ( self . distro )
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-12-06 15:03:43 +05:00
###### FTP Groups and user settings settings
2017-10-24 19:16:36 +05:00
2018-12-06 15:03:43 +05:00
command = ' groupadd -g 2001 ftpgroup '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-12-06 15:03:43 +05:00
command = ' useradd -u 2001 -s /bin/false -d /bin/null -c " pureftpd user " -g ftpgroup ftpuser '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2020-02-12 11:48:58 -05:00
2017-10-24 19:16:36 +05:00
def startPureFTPD ( self ) :
2018-02-04 21:15:30 +05:00
############## Start pureftpd ######################
2018-12-06 15:03:43 +05:00
if self . distro == ubuntu :
command = ' systemctl start pure-ftpd-mysql '
else :
command = ' systemctl start pure-ftpd '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +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
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " Configuring PureFTPD.. " , 1 )
2018-02-04 21:15:30 +05:00
2017-12-09 22:30:10 +05:00
try :
os . mkdir ( " /etc/ssl/private " )
except :
2019-11-13 18:51:57 +05:00
logging . InstallLog . writeToFile ( " [ERROR] Could not create directory for FTP SSL " )
2017-12-09 22:30:10 +05:00
2020-05-13 21:42:16 +05:00
if ( self . distro == centos or self . distro == cent8 ) or ( self . distro == ubuntu and get_Ubuntu_release ( ) == 18.14 ) :
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 :
command = ' openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -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 '
2017-12-09 22:30:10 +05:00
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
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 )
2018-05-29 20:20:05 +05:00
if mysql == ' Two ' :
2018-11-07 16:00:00 -05:00
shutil . copytree ( " pure-ftpd " , ftpdPath )
2018-05-29 20:20:05 +05:00
else :
shutil . copytree ( " pure-ftpd-one " , ftpdPath )
2017-10-24 19:16:36 +05:00
else :
2018-05-29 20:20:05 +05:00
if mysql == ' Two ' :
shutil . copytree ( " pure-ftpd " , ftpdPath )
else :
shutil . copytree ( " pure-ftpd-one " , ftpdPath )
2017-10-24 19:16:36 +05:00
2018-11-07 09:56:45 -05:00
if self . distro == ubuntu :
try :
os . mkdir ( ' /etc/pure-ftpd/conf ' )
os . mkdir ( ' /etc/pure-ftpd/auth ' )
2018-11-08 12:11:42 +05:00
os . mkdir ( ' /etc/pure-ftpd/db ' )
2018-11-07 09:56:45 -05:00
except OSError as err :
2019-11-13 18:51:57 +05:00
self . stdOut ( " [ERROR] Error creating extra pure-ftpd directories: " + str ( err ) , " . Should be ok " , 1 )
2018-11-07 09:56:45 -05:00
2017-10-24 19:16:36 +05:00
data = open ( ftpdPath + " /pureftpd-mysql.conf " , " r " ) . readlines ( )
writeDataToFile = open ( ftpdPath + " /pureftpd-mysql.conf " , " w " )
dataWritten = " MYSQLPassword " + InstallCyberPanel . mysqlPassword + ' \n '
for items in data :
if items . find ( " MYSQLPassword " ) > - 1 :
writeDataToFile . writelines ( dataWritten )
else :
writeDataToFile . writelines ( items )
2018-11-14 13:36:34 +05:00
2017-10-24 19:16:36 +05:00
writeDataToFile . close ( )
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 ' )
shutil . copy ( ftpdPath + " /pureftpd-mysql.conf " , ' /etc/pure-ftpd/db/mysql.conf ' )
else :
shutil . copy ( ftpdPath + " /pureftpd-mysql.conf " , ' /etc/pure-ftpd/db/mysql.conf ' )
command = ' echo 1 > /etc/pure-ftpd/conf/TLS '
2019-03-26 16:19:03 +05:00
subprocess . call ( command , shell = True )
2018-11-08 12:11:42 +05:00
2020-02-03 11:45:34 +05:00
command = ' echo %s > /etc/pure-ftpd/conf/ForcePassiveIP ' % ( self . publicip )
subprocess . call ( command , shell = True )
2020-02-03 17:50:22 +05:00
command = ' echo " 40110 40210 " > /etc/pure-ftpd/conf/PassivePortRange '
subprocess . call ( command , shell = True )
2020-04-17 07:15:09 +05:00
command = ' echo " no " > /etc/pure-ftpd/conf/UnixAuthentication '
subprocess . call ( command , shell = True )
command = ' echo " /etc/pure-ftpd/db/mysql.conf " > /etc/pure-ftpd/conf/MySQLConfigFile '
subprocess . call ( command , shell = True )
2020-04-22 21:16:20 +05:00
2020-04-17 07:15:09 +05:00
command = ' ln -s /etc/pure-ftpd/conf/MySQLConfigFile /etc/pure-ftpd/auth/30mysql '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
command = ' ln -s /etc/pure-ftpd/conf/UnixAuthentication /etc/pure-ftpd/auth/65unix '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-11-08 12:11:42 +05:00
command = ' systemctl restart pure-ftpd-mysql.service '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2018-11-08 12:11:42 +05:00
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " PureFTPD configured! " , 1 )
2018-02-04 21:15:30 +05:00
2019-12-10 15:09:10 +05:00
except IOError as msg :
2019-11-13 18:51:57 +05:00
logging . InstallLog . writeToFile ( ' [ERROR] ' + str ( msg ) + " [installPureFTPDConfigurations] " )
2017-10-24 19:16:36 +05:00
return 0
def installPowerDNS ( self ) :
try :
2018-10-29 09:04:11 -04:00
if self . distro == ubuntu :
command = ' systemctl stop systemd-resolved '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2018-10-29 09:04:11 -04:00
command = ' systemctl disable systemd-resolved.service '
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2018-10-29 10:17:57 -04:00
try :
os . rename ( ' /etc/resolv.conf ' , ' etc/resolved.conf ' )
except OSError as e :
2018-10-29 10:45:46 -04:00
if e . errno != errno . EEXIST and e . errno != errno . ENOENT :
2019-11-13 18:51:57 +05:00
InstallCyberPanel . stdOut ( " [ERROR] Unable to rename /etc/resolv.conf to install PowerDNS: " +
2018-10-29 10:17:57 -04:00
str ( e ) , 1 , 1 , os . EX_OSERR )
try :
os . remove ( ' /etc/resolv.conf ' )
except OSError as e1 :
2019-11-13 18:51:57 +05:00
InstallCyberPanel . stdOut ( " [ERROR] Unable to remove existing /etc/resolv.conf to install PowerDNS: " +
2019-11-13 18:08:14 +05:00
str ( e1 ) , 1 , 1 , os . EX_OSERR )
2019-11-13 16:13:52 +05:00
2019-12-13 22:18:53 +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)
2018-10-29 10:17:57 -04:00
2020-04-13 08:46:08 +05:00
# if self.distro == cent8:
# command = 'dnf config-manager --set-enabled PowerTools'
# install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
#
# command = 'curl -o /etc/yum.repos.d/powerdns-auth-master.repo https://repo.powerdns.com/repo-files/centos-auth-master.repo'
# install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2019-12-18 13:58:23 +05:00
2018-12-06 15:03:43 +05:00
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
2018-12-06 15:03:43 +05:00
else :
command = ' yum -y install pdns pdns-backend-mysql '
2017-10-24 19:16:36 +05:00
2019-11-13 16:13:52 +05:00
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 1 , os . EX_OSERR )
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2019-11-13 18:51:57 +05:00
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 :
2018-02-04 21:15:30 +05:00
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " Configuring PowerDNS.. " , 1 )
2018-02-04 21:15:30 +05:00
2017-10-24 19:16:36 +05:00
os . chdir ( self . cwd )
2019-12-18 13:58:23 +05:00
if self . distro == centos or self . distro == cent8 :
2018-10-30 17:33:43 -04:00
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 )
2018-05-29 20:20:05 +05:00
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 :
2018-05-29 20:20:05 +05:00
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
data = open ( dnsPath , " r " ) . readlines ( )
writeDataToFile = open ( dnsPath , " w " )
dataWritten = " gmysql-password= " + mysqlPassword + " \n "
for items in data :
if items . find ( " gmysql-password " ) > - 1 :
writeDataToFile . writelines ( dataWritten )
else :
writeDataToFile . writelines ( items )
2018-11-14 13:36:34 +05:00
2018-11-12 14:53:10 -05:00
#if self.distro == ubuntu:
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
2018-11-07 15:14:54 -05:00
2017-10-24 19:16:36 +05:00
writeDataToFile . close ( )
2018-12-06 15:03:43 +05:00
InstallCyberPanel . stdOut ( " PowerDNS configured! " , 1 )
2018-02-04 21:15:30 +05:00
2019-12-10 15:09:10 +05:00
except IOError as msg :
2019-11-13 18:51:57 +05:00
logging . InstallLog . writeToFile ( ' [ERROR] ' + str ( msg ) + " [installPowerDNSConfigurations] " )
2017-10-24 19:16:36 +05:00
return 0
return 1
def startPowerDNS ( self ) :
2018-02-04 21:15:30 +05:00
############## Start PowerDNS ######################
2017-10-24 19:16:36 +05:00
2019-11-13 16:13:52 +05:00
command = ' systemctl enable pdns '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2018-12-06 15:03:43 +05:00
2019-11-13 16:13:52 +05:00
command = ' systemctl start pdns '
install . preFlightsChecks . call ( command , self . distro , command , command , 1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2020-07-05 14:39:57 +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 ) :
2017-12-09 22:30:10 +05:00
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 '
2019-07-16 23:23:16 +05:00
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 :
2020-07-05 14:39:57 +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 ( )
2019-07-16 23:23:16 +05:00
2020-07-05 13:26:46 +05:00
if install . preFlightsChecks . debug :
print ( open ( file_name , ' r ' ) . read ( ) )
time . sleep ( 10 )
2018-11-06 00:19:58 +05:00
2020-06-26 18:22:20 +05:00
try :
command = ' chmod 640 %s ' % ( file_name )
install . preFlightsChecks . call ( command , distro , ' [chmod] ' ,
' ' ,
1 , 0 , os . EX_OSERR )
command = ' chown root:cyberpanel %s ' % ( file_name )
install . preFlightsChecks . call ( command , distro , ' [chmod] ' ,
' ' ,
1 , 0 , os . EX_OSERR )
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
2020-07-05 14:39:57 +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
installer . installLiteSpeed ( )
2018-11-10 16:05:40 +05:00
if ent == 0 :
installer . changePortTo80 ( )
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
2018-05-29 20:20:05 +05:00
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
2020-07-02 22:50:31 +05:00
mysqlUtilities . createDatabase ( " cyberpanel " , " cyberpanel " , InstallCyberPanel . mysqlPassword )
2018-11-06 00:19:58 +05:00
2019-06-26 03:57:16 +05:00
if ftp == None :
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 ( )
if dns == None :
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 )
2020-02-12 11:48:58 -05:00
installer . startPowerDNS ( )