2017-10-24 19:16:36 +05:00
import shutil
import subprocess
import os
import pexpect
from mysqlUtilities import mysqlUtilities
import installLog as logging
import shlex
import randomPassword
2018-10-29 10:17:57 -04:00
import errno
2018-10-31 11:06:24 -04:00
import MySQLdb as mariadb
2018-11-06 00:19:58 +05:00
import install
2018-11-14 11:37:17 -05:00
#import stat
2017-10-24 19:16:36 +05:00
2018-10-26 14:24:28 -04:00
#distros
centos = 0
ubuntu = 1
2017-10-24 19:16:36 +05:00
class InstallCyberPanel :
mysql_Root_password = " "
mysqlPassword = " "
2018-11-10 16:05:40 +05:00
def __init__ ( self , rootPath , cwd , distro , ent , serial = 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
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 :
try :
count = 0
while ( 1 ) :
2017-11-02 02:09:47 +05:00
2018-11-10 16:05:40 +05:00
if self . distro == ubuntu :
command = " apt-get -y install openlitespeed "
else :
command = ' yum install -y openlitespeed '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-10 16:05:40 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to install OpenLiteSpeed, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to install OpenLiteSpeed, exiting installer! [installLiteSpeed] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
else :
logging . InstallLog . writeToFile ( " OpenLiteSpeed successfully installed! " )
InstallCyberPanel . stdOut ( " OpenLiteSpeed successfully installed! " )
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installLiteSpeed] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installLiteSpeed] " )
return 0
return 1
else :
try :
count = 0
while ( 1 ) :
command = ' wget https://www.litespeedtech.com/packages/5.0/lsws-5.3-ent-x86_64-linux.tar.gz '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
command = ' tar zxf lsws-5.3-ent-x86_64-linux.tar.gz '
subprocess . call ( shlex . split ( command ) )
writeSerial = open ( ' lsws-5.3/serial.no ' , ' w ' )
writeSerial . writelines ( self . serial )
writeSerial . close ( )
shutil . copy ( ' litespeed/install.sh ' , ' lsws-5.3/ ' )
shutil . copy ( ' litespeed/functions.sh ' , ' lsws-5.3/ ' )
os . chdir ( ' lsws-5.3 ' )
command = ' chmod +x install.sh '
subprocess . call ( shlex . split ( command ) )
command = ' chmod +x functions.sh '
subprocess . call ( shlex . split ( command ) )
command = ' ./install.sh '
res = subprocess . call ( shlex . split ( command ) )
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-10 16:05:40 +05:00
logging . InstallLog . writeToFile (
" Failed to install LiteSpeed Enterprise! [installLiteSpeed] " )
InstallCyberPanel . stdOut ( " Failed to install LiteSpeed Enterprise! " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2017-10-24 19:16:36 +05:00
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
2018-11-10 16:05:40 +05:00
command = ' chown -R lsadm:lsadm ' + confPath
subprocess . call ( shlex . split ( command ) )
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installLiteSpeed] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installLiteSpeed] " )
return 0
return 1
2017-10-24 19:16:36 +05:00
def reStartLiteSpeed ( self ) :
try :
cmd = [ ]
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
cmd . append ( self . server_root_path + " bin/lswsctrl " )
cmd . append ( " restart " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to restart OpenLiteSpeed, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to restart OpenLiteSpeed, you can do this manually later using: systemctl restart lsws! [reStartLiteSpeed] " )
break
else :
logging . InstallLog . writeToFile ( " OpenLiteSpeed successfully restarted! " )
InstallCyberPanel . stdOut ( " OpenLiteSpeed successfully restarted! " )
break
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [reStartLiteSpeed] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [reStartLiteSpeed] " )
return 0
return 1
2017-12-09 22:30:10 +05:00
def fix_ols_configs ( self ) :
try :
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Fixing OpenLiteSpeed configurations! " )
logging . InstallLog . writeToFile ( " Fixing OpenLiteSpeed configurations! " )
2017-12-09 22:30:10 +05:00
2018-02-04 21:15:30 +05:00
## cache module settings
2017-12-09 22:30:10 +05:00
cacheStart = " module cache { \n "
2018-07-05 15:22:48 +05:00
ls_enabled = " ls_enabled 1 \n "
2017-12-09 22:30:10 +05:00
enableCache = " enableCache 0 \n "
qsCache = " qsCache 1 \n "
reqCookieCache = " reqCookieCache 1 \n "
respCookieCache = " respCookieCache 1 \n "
ignoreReqCacheCtrl = " ignoreReqCacheCtrl 1 \n "
ignoreRespCacheCtrl = " ignoreRespCacheCtrl 0 \n "
enablePrivateCache = " enablePrivateCache 0 \n "
privateExpireInSeconds = " privateExpireInSeconds 1000 \n "
expireInSeconds = " expireInSeconds 1000 \n "
storagePath = " storagePath cachedata \n "
checkPrivateCache = " checkPrivateCache 1 \n "
checkPublicCache = " checkPublicCache 1 \n "
cacheEnd = " } \n "
writeDataToFile = open ( self . server_root_path + " conf/httpd_config.conf " , ' a ' )
writeDataToFile . writelines ( cacheStart )
2018-07-05 15:22:48 +05:00
writeDataToFile . writelines ( ls_enabled )
2017-12-09 22:30:10 +05:00
writeDataToFile . writelines ( enableCache )
writeDataToFile . writelines ( qsCache )
writeDataToFile . writelines ( reqCookieCache )
writeDataToFile . writelines ( respCookieCache )
writeDataToFile . writelines ( ignoreReqCacheCtrl )
writeDataToFile . writelines ( ignoreRespCacheCtrl )
writeDataToFile . writelines ( enablePrivateCache )
writeDataToFile . writelines ( privateExpireInSeconds )
writeDataToFile . writelines ( expireInSeconds )
writeDataToFile . writelines ( storagePath )
writeDataToFile . writelines ( checkPrivateCache )
writeDataToFile . writelines ( checkPublicCache )
writeDataToFile . writelines ( cacheEnd )
writeDataToFile . writelines ( " \n " )
writeDataToFile . writelines ( " \n " )
writeDataToFile . close ( )
## 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-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " OpenLiteSpeed Configurations fixed! " )
logging . InstallLog . writeToFile ( " OpenLiteSpeed Configurations fixed! " )
2017-12-09 22:30:10 +05:00
except IOError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [fix_ols_configs] " )
return 0
return self . reStartLiteSpeed ( )
2017-10-24 19:16:36 +05:00
def changePortTo80 ( self ) :
try :
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Changing default port to 80.. " )
logging . InstallLog . writeToFile ( " Changing default port to 80.. " )
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-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Default port is now 80 for OpenLiteSpeed! " )
logging . InstallLog . writeToFile ( " Default port is now 80 for OpenLiteSpeed! " )
2017-10-24 19:16:36 +05:00
except IOError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [changePortTo80] " )
return 0
return self . reStartLiteSpeed ( )
2017-12-09 22:30:10 +05:00
def setupFileManager ( self ) :
2018-11-10 16:05:40 +05:00
if self . ent == 0 :
try :
logging . InstallLog . writeToFile ( " Setting up Filemanager files.. " )
InstallCyberPanel . stdOut ( " Setting up Filemanager files.. " )
2017-10-24 19:16:36 +05:00
2018-11-10 16:05:40 +05:00
os . chdir ( self . cwd )
2017-10-24 19:16:36 +05:00
2018-11-10 16:05:40 +05:00
fileManagerPath = self . server_root_path + " Example/html/FileManager "
shutil . copytree ( " FileManager " , fileManagerPath )
2017-12-09 22:30:10 +05:00
2018-11-10 16:05:40 +05:00
## remove unnecessary files
2017-12-09 22:30:10 +05:00
2018-11-10 16:05:40 +05:00
fileManagerPath = self . server_root_path + " Example/html/ "
2017-12-09 22:30:10 +05:00
2018-11-10 16:05:40 +05:00
shutil . rmtree ( fileManagerPath + " protected " )
shutil . rmtree ( fileManagerPath + " blocked " )
os . remove ( fileManagerPath + " phpinfo.php " )
os . remove ( fileManagerPath + " upload.html " )
os . remove ( fileManagerPath + " upload.php " )
2017-12-09 22:30:10 +05:00
2018-11-10 16:05:40 +05:00
logging . InstallLog . writeToFile ( " Filemanager files are set! " )
InstallCyberPanel . stdOut ( " Filemanager files are set! " )
2018-02-04 21:15:30 +05:00
2018-11-10 16:05:40 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setupFileManager] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setupFileManager] " )
return 0
2017-10-24 19:16:36 +05:00
2018-11-10 16:05:40 +05:00
return 1
else :
try :
logging . InstallLog . writeToFile ( " Setting up Filemanager files.. " )
InstallCyberPanel . stdOut ( " Setting up Filemanager files.. " )
os . chdir ( self . cwd )
fileManagerPath = self . server_root_path + " /FileManager "
shutil . copytree ( " FileManager " , fileManagerPath )
## remove unnecessary files
command = ' chmod -R 777 ' + fileManagerPath
subprocess . call ( shlex . split ( command ) )
logging . InstallLog . writeToFile ( " Filemanager files are set! " )
InstallCyberPanel . stdOut ( " Filemanager files are set! " )
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setupFileManager] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setupFileManager] " )
return 0
return 1
2017-10-24 19:16:36 +05:00
def installAllPHPVersions ( self ) :
try :
count = 0
2018-11-10 02:37:45 +05:00
2017-10-24 19:16:36 +05:00
while ( 1 ) :
2018-11-14 11:37:17 -05:00
failed = False
2018-10-26 14:24:28 -04:00
if self . distro == ubuntu :
2018-11-09 11:21:16 -05:00
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 ' \
2018-11-10 02:37:45 +05:00
' lsphp7?-sqlite3 lsphp7?-tidy '
2018-11-01 13:32:39 -04:00
res = os . system ( command )
2018-11-14 11:37:17 -05:00
if res != 0 :
failed = True
2018-10-26 14:24:28 -04:00
else :
2018-11-14 18:36:56 +05:00
command = ' yum -y install lsphp* '
2018-11-01 13:32:39 -04:00
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
failed = True
2017-11-02 02:09:47 +05:00
2018-11-14 11:37:17 -05:00
if failed :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-11-06 00:19:58 +05:00
InstallCyberPanel . stdOut (
" Trying to install LiteSpeed PHPs, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile (
" Failed to install LiteSpeed PHPs, exiting installer! [installAllPHPVersions] " )
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2017-10-24 19:16:36 +05:00
else :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " LiteSpeed PHPs successfully installed! " )
InstallCyberPanel . stdOut ( " LiteSpeed PHPs successfully installed! " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
## break for outer loop
2017-10-24 19:16:36 +05:00
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installAllPHPVersion] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installAllPHPVersion] " )
return 0
return 1
def setup_mariadb_repo ( self ) :
2018-11-06 00:19:58 +05:00
try :
if self . distro == ubuntu :
2018-10-26 14:24:28 -04:00
# Only needed if the repo is broken or we need the latest version.
2018-11-06 00:19:58 +05:00
# command = "apt-get -y install software-properties-common"
# command = "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8"
# command = "add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main'"
return
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Setting up MariaDB Repo.. " )
InstallCyberPanel . stdOut ( " Setting up MariaDB Repo.. " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
os . chdir ( self . cwd )
2017-10-24 19:16:36 +05:00
shutil . copy ( " mysql/MariaDB.repo " , " /etc/yum.repos.d/MariaDB.repo " )
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " MariaDB repo set! " )
InstallCyberPanel . stdOut ( " MariaDB repo set! " )
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_mariadb_repo] " )
return 0
except BaseException , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_mariadb_repo] " )
return 0
2018-05-29 20:20:05 +05:00
def installMySQL ( self , mysql ) :
2017-10-24 19:16:36 +05:00
try :
############## Install mariadb ######################
count = 0
while ( 1 ) :
2018-10-26 14:24:28 -04:00
if self . distro == ubuntu :
command = " apt-get -y install mariadb-server "
else :
command = ' yum -y install mariadb-server '
2017-11-02 02:09:47 +05:00
cmd = shlex . split ( command )
2018-11-06 00:19:58 +05:00
2017-10-24 19:16:36 +05:00
res = subprocess . call ( cmd )
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Trying to install MariaDB, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Failed to install MariaDB, exiting installer! [installMySQL] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2017-10-24 19:16:36 +05:00
else :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " MariaDB successfully installed! " )
InstallCyberPanel . stdOut ( " MariaDB successfully installed! " )
2017-10-24 19:16:36 +05:00
break
2018-05-29 20:20:05 +05:00
## Fix configurations if two MYSQL are used
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +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
2018-05-29 20:20:05 +05:00
pathConf = " /etc/my.cnf "
pathServiceFile = " /etc/systemd/system/mysqld@.service "
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
if os . path . exists ( pathConf ) :
os . remove ( pathConf )
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
if os . path . exists ( pathServiceFile ) :
os . remove ( pathServiceFile )
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
os . chdir ( self . cwd )
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
shutil . copy ( " mysql/my.cnf " , pathConf )
shutil . copy ( " mysql/mysqld@.service " , pathServiceFile )
2018-02-04 21:15:30 +05:00
2018-05-29 20:20:05 +05:00
logging . InstallLog . writeToFile ( " MariaDB configurations set! " )
InstallCyberPanel . stdOut ( " MariaDB configurations set! " )
2018-02-04 21:15:30 +05:00
2018-05-29 20:20:05 +05:00
##
2018-02-04 21:15:30 +05:00
2018-05-29 20:20:05 +05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-05-29 20:20:05 +05:00
while ( 1 ) :
command = " mysql_install_db --user=mysql --datadir=/var/lib/mysql1 "
2018-02-04 21:15:30 +05:00
2018-05-29 20:20:05 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-05-29 20:20:05 +05:00
count = count + 1
InstallCyberPanel . stdOut (
" Trying to create data directories for second MariaDB instance, trying again, try number: " + str (
count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed to create data directories for second MariaDB instance, exiting installer! [installMySQL] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-05-29 20:20:05 +05:00
else :
logging . InstallLog . writeToFile ( " Data directories created for second MariaDB instance! " )
InstallCyberPanel . stdOut ( " Data directories created for second MariaDB instance! " )
break
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
##
count = 0
while ( 1 ) :
command = " systemctl start mysqld@1 "
res = subprocess . call ( shlex . split ( command ) )
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-05-29 20:20:05 +05:00
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 " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-05-29 20:20:05 +05:00
else :
logging . InstallLog . writeToFile ( " First MariaDB instance successfully started! " )
InstallCyberPanel . stdOut ( " First MariaDB instance successfully started! " )
break
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
count = 0
while ( 1 ) :
command = " systemctl enable mysqld@1 "
res = subprocess . call ( shlex . split ( command ) )
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-05-29 20:20:05 +05:00
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 " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-05-29 20:20:05 +05:00
else :
logging . InstallLog . writeToFile ( " First MariaDB instance successfully enabled at system restart! " )
InstallCyberPanel . stdOut ( " First MariaDB instance successfully enabled at system restart! " )
break
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installMySQL] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installMySQL] " )
return 0
############## Start mariadb ######################
self . startMariaDB ( )
############## Enable mariadb at system startup ######################
try :
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-10-26 16:25:13 -04:00
if self . distro == ubuntu :
command = " systemctl enable mariadb "
else :
command = " systemctl enable mysql "
2018-02-04 21:15:30 +05:00
res = subprocess . call ( shlex . split ( command ) )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
2018-11-06 00:19:58 +05:00
InstallCyberPanel . stdOut ( " Trying to enable MariaDB instance to start and system restart, trying again, try number: " + str ( count ) )
2018-02-04 21:15:30 +05:00
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( " Failed to enable MariaDB instance to run at system restart, you can do this later using systemctl enable mysql! [installMySQL] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " MariaDB instance successfully enabled at system restart! " )
InstallCyberPanel . stdOut ( " MariaDB instance successfully enabled at system restart! " )
break
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " Could not add mariadb to startup [installMySQL] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " Could not add mariadb to startup [installMySQL] " )
return 0
return 1
def changeMYSQLRootPassword ( self ) :
try :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Changing MariaDB root password.. " )
InstallCyberPanel . stdOut ( " Changing MariaDB root password.. " )
2017-10-24 19:16:36 +05:00
expectation = " Enter password: "
securemysql = pexpect . spawn ( " mysql -u root -p " , timeout = 5 )
securemysql . expect ( expectation )
securemysql . sendline ( " " )
expectation = " clear the current input statement. "
securemysql . expect ( expectation )
securemysql . sendline ( " use mysql; " )
expectation = " Database changed "
securemysql . expect ( expectation )
securemysql . sendline ( " update user set password=PASSWORD( ' " + InstallCyberPanel . mysql_Root_password + " ' ) where User= ' root ' ; " )
expectation = " Query OK "
securemysql . expect ( expectation )
securemysql . sendline ( " flush privileges; " )
expectation = " Query OK "
securemysql . expect ( expectation )
securemysql . sendline ( " quit " )
securemysql . wait ( )
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " MariaDB root password changed! " )
InstallCyberPanel . stdOut ( " MariaDB root password changed! " )
2017-10-24 19:16:36 +05:00
except pexpect . EOF , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " Exception EOF [changeMYSQLRootPassword] " )
except pexpect . TIMEOUT , msg :
print securemysql . before
logging . InstallLog . writeToFile ( str ( msg ) + " Exception EOF [changeMYSQLRootPassword] " )
except BaseException , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [changeMYSQLRootPassword] " )
return 0
2018-05-29 20:20:05 +05:00
def changeMYSQLRootPasswordCyberPanel ( self , mysql ) :
2017-10-24 19:16:36 +05:00
try :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Changing CyberPanel MariaDB root password.. " )
InstallCyberPanel . stdOut ( " Changing CyberPanel MariaDB root password.. " )
2017-10-24 19:16:36 +05:00
expectation = " Enter password: "
2018-05-29 20:20:05 +05:00
if mysql == ' Two ' :
securemysql = pexpect . spawn ( " mysql --host=127.0.0.1 --port=3307 -u root -p " , timeout = 5 )
else :
securemysql = pexpect . spawn ( " mysql -u root -p " , timeout = 5 )
2017-10-24 19:16:36 +05:00
securemysql . expect ( expectation )
securemysql . sendline ( " " )
expectation = " clear the current input statement. "
securemysql . expect ( expectation )
securemysql . sendline ( " use mysql; " )
expectation = " Database changed "
securemysql . expect ( expectation )
securemysql . sendline ( " update user set password=PASSWORD( ' " + InstallCyberPanel . mysql_Root_password + " ' ) where User= ' root ' ; " )
expectation = " Query OK "
securemysql . expect ( expectation )
securemysql . sendline ( " flush privileges; " )
expectation = " Query OK "
securemysql . expect ( expectation )
securemysql . sendline ( " quit " )
securemysql . wait ( )
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " CyberPanel MariaDB root password changed! " )
InstallCyberPanel . stdOut ( " CyberPanel MariaDB root password changed! " )
2017-10-24 19:16:36 +05:00
except pexpect . EOF , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " Exception EOF [changeMYSQLRootPasswordCyberPanel] " )
except pexpect . TIMEOUT , msg :
print securemysql . before
logging . InstallLog . writeToFile ( str ( msg ) + " Exception EOF [changeMYSQLRootPasswordCyberPanel] " )
except BaseException , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [changeMYSQLRootPasswordCyberPanel] " )
return 0
def startMariaDB ( self ) :
############## Start mariadb ######################
try :
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
command = " systemctl start mysql "
res = subprocess . call ( shlex . split ( command ) )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to start MariaDB instance, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to start MariaDB instance, exiting installer! [startMariaDB] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " MariaDB instance successfully started! " )
InstallCyberPanel . stdOut ( " MariaDB instance successfully started! " )
break
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [startMariaDB] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [startMariaDB] " )
return 0
return 1
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; ' )
2018-10-31 11:42:51 -04:00
cursor . execute ( ' set global innodb_file_format = Barracuda; ' )
2018-10-31 11:37:42 -04:00
cursor . execute ( ' set global innodb_large_prefix = on; ' )
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 :
self . stdOut ( " Error in setting: " + fileName + " : " + str ( err ) , 1 , 1 , os . EX_OSERR )
os . system ( ' systemctl restart mysql ' )
self . stdOut ( " MariaDB is now setup so it can support Cyberpanel ' s needs " )
2017-10-24 19:16:36 +05:00
def installPureFTPD ( self ) :
try :
count = 0
while ( 1 ) :
2018-10-26 14:24:28 -04:00
if self . distro == ubuntu :
2018-11-07 09:20:05 -05:00
command = ' apt-get -y install ' + install . preFlightsChecks . pureFTPDServiceName ( self . distro )
2018-10-26 14:24:28 -04:00
else :
command = " yum install -y pure-ftpd "
2018-11-06 00:19:58 +05:00
2018-02-04 21:15:30 +05:00
res = subprocess . call ( shlex . split ( command ) )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Trying to install PureFTPD, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Failed to install PureFTPD, exiting installer! [installPureFTPD] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2017-10-24 19:16:36 +05:00
else :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " PureFTPD successfully installed! " )
InstallCyberPanel . stdOut ( " PureFTPD successfully installed! " )
2017-10-24 19:16:36 +05:00
break
####### Install pureftpd to system startup
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-07 09:20:05 -05:00
command = " systemctl enable " + install . preFlightsChecks . pureFTPDServiceName ( self . distro )
2018-02-04 21:15:30 +05:00
res = subprocess . call ( shlex . split ( command ) )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to enable PureFTPD to start and system restart, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to enable PureFTPD to run at system restart, exiting installer! [installPureFTPD] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " PureFTPD successfully enabled at system restart! " )
InstallCyberPanel . stdOut ( " PureFTPD successfully enabled at system restart! " )
break
2017-10-24 19:16:36 +05:00
###### FTP Groups and user settings settings
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
cmd = [ ]
cmd . append ( " groupadd " )
cmd . append ( " -g " )
cmd . append ( " 2001 " )
cmd . append ( " ftpgroup " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to create group for FTP, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to create group for FTP, exiting installer! [installPureFTPD] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " System group for FTP successfully created! " )
InstallCyberPanel . stdOut ( " System group for FTP successfully created! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd = [ ]
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd . append ( " useradd " )
cmd . append ( " -u " )
cmd . append ( " 2001 " )
cmd . append ( " -s " )
cmd . append ( " /bin/false " )
cmd . append ( " -d " )
cmd . append ( " /bin/null " )
cmd . append ( " -c " )
cmd . append ( ' " pureftpd user " ' )
cmd . append ( " -g " )
cmd . append ( " ftpgroup " )
cmd . append ( " ftpuser " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to create user for FTP, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to create user for FTP, exiting installer! [installPureFTPD] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " System user for FTP successfully created! " )
InstallCyberPanel . stdOut ( " System user for FTP successfully created! " )
break
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installPureFTPD] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installPureFTPD] " )
return 0
return 1
2018-11-07 08:54:16 -05:00
2017-10-24 19:16:36 +05:00
def startPureFTPD ( self ) :
2018-02-04 21:15:30 +05:00
############## Start pureftpd ######################
2017-10-24 19:16:36 +05:00
try :
2018-10-30 12:14:56 -04:00
2018-11-06 00:19:58 +05:00
count = 0
2018-02-04 21:15:30 +05:00
while ( 1 ) :
2018-11-08 12:11:42 +05:00
if self . distro == ubuntu :
command = ' systemctl start pure-ftpd-mysql '
else :
command = ' systemctl start pure-ftpd '
res = subprocess . call ( shlex . split ( command ) )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to start PureFTPD instance, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( " Failed to start PureFTPD instance, you can do this manually later using systemctl start pure-ftpd [startPureFTPD] " )
2018-02-10 12:10:38 +05:00
break
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " PureFTPD instance successfully started! " )
InstallCyberPanel . stdOut ( " PureFTPD instance successfully started! " )
break
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [startPureFTPD] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [startPureFTPD] " )
return 0
return 1
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-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Configuring PureFTPD.. " )
InstallCyberPanel . stdOut ( " Configuring PureFTPD.. " )
2017-12-09 22:30:10 +05:00
try :
os . mkdir ( " /etc/ssl/private " )
except :
logging . InstallLog . writeToFile ( " Could not create directory for FTP SSL " )
2018-02-04 21:15:30 +05:00
count = 0
while ( 1 ) :
2018-11-06 00:19:58 +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 '
2018-02-04 21:15:30 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to create SSL for PureFTPD, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to create SSL for PureFTPD! [installPureFTPDConfigurations] " )
break
else :
logging . InstallLog . writeToFile ( " SSL for PureFTPD successfully created! " )
InstallCyberPanel . stdOut ( " SSL for PureFTPD successfully created! " )
break
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 :
self . stdOut ( " Error creating extra pure-ftpd directories: " + str ( err ) , " . Should be ok " , 1 )
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-12 14:53:10 -05:00
#if self.distro == ubuntu:
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
2018-11-14 13:36:34 +05:00
2017-10-24 19:16:36 +05:00
writeDataToFile . close ( )
2018-11-12 14:53:10 -05:00
#if self.distro == ubuntu:
# os.chmod(ftpdPath + '/pureftpd-ldap.conf', stat.S_IRUSR | stat.S_IWUSR)
# os.chmod(ftpdPath + '/pureftpd-pgsql.conf', stat.S_IRUSR | stat.S_IWUSR)
2018-11-07 16:00:00 -05:00
2018-11-08 12:11:42 +05:00
if self . distro == ubuntu :
command = ' apt install pure-ftpd-mysql -y '
subprocess . call ( shlex . split ( command ) )
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 '
subprocess . call ( command , shell = True )
command = ' systemctl restart pure-ftpd-mysql.service '
subprocess . call ( shlex . split ( command ) )
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " PureFTPD configured! " )
InstallCyberPanel . stdOut ( " PureFTPD configured! " )
2017-10-24 19:16:36 +05:00
except IOError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installPureFTPDConfigurations] " )
return 0
return 1
def installPowerDNS ( self ) :
try :
count = 0
2018-10-29 09:04:11 -04:00
if self . distro == ubuntu :
command = ' systemctl stop systemd-resolved '
res = subprocess . call ( shlex . split ( command ) )
if res != 0 :
InstallCyberPanel . stdOut ( ' Unable to stop systemd.resolved, prohits install of PowerDNS, error # ' +
str ( res ) , 1 , 1 , os . EX_OSERR )
command = ' systemctl disable systemd-resolved.service '
res = subprocess . call ( shlex . split ( command ) )
if res != 0 :
2018-11-06 00:19:58 +05:00
InstallCyberPanel . stdOut (
' Unable to disable systemd.resolved, prohits install of PowerDNS, error # ' +
str ( res ) , 1 , 1 , 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 :
2018-10-29 10:17:57 -04:00
InstallCyberPanel . stdOut ( " Unable to rename /etc/resolv.conf to install PowerDNS: " +
str ( e ) , 1 , 1 , os . EX_OSERR )
try :
os . remove ( ' /etc/resolv.conf ' )
except OSError as e1 :
InstallCyberPanel . stdOut ( " Unable to remove existing /etc/resolv.conf to install PowerDNS: " +
str ( e1 ) , 1 , 1 , os . EX_OSERR )
2018-10-29 11:27:50 -04:00
try :
f = open ( ' /etc/resolv.conf ' , ' w ' )
f . write ( ' nameserver 8.8.8.8 ' )
f . close ( )
except IOError as e :
InstallCyberPanel . stdOut ( " Unable to create /etc/resolv.conf: " + str ( e ) +
" . This may need to be fixed manually as ' echo \" nameserver 8.8.8.8 \" > "
" /etc/resolv.conf ' " , 1 , 1 , os . EX_OSERR )
2018-10-29 10:17:57 -04:00
2018-10-26 14:24:28 -04:00
if self . distro == centos :
while ( 1 ) :
command = ' yum -y install epel-release yum-plugin-priorities '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-10-26 14:24:28 -04:00
count = count + 1
2018-11-06 00:19:58 +05:00
InstallCyberPanel . stdOut (
" Trying to install PowerDNS Repositories, trying again, try number: " + str ( count ) )
2018-10-26 14:24:28 -04:00
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile (
" Failed to install PowerDNS Repositories, exiting installer! [installPowerDNS] " )
2018-10-26 14:24:28 -04:00
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
else :
logging . InstallLog . writeToFile ( " PowerDNS Repositories successfully installed! " )
InstallCyberPanel . stdOut ( " PowerDNS Repositories successfully installed! " )
break
2017-10-24 19:16:36 +05:00
2018-10-26 14:24:28 -04:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-06 00:19:58 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-10-26 14:24:28 -04:00
command = ' curl -o /etc/yum.repos.d/powerdns-auth-master.repo ' \
' https://repo.powerdns.com/repo-files/centos-auth-master.repo '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-10-26 14:24:28 -04:00
count = count + 1
InstallCyberPanel . stdOut (
" Trying to install PowerDNS Repositories, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed to install PowerDNS Repositories, exiting installer! [installPowerDNS] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
else :
logging . InstallLog . writeToFile ( " PowerDNS Repositories successfully installed! " )
InstallCyberPanel . stdOut ( " PowerDNS Repositories successfully installed! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 1
2017-10-24 19:16:36 +05:00
2018-11-06 00:19:58 +05:00
while ( 1 ) :
2018-10-26 14:24:28 -04:00
if self . distro == ubuntu :
2018-10-30 09:51:30 -04:00
command = " DEBIAN_FRONTEND=noninteractive apt-get -y install pdns-server pdns-backend-mysql "
2018-10-31 11:06:24 -04:00
res = os . system ( command )
2018-10-26 14:24:28 -04:00
else :
command = ' yum -y install pdns pdns-backend-mysql '
2018-10-31 11:06:24 -04:00
cmd = shlex . split ( command )
2018-11-01 20:40:32 -04:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Trying to install PowerDNS, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile (
" Failed to install PowerDNS, exiting installer! [installPowerDNS] " )
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2017-10-24 19:16:36 +05:00
else :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " PowerDNS successfully installed! " )
InstallCyberPanel . stdOut ( " PowerDNS successfully installed! " )
2017-10-24 19:16:36 +05:00
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [powerDNS] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [powerDNS] " )
return 0
return 1
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
logging . InstallLog . writeToFile ( " Configuring PowerDNS.. " )
InstallCyberPanel . stdOut ( " Configuring PowerDNS.. " )
2017-10-24 19:16:36 +05:00
os . chdir ( self . cwd )
2018-10-30 17:33:43 -04:00
if self . distro == centos :
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-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " PowerDNS configured! " )
InstallCyberPanel . stdOut ( " PowerDNS configured! " )
2017-10-24 19:16:36 +05:00
except IOError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installPowerDNSConfigurations] " )
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
try :
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd = [ ]
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd . append ( " systemctl " )
cmd . append ( " enable " )
cmd . append ( " pdns " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to enable PowerDNS to start and system restart, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( " Failed to enable PowerDNS to run at system restart, you can manually do this later using systemctl enable pdns! [startPowerDNS] " )
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
break
else :
logging . InstallLog . writeToFile ( " PowerDNS successfully enabled at system restart! " )
InstallCyberPanel . stdOut ( " PowerDNS successfully enabled at system restart! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 1
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
command = ' systemctl start pdns '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to start PowerDNS instance, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to start PowerDNS instance, exiting installer! [startPowerDNS] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " PowerDNS instance successfully started! " )
InstallCyberPanel . stdOut ( " PowerDNS instance successfully started! " )
break
2017-10-24 19:16:36 +05:00
except OSError , msg :
2017-11-02 02:09:47 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [startPowerDNS] " )
2017-10-24 19:16:36 +05:00
return 0
except ValueError , msg :
2017-11-02 02:09:47 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [startPowerDNS] " )
2017-10-24 19:16:36 +05:00
return 0
return 1
def installLSCPD ( self ) :
try :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Starting LSCPD installation.. " )
InstallCyberPanel . stdOut ( " Starting LSCPD installation.. " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
os . chdir ( self . cwd )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-06 00:19:58 +05:00
while ( 1 ) :
2018-10-26 14:24:28 -04:00
if self . distro == ubuntu :
command = " apt-get -y install gcc g++ make autoconf rcs "
else :
command = ' yum -y install gcc gcc-c++ make autoconf glibc rcs '
2018-11-06 00:19:58 +05:00
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to install LSCPD prerequisites, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to install LSCPD prerequisites, exiting installer! [installLSCPD] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " LSCPD prerequisites successfully installed! " )
InstallCyberPanel . stdOut ( " LSCPD prerequisites successfully installed! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
2018-10-26 14:24:28 -04:00
if self . distro == ubuntu :
command = " apt-get -y install libpcre3 libpcre3-dev openssl libexpat1 libexpat1-dev libgeoip-dev " \
" zlib1g zlib1g-dev libudns-dev whichman curl "
else :
command = ' yum -y install pcre-devel openssl-devel expat-devel geoip-devel zlib-devel udns-devel ' \
' which curl '
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to install LSCPD prerequisites, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to install LSCPD prerequisites, exiting installer! [installLSCPD] " )
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " LSCPD prerequisites successfully installed! " )
InstallCyberPanel . stdOut ( " LSCPD prerequisites successfully installed! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-10-12 18:18:10 +05:00
command = ' tar zxf lscp.tar.gz -C /usr/local/ '
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2017-12-09 22:30:10 +05:00
res = subprocess . call ( cmd )
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2017-12-09 22:30:10 +05:00
count = count + 1
2018-11-06 00:19:58 +05:00
InstallCyberPanel . stdOut ( " Trying to configure LSCPD, trying again, try number: " + str ( count ) )
2017-12-09 22:30:10 +05:00
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( " Failed to configure LSCPD, exiting installer! [installLSCPD] " )
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2017-12-09 22:30:10 +05:00
else :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( " LSCPD successfully configured! " )
2018-02-04 21:15:30 +05:00
InstallCyberPanel . stdOut ( " LSCPD successfully extracted! " )
2017-12-09 22:30:10 +05:00
break
2018-02-04 21:15:30 +05:00
count = 0
while ( 1 ) :
2017-12-09 22:30:10 +05:00
2018-11-06 00:19:58 +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 /usr/local/lscp/key.pem -out /usr/local/lscp/cert.pem '
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2017-12-09 22:30:10 +05:00
2018-11-14 11:37:17 -05:00
if install . preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
InstallCyberPanel . stdOut ( " Trying to create SSL for LSCPD, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Failed to create SSL for LSCPD! [installLSCPD] " )
2017-12-09 22:30:10 +05:00
break
2018-02-04 21:15:30 +05:00
else :
logging . InstallLog . writeToFile ( " SSL for LSCPD successfully created! " )
InstallCyberPanel . stdOut ( " SSL for LSCPD successfully created! " )
break
2017-12-09 22:30:10 +05:00
2018-02-04 21:15:30 +05:00
try :
os . remove ( " /usr/local/lscp/fcgi-bin/lsphp " )
shutil . copy ( " /usr/local/lsws/lsphp70/bin/lsphp " , " /usr/local/lscp/fcgi-bin/lsphp " )
except :
pass
2017-12-09 22:30:10 +05:00
2018-10-29 16:26:07 -04:00
if self . distro == centos :
command = ' adduser lscpd -M -d /usr/local/lscp '
else :
command = ' useradd lscpd -M -d /usr/local/lscp '
2018-10-12 18:18:10 +05:00
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2018-10-29 16:26:07 -04:00
if self . distro == centos :
command = ' groupadd lscpd '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
# Added group in useradd for Ubuntu
2018-10-12 18:18:10 +05:00
command = ' usermod -a -G lscpd lscpd '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
command = ' usermod -a -G lsadm lscpd '
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
os . mkdir ( ' /usr/local/lscp/cyberpanel ' )
2017-12-09 22:30:10 +05:00
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " LSCPD successfully installed! " )
InstallCyberPanel . stdOut ( " LSCPD successfully installed! " )
2017-12-09 22:30:10 +05:00
except OSError , msg :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [installLSCPD] " )
2017-12-09 22:30:10 +05:00
return 0
except ValueError , msg :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [installLSCPD] " )
2017-12-09 22:30:10 +05:00
return 0
return 1
2017-10-24 19:16:36 +05:00
2018-11-10 16:05:40 +05:00
def Main ( cwd , mysql , distro , ent ) :
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 '
2018-10-30 15:58:45 -04:00
if os . access ( file_name , os . F_OK ) :
2018-10-30 15:51:22 -04:00
password = open ( file_name , ' r ' )
InstallCyberPanel . mysql_Root_password = password . readline ( )
else :
password = open ( file_name , " w " )
password . writelines ( InstallCyberPanel . mysql_Root_password )
2018-11-06 00:19:58 +05:00
2017-10-24 19:16:36 +05:00
password . close ( )
2018-10-30 15:51:22 -04:00
if distro == centos :
InstallCyberPanel . mysqlPassword = randomPassword . generate_pass ( )
else :
InstallCyberPanel . mysqlPassword = InstallCyberPanel . mysql_Root_password
2018-11-10 16:05:40 +05:00
installer = InstallCyberPanel ( " /usr/local/lsws/ " , cwd , distro , ent )
2017-10-24 19:16:36 +05:00
installer . installLiteSpeed ( )
2018-11-10 16:05:40 +05:00
if ent == 0 :
installer . changePortTo80 ( )
2017-12-09 22:30:10 +05:00
installer . setupFileManager ( )
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-11-06 00:19:58 +05:00
2017-10-24 19:16:36 +05:00
installer . setup_mariadb_repo ( )
2018-05-29 20:20:05 +05:00
installer . installMySQL ( mysql )
2018-10-31 11:53:03 -04:00
installer . changeMYSQLRootPassword ( )
installer . changeMYSQLRootPasswordCyberPanel ( mysql )
2017-10-24 19:16:36 +05:00
installer . startMariaDB ( )
2018-10-31 11:06:24 -04:00
if distro == ubuntu :
installer . fixMariaDB ( )
2017-10-24 19:16:36 +05:00
2018-11-06 00:19:58 +05:00
mysqlUtilities . createDatabaseCyberPanel ( " cyberpanel " , " cyberpanel " , InstallCyberPanel . mysqlPassword , mysql )
2017-10-24 19:16:36 +05:00
installer . installPureFTPD ( )
2018-05-29 20:20:05 +05:00
installer . installPureFTPDConfigurations ( mysql )
2017-10-24 19:16:36 +05:00
installer . startPureFTPD ( )
installer . installPowerDNS ( )
2018-05-29 20:20:05 +05:00
installer . installPowerDNSConfigurations ( InstallCyberPanel . mysqlPassword , mysql )
2017-10-24 19:16:36 +05:00
installer . startPowerDNS ( )
installer . installLSCPD ( )