2017-10-24 19:16:36 +05:00
import sys
import subprocess
import shutil
import installLog as logging
import argparse
import os
import shlex
from firewallUtilities import FirewallUtilities
2018-02-04 21:15:30 +05:00
import time
2018-06-11 21:04:55 +05:00
import string
import random
2018-11-06 13:03:12 +05:00
import socket
2018-10-25 16:47:26 -04:00
from os . path import *
from stat import *
2018-11-07 15:14:54 -05:00
import stat
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
# There can not be peace without first a great suffering.
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
# distros
2018-11-06 00:19:58 +05:00
2018-11-16 14:41:40 +05:00
centos = 0
ubuntu = 1
2018-10-25 16:10:01 -04:00
2019-03-26 16:19:03 +05:00
def get_distro ( ) :
distro = - 1
distro_file = " "
if exists ( " /etc/lsb-release " ) :
distro_file = " /etc/lsb-release "
with open ( distro_file ) as f :
for line in f :
if line == " DISTRIB_ID=Ubuntu \n " :
distro = ubuntu
elif exists ( " /etc/os-release " ) :
distro_file = " /etc/os-release "
distro = centos
else :
logging . InstallLog . writeToFile ( " Can ' t find linux release file - fatal error " )
preFlightsChecks . stdOut ( " Can ' t find linux release file - fatal error " )
os . _exit ( os . EX_UNAVAILABLE )
if distro == - 1 :
logging . InstallLog . writeToFile ( " Can ' t find distro name in " + distro_file + " - fatal error " )
preFlightsChecks . stdOut ( " Can ' t find distro name in " + distro_file + " - fatal error " )
os . _exit ( os . EX_UNAVAILABLE )
return distro
def get_Ubuntu_release ( ) :
release = - 1
if exists ( " /etc/lsb-release " ) :
distro_file = " /etc/lsb-release "
with open ( distro_file ) as f :
for line in f :
if line [ : 16 ] == " DISTRIB_RELEASE= " :
release = float ( line [ 16 : ] )
if release == - 1 :
preFlightsChecks . stdOut ( " Can ' t find distro release name in " + distro_file + " - fatal error " , 1 , 1 ,
os . EX_UNAVAILABLE )
else :
logging . InstallLog . writeToFile ( " Can ' t find linux release file - fatal error " )
preFlightsChecks . stdOut ( " Can ' t find linux release file - fatal error " )
os . _exit ( os . EX_UNAVAILABLE )
return release
2018-11-06 00:19:58 +05:00
2018-11-16 14:41:40 +05:00
class preFlightsChecks :
2018-03-08 22:19:23 +05:00
cyberPanelMirror = " mirror.cyberpanel.net/pip "
2018-03-04 13:37:58 +05:00
2018-11-16 14:41:40 +05:00
def __init__ ( self , rootPath , ip , path , cwd , cyberPanelPath , distro ) :
2017-10-24 19:16:36 +05:00
self . ipAddr = ip
self . path = path
self . cwd = cwd
self . server_root_path = rootPath
2017-12-09 22:30:10 +05:00
self . cyberPanelPath = cyberPanelPath
2018-10-25 16:10:01 -04:00
self . distro = distro
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
@staticmethod
def stdOut ( message , log = 0 , do_exit = 0 , code = os . EX_OK ) :
print ( " \n \n " )
print ( " [ " + time . strftime (
" % I- % M- % S- %a - % b- % Y " ) + " ] ######################################################################### \n " )
print ( " [ " + time . strftime ( " % I- % M- % S- %a - % b- % Y " ) + " ] " + message + " \n " )
print ( " [ " + time . strftime (
" % I- % M- % S- %a - % b- % Y " ) + " ] ######################################################################### \n " )
if log :
logging . InstallLog . writeToFile ( message )
if do_exit :
sys . exit ( code )
2019-03-21 23:26:42 +05:00
def mountTemp ( self ) :
try :
2019-03-30 14:21:52 +05:00
command = " dd if=/dev/zero of=/usr/.tempdisk bs=100M count=15 "
2019-03-26 16:19:03 +05:00
preFlightsChecks . call ( command , self . distro , ' [mountTemp] ' ,
' mountTemp ' ,
1 , 0 , os . EX_OSERR )
2019-03-21 23:26:42 +05:00
2019-03-30 14:21:52 +05:00
command = " mkfs.ext4 -F /usr/.tempdisk "
2019-03-26 16:19:03 +05:00
preFlightsChecks . call ( command , self . distro , ' [mountTemp] ' ,
' mountTemp ' ,
1 , 0 , os . EX_OSERR )
2019-03-21 23:26:42 +05:00
2019-03-30 14:21:52 +05:00
command = " mkdir -p /usr/.tmpbak/ "
2019-03-26 16:19:03 +05:00
preFlightsChecks . call ( command , self . distro , ' [mountTemp] ' ,
' mountTemp ' ,
1 , 0 , os . EX_OSERR )
2019-03-21 23:26:42 +05:00
2019-03-30 14:21:52 +05:00
command = " cp -pr /tmp/* /usr/.tmpbak/ "
subprocess . call ( command , shell = True )
command = " mount -o loop,rw,nodev,nosuid,noexec,nofail /usr/.tempdisk /tmp "
2019-03-26 16:19:03 +05:00
preFlightsChecks . call ( command , self . distro , ' [mountTemp] ' ,
' mountTemp ' ,
1 , 0 , os . EX_OSERR )
2019-03-21 23:26:42 +05:00
command = " chmod 1777 /tmp "
2019-03-26 16:19:03 +05:00
preFlightsChecks . call ( command , self . distro , ' [mountTemp] ' ,
' mountTemp ' ,
1 , 0 , os . EX_OSERR )
2019-03-21 23:26:42 +05:00
2019-03-30 14:21:52 +05:00
command = " cp -pr /usr/.tmpbak/* /tmp/ "
subprocess . call ( command , shell = True )
command = " rm -rf /usr/.tmpbak "
preFlightsChecks . call ( command , self . distro , ' [mountTemp] ' ,
' mountTemp ' ,
1 , 0 , os . EX_OSERR )
command = " mount --bind /tmp /var/tmp "
2019-03-26 16:19:03 +05:00
preFlightsChecks . call ( command , self . distro , ' [mountTemp] ' ,
' mountTemp ' ,
1 , 0 , os . EX_OSERR )
2019-03-21 23:26:42 +05:00
2019-03-30 14:21:52 +05:00
tmp = " /usr/.tempdisk /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0 \n "
varTmp = " /tmp /var/tmp none bind 0 0 \n "
2019-03-21 23:26:42 +05:00
fstab = " /etc/fstab "
writeToFile = open ( fstab , " a " )
2019-03-30 14:21:52 +05:00
writeToFile . writelines ( tmp )
2019-03-21 23:26:42 +05:00
writeToFile . writelines ( varTmp )
writeToFile . close ( )
except BaseException , msg :
preFlightsChecks . stdOut ( " [Failed:mountTemp] " + str ( msg ) )
return 0
2018-11-07 09:20:05 -05:00
@staticmethod
2018-11-07 09:28:09 -05:00
def pureFTPDServiceName ( distro ) :
2018-11-07 09:20:05 -05:00
if distro == ubuntu :
2018-11-07 09:56:45 -05:00
return ' pure-ftpd '
2018-11-07 09:20:05 -05:00
return ' pure-ftpd '
2018-11-14 11:37:17 -05:00
@staticmethod
def resFailed ( distro , res ) :
if distro == ubuntu and res != 0 :
return True
2018-12-06 15:03:43 +05:00
elif distro == centos and res != 0 :
2018-11-14 11:37:17 -05:00
return True
return False
@staticmethod
2018-11-16 14:41:40 +05:00
def call ( command , distro , bracket , message , log = 0 , do_exit = 0 , code = os . EX_OK ) :
2018-11-14 11:37:17 -05:00
preFlightsChecks . stdOut ( message + " " + bracket , log )
count = 0
while True :
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( distro , res ) :
count = count + 1
preFlightsChecks . stdOut ( message + " failed, trying again, try number: " + str ( count ) )
if count == 3 :
fatal_message = ' '
if do_exit :
fatal_message = ' . Fatal error, see /var/log/installLogs.txt for full details '
2018-12-06 15:03:43 +05:00
preFlightsChecks . stdOut ( " [ERROR] We are not able to " + message + ' return code: ' + str ( res ) +
2018-11-14 11:37:17 -05:00
fatal_message + " " + bracket , 1 , do_exit , code )
return False
else :
preFlightsChecks . stdOut ( message + ' successful ' , log )
break
return True
2018-11-06 00:19:58 +05:00
def checkIfSeLinuxDisabled ( self ) :
try :
command = " sestatus "
2019-03-26 16:19:03 +05:00
output = subprocess . check_output ( shlex . split ( command ) )
2018-11-06 00:19:58 +05:00
if output . find ( " disabled " ) > - 1 or output . find ( " permissive " ) > - 1 :
logging . InstallLog . writeToFile ( " SELinux Check OK. [checkIfSeLinuxDisabled] " )
preFlightsChecks . stdOut ( " SELinux Check OK. " )
return 1
else :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" SELinux is enabled, please disable SELinux and restart the installation! " )
2018-11-06 00:19:58 +05:00
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
2018-11-16 14:41:40 +05:00
except BaseException , msg :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [checkIfSeLinuxDisabled] " )
logging . InstallLog . writeToFile ( " SELinux Check OK. [checkIfSeLinuxDisabled] " )
preFlightsChecks . stdOut ( " SELinux Check OK. " )
return 1
2018-02-04 21:15:30 +05:00
def checkPythonVersion ( self ) :
if sys . version_info [ 0 ] == 2 and sys . version_info [ 1 ] == 7 :
return 1
else :
preFlightsChecks . stdOut ( " You are running Unsupported python version, please install python 2.7 " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2017-12-09 22:30:10 +05:00
2018-02-04 21:15:30 +05:00
def setup_account_cyberpanel ( self ) :
try :
2017-12-09 22:30:10 +05:00
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-12-13 04:23:08 +05:00
command = " yum install sudo -y "
preFlightsChecks . call ( command , self . distro , ' [setup_account_cyberpanel] ' ,
2018-12-17 18:46:34 +05:00
' Install sudo. ' ,
1 , 0 , os . EX_OSERR )
2017-12-09 22:30:10 +05:00
2018-02-04 21:15:30 +05:00
##
2017-12-09 22:30:10 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2017-11-05 03:02:51 +05:00
2018-10-26 09:56:12 -04:00
if self . distro == ubuntu :
2019-03-30 14:21:52 +05:00
# self.stdOut("Fix sudoers")
# try:
# fileName = '/etc/sudoers'
# data = open(fileName, 'r').readlines()
#
# writeDataToFile = open(fileName, 'w')
# for line in data:
# if line[:5] == '%sudo':
# writeDataToFile.write('%sudo ALL=(ALL:ALL) NOPASSWD: ALL\n')
# else:
# writeDataToFile.write(line)
# writeDataToFile.close()
# except IOError as err:
# self.stdOut("Error in fixing sudoers file: " + str(err), 1, 1, os.EX_OSERR)
2018-11-01 09:43:04 -04:00
2018-10-26 09:52:07 -04:00
self . stdOut ( " Add Cyberpanel user " )
2019-04-15 15:54:23 +05:00
command = ' adduser --disabled-login --gecos " " cyberpanel '
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-10-25 16:10:01 -04:00
if res != 0 and res != 9 :
logging . InstallLog . writeToFile ( " Can not create cyberpanel user, error # " + str ( res ) )
preFlightsChecks . stdOut ( " Can not create cyberpanel user, error # " + str ( res ) )
os . _exit ( 0 )
if res == 0 :
logging . InstallLog . writeToFile ( " CyberPanel user added " )
preFlightsChecks . stdOut ( " CyberPanel user added " )
2017-11-05 03:02:51 +05:00
2018-10-25 16:10:01 -04:00
else :
2019-03-30 14:21:52 +05:00
command = " useradd -s /bin/false cyberpanel "
2018-12-13 04:23:08 +05:00
preFlightsChecks . call ( command , self . distro , ' [setup_account_cyberpanel] ' ,
2018-12-17 18:46:34 +05:00
' add user cyberpanel ' ,
1 , 0 , os . EX_OSERR )
2017-11-05 03:02:51 +05:00
2019-03-30 14:21:52 +05:00
# ##
#
# command = "usermod -aG wheel cyberpanel"
# preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
# 'add user cyberpanel',
# 1, 0, os.EX_OSERR)
2017-11-05 03:02:51 +05:00
2018-11-16 14:41:40 +05:00
###############################
2017-11-05 03:02:51 +05:00
2019-03-30 14:21:52 +05:00
# path = "/etc/sudoers"
#
# data = open(path, 'r').readlines()
#
# writeToFile = open(path, 'w')
#
# for items in data:
# if items.find("wheel ALL=(ALL) NOPASSWD: ALL") > -1:
# writeToFile.writelines("%wheel ALL=(ALL) NOPASSWD: ALL")
# else:
# writeToFile.writelines(items)
#
# writeToFile.close()
2018-02-04 21:15:30 +05:00
2018-11-06 00:19:58 +05:00
###############################
2018-02-04 21:15:30 +05:00
2019-04-15 15:54:23 +05:00
### Docker User/group
if self . distro == ubuntu :
command = ' adduser --disabled-login --gecos " " docker '
else :
command = " adduser docker "
preFlightsChecks . call ( command , self . distro , ' [setup_account_cyberpanel] ' ,
' add user cyberpanel ' ,
1 , 0 , os . EX_OSERR )
command = ' groupadd docker '
preFlightsChecks . call ( command , self . distro , ' [setup_account_cyberpanel] ' ,
' add user cyberpanel ' ,
1 , 0 , os . EX_OSERR )
command = ' usermod -aG docker docker '
preFlightsChecks . call ( command , self . distro , ' [setup_account_cyberpanel] ' ,
' add user cyberpanel ' ,
1 , 0 , os . EX_OSERR )
command = ' usermod -aG docker cyberpanel '
preFlightsChecks . call ( command , self . distro , ' [setup_account_cyberpanel] ' ,
' add user cyberpanel ' ,
1 , 0 , os . EX_OSERR )
###
2018-12-13 04:23:08 +05:00
command = " mkdir -p /etc/letsencrypt/live/ "
preFlightsChecks . call ( command , self . distro , ' [setup_account_cyberpanel] ' ,
2018-12-17 18:46:34 +05:00
' add user cyberpanel ' ,
1 , 0 , os . EX_OSERR )
2018-11-06 00:19:58 +05:00
2018-12-13 04:23:08 +05:00
except BaseException , msg :
logging . InstallLog . writeToFile ( " [ERROR] setup_account_cyberpanel. " + str ( msg ) )
2017-11-05 03:02:51 +05:00
2018-02-04 21:15:30 +05:00
def yum_update ( self ) :
try :
count = 0
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
command = ' yum update -y '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " YUM UPDATE FAILED, trying again, try number: " + str ( count ) + " \n " )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" YUM update failed to run, we are being optimistic that installer will still be able to complete installation. [yum_update] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " YUM UPDATE ran successfully. " )
preFlightsChecks . stdOut ( " YUM UPDATE ran successfully. " )
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [yum_update] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [yum_update] " )
return 0
return 1
2017-10-24 19:16:36 +05:00
def installCyberPanelRepo ( self ) :
2018-10-26 09:11:17 -04:00
self . stdOut ( " Install Cyberpanel repo " )
2017-10-24 19:16:36 +05:00
cmd = [ ]
count = 0
2018-10-26 09:56:12 -04:00
if self . distro == ubuntu :
2018-10-25 16:10:01 -04:00
try :
filename = " enable_lst_debain_repo.sh "
command = " wget http://rpms.litespeedtech.com/debian/ " + filename
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-10-25 16:10:01 -04:00
if res != 0 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile (
" Unable to download Ubuntu CyberPanel installer! [installCyberPanelRepo]: "
" Error # " + str ( res ) )
2018-10-25 16:18:47 -04:00
preFlightsChecks . stdOut ( " Unable to download Ubuntu CyberPanel installer! [installCyberPanelRepo]: "
" Error # " + str ( res ) )
2018-10-25 16:47:26 -04:00
os . _exit ( os . EX_NOINPUT )
2018-10-25 16:10:01 -04:00
2018-10-25 16:47:26 -04:00
os . chmod ( filename , S_IRWXU | S_IRWXG )
2018-10-25 16:10:01 -04:00
command = " ./ " + filename
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-10-25 16:10:01 -04:00
if res != 0 :
2018-10-25 16:18:47 -04:00
logging . InstallLog . writeToFile ( " Unable to install Ubuntu CyberPanel! [installCyberPanelRepo]: "
2018-10-25 16:10:01 -04:00
" Error # " + str ( res ) )
2018-10-25 16:18:47 -04:00
preFlightsChecks . stdOut ( " Unable to install Ubuntu CyberPanel! [installCyberPanelRepo]: "
2018-10-25 16:10:01 -04:00
" Error # " + str ( res ) )
2018-10-25 16:47:26 -04:00
os . _exit ( os . EX_NOINPUT )
2018-10-25 16:10:01 -04:00
except OSError as err :
2018-10-25 16:47:26 -04:00
logging . InstallLog . writeToFile ( " Exception during CyberPanel install: " + str ( err ) )
preFlightsChecks . stdOut ( " Exception during CyberPanel install: " + str ( err ) )
2018-10-25 16:10:01 -04:00
os . _exit ( os . EX_OSERR )
except :
logging . InstallLog . writeToFile ( " Exception during CyberPanel install " )
preFlightsChecks . stdOut ( " Exception during CyberPanel install " )
os . _exit ( os . EX_SOFTWARE )
2018-11-09 22:01:28 +05:00
else :
while ( 1 ) :
cmd . append ( " rpm " )
cmd . append ( " -ivh " )
cmd . append ( " http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm " )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-09 22:01:28 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Unable to add CyberPanel official repository, trying again, try number: " + str ( count ) + " \n " )
if count == 3 :
logging . InstallLog . writeToFile (
" Unable to add CyberPanel official repository, exiting installer! [installCyberPanelRepo] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
else :
logging . InstallLog . writeToFile ( " CyberPanel Repo added! " )
preFlightsChecks . stdOut ( " CyberPanel Repo added! " )
break
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
def enableEPELRepo ( self ) :
try :
cmd = [ ]
count = 0
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
while ( 1 ) :
cmd . append ( " yum " )
cmd . append ( " -y " )
cmd . append ( " install " )
cmd . append ( " epel-release " )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-12-09 22:30:10 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2017-12-09 22:30:10 +05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to add EPEL repository, trying again, try number: " + str ( count ) + " \n " )
2017-12-09 22:30:10 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to add EPEL repository, exiting installer! [enableEPELRepo] " )
2018-02-04 21:15:30 +05:00
preFlightsChecks . 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-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " EPEL Repo added! " )
preFlightsChecks . stdOut ( " EPEL Repo added! " )
2017-12-09 22:30:10 +05:00
break
2018-11-16 14:41:40 +05:00
except OSError , msg :
2017-12-09 22:30:10 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [enableEPELRepo] " )
2018-07-05 15:22:48 +05:00
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
2017-12-09 22:30:10 +05:00
return 0
2018-11-16 14:41:40 +05:00
except ValueError , msg :
2017-12-09 22:30:10 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [enableEPELRepo] " )
2018-07-05 15:22:48 +05:00
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
2017-12-09 22:30:10 +05:00
return 0
return 1
2017-10-24 19:16:36 +05:00
def install_pip ( self ) :
2018-10-26 09:11:17 -04:00
self . stdOut ( " Install pip " )
2017-10-24 19:16:36 +05:00
count = 0
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == ubuntu :
2018-11-02 09:17:16 -04:00
command = " apt-get -y install python-pip "
2018-10-25 16:10:01 -04:00
else :
command = " yum -y install python-pip "
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Unable to install PIP, 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 ( " Unable to install PIP, exiting installer! [install_pip] " )
preFlightsChecks . 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 ( " PIP successfully installed! " )
preFlightsChecks . stdOut ( " PIP successfully installed! " )
2017-10-24 19:16:36 +05:00
break
2018-02-04 21:15:30 +05:00
def install_python_dev ( self ) :
2018-10-26 09:11:17 -04:00
self . stdOut ( " Install python development environment " )
2017-10-24 19:16:36 +05:00
count = 0
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = " yum -y install python-devel "
else :
command = " apt-get -y install python-dev "
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" We are trying to install python development tools, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to install python development tools, exiting installer! [install_python_dev] " )
2018-02-04 21:15:30 +05:00
preFlightsChecks . 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 ( " Python development tools successfully installed! " )
preFlightsChecks . stdOut ( " Python development tools successfully installed! " )
2017-10-24 19:16:36 +05:00
break
2018-02-04 21:15:30 +05:00
def install_gcc ( self ) :
2018-10-26 09:11:17 -04:00
self . stdOut ( " Install gcc " )
2017-10-24 19:16:36 +05:00
count = 0
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = " yum -y install gcc "
2018-10-25 16:47:26 -04:00
else :
2018-10-25 16:10:01 -04:00
command = " apt-get -y install gcc "
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to install GCC, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Unable to install GCC, exiting installer! [install_gcc] " )
preFlightsChecks . 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 ( " GCC Successfully installed! " )
preFlightsChecks . stdOut ( " GCC Successfully installed! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
def install_python_setup_tools ( self ) :
count = 0
while ( 1 ) :
command = " yum -y install python-setuptools "
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
print ( " [ " + time . strftime (
" % I- % M- % S- %a - % b- % Y " ) + " ] " + " Unable to install Python setup tools, trying again, try number: " + str (
count ) + " \n " )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile (
" Unable to install Python setup tools, exiting installer! [install_python_setup_tools] " )
2018-07-05 15:22:48 +05:00
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
2017-10-24 19:16:36 +05:00
else :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Python setup tools Successfully installed! " )
print ( " [ " + time . strftime ( " % I- % M- % S- %a - % b- % Y " ) + " ] " + " Python setup tools Successfully installed! " )
2017-10-24 19:16:36 +05:00
break
def install_python_requests ( self ) :
try :
import requests
2018-03-08 22:19:23 +05:00
## Un-install ULRLIB3 and requests
command = " pip uninstall --yes urllib3 "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
command = " pip uninstall --yes requests "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
## Install specific versions
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /urllib3-1.22.tar.gz "
2018-03-08 22:19:23 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-03-08 22:19:23 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Unable to install urllib3 module, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Unable to install urllib3 module, exiting installer! [install_python_requests] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-03-08 22:19:23 +05:00
else :
logging . InstallLog . writeToFile ( " urllib3 module Successfully installed! " )
preFlightsChecks . stdOut ( " urllib3 module Successfully installed! " )
break
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /requests-2.18.4.tar.gz "
2018-03-08 22:19:23 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-03-08 22:19:23 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Unable to install requests module, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Unable to install requests module, exiting installer! [install_python_requests] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-03-08 22:19:23 +05:00
else :
logging . InstallLog . writeToFile ( " Requests module Successfully installed! " )
preFlightsChecks . stdOut ( " Requests module Successfully installed! " )
break
2017-10-24 19:16:36 +05:00
except :
2018-03-08 22:19:23 +05:00
2017-10-24 19:16:36 +05:00
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /urllib3-1.22.tar.gz "
2018-02-04 21:15:30 +05:00
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-03-08 22:19:23 +05:00
preFlightsChecks . stdOut (
" Unable to install urllib3 module, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-03-08 22:19:23 +05:00
logging . InstallLog . writeToFile (
" Unable to install urllib3 module, exiting installer! [install_python_requests] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-03-08 22:19:23 +05:00
else :
logging . InstallLog . writeToFile ( " urllib3 module Successfully installed! " )
preFlightsChecks . stdOut ( " urllib3 module Successfully installed! " )
break
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /requests-2.18.4.tar.gz "
2018-03-08 22:19:23 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-03-08 22:19:23 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Unable to install requests module, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Unable to install requests module, exiting installer! [install_python_requests] " )
2018-02-04 21:15:30 +05:00
preFlightsChecks . 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 ( " Requests module Successfully installed! " )
preFlightsChecks . stdOut ( " Requests module Successfully installed! " )
2017-10-24 19:16:36 +05:00
break
def install_pexpect ( self ) :
try :
import pexpect
2018-03-08 22:19:23 +05:00
command = " pip uninstall --yes pexpect "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /pexpect-4.4.0.tar.gz "
2018-03-08 22:19:23 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-03-08 22:19:23 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to install pexpect, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to install pexpect, exiting installer! [install_pexpect] " )
2018-03-08 22:19:23 +05:00
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-03-08 22:19:23 +05:00
else :
logging . InstallLog . writeToFile ( " pexpect successfully installed! " )
preFlightsChecks . stdOut ( " pexpect successfully installed! " )
break
2017-10-24 19:16:36 +05:00
except :
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /pexpect-4.4.0.tar.gz "
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Unable to install pexpect, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to install pexpect, exiting installer! [install_pexpect] " )
2018-02-04 21:15:30 +05:00
preFlightsChecks . 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 ( " pexpect successfully installed! " )
preFlightsChecks . stdOut ( " pexpect successfully installed! " )
2017-10-24 19:16:36 +05:00
break
def install_django ( self ) :
count = 0
while ( 1 ) :
2018-02-04 21:15:30 +05:00
command = " pip install django==1.11 "
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Unable to install DJANGO, 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 ( " Unable to install DJANGO, exiting installer! [install_django] " )
preFlightsChecks . 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 ( " DJANGO successfully installed! " )
preFlightsChecks . stdOut ( " DJANGO successfully installed! " )
2017-10-24 19:16:36 +05:00
break
def install_python_mysql_library ( self ) :
2018-10-26 09:11:17 -04:00
self . stdOut ( " Install MySQL python library " )
2017-10-24 19:16:36 +05:00
count = 0
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = " yum -y install MySQL-python "
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = " apt-get -y install libmysqlclient-dev "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Unable to install MySQL-python, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to install MySQL-python, exiting installer! [install_python_mysql_library] " )
2018-02-04 21:15:30 +05:00
preFlightsChecks . 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 ( " MySQL-python successfully installed! " )
preFlightsChecks . stdOut ( " MySQL-python successfully installed! " )
2017-10-24 19:16:36 +05:00
break
2018-11-06 13:03:12 +05:00
if self . distro == ubuntu :
command = " pip install MySQL-python "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-11-06 13:03:12 +05:00
if res != 0 :
logging . InstallLog . writeToFile (
" Unable to install MySQL-python, exiting installer! [install_python_mysql_library] Error: " + str (
res ) )
preFlightsChecks . stdOut (
" Unable to install MySQL-python, exiting installer! [install_python_mysql_library] Error: " + str (
res ) )
os . _exit ( os . EX_OSERR )
2017-10-24 19:16:36 +05:00
def install_gunicorn ( self ) :
2019-03-30 14:21:52 +05:00
self . stdOut ( " Install Gunicorn " )
2017-10-24 19:16:36 +05:00
count = 0
2019-03-30 14:21:52 +05:00
# while (1):
# if self.distro == ubuntu:
# command = "pip install gunicorn"
# else:
# command = "easy_install gunicorn"
# res = subprocess.call(shlex.split(command))
# if preFlightsChecks.resFailed(self.distro, res):
# count = count + 1
# preFlightsChecks.stdOut("Unable to install GUNICORN, trying again, try number: " + str(count))
# if count == 3:
# logging.InstallLog.writeToFile("Unable to install GUNICORN, exiting installer! [install_gunicorn]")
# preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
# os._exit(0)
# else:
# logging.InstallLog.writeToFile("GUNICORN successfully installed!")
# preFlightsChecks.stdOut("GUNICORN successfully installed!")
# break
2017-10-24 19:16:36 +05:00
def setup_gunicorn ( self ) :
try :
os . chdir ( self . cwd )
2019-03-30 14:21:52 +05:00
#
# ##
#
# logging.InstallLog.writeToFile("Configuring Gunicorn..")
#
# service = "/etc/systemd/system/gunicorn.service"
# socket = "/etc/systemd/system/gunicorn.socket"
# conf = "/etc/tmpfiles.d/gunicorn.conf"
#
# shutil.copy("gun-configs/gunicorn.service", service)
# shutil.copy("gun-configs/gunicorn.socket", socket)
# shutil.copy("gun-configs/gunicorn.conf", conf)
#
# logging.InstallLog.writeToFile("Gunicorn Configured!")
#
# ### Enable at system startup
#
# count = 0
#
# while (1):
# command = "systemctl enable gunicorn.socket"
# res = subprocess.call(shlex.split(command))
#
# if preFlightsChecks.resFailed(self.distro, res):
# count = count + 1
# preFlightsChecks.stdOut("Trying to enable Gunicorn at system startup, try number: " + str(count))
# if count == 3:
# logging.InstallLog.writeToFile(
# "Gunicorn will not start after system restart, you can manually enable using systemctl enable gunicorn.socket! [setup_gunicorn]")
# preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
# break
# else:
# logging.InstallLog.writeToFile("Gunicorn can now start after system restart!")
# preFlightsChecks.stdOut("Gunicorn can now start after system restart!")
# break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
except BaseException , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_gunicorn] " )
preFlightsChecks . stdOut ( " Not able to setup gunicorn, see install log. " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
def install_psutil ( self ) :
2017-10-24 19:16:36 +05:00
try :
2018-02-04 21:15:30 +05:00
import psutil
2018-03-08 22:19:23 +05:00
##
command = " pip uninstall --yes psutil "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /psutil-5.4.3.tar.gz "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-03-08 22:19:23 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to install psutil, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Unable to install psutil, exiting installer! [install_psutil] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-03-08 22:19:23 +05:00
else :
logging . InstallLog . writeToFile ( " psutil successfully installed! " )
preFlightsChecks . stdOut ( " psutil successfully installed! " )
break
2017-10-24 19:16:36 +05:00
except :
count = 0
while ( 1 ) :
2018-11-16 14:41:40 +05:00
command = " pip install http:// " + preFlightsChecks . cyberPanelMirror + " /psutil-5.4.3.tar.gz "
2019-03-26 16:19:03 +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 preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Unable to install psutil, 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 ( " Unable to install psutil, exiting installer! [install_psutil] " )
preFlightsChecks . 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 ( " psutil successfully installed! " )
preFlightsChecks . stdOut ( " psutil successfully installed! " )
2017-10-24 19:16:36 +05:00
break
def fix_selinux_issue ( self ) :
2017-11-05 03:02:51 +05:00
try :
cmd = [ ]
2017-10-24 19:16:36 +05:00
2017-11-05 03:02:51 +05:00
cmd . append ( " setsebool " )
cmd . append ( " -P " )
cmd . append ( " httpd_can_network_connect " )
cmd . append ( " 1 " )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-11-05 03:02:51 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2017-11-05 03:02:51 +05:00
logging . InstallLog . writeToFile ( " fix_selinux_issue problem " )
else :
pass
2017-12-09 22:30:10 +05:00
except :
2017-10-24 19:16:36 +05:00
logging . InstallLog . writeToFile ( " fix_selinux_issue problem " )
def install_psmisc ( self ) :
2018-10-26 09:11:17 -04:00
self . stdOut ( " Install psmisc " )
2017-10-24 19:16:36 +05:00
count = 0
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = " yum -y install psmisc "
else :
command = " apt-get -y install psmisc "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Unable to install psmisc, 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 ( " Unable to install psmisc, exiting installer! [install_psmisc] " )
preFlightsChecks . 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 ( " psmisc successfully installed! " )
preFlightsChecks . stdOut ( " psmisc successfully installed! " )
2017-10-24 19:16:36 +05:00
break
2018-11-16 14:41:40 +05:00
def download_install_CyberPanel ( self , mysqlPassword , mysql ) :
2017-10-24 19:16:36 +05:00
try :
2018-02-04 21:15:30 +05:00
## On OpenVZ there is an issue with requests module, which needs to upgrade requests module
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
if subprocess . check_output ( ' systemd-detect-virt ' ) . find ( " openvz " ) > - 1 :
2018-12-17 18:46:34 +05:00
command = " pip install --upgrade requests "
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [download_install_CyberPanel] ' ,
2018-12-17 18:46:34 +05:00
' Upgrade requests ' ,
1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
except :
pass
2018-02-04 21:15:30 +05:00
##
2017-10-24 19:16:36 +05:00
os . chdir ( self . path )
2019-07-03 13:15:26 +05:00
command = " wget http://cyberpanel.sh/CyberPanel.1.8.5.tar.gz "
2019-04-15 15:54:23 +05:00
#command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz"
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [download_install_CyberPanel] ' ,
2018-12-17 18:46:34 +05:00
' CyberPanel Download ' ,
1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
##
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2019-07-03 13:15:26 +05:00
command = " tar zxf CyberPanel.1.8.5.tar.gz "
2019-04-15 15:54:23 +05:00
#command = "tar zxf CyberPanelTemp.tar.gz"
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [download_install_CyberPanel] ' ,
2018-12-17 18:46:34 +05:00
' Extract CyberPanel ' , 1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
### update password:
passFile = " /etc/cyberpanel/mysqlPassword "
f = open ( passFile )
data = f . read ( )
password = data . split ( ' \n ' , 1 ) [ 0 ]
2018-02-04 21:15:30 +05:00
### Put correct mysql passwords in settings file!
logging . InstallLog . writeToFile ( " Updating settings.py! " )
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
path = self . cyberPanelPath + " /CyberCP/settings.py "
2017-10-24 19:16:36 +05:00
data = open ( path , " r " ) . readlines ( )
writeDataToFile = open ( path , " w " )
counter = 0
for items in data :
2018-05-29 20:20:05 +05:00
if mysql == ' Two ' :
if items . find ( " ' PASSWORD ' : " ) > - 1 :
if counter == 0 :
writeDataToFile . writelines ( " ' PASSWORD ' : ' " + mysqlPassword + " ' , " + " \n " )
counter = counter + 1
else :
writeDataToFile . writelines ( " ' PASSWORD ' : ' " + password + " ' , " + " \n " )
2017-10-24 19:16:36 +05:00
2018-05-29 20:20:05 +05:00
else :
writeDataToFile . writelines ( items )
2017-10-24 19:16:36 +05:00
else :
2018-05-29 20:20:05 +05:00
if items . find ( " ' PASSWORD ' : " ) > - 1 :
if counter == 0 :
writeDataToFile . writelines ( " ' PASSWORD ' : ' " + mysqlPassword + " ' , " + " \n " )
counter = counter + 1
else :
writeDataToFile . writelines ( " ' PASSWORD ' : ' " + password + " ' , " + " \n " )
elif items . find ( ' 127.0.0.1 ' ) > - 1 :
writeDataToFile . writelines ( " ' HOST ' : ' localhost ' , \n " )
elif items . find ( " ' PORT ' : ' 3307 ' " ) > - 1 :
writeDataToFile . writelines ( " ' PORT ' : ' ' , \n " )
else :
writeDataToFile . writelines ( items )
2017-10-24 19:16:36 +05:00
2018-11-12 18:39:04 +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 ( " settings.py updated! " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
### Applying migrations
2017-10-24 19:16:36 +05:00
2018-11-06 00:19:58 +05:00
os . chdir ( " CyberCP " )
2017-10-24 19:16:36 +05:00
2018-12-17 18:46:34 +05:00
command = " python manage.py makemigrations "
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [download_install_CyberPanel] ' ,
2018-12-17 18:46:34 +05:00
' CyberPanel Make Migrations ' ,
1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
##
2017-10-24 19:16:36 +05:00
2018-12-17 18:46:34 +05:00
command = " python manage.py migrate "
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [download_install_CyberPanel] ' ,
2018-12-17 18:46:34 +05:00
' CyberPanel Migrate ' , 1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2019-03-30 14:21:52 +05:00
if not os . path . exists ( " /usr/local/CyberCP/public " ) :
os . mkdir ( " /usr/local/CyberCP/public " )
2018-02-04 21:15:30 +05:00
## Moving static content to lscpd location
2019-03-30 14:21:52 +05:00
command = ' mv static /usr/local/CyberCP/public/ '
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [download_install_CyberPanel] ' ,
2018-12-17 18:46:34 +05:00
' Move static content ' , 1 , 1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2019-04-15 15:54:23 +05:00
try :
path = " /usr/local/CyberCP/version.txt "
writeToFile = open ( path , ' w ' )
writeToFile . writelines ( ' 1.8 \n ' )
writeToFile . writelines ( ' 2 ' )
writeToFile . close ( )
except :
pass
2019-03-26 16:19:03 +05:00
def fixCyberPanelPermissions ( self ) :
2019-04-15 15:54:23 +05:00
2019-03-26 16:19:03 +05:00
###### fix Core CyberPanel permissions
2017-10-24 19:16:36 +05:00
2019-04-15 15:54:23 +05:00
command = " usermod -G lscpd,lsadm,nobody lscpd "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' add lscpd to important groups ' , 0 , 0 , os . EX_OSERR )
command = " usermod -G lscpd,lsadm,nogroup lscpd "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' add lscpd to important groups ' , 0 , 0 , os . EX_OSERR )
2019-03-26 16:19:03 +05:00
command = " find /usr/local/CyberCP -type d -exec chmod 0755 {} \ ; "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-03-26 16:19:03 +05:00
' fix permissions /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
2018-01-18 22:37:12 +05:00
2019-03-26 16:19:03 +05:00
command = " find /usr/local/CyberCP -type f -exec chmod 0644 {} \ ; "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-03-26 16:19:03 +05:00
' fix permissions /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
command = " chmod -R 755 /usr/local/CyberCP/bin "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-03-26 16:19:03 +05:00
' fix permissions /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
2018-01-23 20:37:44 +05:00
2018-02-04 21:15:30 +05:00
## change owner
2018-01-23 20:37:44 +05:00
2019-03-26 16:19:03 +05:00
command = " chown -R root:root /usr/local/CyberCP "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-03-26 16:19:03 +05:00
' change owner /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
########### Fix LSCPD
command = " find /usr/local/lscp -type d -exec chmod 0755 {} \ ; "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-03-26 16:19:03 +05:00
' fix permissions /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
command = " find /usr/local/lscp -type f -exec chmod 0644 {} \ ; "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-03-26 16:19:03 +05:00
' fix permissions /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
command = " chmod -R 755 /usr/local/lscp/bin "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' fix permissions /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
command = " chmod -R 755 /usr/local/lscp/fcgi-bin "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' fix permissions /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
2019-04-15 15:54:23 +05:00
command = " chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin/tmp "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-04-15 15:54:23 +05:00
' fix permissions /usr/local/CyberCP/public/phpmyadmin/tmp ' , 1 , 0 , os . EX_OSERR )
2019-03-26 16:19:03 +05:00
## change owner
command = " chown -R root:root /usr/local/lscp "
2019-03-30 14:21:52 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
2019-03-26 16:19:03 +05:00
' change owner /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
2018-01-23 20:37:44 +05:00
2019-04-15 15:54:23 +05:00
command = " chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' change owner /usr/local/CyberCP ' , 1 , 0 , os . EX_OSERR )
command = " chmod 700 /usr/local/CyberCP/cli/cyberPanel.py "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' Change permissions for CLI. ' , 1 , 0 , os . EX_OSERR )
command = " chmod 700 /usr/local/CyberCP/plogical/upgradeCritical.py "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' Change permissions for upgrade. ' , 1 , 0 , os . EX_OSERR )
command = " chmod 700 /usr/local/CyberCP/postfixSenderPolicy/client.py "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' Change permissions for client. ' , 1 , 0 , os . EX_OSERR )
2019-04-22 03:38:40 +05:00
command = " chmod 640 /usr/local/CyberCP/CyberCP/settings.py "
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' Change permissions for client. ' , 1 , 0 , os . EX_OSERR )
command = " chown root:cyberpanel /usr/local/CyberCP/CyberCP/settings.py "
2019-04-15 15:54:23 +05:00
preFlightsChecks . call ( command , self . distro , ' [fixCyberPanelPermissions] ' ,
' Change permissions for client. ' , 1 , 0 , os . EX_OSERR )
2018-02-04 21:15:30 +05:00
2017-12-09 22:30:10 +05:00
def install_unzip ( self ) :
2018-12-17 18:46:34 +05:00
self . stdOut ( " Install unzip " )
2017-10-24 19:16:36 +05:00
try :
2018-12-17 18:46:34 +05:00
if self . distro == centos :
command = ' yum -y install unzip '
else :
command = ' apt-get -y install unzip '
2017-12-09 22:30:10 +05:00
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [install_unzip] ' ,
2018-12-17 18:46:34 +05:00
' Install unzip ' , 1 , 0 , os . EX_OSERR )
except BaseException , msg :
2017-12-09 22:30:10 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [install_unzip] " )
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
def install_zip ( self ) :
2018-10-26 09:11:17 -04:00
self . stdOut ( " Install zip " )
2017-10-24 19:16:36 +05:00
try :
2018-12-17 18:46:34 +05:00
if self . distro == centos :
command = ' yum -y install zip '
else :
command = ' apt-get -y install zip '
2017-10-24 19:16:36 +05:00
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [install_zip] ' ,
2018-12-17 18:46:34 +05:00
' Install zip ' , 1 , 0 , os . EX_OSERR )
except BaseException , msg :
2017-12-09 22:30:10 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [install_zip] " )
2017-10-24 19:16:36 +05:00
def download_install_phpmyadmin ( self ) :
try :
2019-03-21 23:26:42 +05:00
2019-03-30 14:21:52 +05:00
if not os . path . exists ( " /usr/local/CyberCP/public " ) :
os . mkdir ( " /usr/local/CyberCP/public " )
os . chdir ( " /usr/local/CyberCP/public " )
2017-10-24 19:16:36 +05:00
2019-03-21 23:26:42 +05:00
command = ' composer create-project phpmyadmin/phpmyadmin '
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [download_install_phpmyadmin] ' ,
2018-12-17 18:46:34 +05:00
' Download PHPMYAdmin ' , 1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-06-11 21:04:55 +05:00
## Write secret phrase
rString = ' ' . join ( [ random . choice ( string . ascii_letters + string . digits ) for n in xrange ( 32 ) ] )
data = open ( ' phpmyadmin/config.sample.inc.php ' , ' r ' ) . readlines ( )
writeToFile = open ( ' phpmyadmin/config.inc.php ' , ' w ' )
for items in data :
if items . find ( ' blowfish_secret ' ) > - 1 :
2018-11-16 14:41:40 +05:00
writeToFile . writelines (
" $cfg[ ' blowfish_secret ' ] = ' " + rString + " ' ; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ \n " )
2018-06-11 21:04:55 +05:00
else :
writeToFile . writelines ( items )
2019-03-30 14:21:52 +05:00
writeToFile . writelines ( " $cfg[ ' TempDir ' ] = ' /usr/local/CyberCP/public/phpmyadmin/tmp ' ; \n " )
2018-06-11 21:04:55 +05:00
writeToFile . close ( )
2019-03-30 14:21:52 +05:00
os . mkdir ( ' /usr/local/CyberCP/public/phpmyadmin/tmp ' )
2018-06-11 21:04:55 +05:00
2019-03-30 14:21:52 +05:00
command = ' chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-06-11 21:04:55 +05:00
2018-12-17 18:46:34 +05:00
except BaseException , msg :
2017-10-24 19:16:36 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [download_install_phpmyadmin] " )
return 0
###################################################### Email setup
def install_postfix_davecot ( self ) :
2018-10-30 09:51:30 -04:00
self . stdOut ( " Install dovecot - first remove postfix " )
2019-07-03 13:15:26 +05:00
if self . distro == centos :
path = ' /etc/yum.repos.d/dovecot.repo '
content = """ [dovecot-2.3-latest]
name = Dovecot 2.3 CentOS $ releasever - $ basearch
baseurl = http : / / repo . dovecot . org / ce - 2.3 - latest / centos / $ releasever / RPMS / $ basearch
gpgkey = https : / / repo . dovecot . org / DOVECOT - REPO - GPG
gpgcheck = 1
enabled = 1 """
writeToFile = open ( path , ' w ' )
writeToFile . write ( content )
writeToFile . close ( )
2017-10-24 19:16:36 +05:00
try :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' yum remove postfix -y '
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = ' apt-get -y remove postfix '
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2017-10-24 19:16:36 +05:00
2018-10-30 09:51:30 -04:00
self . stdOut ( " Install dovecot - do the install " )
2018-10-13 18:31:47 +05:00
count = 0
2018-11-06 00:19:58 +05:00
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2019-03-21 23:26:42 +05:00
command = ' yum install -y postfix '
2018-10-25 16:58:15 -04:00
else :
2018-10-30 17:33:43 -04:00
command = ' apt-get -y debconf-utils '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-10-30 17:33:43 -04:00
file_name = self . cwd + ' /pf.unattend.text '
pf = open ( file_name , ' w ' )
pf . write ( ' postfix postfix/mailname string ' + str ( socket . getfqdn ( ) + ' \n ' ) )
pf . write ( ' postfix postfix/main_mailer_type string " Internet Site " \n ' )
pf . close ( )
command = ' debconf-set-selections ' + file_name
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-10-30 09:51:30 -04:00
command = ' apt-get -y install postfix '
2018-10-30 17:33:43 -04:00
# os.remove(file_name)
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to install Postfix, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile (
" Unable to install Postfix, you will not be able to send mails and rest should work fine! [install_postfix_davecot] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Postfix successfully installed! " )
preFlightsChecks . stdOut ( " Postfix successfully installed! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2018-10-13 18:31:47 +05:00
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2019-03-21 23:26:42 +05:00
break
2018-10-25 16:58:15 -04:00
else :
2018-10-26 10:50:58 -04:00
command = ' apt-get -y install dovecot-imapd dovecot-pop3d postfix-mysql '
2018-10-13 18:31:47 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-10-13 18:31:47 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-10-13 18:31:47 +05:00
count = count + 1
2018-10-26 10:50:58 -04:00
preFlightsChecks . stdOut ( " Unable to install Postfix agent, trying again, try number: " + str ( count ) )
2018-10-13 18:31:47 +05:00
if count == 3 :
logging . InstallLog . writeToFile (
2018-10-26 10:50:58 -04:00
" Unable to install Postfix agent, you will not be able to send mails and rest should work fine! [install_postfix_davecot] " )
2018-10-13 18:31:47 +05:00
break
else :
logging . InstallLog . writeToFile ( " Postfix successfully installed! " )
preFlightsChecks . stdOut ( " Postfix successfully installed! " )
break
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 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' yum -y install dovecot dovecot-mysql '
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = ' apt-get -y install dovecot-mysql '
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
2018-11-06 00:19:58 +05:00
preFlightsChecks . stdOut (
" Unable to install Dovecot and Dovecot-MySQL, 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 (
" Unable to install install Dovecot and Dovecot-MySQL, you will not be able to send mails and rest should work fine! [install_postfix_davecot] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Dovecot and Dovecot-MySQL successfully installed! " )
preFlightsChecks . stdOut ( " Dovecot and Dovecot-MySQL successfully installed! " )
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 ) + " [install_postfix_davecot] " )
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 ) + " [install_postfix_davecot] " )
2017-10-24 19:16:36 +05:00
return 0
return 1
2018-11-16 14:41:40 +05:00
def setup_email_Passwords ( self , mysqlPassword , mysql ) :
2017-10-24 19:16:36 +05:00
try :
2018-02-04 21:15:30 +05:00
2018-11-07 15:14:54 -05:00
logging . InstallLog . writeToFile ( " Setting up authentication for Postfix and Dovecot... " )
2018-02-04 21:15:30 +05:00
2018-11-07 15:14:54 -05:00
os . chdir ( self . cwd )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
if mysql == ' Two ' :
mysql_virtual_domains = " email-configs/mysql-virtual_domains.cf "
mysql_virtual_forwardings = " email-configs/mysql-virtual_forwardings.cf "
mysql_virtual_mailboxes = " email-configs/mysql-virtual_mailboxes.cf "
mysql_virtual_email2email = " email-configs/mysql-virtual_email2email.cf "
davecotmysql = " email-configs/dovecot-sql.conf.ext "
else :
mysql_virtual_domains = " email-configs-one/mysql-virtual_domains.cf "
mysql_virtual_forwardings = " email-configs-one/mysql-virtual_forwardings.cf "
mysql_virtual_mailboxes = " email-configs-one/mysql-virtual_mailboxes.cf "
mysql_virtual_email2email = " email-configs-one/mysql-virtual_email2email.cf "
davecotmysql = " email-configs-one/dovecot-sql.conf.ext "
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
### update password:
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
data = open ( davecotmysql , " r " ) . readlines ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile = open ( davecotmysql , " w " )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
if mysql == ' Two ' :
2018-11-16 14:41:40 +05:00
dataWritten = " connect = host=127.0.0.1 dbname=cyberpanel user=cyberpanel password= " + mysqlPassword + " port=3307 \n "
2018-11-07 15:14:54 -05:00
else :
dataWritten = " connect = host=localhost dbname=cyberpanel user=cyberpanel password= " + mysqlPassword + " port=3306 \n "
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
for items in data :
if items . find ( " connect " ) > - 1 :
writeDataToFile . writelines ( dataWritten )
else :
writeDataToFile . writelines ( items )
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
# if self.distro == ubuntu:
2018-11-12 14:53:10 -05:00
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile . close ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
### update password:
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
data = open ( mysql_virtual_domains , " r " ) . readlines ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile = open ( mysql_virtual_domains , " w " )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
dataWritten = " password = " + mysqlPassword + " \n "
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
for items in data :
if items . find ( " password " ) > - 1 :
writeDataToFile . writelines ( dataWritten )
else :
writeDataToFile . writelines ( items )
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
# if self.distro == ubuntu:
2018-11-12 14:53:10 -05:00
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile . close ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
### update password:
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
data = open ( mysql_virtual_forwardings , " r " ) . readlines ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile = open ( mysql_virtual_forwardings , " w " )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
dataWritten = " password = " + mysqlPassword + " \n "
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
for items in data :
if items . find ( " password " ) > - 1 :
writeDataToFile . writelines ( dataWritten )
else :
writeDataToFile . writelines ( items )
2018-11-14 13:36:34 +05:00
2018-11-16 14:41:40 +05:00
# if self.distro == ubuntu:
2018-11-12 14:53:10 -05:00
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile . close ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
### update password:
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
data = open ( mysql_virtual_mailboxes , " r " ) . readlines ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile = open ( mysql_virtual_mailboxes , " w " )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
dataWritten = " password = " + mysqlPassword + " \n "
for items in data :
if items . find ( " password " ) > - 1 :
writeDataToFile . writelines ( dataWritten )
else :
writeDataToFile . writelines ( items )
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
# if self.distro == ubuntu:
2018-11-12 14:53:10 -05:00
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile . close ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
### update password:
data = open ( mysql_virtual_email2email , " r " ) . readlines ( )
writeDataToFile = open ( mysql_virtual_email2email , " w " )
dataWritten = " password = " + mysqlPassword + " \n "
for items in data :
if items . find ( " password " ) > - 1 :
writeDataToFile . writelines ( dataWritten )
else :
writeDataToFile . writelines ( items )
2018-11-14 13:36:34 +05:00
2018-11-16 14:41:40 +05:00
# if self.distro == ubuntu:
2018-11-12 14:53:10 -05:00
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
writeDataToFile . close ( )
2017-10-24 19:16:36 +05:00
2018-11-07 15:14:54 -05:00
logging . InstallLog . writeToFile ( " Authentication for Postfix and Dovecot set. " )
2017-10-24 19:16:36 +05:00
except OSError , msg :
2017-11-02 02:09:47 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_email_Passwords] " )
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 ) + " [setup_email_Passwords] " )
2017-10-24 19:16:36 +05:00
return 0
return 1
2018-11-06 12:18:24 -05:00
def centos_lib_dir_to_ubuntu ( self , filename , old , new ) :
2018-11-06 11:16:50 -05:00
try :
fd = open ( filename , ' r ' )
lines = fd . readlines ( )
2018-11-06 11:50:48 -05:00
fd . close ( )
2018-11-06 11:16:50 -05:00
fd = open ( filename , ' w ' )
2018-11-06 12:18:24 -05:00
centos_prefix = old
ubuntu_prefix = new
2018-11-06 11:16:50 -05:00
for line in lines :
index = line . find ( centos_prefix )
if index != - 1 :
line = line [ : index ] + ubuntu_prefix + line [ index + len ( centos_prefix ) : ]
fd . write ( line )
fd . close ( )
except IOError as err :
self . stdOut ( " Error converting: " + filename + " from centos defaults to ubuntu defaults: " + str ( err ) , 1 ,
2018-11-07 08:54:16 -05:00
1 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
def setup_postfix_davecot_config ( self , mysql ) :
try :
logging . InstallLog . writeToFile ( " Configuring postfix and dovecot... " )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
os . chdir ( self . cwd )
2018-11-06 00:19:58 +05:00
2018-11-06 11:16:50 -05:00
mysql_virtual_domains = " /etc/postfix/mysql-virtual_domains.cf "
mysql_virtual_forwardings = " /etc/postfix/mysql-virtual_forwardings.cf "
mysql_virtual_mailboxes = " /etc/postfix/mysql-virtual_mailboxes.cf "
mysql_virtual_email2email = " /etc/postfix/mysql-virtual_email2email.cf "
main = " /etc/postfix/main.cf "
master = " /etc/postfix/master.cf "
davecot = " /etc/dovecot/dovecot.conf "
davecotmysql = " /etc/dovecot/dovecot-sql.conf.ext "
2018-11-06 00:19:58 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( mysql_virtual_domains ) :
os . remove ( mysql_virtual_domains )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( mysql_virtual_forwardings ) :
os . remove ( mysql_virtual_forwardings )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( mysql_virtual_mailboxes ) :
os . remove ( mysql_virtual_mailboxes )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( mysql_virtual_email2email ) :
os . remove ( mysql_virtual_email2email )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( main ) :
os . remove ( main )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( master ) :
os . remove ( master )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( davecot ) :
os . remove ( davecot )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
if os . path . exists ( davecotmysql ) :
os . remove ( davecotmysql )
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
###############Getting SSL
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-06 11:16:50 -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/postfix/key.pem -out /etc/postfix/cert.pem '
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:16:50 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to generate SSL for Postfix, trying again, try number: " + str ( count ) )
2018-11-06 11:16:50 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to generate SSL for Postfix, you will not be able to send emails and rest should work fine! [setup_postfix_davecot_config] " )
2018-11-06 11:16:50 -05:00
return
else :
logging . InstallLog . writeToFile ( " SSL for Postfix generated! " )
preFlightsChecks . stdOut ( " SSL for Postfix generated! " )
break
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-11-02 02:09:47 +05:00
2018-11-06 11:16:50 -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/dovecot/key.pem -out /etc/dovecot/cert.pem '
2017-11-02 02:09:47 +05:00
2018-11-06 11:16:50 -05:00
cmd = shlex . split ( command )
2017-11-02 02:09:47 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-11-02 02:09:47 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:16:50 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to generate ssl for Dovecot, trying again, try number: " + str ( count ) )
2018-11-06 11:16:50 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to generate SSL for Dovecot, you will not be able to send emails and rest should work fine! [setup_postfix_davecot_config] " )
2018-11-06 11:16:50 -05:00
return
else :
logging . InstallLog . writeToFile ( " SSL generated for Dovecot! " )
preFlightsChecks . stdOut ( " SSL generated for Dovecot! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
# Cleanup config files for ubuntu
if self . distro == ubuntu :
preFlightsChecks . stdOut ( " Cleanup postfix/dovecot config files " , 1 )
if mysql == ' Two ' :
2018-11-06 12:18:24 -05:00
self . centos_lib_dir_to_ubuntu ( " email-configs/master.cf " , " /usr/libexec/ " , " /usr/lib/ " )
self . centos_lib_dir_to_ubuntu ( " email-configs/main.cf " , " /usr/libexec/postfix " ,
" /usr/lib/postfix/sbin " )
2018-11-06 11:16:50 -05:00
else :
2018-11-06 12:18:24 -05:00
self . centos_lib_dir_to_ubuntu ( " email-configs-one/master.cf " , " /usr/libexec/ " , " /usr/lib/ " )
self . centos_lib_dir_to_ubuntu ( " email-configs-one/main.cf " , " /usr/libexec/postfix " ,
" /usr/lib/postfix/sbin " )
2017-10-24 19:16:36 +05:00
2018-11-06 11:16:50 -05:00
########### Copy config files
if mysql == ' Two ' :
2018-11-16 14:41:40 +05:00
shutil . copy ( " email-configs/mysql-virtual_domains.cf " , " /etc/postfix/mysql-virtual_domains.cf " )
2018-11-06 11:16:50 -05:00
shutil . copy ( " email-configs/mysql-virtual_forwardings.cf " , " /etc/postfix/mysql-virtual_forwardings.cf " )
shutil . copy ( " email-configs/mysql-virtual_mailboxes.cf " , " /etc/postfix/mysql-virtual_mailboxes.cf " )
shutil . copy ( " email-configs/mysql-virtual_email2email.cf " , " /etc/postfix/mysql-virtual_email2email.cf " )
shutil . copy ( " email-configs/main.cf " , main )
2018-11-16 14:41:40 +05:00
shutil . copy ( " email-configs/master.cf " , master )
shutil . copy ( " email-configs/dovecot.conf " , davecot )
shutil . copy ( " email-configs/dovecot-sql.conf.ext " , davecotmysql )
2018-11-06 11:16:50 -05:00
else :
shutil . copy ( " email-configs-one/mysql-virtual_domains.cf " , " /etc/postfix/mysql-virtual_domains.cf " )
2018-11-16 14:41:40 +05:00
shutil . copy ( " email-configs-one/mysql-virtual_forwardings.cf " ,
" /etc/postfix/mysql-virtual_forwardings.cf " )
2018-11-06 11:16:50 -05:00
shutil . copy ( " email-configs-one/mysql-virtual_mailboxes.cf " , " /etc/postfix/mysql-virtual_mailboxes.cf " )
2018-11-16 14:41:40 +05:00
shutil . copy ( " email-configs-one/mysql-virtual_email2email.cf " ,
" /etc/postfix/mysql-virtual_email2email.cf " )
2018-11-06 11:16:50 -05:00
shutil . copy ( " email-configs-one/main.cf " , main )
shutil . copy ( " email-configs-one/master.cf " , master )
shutil . copy ( " email-configs-one/dovecot.conf " , davecot )
shutil . copy ( " email-configs-one/dovecot-sql.conf.ext " , davecotmysql )
2018-11-06 11:31:20 -05:00
######################################## Permissions
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' chmod o= /etc/postfix/mysql-virtual_domains.cf '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for mysql-virtual_domains.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for mysql-virtual_domains.cf. [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for mysql-virtual_domains.cf! " )
preFlightsChecks . stdOut ( " Permissions changed for mysql-virtual_domains.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
command = ' chmod o= /etc/postfix/mysql-virtual_forwardings.cf '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for mysql-virtual_forwardings.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for mysql-virtual_forwardings.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for mysql-virtual_forwardings.cf! " )
preFlightsChecks . stdOut ( " Permissions changed for mysql-virtual_forwardings.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' chmod o= /etc/postfix/mysql-virtual_mailboxes.cf '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for mysql-virtual_mailboxes.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for mysql-virtual_mailboxes.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for mysql-virtual_mailboxes.cf! " )
preFlightsChecks . stdOut ( " Permissions changed for mysql-virtual_mailboxes.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' chmod o= /etc/postfix/mysql-virtual_email2email.cf '
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for mysql-virtual_email2email.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for mysql-virtual_email2email.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for mysql-virtual_email2email.cf! " )
preFlightsChecks . stdOut ( " Permissions changed for mysql-virtual_email2email.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-12 18:39:04 +05:00
command = ' chmod o= ' + main
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for /etc/postfix/main.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for /etc/postfix/main.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for /etc/postfix/main.cf! " )
preFlightsChecks . stdOut ( " Permissions changed for /etc/postfix/main.cf! " )
break
##
count = 0
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-12 18:39:04 +05:00
command = ' chmod o= ' + master
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2018-02-04 21:15:30 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for /etc/postfix/master.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for /etc/postfix/master.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for /etc/postfix/master.cf! " )
preFlightsChecks . stdOut ( " Permissions changed for /etc/postfix/master.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
#######################################
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-06 11:31:20 -05:00
command = ' chgrp postfix /etc/postfix/mysql-virtual_domains.cf '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change group for mysql-virtual_domains.cf, trying again, try number: " + str ( count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change group for mysql-virtual_domains.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Group changed for mysql-virtual_domains.cf! " )
preFlightsChecks . stdOut ( " Group changed for mysql-virtual_domains.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-06 11:31:20 -05:00
command = ' chgrp postfix /etc/postfix/mysql-virtual_forwardings.cf '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change group for mysql-virtual_forwardings.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change group for mysql-virtual_forwardings.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Group changed for mysql-virtual_forwardings.cf! " )
preFlightsChecks . stdOut ( " Group changed for mysql-virtual_forwardings.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-06 11:31:20 -05:00
command = ' chgrp postfix /etc/postfix/mysql-virtual_mailboxes.cf '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change group for mysql-virtual_mailboxes.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change group for mysql-virtual_mailboxes.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Group changed for mysql-virtual_mailboxes.cf! " )
preFlightsChecks . stdOut ( " Group changed for mysql-virtual_mailboxes.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' chgrp postfix /etc/postfix/mysql-virtual_email2email.cf '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change group for mysql-virtual_email2email.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change group for mysql-virtual_email2email.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Group changed for mysql-virtual_email2email.cf! " )
preFlightsChecks . stdOut ( " Group changed for mysql-virtual_email2email.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-12 18:39:04 +05:00
command = ' chgrp postfix ' + main
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change group for /etc/postfix/main.cf, trying again, try number: " + str ( count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change group for /etc/postfix/main.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Group changed for /etc/postfix/main.cf! " )
preFlightsChecks . stdOut ( " Group changed for /etc/postfix/main.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
##
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' chgrp postfix ' + master
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change group for /etc/postfix/master.cf, trying again, try number: " + str ( count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change group for /etc/postfix/master.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Group changed for /etc/postfix/master.cf! " )
preFlightsChecks . stdOut ( " Group changed for /etc/postfix/master.cf! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
######################################## users and groups
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' groupadd -g 5000 vmail '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to add system group vmail, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to add system group vmail! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " System group vmail created successfully! " )
preFlightsChecks . stdOut ( " System group vmail created successfully! " )
break
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
##
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' useradd -g vmail -u 5000 vmail -d /home/vmail -m '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2018-02-04 21:15:30 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to add system user vmail, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to add system user vmail! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " System user vmail created successfully! " )
preFlightsChecks . stdOut ( " System user vmail created successfully! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
######################################## Further configurations
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
# hostname = socket.gethostname()
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
################################### Restart postix
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' systemctl enable postfix.service '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Trying to add Postfix to system startup, trying again, try number: " + str ( count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Failed to enable Postfix to run at system restart you can manually do this using systemctl enable postfix.service! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " postfix.service successfully enabled! " )
preFlightsChecks . stdOut ( " postfix.service successfully enabled! " )
break
2018-02-04 21:15:30 +05:00
##
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-14 13:36:34 +05:00
command = ' systemctl start postfix.service '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2018-02-04 21:15:30 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
preFlightsChecks . stdOut ( " Trying to start Postfix, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to start Postfix, you can not send email until you manually start Postfix using systemctl start postfix.service! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " postfix.service started successfully! " )
preFlightsChecks . stdOut ( " postfix.service started successfully! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
######################################## Permissions
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' chgrp dovecot /etc/dovecot/dovecot-sql.conf.ext '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change group for /etc/dovecot/dovecot-sql.conf.ext, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change group for /etc/dovecot/dovecot-sql.conf.ext! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Group changed for /etc/dovecot/dovecot-sql.conf.ext! " )
preFlightsChecks . stdOut ( " Group changed for /etc/dovecot/dovecot-sql.conf.ext! " )
break
##
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' chmod o= /etc/dovecot/dovecot-sql.conf.ext '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2018-02-04 21:15:30 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for /etc/dovecot/dovecot-sql.conf.ext, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for /etc/dovecot/dovecot-sql.conf.ext! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for /etc/dovecot/dovecot-sql.conf.ext! " )
preFlightsChecks . stdOut ( " Permissions changed for /etc/dovecot/dovecot-sql.conf.ext! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
################################### Restart davecot
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' systemctl enable dovecot.service '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to enable dovecot.service, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to enable dovecot.service! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " dovecot.service successfully enabled! " )
preFlightsChecks . stdOut ( " dovecot.service successfully enabled! " )
break
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
##
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-06 11:31:20 -05:00
command = ' systemctl start dovecot.service '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to start dovecot.service, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to start dovecot.service! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " dovecot.service successfully started! " )
preFlightsChecks . stdOut ( " dovecot.service successfully started! " )
break
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
##
2018-02-04 21:15:30 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
command = ' systemctl restart postfix.service '
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to restart postfix.service, trying again, try number: " + str ( count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to restart postfix.service! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " dovecot.service successfully restarted! " )
preFlightsChecks . stdOut ( " postfix.service successfully restarted! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 11:31:20 -05:00
## chaging permissions for main.cf
2017-12-09 22:30:10 +05:00
2018-11-06 11:31:20 -05:00
count = 0
2018-02-04 21:15:30 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2017-12-09 22:30:10 +05:00
2018-11-12 18:39:04 +05:00
command = " chmod 755 " + main
2018-11-06 11:31:20 -05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-11-06 11:31:20 -05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for /etc/postfix/main.cf, trying again, try number: " + str (
count ) )
2018-11-06 11:31:20 -05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for /etc/postfix/main.cf! [setup_postfix_davecot_config] " )
2018-11-06 11:31:20 -05:00
break
else :
logging . InstallLog . writeToFile ( " Permissions changed for /etc/postfix/main.cf! " )
preFlightsChecks . stdOut ( " Permissions changed for /etc/postfix/main.cf! " )
break
2017-12-09 22:30:10 +05:00
2018-11-06 11:31:20 -05:00
if self . distro == ubuntu :
command = " mkdir -p /etc/pki/dovecot/private/ "
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-11-06 13:03:12 +05:00
2018-11-07 12:14:38 +05:00
command = " mkdir -p /etc/pki/dovecot/certs/ "
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-11-07 12:14:38 +05:00
2018-11-06 11:31:20 -05:00
command = " mkdir -p /etc/opendkim/keys/ "
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-11-06 13:03:12 +05:00
2018-11-06 11:31:20 -05:00
command = " sed -i ' s/auth_mechanisms = plain/#auth_mechanisms = plain/g ' /etc/dovecot/conf.d/10-auth.conf "
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-11-06 13:03:12 +05:00
2018-11-14 18:36:56 +05:00
## Ubuntu 18.10 ssl_dh for dovecot 2.3.2.1
if get_Ubuntu_release ( ) == 18.10 :
dovecotConf = ' /etc/dovecot/dovecot.conf '
data = open ( dovecotConf , ' r ' ) . readlines ( )
writeToFile = open ( dovecotConf , ' w ' )
for items in data :
if items . find ( ' ssl_key = <key.pem ' ) > - 1 :
writeToFile . writelines ( items )
writeToFile . writelines ( ' ssl_dh = </usr/share/dovecot/dh.pem \n ' )
else :
writeToFile . writelines ( items )
writeToFile . close ( )
2018-11-07 12:14:38 +05:00
command = " systemctl restart dovecot "
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-11-07 12:14:38 +05:00
2018-11-06 11:31:20 -05:00
logging . InstallLog . writeToFile ( " Postfix and Dovecot configured " )
2017-12-09 22:30:10 +05:00
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_postfix_davecot_config] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_postfix_davecot_config] " )
return 0
return 1
def downoad_and_install_raindloop ( self ) :
try :
2018-02-04 21:15:30 +05:00
#######
2017-10-24 19:16:36 +05:00
2019-03-30 14:21:52 +05:00
if not os . path . exists ( " /usr/local/CyberCP/public " ) :
os . mkdir ( " /usr/local/CyberCP/public " )
2019-04-15 15:54:23 +05:00
if os . path . exists ( " /usr/local/CyberCP/public/rainloop " ) :
return 0
2019-03-30 14:21:52 +05:00
os . chdir ( " /usr/local/CyberCP/public " )
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-16 14:41:40 +05:00
while ( 1 ) :
2018-02-04 21:15:30 +05:00
command = ' wget https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip '
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Trying to download Rainloop, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to download Rainloop, installation can continue but you will not be able to send emails! [downoad_and_install_raindloop] " )
2018-02-04 21:15:30 +05:00
return
else :
logging . InstallLog . writeToFile ( " Rainloop Downloaded! " )
preFlightsChecks . stdOut ( " Rainloop Downloaded! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
#############
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-16 14:41:40 +05:00
while ( 1 ) :
2019-03-30 14:21:52 +05:00
command = ' unzip rainloop-community-latest.zip -d /usr/local/CyberCP/public/rainloop '
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Trying to unzip rainloop, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" We could not unzip Rainloop, so you will not be able to send emails! [downoad_and_install_raindloop] " )
2018-02-04 21:15:30 +05:00
return
else :
logging . InstallLog . writeToFile ( " Rainloop successfully unzipped! " )
preFlightsChecks . stdOut ( " Rainloop successfully unzipped! " )
break
2017-10-24 19:16:36 +05:00
os . remove ( " rainloop-community-latest.zip " )
2018-02-04 21:15:30 +05:00
#######
2017-10-24 19:16:36 +05:00
2019-03-30 14:21:52 +05:00
os . chdir ( " /usr/local/CyberCP/public/rainloop " )
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-16 14:41:40 +05:00
while ( 1 ) :
2018-02-04 21:15:30 +05:00
command = ' find . -type d -exec chmod 755 {} \ ; '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Trying to change permissions for Rainloop, trying again, try number: " + str ( count ) )
2018-02-04 21:15:30 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Failed to change permissions for Rainloop, so you will not be able to send emails!! [downoad_and_install_raindloop] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Rainloop permissions changed! " )
print (
" [ " + time . strftime ( " % I- % M- % S- %a - % b- % Y " ) + " ] " + " Rainloop permissions changed! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
#############
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-16 14:41:40 +05:00
while ( 1 ) :
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
command = ' find . -type f -exec chmod 644 {} \ ; '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Trying to change permissions for Rainloop, trying again, try number: " + str ( count ) )
2018-02-04 21:15:30 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Failed to change permissions for Rainloop, so you will not be able to send emails!! [downoad_and_install_raindloop] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Rainloop permissions changed! " )
preFlightsChecks . stdOut ( " Rainloop permissions changed! " )
break
######
2017-10-24 19:16:36 +05:00
2019-04-15 15:54:23 +05:00
command = " mkdir -p /usr/local/lscp/cyberpanel/rainloop/data "
preFlightsChecks . call ( command , self . distro , ' [downoad_and_install_rainloop] ' ,
' rainlooop data folder ' ,
1 , 0 , os . EX_OSERR )
path = " /usr/local/CyberCP/public/rainloop/rainloop/v/1.12.1/include.php "
data = open ( path , ' r ' ) . readlines ( )
writeToFile = open ( path , ' w ' )
for items in data :
if items . find ( " $sCustomDataPath = ' ' ; " ) > - 1 :
writeToFile . writelines (
" $sCustomDataPath = ' /usr/local/lscp/cyberpanel/rainloop/data ' ; \n " )
else :
writeToFile . writelines ( items )
writeToFile . close ( )
2017-10-24 19:16:36 +05:00
except OSError , msg :
2017-11-02 02:09:47 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [downoad_and_install_rainloop] " )
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 ) + " [downoad_and_install_rainloop] " )
2017-10-24 19:16:36 +05:00
return 0
return 1
2018-02-04 21:15:30 +05:00
###################################################### Email setup ends!
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
def reStartLiteSpeed ( self ) :
2017-10-24 19:16:36 +05:00
try :
2018-02-04 21:15:30 +05:00
count = 0
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-02-04 21:15:30 +05:00
cmd = [ ]
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
cmd . append ( self . server_root_path + " bin/lswsctrl " )
2018-02-04 21:15:30 +05:00
cmd . append ( " restart " )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to restart OpenLiteSpeed, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Unable to restart OpenLiteSpeed! [reStartLiteSpeed] " )
break
else :
logging . InstallLog . writeToFile ( " OpenLiteSpeed restarted Successfully! " )
preFlightsChecks . stdOut ( " OpenLiteSpeed restarted Successfully! " )
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
2018-11-14 11:37:17 -05:00
def removeUfw ( self ) :
try :
preFlightsChecks . stdOut ( " Checking to see if ufw firewall is installed (will be removed) " , 1 )
2019-03-26 16:19:03 +05:00
status = subprocess . check_output ( shlex . split ( ' ufw status ' ) )
2018-11-14 11:37:17 -05:00
preFlightsChecks . stdOut ( " ufw current status: " + status + " ...will be removed " )
2018-11-21 14:50:27 +05:00
except BaseException , msg :
2018-11-14 11:37:17 -05:00
preFlightsChecks . stdOut ( " Expected access to ufw not available, do not need to remove it " , 1 )
return True
2018-11-21 14:50:27 +05:00
try :
preFlightsChecks . call ( ' apt-get -y remove ufw ' , self . distro , ' [remove_ufw] ' , ' Remove ufw firewall ' +
' (using firewalld) ' , 1 , 0 , os . EX_OSERR )
except :
pass
2018-11-14 11:37:17 -05:00
return True
2017-10-24 19:16:36 +05:00
def installFirewalld ( self ) :
2018-11-14 11:37:17 -05:00
if self . distro == ubuntu :
self . removeUfw ( )
2017-10-24 19:16:36 +05:00
try :
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Enabling Firewall! " )
2017-10-24 19:16:36 +05:00
2018-12-20 16:18:16 +05:00
if self . distro == ubuntu :
command = ' apt-get -y install firewalld '
else :
command = ' yum -y install firewalld '
2017-10-24 19:16:36 +05:00
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [installFirewalld] ' ,
' Install FirewallD ' ,
1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
######
2018-11-14 11:37:17 -05:00
if self . distro == centos :
2018-11-16 14:41:40 +05:00
# Not available in ubuntu
2018-11-14 11:37:17 -05:00
command = ' systemctl restart dbus '
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [installFirewalld] ' ,
' Start dbus ' ,
1 , 0 , os . EX_OSERR )
2018-07-19 22:38:37 +05:00
2018-07-28 01:25:51 +05:00
command = ' systemctl restart systemd-logind '
2018-12-20 16:18:16 +05:00
preFlightsChecks . call ( command , self . distro , ' [installFirewalld] ' ,
' restart logind ' ,
1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-12-20 16:18:16 +05:00
command = ' systemctl start firewalld '
preFlightsChecks . call ( command , self . distro , ' [installFirewalld] ' ,
' Restart FirewallD ' ,
1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
##########
2017-10-24 19:16:36 +05:00
2018-12-20 16:18:16 +05:00
command = ' systemctl enable firewalld '
preFlightsChecks . call ( command , self . distro , ' [installFirewalld] ' ,
' Install FirewallD ' ,
1 , 0 , os . EX_OSERR )
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
FirewallUtilities . addRule ( " tcp " , " 8090 " )
2017-10-24 19:16:36 +05:00
FirewallUtilities . addRule ( " tcp " , " 80 " )
FirewallUtilities . addRule ( " tcp " , " 443 " )
FirewallUtilities . addRule ( " tcp " , " 21 " )
2019-03-26 16:19:03 +05:00
FirewallUtilities . addRule ( " tcp " , " 25 " )
FirewallUtilities . addRule ( " tcp " , " 587 " )
FirewallUtilities . addRule ( " tcp " , " 465 " )
FirewallUtilities . addRule ( " tcp " , " 110 " )
FirewallUtilities . addRule ( " tcp " , " 143 " )
FirewallUtilities . addRule ( " tcp " , " 993 " )
FirewallUtilities . addRule ( " udp " , " 53 " )
FirewallUtilities . addRule ( " tcp " , " 53 " )
2017-12-09 22:30:10 +05:00
FirewallUtilities . addRule ( " tcp " , " 40110-40210 " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " FirewallD installed and configured! " )
preFlightsChecks . stdOut ( " FirewallD installed and configured! " )
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installFirewalld] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installFirewalld] " )
return 0
return 1
2018-02-04 21:15:30 +05:00
## from here
2019-03-26 16:19:03 +05:00
def installLSCPD ( self ) :
try :
logging . InstallLog . writeToFile ( " Starting LSCPD installation.. " )
os . chdir ( self . cwd )
if self . distro == ubuntu :
command = " apt-get -y install gcc g++ make autoconf rcs "
else :
command = ' yum -y install gcc gcc-c++ make autoconf glibc rcs '
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 1 , os . EX_OSERR )
if self . distro == ubuntu :
command = " apt-get -y install libpcre3 libpcre3-dev openssl libexpat1 libexpat1-dev libgeoip-dev " \
" zlib1g zlib1g-dev libudns-dev whichman curl "
else :
command = ' yum -y install pcre-devel openssl-devel expat-devel geoip-devel zlib-devel udns-devel ' \
' which curl '
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 1 , os . EX_OSERR )
command = ' tar zxf lscp.tar.gz -C /usr/local/ '
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 1 , os . EX_OSERR )
2019-04-15 15:54:23 +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/conf/key.pem -out /usr/local/lscp/conf/cert.pem '
2019-03-26 16:19:03 +05:00
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 1 , os . EX_OSERR )
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
if self . distro == centos :
command = ' adduser lscpd -M -d /usr/local/lscp '
else :
command = ' useradd lscpd -M -d /usr/local/lscp '
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 0 , os . EX_OSERR )
if self . distro == centos :
command = ' groupadd lscpd '
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 0 , os . EX_OSERR )
# Added group in useradd for Ubuntu
command = ' usermod -a -G lscpd lscpd '
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 0 , os . EX_OSERR )
command = ' usermod -a -G lsadm lscpd '
preFlightsChecks . call ( command , self . distro , ' [installLSCPD] ' ,
' Install LSCPD ' ,
1 , 0 , os . EX_OSERR )
2019-04-15 15:54:23 +05:00
try :
os . mkdir ( ' /usr/local/lscp/cyberpanel ' )
except :
pass
try :
os . mkdir ( ' /usr/local/lscp/cyberpanel/logs ' )
except :
pass
2019-03-26 16:19:03 +05:00
2019-04-15 15:54:23 +05:00
#self.setupComodoRules()
2019-03-26 16:19:03 +05:00
self . setupPort ( )
2019-03-30 14:21:52 +05:00
self . setupPythonWSGI ( )
2019-03-26 16:19:03 +05:00
logging . InstallLog . writeToFile ( " LSCPD successfully installed! " )
except BaseException , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installLSCPD] " )
def setupComodoRules ( self ) :
try :
os . chdir ( self . cwd )
extractLocation = " /usr/local/lscp/modsec "
command = " mkdir -p /usr/local/lscp/modsec "
preFlightsChecks . call ( command , self . distro , ' [setupComodoRules] ' ,
' setupComodoRules ' ,
1 , 0 , os . EX_OSERR )
try :
if os . path . exists ( ' comodo.tar.gz ' ) :
os . remove ( ' comodo.tar.gz ' )
except :
pass
command = " wget https://cyberpanel.net/modsec/comodo.tar.gz "
result = preFlightsChecks . call ( command , self . distro , ' [setupComodoRules] ' ,
' setupComodoRules ' ,
1 , 0 , os . EX_OSERR )
command = " tar -zxf comodo.tar.gz -C /usr/local/lscp/modsec "
preFlightsChecks . call ( command , self . distro , ' [setupComodoRules] ' ,
' setupComodoRules ' ,
1 , 0 , os . EX_OSERR )
###
modsecConfPath = " /usr/local/lscp/conf/modsec.conf "
modsecConfig = """
module mod_security {
2019-04-15 15:54:23 +05:00
ls_enabled 0
2019-03-26 16:19:03 +05:00
modsecurity on
modsecurity_rules `
SecDebugLogLevel 0
SecDebugLog / usr / local / lscp / logs / modsec . log
SecAuditEngine on
SecAuditLogRelevantStatus " ^(?:5|4(?!04)) "
SecAuditLogParts AFH
SecAuditLogType Serial
SecAuditLog / usr / local / lscp / logs / auditmodsec . log
2019-03-30 14:21:52 +05:00
SecRuleEngine Off
2019-03-26 16:19:03 +05:00
`
modsecurity_rules_file / usr / local / lscp / modsec / comodo / modsecurity . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 00 _Init_Initialization . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 01 _Init_AppsInitialization . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 02 _Global_Generic . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 03 _Global_Agents . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 04 _Global_Domains . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 05 _Global_Backdoor . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 06 _XSS_XSS . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 07 _Global_Other . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 08 _Bruteforce_Bruteforce . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 09 _HTTP_HTTP . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 10 _HTTP_HTTPDoS . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 11 _HTTP_Protocol . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 12 _HTTP_Request . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 13 _Outgoing_FilterGen . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 14 _Outgoing_FilterASP . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 15 _Outgoing_FilterPHP . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 16 _Outgoing_FilterSQL . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 17 _Outgoing_FilterOther . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 18 _Outgoing_FilterInFrame . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 19 _Outgoing_FiltersEnd . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 20 _PHP_PHPGen . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 21 _SQL_SQLi . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 22 _Apps_Joomla . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 23 _Apps_JComponent . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 24 _Apps_WordPress . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 25 _Apps_WPPlugin . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 26 _Apps_WHMCS . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 27 _Apps_Drupal . conf
modsecurity_rules_file / usr / local / lscp / modsec / comodo / 28 _Apps_OtherApps . conf
}
"""
writeToFile = open ( modsecConfPath , ' w ' )
writeToFile . write ( modsecConfig )
writeToFile . close ( )
###
command = " chown -R lscpd:lscpd /usr/local/lscp/modsec "
preFlightsChecks . call ( command , self . distro , ' [setupComodoRules] ' ,
' setupComodoRules ' ,
1 , 0 , os . EX_OSERR )
return 1
except BaseException , msg :
logging . InstallLog . writeToFile ( " [Failed:setupComodoRules] " + str ( msg ) )
return 0
def setupPort ( self ) :
try :
###
bindConfPath = " /usr/local/lscp/conf/bind.conf "
writeToFile = open ( bindConfPath , ' w ' )
writeToFile . write ( " *: " + self . port )
writeToFile . close ( )
except :
return 0
2019-03-30 14:21:52 +05:00
def setupPythonWSGI ( self ) :
try :
command = " wget http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.4.tgz "
preFlightsChecks . call ( command , self . distro , ' [setupPythonWSGI] ' ,
' setupPythonWSGI ' ,
1 , 0 , os . EX_OSERR )
command = " tar xf wsgi-lsapi-1.4.tgz "
preFlightsChecks . call ( command , self . distro , ' [setupPythonWSGI] ' ,
' setupPythonWSGI ' ,
1 , 0 , os . EX_OSERR )
os . chdir ( " wsgi-lsapi-1.4 " )
command = " python ./configure.py "
preFlightsChecks . call ( command , self . distro , ' [setupPythonWSGI] ' ,
' setupPythonWSGI ' ,
1 , 0 , os . EX_OSERR )
command = " make "
preFlightsChecks . call ( command , self . distro , ' [setupPythonWSGI] ' ,
' setupPythonWSGI ' ,
1 , 0 , os . EX_OSERR )
command = " cp lswsgi /usr/local/CyberCP/bin/ "
preFlightsChecks . call ( command , self . distro , ' [setupPythonWSGI] ' ,
' setupPythonWSGI ' ,
1 , 0 , os . EX_OSERR )
os . chdir ( self . cwd )
except :
return 0
2017-10-24 19:16:36 +05:00
def setupLSCPDDaemon ( self ) :
try :
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Trying to setup LSCPD Daemon! " )
logging . InstallLog . writeToFile ( " Trying to setup LSCPD Daemon! " )
2017-10-24 19:16:36 +05:00
os . chdir ( self . cwd )
2018-11-16 14:41:40 +05:00
shutil . copy ( " lscpd/lscpd.service " , " /etc/systemd/system/lscpd.service " )
shutil . copy ( " lscpd/lscpdctrl " , " /usr/local/lscp/bin/lscpdctrl " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
##
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-16 14:41:40 +05:00
while ( 1 ) :
2018-02-04 21:15:30 +05:00
command = ' chmod +x /usr/local/lscp/bin/lscpdctrl '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Unable to change permissions for /usr/local/lscp/bin/lscpdctrl, trying again, try number: " + str (
count ) )
2018-02-04 21:15:30 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for /usr/local/lscp/bin/lscpdctrl [setupLSCPDDaemon] " )
2018-02-04 21:15:30 +05:00
break
else :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Successfully changed permissions for /usr/local/lscp/bin/lscpdctrl! " )
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Successfully changed permissions for /usr/local/lscp/bin/lscpdctrl! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
##
2017-10-24 19:16:36 +05:00
2019-03-30 14:21:52 +05:00
path = " /usr/local/lscpd/admin/ "
command = " mkdir -p " + path
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
path = " /usr/local/CyberCP/conf/ "
command = " mkdir -p " + path
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
path = " /usr/local/CyberCP/conf/token_env "
writeToFile = open ( path , " w " )
writeToFile . write ( " abc \n " )
writeToFile . close ( )
command = " chmod 600 " + path
cmd = shlex . split ( command )
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
count = 1
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-14 13:36:34 +05:00
2018-02-04 21:15:30 +05:00
command = ' systemctl enable lscpd.service '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Trying to enable LSCPD on system startup, trying again, try number: " + str ( count ) )
2018-02-04 21:15:30 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to change permissions for /usr/local/lscp/bin/lscpdctrl, you can do it manually using systemctl enable lscpd.service [setupLSCPDDaemon] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " LSCPD Successfully enabled at system startup! " )
preFlightsChecks . stdOut ( " LSCPD Successfully enabled at system startup! " )
break
2018-11-06 13:03:12 +05:00
##
count = 0
# In Ubuntu, the library that lscpd looks for is libpcre.so.1, but the one it installs is libpcre.so.3...
if self . distro == ubuntu :
command = ' ln -s /lib/x86_64-linux-gnu/libpcre.so.3 /lib/x86_64-linux-gnu/libpcre.so.1 '
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-11-06 13:03:12 +05:00
if res == 0 :
self . stdOut ( " Created ubuntu symbolic link to pcre " )
else :
self . stdOut ( " Error creating symbolic link to pcre: " + str ( res ) )
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-16 14:41:40 +05:00
while ( 1 ) :
2018-02-04 21:15:30 +05:00
command = ' systemctl start lscpd '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Unable to start LSCPD, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile ( " Unable to start LSCPD! [setupLSCPDDaemon] " )
break
else :
logging . InstallLog . writeToFile ( " LSCPD successfully started! " )
preFlightsChecks . stdOut ( " LSCPD successfully started! " )
break
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " LSCPD Daemon Set! " )
2017-10-24 19:16:36 +05:00
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " LSCPD Daemon Set! " )
2017-10-24 19:16:36 +05:00
except OSError , msg :
2017-11-02 02:09:47 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [setupLSCPDDaemon] " )
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 ) + " [setupLSCPDDaemon] " )
2017-10-24 19:16:36 +05:00
return 0
return 1
def setup_cron ( self ) :
try :
2017-11-05 21:07:12 +05:00
## first install crontab
2018-11-06 00:19:58 +05:00
file = open ( " installLogs.txt " , ' a ' )
2018-02-04 21:15:30 +05:00
count = 0
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' yum install cronie -y '
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = ' apt-get -y install cron '
2017-11-05 21:07:12 +05:00
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2017-11-05 21:07:12 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd , stdout = file )
2017-11-05 21:07:12 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Trying to install cronie, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to install cronie, cron jobs will not work. [setup_cron] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Cronie successfully installed! " )
preFlightsChecks . stdOut ( " Cronie successfully installed! " )
break
2017-11-05 21:07:12 +05:00
2018-02-04 21:15:30 +05:00
count = 0
2017-11-05 21:07:12 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-11-06 00:19:58 +05:00
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' systemctl enable crond '
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = ' systemctl enable cron '
2018-11-06 00:19:58 +05:00
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd , stdout = file )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
2018-11-16 14:41:40 +05:00
preFlightsChecks . stdOut (
" Trying to enable cronie on system startup, trying again, try number: " + str ( count ) )
2018-02-04 21:15:30 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" We are not able to enable cron jobs at system startup, you can manually run systemctl enable crond. [setup_cron] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Cronie successfully enabled at system startup! " )
preFlightsChecks . stdOut ( " Cronie successfully enabled at system startup! " )
break
count = 0
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' systemctl start crond '
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = ' systemctl start cron '
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd , stdout = file )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Trying to start crond, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" We are not able to start crond, you can manually run systemctl start crond. [setup_cron] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Crond successfully started! " )
preFlightsChecks . stdOut ( " Crond successfully started! " )
break
2017-11-05 21:07:12 +05:00
##
2017-12-09 22:30:10 +05:00
cronFile = open ( " /etc/crontab " , " a " )
cronFile . writelines ( " 0 * * * * root python /usr/local/CyberCP/plogical/findBWUsage.py " + " \n " )
2018-06-30 15:29:56 +05:00
cronFile . writelines ( " 0 * * * * root /usr/local/CyberCP/postfixSenderPolicy/client.py hourlyCleanup " + " \n " )
cronFile . writelines ( " 0 0 1 * * root /usr/local/CyberCP/postfixSenderPolicy/client.py monthlyCleanup " + " \n " )
2019-03-21 23:26:42 +05:00
cronFile . writelines ( " 0 2 * * * root /usr/local/CyberCP/plogical/upgradeCritical.py " + " \n " )
2017-10-24 19:16:36 +05:00
cronFile . close ( )
command = ' chmod +x /usr/local/CyberCP/plogical/findBWUsage.py '
2018-06-30 15:29:56 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd , stdout = file )
2019-03-21 23:26:42 +05:00
command = ' chmod +x /usr/local/CyberCP/plogical/upgradeCritical.py '
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd , stdout = file )
2018-07-05 15:22:48 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-07-05 15:22:48 +05:00
logging . InstallLog . writeToFile ( " 1427 [setup_cron] " )
else :
pass
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
command = ' chmod +x /usr/local/CyberCP/postfixSenderPolicy/client.py '
2017-10-24 19:16:36 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd , stdout = file )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
logging . InstallLog . writeToFile ( " 1428 [setup_cron] " )
else :
pass
2018-02-04 21:15:30 +05:00
count = 0
2017-10-24 19:16:36 +05:00
2018-11-16 14:41:40 +05:00
while ( 1 ) :
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' systemctl restart crond.service '
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = ' systemctl restart cron.service '
2018-02-04 21:15:30 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd , stdout = file )
2018-02-04 21:15:30 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-02-04 21:15:30 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Trying to restart crond, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" We are not able to restart crond, you can manually run systemctl restart crond. [setup_cron] " )
2018-02-04 21:15:30 +05:00
break
else :
logging . InstallLog . writeToFile ( " Crond successfully restarted! " )
preFlightsChecks . stdOut ( " Crond successfully restarted! " )
break
2017-10-24 19:16:36 +05:00
2018-11-06 00:19:58 +05:00
file . close ( )
2017-10-24 19:16:36 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_cron] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setup_cron] " )
return 0
return 1
def install_default_keys ( self ) :
try :
count = 0
path = " /root/.ssh "
if not os . path . exists ( path ) :
os . mkdir ( path )
while ( 1 ) :
command = " ssh-keygen -f /root/.ssh/cyberpanel -t rsa -N ' ' "
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Trying to setup default SSH keys, 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 ( " Unable to setup default SSH keys. [install_default_keys] " )
2017-10-24 19:16:36 +05:00
break
else :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Succcessfully created default SSH keys! " )
preFlightsChecks . stdOut ( " Succcessfully created default SSH keys! " )
2017-10-24 19:16:36 +05:00
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [install_default_keys] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [install_default_keys] " )
return 0
return 1
def install_rsync ( self ) :
try :
count = 0
while ( 1 ) :
2018-11-06 00:19:58 +05:00
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' yum -y install rsync '
2018-10-25 16:58:15 -04:00
else :
2018-10-25 16:10:01 -04:00
command = ' apt-get -y install rsync '
2017-10-24 19:16:36 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2017-10-24 19:16:36 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2017-10-24 19:16:36 +05:00
count = count + 1
2018-02-04 21:15:30 +05:00
preFlightsChecks . stdOut ( " Trying to install rsync, trying again, try number: " + str ( count ) )
2017-10-24 19:16:36 +05:00
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to install rsync, some of backup functions will not work. [install_rsync] " )
2017-10-24 19:16:36 +05:00
break
else :
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Succcessfully installed rsync! " )
preFlightsChecks . stdOut ( " Succcessfully installed rsync! " )
2017-10-24 19:16:36 +05:00
break
except OSError , msg :
2017-11-02 02:09:47 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [install_rsync] " )
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 ) + " [install_rsync] " )
2017-10-24 19:16:36 +05:00
return 0
return 1
2017-12-16 11:59:47 +05:00
def test_Requests ( self ) :
try :
import requests
getVersion = requests . get ( ' https://cyberpanel.net/version.txt ' )
latest = getVersion . json ( )
2018-11-16 14:41:40 +05:00
except BaseException , msg :
2017-12-16 11:59:47 +05:00
2018-03-08 22:19:23 +05:00
command = " pip uninstall --yes urllib3 "
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2017-12-16 11:59:47 +05:00
command = " pip uninstall --yes requests "
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2017-12-16 11:59:47 +05:00
2018-03-08 22:19:23 +05:00
count = 0
while ( 1 ) :
2017-12-16 11:59:47 +05:00
2018-03-08 22:19:23 +05:00
command = " pip install http://mirror.cyberpanel.net/urllib3-1.22.tar.gz "
2017-12-16 11:59:47 +05:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-03-08 22:19:23 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Unable to install urllib3 module, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Unable to install urllib3 module, exiting installer! [install_python_requests] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-03-08 22:19:23 +05:00
else :
logging . InstallLog . writeToFile ( " urllib3 module Successfully installed! " )
preFlightsChecks . stdOut ( " urllib3 module Successfully installed! " )
break
count = 0
while ( 1 ) :
command = " pip install http://mirror.cyberpanel.net/requests-2.18.4.tar.gz "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-03-08 22:19:23 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-03-08 22:19:23 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Unable to install requests module, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Unable to install requests module, exiting installer! [install_python_requests] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-03-08 22:19:23 +05:00
else :
logging . InstallLog . writeToFile ( " Requests module Successfully installed! " )
preFlightsChecks . stdOut ( " Requests module Successfully installed! " )
break
2017-12-16 11:59:47 +05:00
2018-02-04 21:15:30 +05:00
def installation_successfull ( self ) :
print ( " ################################################################### " )
print ( " CyberPanel Successfully Installed " )
print ( " " )
print ( " " )
print ( " " )
print ( " Visit: https:// " + self . ipAddr + " :8090 " )
print ( " Username: admin " )
print ( " Password: 1234567 " )
2018-11-06 00:19:58 +05:00
2018-02-04 21:15:30 +05:00
print ( " ################################################################### " )
def installCertBot ( self ) :
try :
2018-03-08 22:19:23 +05:00
command = " pip uninstall --yes pyOpenSSL "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-02-04 21:15:30 +05:00
2018-03-08 22:19:23 +05:00
command = " pip uninstall --yes certbot "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-02-04 21:15:30 +05:00
2019-03-30 14:21:52 +05:00
command = ' wget -O - https://get.acme.sh | sh '
subprocess . call ( command , shell = True )
2017-12-16 11:59:47 +05:00
2018-02-04 21:15:30 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installCertBot] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installCertBot] " )
return 0
return 1
2017-10-24 19:16:36 +05:00
2018-03-26 20:39:56 +05:00
def modSecPreReqs ( self ) :
try :
2018-11-16 14:41:40 +05:00
pathToRemoveGarbageFile = os . path . join ( self . server_root_path , " modules/mod_security.so " )
2018-03-26 20:39:56 +05:00
os . remove ( pathToRemoveGarbageFile )
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [modSecPreReqs] " )
return 0
2018-04-20 23:49:49 +05:00
def installTLDExtract ( self ) :
try :
count = 0
while ( 1 ) :
command = " pip install tldextract "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-04-20 23:49:49 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-04-20 23:49:49 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Trying to install tldextract, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed to install tldextract! [installTLDExtract] " )
else :
logging . InstallLog . writeToFile ( " tldextract successfully installed! [pip] " )
preFlightsChecks . stdOut ( " tldextract successfully installed! [pip] " )
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installTLDExtract] " )
return 0
2018-10-17 23:20:02 +05:00
def installPYDNS ( self ) :
2019-01-09 14:55:10 +05:00
command = " pip install pydns "
preFlightsChecks . call ( command , self . distro , ' [installPYDNS] ' ,
' Install PYDNS ' ,
1 , 0 , os . EX_OSERR )
def installDockerPY ( self ) :
command = " pip install docker "
preFlightsChecks . call ( command , self . distro , ' [installDockerPY] ' ,
' Install DockerPY ' ,
1 , 0 , os . EX_OSERR )
2018-10-17 23:20:02 +05:00
2018-05-01 00:49:47 +05:00
def installOpenDKIM ( self ) :
try :
count = 0
while ( 1 ) :
2018-11-06 00:19:58 +05:00
2018-10-26 09:56:12 -04:00
if self . distro == centos :
2018-10-25 16:10:01 -04:00
command = ' yum -y install opendkim '
else :
command = ' apt-get -y install opendkim '
2018-05-01 00:49:47 +05:00
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-05-01 00:49:47 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-05-01 00:49:47 +05:00
count = count + 1
preFlightsChecks . stdOut ( " Trying to install opendkim, trying again, try number: " + str ( count ) )
if count == 3 :
2018-11-16 14:41:40 +05:00
logging . InstallLog . writeToFile (
" Unable to install opendkim, your mail may not end up in inbox. [installOpenDKIM] " )
2018-05-01 00:49:47 +05:00
break
else :
logging . InstallLog . writeToFile ( " Succcessfully installed opendkim! " )
preFlightsChecks . stdOut ( " Succcessfully installed opendkim! " )
break
2018-11-07 12:14:38 +05:00
if self . distro == ubuntu :
2018-11-14 18:36:56 +05:00
try :
command = ' apt install opendkim-tools '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-11-14 18:36:56 +05:00
except :
pass
2018-11-06 13:03:12 +05:00
2018-11-14 18:36:56 +05:00
try :
command = ' mkdir -p /etc/opendkim/keys/ '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-11-14 18:36:56 +05:00
except :
pass
2018-11-06 13:03:12 +05:00
2018-05-01 00:49:47 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installOpenDKIM] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installOpenDKIM] " )
return 0
return 1
def configureOpenDKIM ( self ) :
try :
## Configure OpenDKIM specific settings
openDKIMConfigurePath = " /etc/opendkim.conf "
configData = """
Mode sv
Canonicalization relaxed / simple
KeyTable refile : / etc / opendkim / KeyTable
SigningTable refile : / etc / opendkim / SigningTable
ExternalIgnoreList refile : / etc / opendkim / TrustedHosts
InternalHosts refile : / etc / opendkim / TrustedHosts
"""
2018-11-16 14:41:40 +05:00
writeToFile = open ( openDKIMConfigurePath , ' a ' )
2018-05-01 00:49:47 +05:00
writeToFile . write ( configData )
writeToFile . close ( )
## Configure postfix specific settings
postfixFilePath = " /etc/postfix/main.cf "
configData = """
smtpd_milters = inet : 127.0 .0 .1 : 8891
non_smtpd_milters = $ smtpd_milters
milter_default_action = accept
"""
2018-11-16 14:41:40 +05:00
writeToFile = open ( postfixFilePath , ' a ' )
2018-05-01 00:49:47 +05:00
writeToFile . write ( configData )
writeToFile . close ( )
2018-11-14 18:36:56 +05:00
if self . distro == ubuntu :
data = open ( openDKIMConfigurePath , ' r ' ) . readlines ( )
writeToFile = open ( openDKIMConfigurePath , ' w ' )
for items in data :
if items . find ( ' Socket ' ) > - 1 and items . find ( ' local: ' ) and items [ 0 ] != ' # ' :
writeToFile . writelines ( ' Socket inet:8891@localhost \n ' )
else :
writeToFile . writelines ( items )
writeToFile . close ( )
2018-05-01 00:49:47 +05:00
#### Restarting Postfix and OpenDKIM
command = " systemctl start opendkim "
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-05-01 00:49:47 +05:00
command = " systemctl enable opendkim "
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-05-01 00:49:47 +05:00
##
command = " systemctl start postfix "
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-05-01 00:49:47 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [configureOpenDKIM] " )
return 0
except ValueError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [configureOpenDKIM] " )
return 0
return 1
2018-05-06 14:18:41 +05:00
def installdnsPython ( self ) :
try :
count = 0
while ( 1 ) :
command = " pip install dnspython "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-05-06 14:18:41 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-05-06 14:18:41 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Trying to install dnspython, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed to install dnspython! [installdnsPython] " )
else :
logging . InstallLog . writeToFile ( " dnspython successfully installed! [pip] " )
preFlightsChecks . stdOut ( " dnspython successfully installed! [pip] " )
break
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [installdnsPython] " )
return 0
2018-06-05 00:53:45 +05:00
def setupCLI ( self ) :
try :
count = 0
while ( 1 ) :
command = " ln -s /usr/local/CyberCP/cli/cyberPanel.py /usr/bin/cyberpanel "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-06-05 00:53:45 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( self . distro , res ) :
2018-06-05 00:53:45 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Trying to setup CLI, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed to setup CLI! [setupCLI] " )
else :
logging . InstallLog . writeToFile ( " CLI setup successfull! " )
preFlightsChecks . stdOut ( " CLI setup successfull! " )
break
command = " chmod +x /usr/local/CyberCP/cli/cyberPanel.py "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-06-05 00:53:45 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setupCLI] " )
return 0
2018-07-13 21:45:40 +05:00
def setupPHPAndComposer ( self ) :
try :
2018-11-06 00:19:58 +05:00
2018-10-31 14:42:42 -04:00
if self . distro == ubuntu :
2018-10-31 14:57:51 -04:00
if not os . access ( ' /usr/local/lsws/lsphp70/bin/php ' , os . R_OK ) :
if os . access ( ' /usr/local/lsws/lsphp70/bin/php7.0 ' , os . R_OK ) :
2018-10-31 14:42:42 -04:00
os . symlink ( ' /usr/local/lsws/lsphp70/bin/php7.0 ' , ' /usr/local/lsws/lsphp70/bin/php ' )
2018-10-31 14:57:51 -04:00
if not os . access ( ' /usr/local/lsws/lsphp71/bin/php ' , os . R_OK ) :
if os . access ( ' /usr/local/lsws/lsphp71/bin/php7.1 ' , os . R_OK ) :
2018-10-31 14:42:42 -04:00
os . symlink ( ' /usr/local/lsws/lsphp71/bin/php7.1 ' , ' /usr/local/lsws/lsphp71/bin/php ' )
2018-10-31 14:57:51 -04:00
if not os . access ( ' /usr/local/lsws/lsphp72/bin/php ' , os . R_OK ) :
if os . access ( ' /usr/local/lsws/lsphp72/bin/php7.2 ' , os . R_OK ) :
2018-10-31 14:42:42 -04:00
os . symlink ( ' /usr/local/lsws/lsphp72/bin/php7.2 ' , ' /usr/local/lsws/lsphp72/bin/php ' )
2018-07-13 21:45:40 +05:00
command = " cp /usr/local/lsws/lsphp71/bin/php /usr/bin/ "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-07-13 21:45:40 +05:00
os . chdir ( self . cwd )
2019-03-21 23:26:42 +05:00
command = " chmod +x composer.sh "
2018-10-31 14:42:42 -04:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-07-13 21:45:40 +05:00
2019-03-21 23:26:42 +05:00
command = " ./composer.sh "
2018-10-31 14:42:42 -04:00
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-07-13 21:45:40 +05:00
except OSError , msg :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [setupPHPAndComposer] " )
2018-07-13 21:45:40 +05:00
return 0
2018-06-27 00:16:50 +05:00
@staticmethod
2018-11-02 09:17:16 -04:00
def installOne ( package ) :
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( ' apt-get -y install ' + package ) )
2018-11-02 09:17:16 -04:00
if res != 0 :
preFlightsChecks . stdOut ( " Error # " + str ( res ) + ' installing: ' + package + ' . This may not be an issue ' \
2018-11-06 00:19:58 +05:00
' but may affect installation of something later ' ,
1 )
2018-11-02 09:17:16 -04:00
2018-11-06 00:19:58 +05:00
return res # Though probably not used
2018-11-02 09:17:16 -04:00
2018-06-27 00:16:50 +05:00
@staticmethod
2018-10-31 11:53:03 -04:00
def setupVirtualEnv ( distro ) :
2018-06-27 00:16:50 +05:00
try :
##
count = 0
2018-11-02 09:17:16 -04:00
if distro == ubuntu :
# You can't install all at once! So install one at a time.
preFlightsChecks . stdOut ( " Installing python prerequisites " , 1 )
preFlightsChecks . installOne ( ' libcurl4-gnutls-dev ' )
preFlightsChecks . installOne ( ' libgnutls-dev ' )
preFlightsChecks . installOne ( ' libgcrypt20-dev ' )
preFlightsChecks . installOne ( ' libattr1 ' )
preFlightsChecks . installOne ( ' libattr1-dev ' )
preFlightsChecks . installOne ( ' liblzma-dev ' )
preFlightsChecks . installOne ( ' libgpgme-dev ' )
preFlightsChecks . installOne ( ' libmariadbclient-dev ' )
preFlightsChecks . installOne ( ' libcurl4-gnutls-dev ' )
preFlightsChecks . installOne ( ' libssl-dev ' )
preFlightsChecks . installOne ( ' nghttp2 ' )
preFlightsChecks . installOne ( ' libnghttp2-dev ' )
preFlightsChecks . installOne ( ' idn2 ' )
preFlightsChecks . installOne ( ' libidn2-dev ' )
preFlightsChecks . installOne ( ' libidn2-0-dev ' )
preFlightsChecks . installOne ( ' librtmp-dev ' )
preFlightsChecks . installOne ( ' libpsl-dev ' )
preFlightsChecks . installOne ( ' nettle-dev ' )
preFlightsChecks . installOne ( ' libgnutls28-dev ' )
preFlightsChecks . installOne ( ' libldap2-dev ' )
preFlightsChecks . installOne ( ' libgssapi-krb5-2 ' )
preFlightsChecks . installOne ( ' libk5crypto3 ' )
preFlightsChecks . installOne ( ' libkrb5-dev ' )
preFlightsChecks . installOne ( ' libcomerr2 ' )
preFlightsChecks . installOne ( ' libldap2-dev ' )
preFlightsChecks . installOne ( ' python-gpg ' )
preFlightsChecks . installOne ( ' python-gpgme ' )
else :
while ( 1 ) :
2018-10-30 11:44:41 -04:00
command = " yum install -y libattr-devel xz-devel gpgme-devel mariadb-devel curl-devel "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-06-27 00:16:50 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( distro , res ) :
2018-11-02 09:17:16 -04:00
count = count + 1
preFlightsChecks . stdOut (
" Trying to install project dependant modules, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed to install project dependant modules! [setupVirtualEnv] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
os . _exit ( 0 )
else :
logging . InstallLog . writeToFile ( " Project dependant modules installed successfully! " )
preFlightsChecks . stdOut ( " Project dependant modules installed successfully!! " )
break
2018-06-27 00:16:50 +05:00
##
count = 0
while ( 1 ) :
command = " pip install virtualenv "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-06-27 00:16:50 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( distro , res ) :
2018-06-27 00:16:50 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Trying to install virtualenv, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed install virtualenv! [setupVirtualEnv] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-06-27 00:16:50 +05:00
else :
logging . InstallLog . writeToFile ( " virtualenv installed successfully! " )
preFlightsChecks . stdOut ( " virtualenv installed successfully! " )
break
####
count = 0
while ( 1 ) :
2018-07-05 15:22:48 +05:00
command = " virtualenv --system-site-packages /usr/local/CyberCP "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-06-27 00:16:50 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( distro , res ) :
2018-06-27 00:16:50 +05:00
count = count + 1
preFlightsChecks . stdOut (
" Trying to setup virtualenv, trying again, try number: " + str ( count ) )
if count == 3 :
logging . InstallLog . writeToFile (
" Failed to setup virtualenv! [setupVirtualEnv] " )
preFlightsChecks . stdOut ( " Installation failed, consult: /var/log/installLogs.txt " )
2018-07-05 15:22:48 +05:00
os . _exit ( 0 )
2018-06-27 00:16:50 +05:00
else :
2018-10-31 12:16:08 -04:00
logging . InstallLog . writeToFile ( " virtualenv setup successfully! " )
preFlightsChecks . stdOut ( " virtualenv setup successfully! " )
2018-06-27 00:16:50 +05:00
break
##
env_path = ' /usr/local/CyberCP '
2019-03-26 16:19:03 +05:00
subprocess . call ( [ ' virtualenv ' , env_path ] )
2018-06-27 00:16:50 +05:00
activate_this = os . path . join ( env_path , ' bin ' , ' activate_this.py ' )
execfile ( activate_this , dict ( __file__ = activate_this ) )
##
2018-11-01 16:10:29 -04:00
install_file = ' /usr/local/CyberCP/requirments.txt '
2018-11-02 11:53:08 -04:00
if distro == ubuntu and get_Ubuntu_release ( ) < 18.04 :
install_file_new = ' /usr/local/CyberCP/requirements.txt '
2018-11-06 00:19:58 +05:00
fd = open ( install_file , ' r ' )
fd_new = open ( install_file_new , ' w ' )
2018-11-02 11:53:08 -04:00
lines = fd . readlines ( )
for line in lines :
2018-11-02 12:09:30 -04:00
if line [ : 6 ] != ' pycurl ' and line [ : 7 ] != ' pygpgme ' :
2018-11-02 11:53:08 -04:00
fd_new . write ( line )
fd . close ( )
fd_new . close ( )
preFlightsChecks . stdOut ( " Install updated " + install_file_new , 1 )
install_file = install_file_new
2018-11-01 16:10:29 -04:00
2018-06-27 00:16:50 +05:00
count = 0
while ( 1 ) :
2018-11-01 16:10:29 -04:00
command = " pip install --ignore-installed -r " + install_file
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-06-27 00:16:50 +05:00
2018-11-14 11:37:17 -05:00
if preFlightsChecks . resFailed ( distro , res ) :
2018-06-27 00:16:50 +05:00
count = count + 1
preFlightsChecks . stdOut (
2018-11-01 16:10:29 -04:00
" Trying to install Python project dependant modules, trying again, try number: " + str ( count ) )
2018-06-27 00:16:50 +05:00
if count == 3 :
logging . InstallLog . writeToFile (
2018-11-01 16:10:29 -04:00
" Failed to install Python project dependant modules! [setupVirtualEnv] " )
2018-07-05 15:22:48 +05:00
break
2018-06-27 00:16:50 +05:00
else :
2018-11-01 16:10:29 -04:00
logging . InstallLog . writeToFile ( " Python project dependant modules installed successfully! " )
preFlightsChecks . stdOut ( " Python project dependant modules installed successfully!! " )
2018-06-27 00:16:50 +05:00
break
2019-03-30 14:21:52 +05:00
# command = "systemctl restart gunicorn.socket"
# res = subprocess.call(shlex.split(command))
2018-06-27 00:16:50 +05:00
2018-07-05 15:22:48 +05:00
command = " virtualenv --system-site-packages /usr/local/CyberCP "
2019-03-26 16:19:03 +05:00
res = subprocess . call ( shlex . split ( command ) )
2018-07-05 15:22:48 +05:00
2018-06-27 00:16:50 +05:00
except OSError , msg :
logging . InstallLog . writeToFile ( str ( msg ) + " [setupVirtualEnv] " )
return 0
2018-07-23 22:11:42 +05:00
@staticmethod
def enableDisableDNS ( state ) :
try :
servicePath = ' /home/cyberpanel/powerdns '
if state == ' Off ' :
command = ' sudo systemctl stop pdns '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-07-23 22:11:42 +05:00
command = ' sudo systemctl disable pdns '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-07-23 22:11:42 +05:00
try :
os . remove ( servicePath )
except :
pass
else :
writeToFile = open ( servicePath , ' w+ ' )
writeToFile . close ( )
except OSError , msg :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [enableDisableDNS] " )
2018-07-23 22:11:42 +05:00
return 0
@staticmethod
def enableDisableEmail ( state ) :
try :
servicePath = ' /home/cyberpanel/postfix '
if state == ' Off ' :
command = ' sudo systemctl stop postfix '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-07-23 22:11:42 +05:00
command = ' sudo systemctl disable postfix '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-07-23 22:11:42 +05:00
try :
os . remove ( servicePath )
except :
pass
else :
writeToFile = open ( servicePath , ' w+ ' )
writeToFile . close ( )
except OSError , msg :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [enableDisableEmail] " )
2018-07-23 22:11:42 +05:00
return 0
@staticmethod
2018-11-07 08:54:16 -05:00
def enableDisableFTP ( state , distro ) :
2018-07-23 22:11:42 +05:00
try :
servicePath = ' /home/cyberpanel/pureftpd '
if state == ' Off ' :
2018-11-07 09:20:05 -05:00
command = ' sudo systemctl stop ' + preFlightsChecks . pureFTPDServiceName ( distro )
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-07-23 22:11:42 +05:00
2018-11-07 09:20:05 -05:00
command = ' sudo systemctl disable ' + preFlightsChecks . pureFTPDServiceName ( distro )
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-07-23 22:11:42 +05:00
try :
os . remove ( servicePath )
except :
pass
else :
writeToFile = open ( servicePath , ' w+ ' )
writeToFile . close ( )
except OSError , msg :
2018-11-06 00:19:58 +05:00
logging . InstallLog . writeToFile ( str ( msg ) + " [enableDisableEmail] " )
2018-07-23 22:11:42 +05:00
return 0
2018-11-14 13:36:34 +05:00
@staticmethod
def setUpFirstAccount ( ) :
try :
command = ' python /usr/local/CyberCP/plogical/adminPass.py --password 1234567 '
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-11-14 13:36:34 +05:00
except :
pass
2018-11-16 14:41:40 +05:00
def main ( ) :
2017-10-24 19:16:36 +05:00
parser = argparse . ArgumentParser ( description = ' CyberPanel Installer ' )
parser . add_argument ( ' publicip ' , help = ' Please enter public IP for your VPS or dedicated server. ' )
2018-06-01 02:08:21 +05:00
parser . add_argument ( ' --mysql ' , help = ' Specify number of MySQL instances to be used. ' )
2018-07-23 22:11:42 +05:00
parser . add_argument ( ' --postfix ' , help = ' Enable or disable Email Service. ' )
parser . add_argument ( ' --powerdns ' , help = ' Enable or disable DNS Service. ' )
parser . add_argument ( ' --ftp ' , help = ' Enable or disable ftp Service. ' )
2018-11-10 16:05:40 +05:00
parser . add_argument ( ' --ent ' , help = ' Install LS Ent or OpenLiteSpeed ' )
parser . add_argument ( ' --serial ' , help = ' Install LS Ent or OpenLiteSpeed ' )
2019-03-26 16:19:03 +05:00
parser . add_argument ( ' --port ' , help = ' LSCPD Port ' )
2017-10-24 19:16:36 +05:00
args = parser . parse_args ( )
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " Starting CyberPanel installation.. " )
preFlightsChecks . stdOut ( " Starting CyberPanel installation.. " )
2018-11-21 14:50:27 +05:00
if args . ent == None :
ent = 0
preFlightsChecks . stdOut ( " OpenLiteSpeed web server will be installed. " )
else :
if args . ent == ' ols ' :
ent = 0
preFlightsChecks . stdOut ( " OpenLiteSpeed web server will be installed. " )
else :
preFlightsChecks . stdOut ( " LiteSpeed Enterprise web server will be installed. " )
ent = 1
if args . serial != None :
serial = args . serial
preFlightsChecks . stdOut ( " LiteSpeed Enterprise Serial detected: " + serial )
else :
preFlightsChecks . stdOut ( " Installation failed, please specify LiteSpeed Enterprise key using --serial " )
os . _exit ( 0 )
2018-02-13 11:45:44 +05:00
## Writing public IP
2018-11-21 14:50:27 +05:00
try :
os . mkdir ( " /etc/cyberpanel " )
except :
pass
2018-02-13 11:45:44 +05:00
machineIP = open ( " /etc/cyberpanel/machineIP " , " w " )
machineIP . writelines ( args . publicip )
machineIP . close ( )
2017-10-24 19:16:36 +05:00
cwd = os . getcwd ( )
2018-10-25 16:47:26 -04:00
distro = get_distro ( )
2018-10-26 16:25:13 -04:00
checks = preFlightsChecks ( " /usr/local/lsws/ " , args . publicip , " /usr/local " , cwd , " /usr/local/CyberCP " , distro )
2019-03-21 23:26:42 +05:00
checks . mountTemp ( )
2018-10-25 16:10:01 -04:00
if distro == ubuntu :
os . chdir ( " /etc/cyberpanel " )
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
if args . port == None :
port = " 8090 "
else :
port = args . port
2018-08-12 14:53:05 +05:00
if args . mysql == None :
2018-06-01 02:08:21 +05:00
mysql = ' One '
2018-08-12 14:53:05 +05:00
preFlightsChecks . stdOut ( " Single MySQL instance version will be installed. " )
else :
mysql = args . mysql
2018-11-06 00:19:58 +05:00
preFlightsChecks . stdOut ( " Dobule MySQL instance version will be installed. " )
2017-10-24 19:16:36 +05:00
checks . checkPythonVersion ( )
2017-12-09 22:30:10 +05:00
checks . setup_account_cyberpanel ( )
2018-10-25 16:10:01 -04:00
if distro == centos :
checks . yum_update ( )
2017-10-24 19:16:36 +05:00
checks . installCyberPanelRepo ( )
2018-10-25 16:10:01 -04:00
if distro == centos :
checks . enableEPELRepo ( )
2017-10-24 19:16:36 +05:00
checks . install_pip ( )
checks . install_python_dev ( )
checks . install_gcc ( )
2018-10-25 16:10:01 -04:00
if distro == centos :
checks . install_python_setup_tools ( )
2017-10-24 19:16:36 +05:00
checks . install_django ( )
checks . install_pexpect ( )
checks . install_python_mysql_library ( )
checks . install_gunicorn ( )
checks . install_psutil ( )
checks . setup_gunicorn ( )
2018-11-07 09:20:05 -05:00
import installCyberPanel
2019-04-15 15:54:23 +05:00
2018-11-10 16:05:40 +05:00
if ent == 0 :
2019-06-26 03:57:16 +05:00
installCyberPanel . Main ( cwd , mysql , distro , ent , None , port , args . ftp , args . powerdns )
2018-11-10 16:05:40 +05:00
else :
2019-06-26 03:57:16 +05:00
installCyberPanel . Main ( cwd , mysql , distro , ent , serial , port , args . ftp , args . powerdns )
2018-11-07 09:20:05 -05:00
2019-03-30 14:21:52 +05:00
2019-03-21 23:26:42 +05:00
checks . setupPHPAndComposer ( )
2017-10-24 19:16:36 +05:00
checks . fix_selinux_issue ( )
checks . install_psmisc ( )
2019-06-26 03:57:16 +05:00
2019-07-03 13:15:26 +05:00
if args . postfix == None :
2019-06-26 03:57:16 +05:00
checks . install_postfix_davecot ( )
checks . setup_email_Passwords ( installCyberPanel . InstallCyberPanel . mysqlPassword , mysql )
checks . setup_postfix_davecot_config ( mysql )
else :
if args . postfix == ' On ' :
checks . install_postfix_davecot ( )
checks . setup_email_Passwords ( installCyberPanel . InstallCyberPanel . mysqlPassword , mysql )
checks . setup_postfix_davecot_config ( mysql )
2017-10-24 19:16:36 +05:00
checks . install_unzip ( )
2017-12-09 22:30:10 +05:00
checks . install_zip ( )
2017-10-24 19:16:36 +05:00
checks . install_rsync ( )
checks . installFirewalld ( )
2019-03-26 16:19:03 +05:00
2017-10-24 19:16:36 +05:00
checks . install_python_requests ( )
checks . install_default_keys ( )
2018-02-04 21:15:30 +05:00
checks . installCertBot ( )
2017-12-16 11:59:47 +05:00
checks . test_Requests ( )
2018-10-17 23:20:02 +05:00
checks . installPYDNS ( )
2019-01-09 14:55:10 +05:00
checks . installDockerPY ( )
2018-06-01 02:08:21 +05:00
checks . download_install_CyberPanel ( installCyberPanel . InstallCyberPanel . mysqlPassword , mysql )
2019-03-30 14:21:52 +05:00
checks . downoad_and_install_raindloop ( )
checks . download_install_phpmyadmin ( )
2018-06-05 00:53:45 +05:00
checks . setupCLI ( )
2017-11-02 02:09:47 +05:00
checks . setup_cron ( )
2018-04-20 23:49:49 +05:00
checks . installTLDExtract ( )
2018-11-16 14:41:40 +05:00
# checks.installdnsPython()
2018-05-01 00:49:47 +05:00
## Install and Configure OpenDKIM.
checks . installOpenDKIM ( )
checks . configureOpenDKIM ( )
2018-03-26 20:39:56 +05:00
checks . modSecPreReqs ( )
2018-11-06 13:03:12 +05:00
checks . setupVirtualEnv ( distro )
2019-03-30 14:21:52 +05:00
checks . installLSCPD ( )
checks . setupLSCPDDaemon ( )
2019-03-26 16:19:03 +05:00
checks . fixCyberPanelPermissions ( )
2019-03-21 23:26:42 +05:00
2018-07-23 22:11:42 +05:00
2018-08-12 14:53:05 +05:00
if args . postfix != None :
checks . enableDisableEmail ( args . postfix )
else :
preFlightsChecks . stdOut ( " Postfix will be installed and enabled. " )
2018-07-23 22:11:42 +05:00
checks . enableDisableEmail ( ' On ' )
2018-08-12 14:53:05 +05:00
if args . powerdns != None :
checks . enableDisableDNS ( args . powerdns )
else :
preFlightsChecks . stdOut ( " PowerDNS will be installed and enabled. " )
2018-07-23 22:11:42 +05:00
checks . enableDisableDNS ( ' On ' )
2018-08-12 14:53:05 +05:00
if args . ftp != None :
2018-11-07 08:54:16 -05:00
checks . enableDisableFTP ( args . ftp , distro )
2018-08-12 14:53:05 +05:00
else :
preFlightsChecks . stdOut ( " Pure-FTPD will be installed and enabled. " )
2018-11-07 08:54:16 -05:00
checks . enableDisableFTP ( ' On ' , distro )
2019-03-21 23:26:42 +05:00
2019-03-26 16:19:03 +05:00
2018-11-14 13:36:34 +05:00
checks . setUpFirstAccount ( )
2018-02-04 21:15:30 +05:00
logging . InstallLog . writeToFile ( " CyberPanel installation successfully completed! " )
2018-11-06 13:03:12 +05:00
checks . installation_successfull ( )
2018-11-06 00:19:58 +05:00
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
if __name__ == " __main__ " :
2018-12-17 18:46:34 +05:00
main ( )