Files
CyberPanel/install/install.py

2348 lines
92 KiB
Python
Raw Normal View History

2017-10-24 19:16:36 +05:00
import sys
import subprocess
import shutil
2019-12-12 13:51:35 +05:00
import installLog as logging
2017-10-24 19:16:36 +05:00
import argparse
import os
import shlex
2019-12-12 13:51:35 +05:00
from firewallUtilities import FirewallUtilities
import time
2018-06-11 21:04:55 +05:00
import string
import random
2018-11-06 13:03:12 +05:00
import socket
from os.path import *
from stat import *
import stat
2020-03-29 21:18:55 +05:00
VERSION = '2.0'
2020-08-04 20:20:19 +05:00
BUILD = 3
2020-03-29 21:18:55 +05:00
char_set = {'small': 'abcdefghijklmnopqrstuvwxyz',
'nums': '0123456789',
'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
}
def generate_pass(length=14):
2019-12-10 22:34:39 +05:00
chars = string.ascii_uppercase + string.ascii_lowercase + string.digits
size = length
return ''.join(random.choice(chars) for x in range(size))
2017-10-24 19:16:36 +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
2019-12-17 21:34:55 +05:00
cent8 = 2
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
2019-12-17 21:34:55 +05:00
data = open('/etc/redhat-release', 'r').read()
if data.find('CentOS Linux release 8') > -1:
return cent8
2019-03-26 16:19:03 +05:00
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:
2020-07-05 13:26:46 +05:00
debug = 1
cyberPanelMirror = "mirror.cyberpanel.net/pip"
2019-12-27 20:35:12 +05:00
cdn = 'cyberpanel.sh'
2018-03-04 13:37:58 +05:00
2020-07-05 14:39:57 +05:00
def __init__(self, rootPath, ip, path, cwd, cyberPanelPath, distro, remotemysql = None , mysqlhost = None, mysqldb = None, mysqluser = None, mysqlpassword = None, mysqlport = None):
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
2020-06-26 18:22:20 +05:00
self.remotemysql = remotemysql
self.mysqlhost = mysqlhost
self.mysqluser = mysqluser
self.mysqlpassword = mysqlpassword
self.mysqlport = mysqlport
2020-07-05 14:39:57 +05:00
self.mysqldb = mysqldb
2017-10-24 19:16:36 +05:00
2019-03-26 16:19:03 +05:00
@staticmethod
def stdOut(message, log=0, do_exit=0, code=os.EX_OK):
print("\n\n")
2019-12-10 15:09:10 +05:00
print(("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "] #########################################################################\n"))
print(("[" + time.strftime("%m.%d.%Y_%H-%M-%S") + "] " + message + "\n"))
print(("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "] #########################################################################\n"))
2019-03-26 16:19:03 +05:00
if log:
logging.InstallLog.writeToFile(message)
if do_exit:
2019-11-13 19:59:42 +05:00
logging.InstallLog.writeToFile(message)
2019-03-26 16:19:03 +05:00
sys.exit(code)
2019-03-21 23:26:42 +05:00
def mountTemp(self):
try:
## On OpenVZ there is an issue using .tempdisk for /tmp as it breaks network on container after reboot.
2019-12-15 13:30:40 +05:00
if subprocess.check_output('systemd-detect-virt').decode("utf-8").find("openvz") > -1:
varTmp = "/var/tmp /tmp none bind 0 0\n"
fstab = "/etc/fstab"
writeToFile = open(fstab, "a")
writeToFile.writelines(varTmp)
writeToFile.close()
else:
command = "dd if=/dev/zero of=/usr/.tempdisk bs=100M count=15"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2019-11-13 13:08:26 +05:00
1, 0, os.EX_OSERR)
command = "mkfs.ext4 -F /usr/.tempdisk"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2019-11-13 13:08:26 +05:00
1, 0, os.EX_OSERR)
command = "mkdir -p /usr/.tmpbak/"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2019-11-13 13:08:26 +05:00
1, 0, os.EX_OSERR)
command = "cp -pr /tmp/* /usr/.tmpbak/"
subprocess.call(command, shell=True)
command = "mount -o loop,rw,nodev,nosuid,noexec,nofail /usr/.tempdisk /tmp"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2019-11-13 13:08:26 +05:00
1, 0, os.EX_OSERR)
command = "chmod 1777 /tmp"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2019-11-13 13:08:26 +05:00
1, 0, os.EX_OSERR)
command = "cp -pr /usr/.tmpbak/* /tmp/"
subprocess.call(command, shell=True)
command = "rm -rf /usr/.tmpbak"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2019-11-13 13:08:26 +05:00
1, 0, os.EX_OSERR)
command = "mount --bind /tmp /var/tmp"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2019-11-13 13:08:26 +05:00
1, 0, os.EX_OSERR)
tmp = "/usr/.tempdisk /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0\n"
varTmp = "/tmp /var/tmp none bind 0 0\n"
fstab = "/etc/fstab"
writeToFile = open(fstab, "a")
writeToFile.writelines(tmp)
writeToFile.writelines(varTmp)
writeToFile.close()
2019-03-21 23:26:42 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
preFlightsChecks.stdOut('[ERROR] ' + str(msg))
2019-03-21 23:26:42 +05:00
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:
2020-04-17 06:06:22 +05:00
return 'pure-ftpd-mysql'
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
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):
2019-11-13 18:08:14 +05:00
finalMessage = 'Running: %s' % (message)
preFlightsChecks.stdOut(finalMessage, log)
2018-11-14 11:37:17 -05:00
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
2019-11-13 18:08:14 +05:00
finalMessage = 'Running %s failed. Running again, try number %s' % (message, str(count))
preFlightsChecks.stdOut(finalMessage)
2018-11-14 11:37:17 -05:00
if count == 3:
fatal_message = ''
if do_exit:
fatal_message = '. Fatal error, see /var/log/installLogs.txt for full details'
2019-11-13 18:08:14 +05:00
preFlightsChecks.stdOut("[ERROR] We are not able to run " + message + ' return code: ' + str(res) +
fatal_message + ".", 1, do_exit, code)
2018-11-14 11:37:17 -05:00
return False
else:
preFlightsChecks.stdOut('Successfully ran: %s.' % (message), log)
2018-11-14 11:37:17 -05:00
break
2019-11-13 18:08:14 +05:00
2018-11-14 11:37:17 -05:00
return True
2018-11-06 00:19:58 +05:00
def checkIfSeLinuxDisabled(self):
try:
command = "sestatus"
2019-12-15 13:30:40 +05:00
output = subprocess.check_output(shlex.split(command)).decode("utf-8")
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + "[checkIfSeLinuxDisabled]")
logging.InstallLog.writeToFile('[ERROR] ' + "SELinux Check OK. [checkIfSeLinuxDisabled]")
preFlightsChecks.stdOut('[ERROR] ' + "SELinux Check OK.")
2018-11-06 00:19:58 +05:00
return 1
def checkPythonVersion(self):
2019-12-10 15:16:11 +05:00
if sys.version_info[0] == 3:
return 1
else:
2019-12-24 12:16:00 +05:00
preFlightsChecks.stdOut("You are running Unsupported python version, please install python 3.x")
2018-07-05 15:22:48 +05:00
os._exit(0)
2017-12-09 22:30:10 +05:00
def setup_account_cyberpanel(self):
try:
2017-12-09 22:30:10 +05:00
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2018-12-13 04:23:08 +05:00
command = "yum install sudo -y"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,
command,
2018-12-17 18:46:34 +05:00
1, 0, os.EX_OSERR)
2017-12-09 22:30:10 +05:00
##
2017-12-09 22:30:10 +05:00
2018-10-26 09:56:12 -04:00
if self.distro == ubuntu:
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'
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,command,1, 1, os.EX_OSERR)
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"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,command,1, 1, os.EX_OSERR)
2017-11-05 03:02:51 +05:00
2018-11-06 00:19:58 +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"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,command,1, 0, os.EX_OSERR)
2019-04-15 15:54:23 +05:00
command = 'groupadd docker'
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,command,1, 0, os.EX_OSERR)
2019-04-15 15:54:23 +05:00
command = 'usermod -aG docker docker'
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,command,1, 0, os.EX_OSERR)
2019-04-15 15:54:23 +05:00
command = 'usermod -aG docker cyberpanel'
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,command,1, 0, os.EX_OSERR)
2019-04-15 15:54:23 +05:00
###
2018-12-13 04:23:08 +05:00
command = "mkdir -p /etc/letsencrypt/live/"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command,command,1, 0, os.EX_OSERR)
2018-11-06 00:19:58 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
logging.InstallLog.writeToFile("[ERROR] setup_account_cyberpanel. " + str(msg))
2017-11-05 03:02:51 +05:00
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
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
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2018-10-25 16:10:01 -04:00
os.chmod(filename, S_IRWXU | S_IRWXG)
2018-10-25 16:10:01 -04:00
command = "./" + filename
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2018-10-25 16:10:01 -04:00
except:
logging.InstallLog.writeToFile("[ERROR] Exception during CyberPanel install")
preFlightsChecks.stdOut("[ERROR] Exception during CyberPanel install")
2018-10-25 16:10:01 -04:00
os._exit(os.EX_SOFTWARE)
2019-12-18 13:39:32 +05:00
elif self.distro == centos:
2020-05-13 01:32:55 +05:00
command = 'rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.2-1.el7.noarch.rpm'
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2019-12-18 13:39:32 +05:00
elif self.distro == cent8:
command = 'rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el8.noarch.rpm'
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2017-10-24 19:16:36 +05:00
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:
logging.InstallLog.writeToFile("[ERROR] fix_selinux_issue problem")
2017-10-24 19:16:36 +05:00
def install_psmisc(self):
2018-10-26 09:11:17 -04:00
self.stdOut("Install psmisc")
2017-10-24 19:16:36 +05:00
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-11-13 13:08:26 +05:00
command = "yum -y install psmisc"
else:
command = "apt-get -y install psmisc"
2019-11-07 14:47:02 +05:00
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-11-07 14:47:02 +05:00
2019-11-13 13:08:26 +05:00
def download_install_CyberPanel(self, mysqlPassword, mysql):
##
2017-10-24 19:16:36 +05:00
os.chdir(self.path)
2019-11-07 14:47:02 +05:00
os.chdir('/usr/local')
command = "git clone https://github.com/usmannasir/cyberpanel"
2019-11-13 16:13:52 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2017-10-24 19:16:36 +05:00
2019-11-07 14:47:02 +05:00
shutil.move('cyberpanel', 'CyberCP')
2017-10-24 19:16:36 +05:00
2019-11-07 14:47:02 +05:00
##
2017-10-24 19:16:36 +05:00
### update password:
2020-06-26 18:22:20 +05:00
if self.remotemysql == 'OFF':
passFile = "/etc/cyberpanel/mysqlPassword"
f = open(passFile)
data = f.read()
password = data.split('\n', 1)[0]
else:
password = self.mysqlpassword
2017-10-24 19:16:36 +05:00
2019-12-12 13:54:25 +05:00
### Put correct mysql passwords in settings file!
logging.InstallLog.writeToFile("Updating settings.py!")
path = self.cyberPanelPath + "/CyberCP/settings.py"
data = open(path, "r").readlines()
writeDataToFile = open(path, "w")
counter = 0
for items in data:
if items.find('SECRET_KEY') > -1:
SK = "SECRET_KEY = '%s'\n" % (generate_pass(50))
writeDataToFile.writelines(SK)
continue
2020-06-26 18:22:20 +05:00
2019-12-12 13:54:25 +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")
else:
writeDataToFile.writelines(items)
else:
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)
2020-07-05 13:26:46 +05:00
if self.distro == ubuntu:
os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
2020-06-26 18:59:44 +05:00
if self.remotemysql == 'ON':
2020-07-05 14:38:24 +05:00
command = "sed -i 's|localhost|%s|g' %s" % (self.mysqlhost, path)
2020-06-26 18:59:44 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2020-06-26 18:22:20 +05:00
2020-07-05 19:29:26 +05:00
# command = "sed -i 's|'mysql'|'%s'|g' %s" % (self.mysqldb, path)
# preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2020-07-05 14:39:57 +05:00
2020-08-26 14:10:55 +05:00
command = "sed -i 's|root|%s|g' %s" % (self.mysqluser, path)
2020-06-26 18:59:44 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2020-06-26 18:22:20 +05:00
2020-06-26 18:59:44 +05:00
command = "sed -i 's|'PORT':''|'PORT':'%s'|g' %s" % (self.mysqlport, path)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2020-06-26 18:22:20 +05:00
2019-12-12 13:54:25 +05:00
logging.InstallLog.writeToFile("settings.py updated!")
#self.setupVirtualEnv(self.distro)
### Applying migrations
os.chdir("/usr/local/CyberCP")
command = "/usr/local/CyberPanel/bin/python manage.py makemigrations"
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
##
command = "/usr/local/CyberPanel/bin/python manage.py migrate"
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
if not os.path.exists("/usr/local/CyberCP/public"):
os.mkdir("/usr/local/CyberCP/public")
## Moving static content to lscpd location
command = 'mv static /usr/local/CyberCP/public/'
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
try:
2020-03-29 21:48:10 +05:00
path = "/usr/local/CyberCP/version.txt"
2019-12-12 13:54:25 +05:00
writeToFile = open(path, 'w')
2020-03-29 21:18:55 +05:00
writeToFile.writelines('%s\n' % (VERSION))
writeToFile.writelines(str(BUILD))
2019-12-12 13:54:25 +05:00
writeToFile.close()
except:
pass
def fixCyberPanelPermissions(self):
###### fix Core CyberPanel permissions
command = "usermod -G lscpd,lsadm,nobody lscpd"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "usermod -G lscpd,lsadm,nogroup lscpd"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "find /usr/local/CyberCP -type d -exec chmod 0755 {} \;"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "find /usr/local/CyberCP -type f -exec chmod 0644 {} \;"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod -R 755 /usr/local/CyberCP/bin"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
## change owner
command = "chown -R root:root /usr/local/CyberCP"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
########### Fix LSCPD
command = "find /usr/local/lscp -type d -exec chmod 0755 {} \;"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "find /usr/local/lscp -type f -exec chmod 0644 {} \;"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod -R 755 /usr/local/lscp/bin"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod -R 755 /usr/local/lscp/fcgi-bin"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin/tmp"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
## change owner
command = "chown -R root:root /usr/local/lscp"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod 700 /usr/local/CyberCP/cli/cyberPanel.py"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod 700 /usr/local/CyberCP/plogical/upgradeCritical.py"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod 755 /usr/local/CyberCP/postfixSenderPolicy/client.py"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod 640 /usr/local/CyberCP/CyberCP/settings.py"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chown root:cyberpanel /usr/local/CyberCP/CyberCP/settings.py"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
files = ['/etc/yum.repos.d/MariaDB.repo', '/etc/pdns/pdns.conf', '/etc/systemd/system/lscpd.service',
'/etc/pure-ftpd/pure-ftpd.conf', '/etc/pure-ftpd/pureftpd-pgsql.conf',
'/etc/pure-ftpd/pureftpd-mysql.conf', '/etc/pure-ftpd/pureftpd-ldap.conf',
'/etc/dovecot/dovecot.conf', '/usr/local/lsws/conf/httpd_config.xml',
'/usr/local/lsws/conf/modsec.conf', '/usr/local/lsws/conf/httpd.conf']
for items in files:
command = 'chmod 644 %s' % (items)
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
impFile = ['/etc/pure-ftpd/pure-ftpd.conf', '/etc/pure-ftpd/pureftpd-pgsql.conf',
'/etc/pure-ftpd/pureftpd-mysql.conf', '/etc/pure-ftpd/pureftpd-ldap.conf',
'/etc/dovecot/dovecot.conf', '/etc/pdns/pdns.conf', '/etc/pure-ftpd/db/mysql.conf',
'/etc/powerdns/pdns.conf']
for items in impFile:
command = 'chmod 600 %s' % (items)
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'chmod 640 /etc/postfix/*.cf'
subprocess.call(command, shell=True)
command = 'chmod 644 /etc/postfix/main.cf'
subprocess.call(command, shell=True)
command = 'chmod 640 /etc/dovecot/*.conf'
subprocess.call(command, shell=True)
command = 'chmod 644 /etc/dovecot/dovecot.conf'
subprocess.call(command, shell=True)
command = 'chmod 640 /etc/dovecot/dovecot-sql.conf.ext'
subprocess.call(command, shell=True)
command = 'chmod 644 /etc/postfix/dynamicmaps.cf'
subprocess.call(command, shell=True)
fileM = ['/usr/local/lsws/FileManager/', '/usr/local/CyberCP/install/FileManager',
'/usr/local/CyberCP/serverStatus/litespeed/FileManager', '/usr/local/lsws/Example/html/FileManager']
for items in fileM:
try:
shutil.rmtree(items)
except:
pass
command = 'chmod 755 /etc/pure-ftpd/'
subprocess.call(command, shell=True)
command = 'chmod +x /usr/local/CyberCP/plogical/renew.py'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-22 12:08:24 +05:00
command = 'chmod +x /usr/local/CyberCP/CLManager/CLPackages.py'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-28 18:01:12 +05:00
clScripts = ['/usr/local/CyberCP/CLScript/panel_info.py', '/usr/local/CyberCP/CLScript/CloudLinuxPackages.py',
'/usr/local/CyberCP/CLScript/CloudLinuxUsers.py',
'/usr/local/CyberCP/CLScript/CloudLinuxDomains.py'
2019-12-31 19:55:29 +05:00
, '/usr/local/CyberCP/CLScript/CloudLinuxResellers.py', '/usr/local/CyberCP/CLScript/CloudLinuxAdmins.py',
'/usr/local/CyberCP/CLScript/CloudLinuxDB.py', '/usr/local/CyberCP/CLScript/UserInfo.py']
2019-12-28 18:01:12 +05:00
for items in clScripts:
command = 'chmod +x %s' % (items)
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-01-14 16:34:06 +05:00
command = 'chmod 600 /usr/local/CyberCP/plogical/adminPass.py'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-01-29 17:27:43 +05:00
command = 'chmod 600 /etc/cagefs/exclude/cyberpanelexclude'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-01-17 14:17:44 +05:00
command = "find /usr/local/CyberCP/ -name '*.pyc' -delete"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-06-22 11:14:16 +05:00
if self.distro == cent8:
command = 'chown root:pdns /etc/pdns/pdns.conf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'chmod 640 /etc/pdns/pdns.conf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-12 13:54:25 +05:00
def install_unzip(self):
self.stdOut("Install unzip")
try:
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'yum -y install unzip'
else:
command = 'apt-get -y install unzip'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] '+ str(msg) + " [install_unzip]")
def install_zip(self):
self.stdOut("Install zip")
try:
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'yum -y install zip'
else:
command = 'apt-get -y install zip'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_zip]")
def download_install_phpmyadmin(self):
try:
if not os.path.exists("/usr/local/CyberCP/public"):
os.mkdir("/usr/local/CyberCP/public")
2019-12-27 20:07:27 +05:00
command = 'wget -O /usr/local/CyberCP/public/phpmyadmin.zip https://%s/misc/phpmyadmin.zip' % (preFlightsChecks.cdn)
2019-12-27 21:02:17 +05:00
2019-12-27 20:07:27 +05:00
preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]',
command, 1, 0, os.EX_OSERR)
command = 'unzip /usr/local/CyberCP/public/phpmyadmin.zip -d /usr/local/CyberCP/public/'
preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]',
command, 1, 0, os.EX_OSERR)
2019-12-12 13:54:25 +05:00
2020-03-26 13:34:41 +01:00
command = 'mv /usr/local/CyberCP/public/phpMyAdmin-*-all-languages /usr/local/CyberCP/public/phpmyadmin'
2020-03-27 11:29:58 +05:00
subprocess.call(command, shell=True)
2019-12-27 20:07:27 +05:00
command = 'rm -f /usr/local/CyberCP/public/phpmyadmin.zip'
preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]',
command, 1, 0, os.EX_OSERR)
2019-12-12 13:54:25 +05:00
## Write secret phrase
rString = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)])
2019-12-27 20:07:27 +05:00
data = open('/usr/local/CyberCP/public/phpmyadmin/config.sample.inc.php', 'r').readlines()
2019-12-12 13:54:25 +05:00
2019-12-27 20:07:27 +05:00
writeToFile = open('/usr/local/CyberCP/public/phpmyadmin/config.inc.php', 'w')
2019-12-12 13:54:25 +05:00
writeE = 1
phpMyAdminContent = """
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Servers'][$i]['auth_type'] = 'signon';
$cfg['Servers'][$i]['SignonSession'] = 'SignonSession';
$cfg['Servers'][$i]['SignonURL'] = 'phpmyadminsignin.php';
2020-08-13 11:09:43 +05:00
$cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
"""
2019-12-12 13:54:25 +05:00
for items in data:
if items.find('blowfish_secret') > -1:
writeToFile.writelines(
"$cfg['blowfish_secret'] = '" + rString + "'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */\n")
2020-08-13 11:19:30 +05:00
elif items.find('/* Authentication type */') > -1:
2019-12-12 13:54:25 +05:00
writeToFile.writelines(items)
writeToFile.write(phpMyAdminContent)
writeE = 0
2020-08-13 11:19:30 +05:00
elif items.find("$cfg['Servers'][$i]['AllowNoPassword']") > -1:
writeE = 1
else:
if writeE:
writeToFile.writelines(items)
2019-12-12 13:54:25 +05:00
writeToFile.writelines("$cfg['TempDir'] = '/usr/local/CyberCP/public/phpmyadmin/tmp';\n")
writeToFile.close()
os.mkdir('/usr/local/CyberCP/public/phpmyadmin/tmp')
command = 'chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin'
preFlightsChecks.call(command, self.distro, '[chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin]',
'chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin', 1, 0, os.EX_OSERR)
if self.remotemysql == 'ON':
command = "sed -i 's|'localhost'|'%s'|g' %s" % (self.mysqlhost, '/usr/local/CyberCP/public/phpmyadmin/config.inc.php')
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-08-09 12:45:18 +05:00
command = 'cp /usr/local/CyberCP/plogical/phpmyadminsignin.php /usr/local/CyberCP/public/phpmyadmin/phpmyadminsignin.php'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
if self.remotemysql == 'ON':
command = "sed -i 's|localhost|%s|g' /usr/local/CyberCP/public/phpmyadmin/phpmyadminsignin.php" % (self.mysqlhost)
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-12 13:54:25 +05:00
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [download_install_phpmyadmin]")
return 0
###################################################### Email setup
def install_postfix_davecot(self):
self.stdOut("Install dovecot - first remove postfix")
try:
if self.distro == centos:
command = 'yum remove postfix -y'
2019-12-18 15:34:33 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-18 16:03:52 +05:00
elif self.distro == ubuntu:
2019-12-12 13:54:25 +05:00
command = 'apt-get -y remove postfix'
2019-12-18 15:34:33 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-12 13:54:25 +05:00
self.stdOut("Install dovecot - do the install")
if self.distro == centos:
command = 'yum install --enablerepo=gf-plus -y postfix3 postfix3-ldap postfix3-mysql postfix3-pcre'
2019-12-18 13:58:23 +05:00
elif self.distro == cent8:
2020-06-09 15:20:39 +05:00
2020-06-09 15:02:53 +05:00
command = 'dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm'
2020-06-09 15:20:39 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-06-09 15:02:53 +05:00
command = 'dnf install --enablerepo=gf-plus postfix3 postfix3-mysql -y'
2019-12-12 13:54:25 +05:00
else:
command = 'apt-get -y debconf-utils'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
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
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'apt-get -y install postfix'
# os.remove(file_name)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2019-12-18 16:21:57 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
pass
else:
command = 'apt-get -y install dovecot-imapd dovecot-pop3d postfix-mysql'
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
##
2020-04-13 16:11:34 +05:00
if self.distro == centos:
command = 'yum --enablerepo=gf-plus -y install dovecot dovecot-mysql'
2020-04-13 00:58:56 +05:00
elif self.distro == cent8:
2020-06-09 15:02:53 +05:00
command = 'dnf install --enablerepo=gf-plus dovecot23 dovecot23-mysql -y'
2019-12-12 13:54:25 +05:00
else:
command = 'apt-get -y install dovecot-mysql'
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
if self.distro != centos:
command = 'curl https://repo.dovecot.org/DOVECOT-REPO-GPG | gpg --import'
subprocess.call(command, shell=True)
command = 'gpg --export ED409DA1 > /etc/apt/trusted.gpg.d/dovecot.gpg'
subprocess.call(command, shell=True)
debPath = '/etc/apt/sources.list.d/dovecot.list'
writeToFile = open(debPath, 'w')
writeToFile.write('deb https://repo.dovecot.org/ce-2.3-latest/ubuntu/bionic bionic main\n')
writeToFile.close()
try:
command = 'apt update -y'
subprocess.call(command, shell=True)
except:
pass
try:
command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y'
subprocess.call(command, shell=True)
command = 'dpkg --configure -a'
subprocess.call(command, shell=True)
command = 'apt --fix-broken install -y'
subprocess.call(command, shell=True)
command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y'
subprocess.call(command, shell=True)
except:
pass
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_postfix_davecot]")
return 0
return 1
def setup_email_Passwords(self, mysqlPassword, mysql):
try:
logging.InstallLog.writeToFile("Setting up authentication for Postfix and Dovecot...")
os.chdir(self.cwd)
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"
### update password:
data = open(davecotmysql, "r").readlines()
writeDataToFile = open(davecotmysql, "w")
if mysql == 'Two':
dataWritten = "connect = host=127.0.0.1 dbname=cyberpanel user=cyberpanel password=" + mysqlPassword + " port=3307\n"
else:
dataWritten = "connect = host=localhost dbname=cyberpanel user=cyberpanel password=" + mysqlPassword + " port=3306\n"
for items in data:
if items.find("connect") > -1:
writeDataToFile.writelines(dataWritten)
else:
writeDataToFile.writelines(items)
# if self.distro == ubuntu:
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
### update password:
data = open(mysql_virtual_domains, "r").readlines()
writeDataToFile = open(mysql_virtual_domains, "w")
dataWritten = "password = " + mysqlPassword + "\n"
for items in data:
if items.find("password") > -1:
writeDataToFile.writelines(dataWritten)
else:
writeDataToFile.writelines(items)
# if self.distro == ubuntu:
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
### update password:
data = open(mysql_virtual_forwardings, "r").readlines()
writeDataToFile = open(mysql_virtual_forwardings, "w")
dataWritten = "password = " + mysqlPassword + "\n"
for items in data:
if items.find("password") > -1:
writeDataToFile.writelines(dataWritten)
else:
writeDataToFile.writelines(items)
# if self.distro == ubuntu:
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
### update password:
data = open(mysql_virtual_mailboxes, "r").readlines()
writeDataToFile = open(mysql_virtual_mailboxes, "w")
dataWritten = "password = " + mysqlPassword + "\n"
for items in data:
if items.find("password") > -1:
writeDataToFile.writelines(dataWritten)
else:
writeDataToFile.writelines(items)
# if self.distro == ubuntu:
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
### 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)
# if self.distro == ubuntu:
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
2020-07-06 11:28:41 +05:00
if self.remotemysql == 'ON':
command = "sed -i 's|host=localhost|host=%s|g' %s" % (self.mysqlhost, davecotmysql)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = "sed -i 's|port=3306|port=%s|g' %s" % (self.mysqlport, davecotmysql)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
##
command = "sed -i 's|localhost|%s:%s|g' %s" % (self.mysqlhost, self.mysqlport, mysql_virtual_domains)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = "sed -i 's|localhost|%s:%s|g' %s" % (
self.mysqlhost, self.mysqlport, mysql_virtual_forwardings)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = "sed -i 's|localhost|%s:%s|g' %s" % (
self.mysqlhost, self.mysqlport, mysql_virtual_mailboxes)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = "sed -i 's|localhost|%s:%s|g' %s" % (
self.mysqlhost, self.mysqlport, mysql_virtual_email2email)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
2019-12-12 13:54:25 +05:00
logging.InstallLog.writeToFile("Authentication for Postfix and Dovecot set.")
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR]' + str(msg) + " [setup_email_Passwords]")
return 0
return 1
def centos_lib_dir_to_ubuntu(self, filename, old, new):
try:
fd = open(filename, 'r')
lines = fd.readlines()
fd.close()
fd = open(filename, 'w')
centos_prefix = old
ubuntu_prefix = new
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] Error converting: " + filename + " from centos defaults to ubuntu defaults: " + str(err), 1,
1, os.EX_OSERR)
def setup_postfix_davecot_config(self, mysql):
try:
logging.InstallLog.writeToFile("Configuring postfix and dovecot...")
os.chdir(self.cwd)
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"
if os.path.exists(mysql_virtual_domains):
os.remove(mysql_virtual_domains)
if os.path.exists(mysql_virtual_forwardings):
os.remove(mysql_virtual_forwardings)
if os.path.exists(mysql_virtual_mailboxes):
os.remove(mysql_virtual_mailboxes)
if os.path.exists(mysql_virtual_email2email):
os.remove(mysql_virtual_email2email)
if os.path.exists(main):
os.remove(main)
if os.path.exists(master):
os.remove(master)
if os.path.exists(davecot):
os.remove(davecot)
if os.path.exists(davecotmysql):
os.remove(davecotmysql)
###############Getting SSL
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'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
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'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
# Cleanup config files for ubuntu
if self.distro == ubuntu:
preFlightsChecks.stdOut("Cleanup postfix/dovecot config files", 1)
if mysql == 'Two':
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")
else:
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")
########### Copy config files
if mysql == 'Two':
shutil.copy("email-configs/mysql-virtual_domains.cf", "/etc/postfix/mysql-virtual_domains.cf")
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)
shutil.copy("email-configs/master.cf", master)
shutil.copy("email-configs/dovecot.conf", davecot)
shutil.copy("email-configs/dovecot-sql.conf.ext", davecotmysql)
else:
shutil.copy("email-configs-one/mysql-virtual_domains.cf", "/etc/postfix/mysql-virtual_domains.cf")
shutil.copy("email-configs-one/mysql-virtual_forwardings.cf",
"/etc/postfix/mysql-virtual_forwardings.cf")
shutil.copy("email-configs-one/mysql-virtual_mailboxes.cf", "/etc/postfix/mysql-virtual_mailboxes.cf")
shutil.copy("email-configs-one/mysql-virtual_email2email.cf",
"/etc/postfix/mysql-virtual_email2email.cf")
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)
######################################## Permissions
command = 'chmod o= /etc/postfix/mysql-virtual_domains.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chmod o= /etc/postfix/mysql-virtual_forwardings.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chmod o= /etc/postfix/mysql-virtual_mailboxes.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chmod o= /etc/postfix/mysql-virtual_email2email.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chmod o= ' + main
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chmod o= ' + master
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
#######################################
command = 'chgrp postfix /etc/postfix/mysql-virtual_domains.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chgrp postfix /etc/postfix/mysql-virtual_forwardings.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chgrp postfix /etc/postfix/mysql-virtual_mailboxes.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chgrp postfix /etc/postfix/mysql-virtual_email2email.cf'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chgrp postfix ' + main
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chgrp postfix ' + master
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
######################################## users and groups
command = 'groupadd -g 5000 vmail'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'useradd -g vmail -u 5000 vmail -d /home/vmail -m'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
######################################## Further configurations
# hostname = socket.gethostname()
################################### Restart postix
command = 'systemctl enable postfix.service'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'systemctl start postfix.service'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
######################################## Permissions
command = 'chgrp dovecot /etc/dovecot/dovecot-sql.conf.ext'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'chmod o= /etc/dovecot/dovecot-sql.conf.ext'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
################################### Restart davecot
command = 'systemctl enable dovecot.service'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'systemctl start dovecot.service'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'systemctl restart postfix.service'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
## chaging permissions for main.cf
command = "chmod 755 " + main
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
if self.distro == ubuntu:
command = "mkdir -p /etc/pki/dovecot/private/"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "mkdir -p /etc/pki/dovecot/certs/"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "mkdir -p /etc/opendkim/keys/"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "sed -i 's/auth_mechanisms = plain/#auth_mechanisms = plain/g' /etc/dovecot/conf.d/10-auth.conf"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
## 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()
command = "systemctl restart dovecot"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
logging.InstallLog.writeToFile("Postfix and Dovecot configured")
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setup_postfix_davecot_config]")
return 0
return 1
def downoad_and_install_raindloop(self):
try:
#######
if not os.path.exists("/usr/local/CyberCP/public"):
os.mkdir("/usr/local/CyberCP/public")
if os.path.exists("/usr/local/CyberCP/public/rainloop"):
return 0
os.chdir("/usr/local/CyberCP/public")
command = 'wget https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip'
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
#############
command = 'unzip rainloop-community-latest.zip -d /usr/local/CyberCP/public/rainloop'
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
os.remove("rainloop-community-latest.zip")
#######
os.chdir("/usr/local/CyberCP/public/rainloop")
command = 'find . -type d -exec chmod 755 {} \;'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
#############
command = 'find . -type f -exec chmod 644 {} \;'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
######
command = "mkdir -p /usr/local/lscp/cyberpanel/rainloop/data"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
### Enable sub-folders
command = "mkdir -p /usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/configs/"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
labsPath = '/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/configs/application.ini'
labsData = """[labs]
imap_folder_list_limit = 0
"""
writeToFile = open(labsPath, 'w')
writeToFile.write(labsData)
writeToFile.close()
iPath = os.listdir('/usr/local/CyberCP/public/rainloop/rainloop/v/')
path = "/usr/local/CyberCP/public/rainloop/rainloop/v/%s/include.php" % (iPath[0])
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()
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [downoad_and_install_rainloop]")
return 0
return 1
###################################################### Email setup ends!
def reStartLiteSpeed(self):
command = '%sbin/lswsctrl restart' % (self.server_root_path)
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def removeUfw(self):
try:
preFlightsChecks.stdOut("Checking to see if ufw firewall is installed (will be removed)", 1)
2019-12-15 13:30:40 +05:00
status = subprocess.check_output(shlex.split('ufw status')).decode("utf-8")
2019-12-12 13:54:25 +05:00
preFlightsChecks.stdOut("ufw current status: " + status + "...will be removed")
except BaseException as msg:
preFlightsChecks.stdOut("[ERROR] Expected access to ufw not available, do not need to remove it", 1)
return True
try:
preFlightsChecks.call('apt-get -y remove ufw', self.distro, '[remove_ufw]', 'Remove ufw firewall ' +
'(using firewalld)', 1, 0, os.EX_OSERR)
except:
pass
return True
def installFirewalld(self):
2019-12-18 14:08:24 +05:00
2019-12-12 13:54:25 +05:00
if self.distro == ubuntu:
self.removeUfw()
try:
preFlightsChecks.stdOut("Enabling Firewall!")
if self.distro == ubuntu:
command = 'apt-get -y install firewalld'
else:
command = 'yum -y install firewalld'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
######
2020-05-29 23:10:00 +05:00
if self.distro == centos:
2019-12-12 13:54:25 +05:00
# Not available in ubuntu
command = 'systemctl restart dbus'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'systemctl restart systemd-logind'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'systemctl start firewalld'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##########
command = 'systemctl enable firewalld'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
FirewallUtilities.addRule("tcp", "8090")
FirewallUtilities.addRule("tcp", "80")
FirewallUtilities.addRule("tcp", "443")
FirewallUtilities.addRule("tcp", "21")
FirewallUtilities.addRule("tcp", "25")
FirewallUtilities.addRule("tcp", "587")
FirewallUtilities.addRule("tcp", "465")
FirewallUtilities.addRule("tcp", "110")
FirewallUtilities.addRule("tcp", "143")
FirewallUtilities.addRule("tcp", "993")
2020-02-01 17:52:33 +05:00
FirewallUtilities.addRule("tcp", "995")
2019-12-12 13:54:25 +05:00
FirewallUtilities.addRule("udp", "53")
FirewallUtilities.addRule("tcp", "53")
FirewallUtilities.addRule("udp", "443")
FirewallUtilities.addRule("tcp", "40110-40210")
logging.InstallLog.writeToFile("FirewallD installed and configured!")
preFlightsChecks.stdOut("FirewallD installed and configured!")
except OSError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installFirewalld]")
return 0
except ValueError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installFirewalld]")
return 0
return 1
## from here
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:
2019-12-18 16:21:57 +05:00
command = 'yum -y install gcc gcc-c++ make autoconf glibc'
2019-12-12 13:54:25 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, 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:
2019-12-18 16:37:12 +05:00
command = 'yum -y install pcre-devel openssl-devel expat-devel geoip-devel zlib-devel udns-devel'
2019-12-12 13:54:25 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'tar zxf lscp.tar.gz -C /usr/local/'
2020-04-14 23:22:48 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
###
lscpdPath = '/usr/local/lscp/bin/lscpd'
command = 'cp -f /usr/local/CyberCP/lscpd-0.2.7 /usr/local/lscp/bin/lscpd-0.2.7'
2020-04-14 23:22:48 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = 'rm -f /usr/local/lscp/bin/lscpd'
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = 'mv /usr/local/lscp/bin/lscpd-0.2.7 /usr/local/lscp/bin/lscpd'
2020-04-14 23:22:48 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
command = 'chmod 755 %s' % (lscpdPath)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
##
2019-12-12 13:54:25 +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'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
try:
os.remove("/usr/local/lscp/fcgi-bin/lsphp")
2020-08-10 21:49:32 +02:00
shutil.copy("/usr/local/lsws/lsphp73/bin/lsphp", "/usr/local/lscp/fcgi-bin/lsphp")
2019-12-12 13:54:25 +05:00
except:
pass
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'adduser lscpd -M -d /usr/local/lscp'
else:
command = 'useradd lscpd -M -d /usr/local/lscp'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'groupadd lscpd'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
# Added group in useradd for Ubuntu
command = 'usermod -a -G lscpd lscpd'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'usermod -a -G lsadm lscpd'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
try:
os.mkdir('/usr/local/lscp/cyberpanel')
except:
pass
try:
os.mkdir('/usr/local/lscp/cyberpanel/logs')
except:
pass
# self.setupComodoRules()
logging.InstallLog.writeToFile("LSCPD successfully installed!")
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + 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, command, command, 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"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "tar -zxf comodo.tar.gz -C /usr/local/lscp/modsec"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
###
modsecConfPath = "/usr/local/lscp/conf/modsec.conf"
modsecConfig = """
module mod_security {
ls_enabled 0
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
SecRuleEngine Off
`
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, command, command, 1, 0, os.EX_OSERR)
return 1
except BaseException as msg:
logging.InstallLog.writeToFile("[ERROR]" + 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
def setupPythonWSGI(self):
try:
2020-05-11 22:27:13 +05:00
command = "wget http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.6.tgz"
2019-12-12 13:54:25 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-05-11 22:27:13 +05:00
command = "tar xf wsgi-lsapi-1.6.tgz"
2019-12-12 13:54:25 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-05-11 22:27:13 +05:00
os.chdir("wsgi-lsapi-1.6")
2019-12-12 13:54:25 +05:00
2019-12-13 11:05:18 +05:00
command = "/usr/local/CyberPanel/bin/python ./configure.py"
2019-12-12 13:54:25 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "make"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-12 14:26:54 +05:00
if not os.path.exists('/usr/local/CyberCP/bin/'):
os.mkdir('/usr/local/CyberCP/bin/')
2019-12-12 13:54:25 +05:00
command = "cp lswsgi /usr/local/CyberCP/bin/"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
os.chdir(self.cwd)
except:
return 0
def setupLSCPDDaemon(self):
try:
preFlightsChecks.stdOut("Trying to setup LSCPD Daemon!")
logging.InstallLog.writeToFile("Trying to setup LSCPD Daemon!")
os.chdir(self.cwd)
shutil.copy("lscpd/lscpd.service", "/etc/systemd/system/lscpd.service")
shutil.copy("lscpd/lscpdctrl", "/usr/local/lscp/bin/lscpdctrl")
##
command = 'chmod +x /usr/local/lscp/bin/lscpdctrl'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
path = "/usr/local/lscpd/admin/"
command = "mkdir -p " + path
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
path = "/usr/local/CyberCP/conf/"
command = "mkdir -p " + path
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
path = "/usr/local/CyberCP/conf/token_env"
writeToFile = open(path, "w")
writeToFile.write("abc\n")
writeToFile.close()
command = "chmod 600 " + path
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'systemctl enable lscpd.service'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
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'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = 'systemctl start lscpd'
#preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
preFlightsChecks.stdOut("LSCPD Daemon Set!")
logging.InstallLog.writeToFile("LSCPD Daemon Set!")
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setupLSCPDDaemon]")
return 0
return 1
def setup_cron(self):
try:
## first install crontab
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'yum install cronie -y'
else:
command = 'apt-get -y install cron'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'systemctl enable crond'
else:
command = 'systemctl enable cron'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'systemctl start crond'
else:
command = 'systemctl start cron'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
2020-02-29 08:12:03 +05:00
CentOSPath = '/etc/redhat-release'
2019-12-12 13:54:25 +05:00
2020-02-29 08:12:03 +05:00
if os.path.exists(CentOSPath):
cronPath = '/var/spool/cron/root'
else:
cronPath = '/var/spool/cron/crontabs/root'
2019-12-12 13:54:25 +05:00
2020-02-29 08:12:03 +05:00
cronFile = open(cronPath, "w")
2019-12-12 13:54:25 +05:00
2020-02-29 08:12:03 +05:00
content = """
0 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/findBWUsage.py >/dev/null 2>&1
0 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/postfixSenderPolicy/client.py hourlyCleanup >/dev/null 2>&1
0 0 1 * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/postfixSenderPolicy/client.py monthlyCleanup >/dev/null 2>&1
0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/upgradeCritical.py >/dev/null 2>&1
0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/renew.py >/dev/null 2>&1
7 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
2020-03-11 15:06:42 +05:00
0 12 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Daily
0 0 * * 0 /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Weekly
*/3 * * * * if ! find /home/*/public_html/ -maxdepth 2 -type f -newer /usr/local/lsws/cgid -name '.htaccess' -exec false {} +; then /usr/local/lsws/bin/lswsctrl restart; fi
2020-02-29 08:12:03 +05:00
"""
cronFile.write(content)
cronFile.close()
2019-12-12 13:54:25 +05:00
2020-03-25 12:00:32 +05:00
if not os.path.exists(CentOSPath):
command = 'chmod 600 %s' % (cronPath)
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'systemctl restart crond.service'
else:
command = 'systemctl restart cron.service'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setup_cron]")
return 0
def install_default_keys(self):
try:
path = "/root/.ssh"
if not os.path.exists(path):
os.mkdir(path)
command = "ssh-keygen -f /root/.ssh/cyberpanel -t rsa -N ''"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_default_keys]")
return 0
def install_rsync(self):
try:
2019-12-18 13:58:23 +05:00
if self.distro == centos or self.distro == cent8:
2019-12-12 13:54:25 +05:00
command = 'yum -y install rsync'
else:
command = 'apt-get -y install rsync'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_rsync]")
return 0
def test_Requests(self):
try:
import requests
getVersion = requests.get('https://cyberpanel.net/version.txt')
latest = getVersion.json()
except BaseException as msg:
command = "pip uninstall --yes urllib3"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "pip uninstall --yes requests"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "pip install http://mirror.cyberpanel.net/urllib3-1.22.tar.gz"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "pip install http://mirror.cyberpanel.net/requests-2.18.4.tar.gz"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def installation_successfull(self):
print("###################################################################")
print(" CyberPanel Successfully Installed ")
print(" ")
print(" ")
print(" ")
print((" Visit: https://" + self.ipAddr + ":8090 "))
print(" Username: admin ")
print(" Password: 1234567 ")
print("###################################################################")
def modSecPreReqs(self):
try:
pathToRemoveGarbageFile = os.path.join(self.server_root_path, "modules/mod_security.so")
os.remove(pathToRemoveGarbageFile)
except OSError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [modSecPreReqs]")
return 0
def installOpenDKIM(self):
try:
2020-04-13 00:58:56 +05:00
if self.distro == centos:
2019-12-12 13:54:25 +05:00
command = 'yum -y install opendkim'
2020-04-13 00:58:56 +05:00
elif self.distro == cent8:
2020-06-08 00:11:14 +05:00
command = 'dnf install opendkim -y'
2019-12-12 13:54:25 +05:00
else:
command = 'apt-get -y install opendkim'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
if self.distro == ubuntu:
2019-12-13 17:43:00 +05:00
command = 'apt install opendkim-tools -y'
2019-12-12 13:54:25 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'mkdir -p /etc/opendkim/keys/'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + 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
"""
writeToFile = open(openDKIMConfigurePath, 'a')
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
"""
writeToFile = open(postfixFilePath, 'a')
writeToFile.write(configData)
writeToFile.close()
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()
#### Restarting Postfix and OpenDKIM
command = "systemctl start opendkim"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "systemctl enable opendkim"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
##
command = "systemctl start postfix"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [configureOpenDKIM]")
return 0
return 1
def setupCLI(self):
command = "ln -s /usr/local/CyberCP/cli/cyberPanel.py /usr/bin/cyberpanel"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "chmod +x /usr/local/CyberCP/cli/cyberPanel.py"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def setupPHPAndComposer(self):
try:
if self.distro == ubuntu:
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):
os.symlink('/usr/local/lsws/lsphp70/bin/php7.0', '/usr/local/lsws/lsphp70/bin/php')
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):
os.symlink('/usr/local/lsws/lsphp71/bin/php7.1', '/usr/local/lsws/lsphp71/bin/php')
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):
os.symlink('/usr/local/lsws/lsphp72/bin/php7.2', '/usr/local/lsws/lsphp72/bin/php')
command = "cp /usr/local/lsws/lsphp71/bin/php /usr/bin/"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
os.chdir(self.cwd)
command = "chmod +x composer.sh"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = "./composer.sh"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setupPHPAndComposer]")
return 0
@staticmethod
def installOne(package):
res = subprocess.call(shlex.split('apt-get -y install ' + package))
if res != 0:
preFlightsChecks.stdOut("Error #" + str(res) + ' installing:' + package + '. This may not be an issue ' \
'but may affect installation of something later',
1)
return res # Though probably not used
@staticmethod
def enableDisableDNS(state):
try:
servicePath = '/home/cyberpanel/powerdns'
2020-01-03 14:39:22 +05:00
if state == 'off':
2019-12-12 13:54:25 +05:00
command = 'sudo systemctl stop pdns'
subprocess.call(shlex.split(command))
command = 'sudo systemctl disable pdns'
subprocess.call(shlex.split(command))
try:
os.remove(servicePath)
except:
pass
else:
writeToFile = open(servicePath, 'w+')
writeToFile.close()
except OSError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableDNS]")
return 0
@staticmethod
def enableDisableEmail(state):
try:
servicePath = '/home/cyberpanel/postfix'
2020-01-03 14:39:22 +05:00
if state == 'off':
2019-12-12 13:54:25 +05:00
command = 'sudo systemctl stop postfix'
subprocess.call(shlex.split(command))
command = 'sudo systemctl disable postfix'
subprocess.call(shlex.split(command))
try:
os.remove(servicePath)
except:
pass
else:
writeToFile = open(servicePath, 'w+')
writeToFile.close()
except OSError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]")
return 0
@staticmethod
def enableDisableFTP(state, distro):
try:
servicePath = '/home/cyberpanel/pureftpd'
2020-01-03 14:39:22 +05:00
if state == 'off':
2019-12-12 13:54:25 +05:00
command = 'sudo systemctl stop ' + preFlightsChecks.pureFTPDServiceName(distro)
subprocess.call(shlex.split(command))
command = 'sudo systemctl disable ' + preFlightsChecks.pureFTPDServiceName(distro)
subprocess.call(shlex.split(command))
try:
os.remove(servicePath)
except:
pass
else:
writeToFile = open(servicePath, 'w+')
writeToFile.close()
except OSError as msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]")
return 0
@staticmethod
def setUpFirstAccount():
try:
command = 'python /usr/local/CyberCP/plogical/adminPass.py --password 1234567'
subprocess.call(shlex.split(command))
except:
pass
def installRestic(self):
try:
CentOSPath = '/etc/redhat-release'
if os.path.exists(CentOSPath):
2020-04-13 00:58:56 +05:00
if self.distro == centos:
2020-09-08 20:25:21 +05:00
command = 'yum install restic -y'
2020-06-12 12:08:15 +05:00
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
elif self.distro == cent8:
command = 'cat /proc/cpuinfo'
result = subprocess.check_output(shlex.split(command)).decode("utf-8")
if result.find('ARM') > -1 or result.find('arm') > -1:
command = 'wget -O /usr/bin/restic https://rep.cyberpanel.net/restic_0.9.6_linux_arm64'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
else:
command = 'wget -O /usr/bin/restic https://rep.cyberpanel.net/restic_0.9.6_linux_amd64'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'chmod +x /usr/bin/restic'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-04-13 00:58:56 +05:00
2019-12-12 13:54:25 +05:00
else:
command = 'apt-get update -y'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'apt-get install restic -y'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except:
pass
2019-12-28 18:01:12 +05:00
def installCLScripts(self):
try:
CentOSPath = '/etc/redhat-release'
if os.path.exists(CentOSPath):
command = 'mkdir -p /opt/cpvendor/etc/'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
content = """[integration_scripts]
panel_info = /usr/local/CyberCP/CLScript/panel_info.py
packages = /usr/local/CyberCP/CLScript/CloudLinuxPackages.py
users = /usr/local/CyberCP/CLScript/CloudLinuxUsers.py
domains = /usr/local/CyberCP/CLScript/CloudLinuxDomains.py
resellers = /usr/local/CyberCP/CLScript/CloudLinuxResellers.py
admins = /usr/local/CyberCP/CLScript/CloudLinuxAdmins.py
2019-12-31 19:55:29 +05:00
db_info = /usr/local/CyberCP/CLScript/CloudLinuxDB.py
2019-12-28 18:01:12 +05:00
[lvemanager_config]
2019-12-31 19:55:29 +05:00
ui_user_info =/usr/local/CyberCP/CLScript/UserInfo.py
base_path = /usr/local/lvemanager
2019-12-28 18:01:12 +05:00
run_service = 1
service_port = 9000
"""
writeToFile = open('/opt/cpvendor/etc/integration.ini', 'w')
writeToFile.write(content)
writeToFile.close()
2020-01-29 17:27:43 +05:00
command = 'mkdir -p /etc/cagefs/exclude'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
content = """cyberpanel
docker
ftpuser
lscpd
opendkim
pdns
vmail
"""
writeToFile = open('/etc/cagefs/exclude/cyberpanelexclude', 'w')
writeToFile.write(content)
writeToFile.close()
2019-12-28 18:01:12 +05:00
except:
pass
2019-12-12 13:54:25 +05:00
def installAcme(self):
command = 'wget -O - https://get.acme.sh | sh'
subprocess.call(command, shell=True)
command = '/root/.acme.sh/acme.sh --upgrade --auto-upgrade'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-01-11 18:31:18 +05:00
def installRedis(self):
if self.distro == ubuntu:
command = 'apt install redis-server -y'
elif self.distro == centos:
command = 'yum install redis -y'
else:
command = 'dnf install redis -y'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
2020-01-11 19:27:49 +05:00
## install redis conf
redisConf = '/usr/local/lsws/conf/dvhost_redis.conf'
writeToFile = open(redisConf, 'w')
writeToFile.write('127.0.0.1,6379,<auth_password>\n')
writeToFile.close()
2020-03-02 11:26:06 +05:00
##
os.chdir(self.cwd)
2020-01-11 19:27:49 +05:00
confPath = '/usr/local/lsws/conf/'
if os.path.exists('%shttpd.conf' % (confPath)):
os.remove('%shttpd.conf' % (confPath))
2020-03-02 11:49:29 +05:00
shutil.copy('litespeed/httpd-redis.conf', '%shttpd.conf' % (confPath))
2020-01-11 19:27:49 +05:00
## start and enable
2020-01-11 18:31:18 +05:00
command = 'systemctl start redis'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'systemctl enable redis'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def disablePackegeUpdates(self):
if self.distro == centos:
mainConfFile = '/etc/yum.conf'
content = 'exclude=MariaDB-client MariaDB-common MariaDB-devel MariaDB-server MariaDB-shared ' \
'pdns pdns-backend-mysql dovecot dovecot-mysql postfix3 postfix3-ldap postfix3-mysql ' \
'postfix3-pcre restic opendkim libopendkim pure-ftpd ftp\n'
writeToFile = open(mainConfFile, 'a')
writeToFile.write(content)
writeToFile.close()
2019-12-12 13:54:25 +05:00
def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer')
parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.')
parser.add_argument('--mysql', help='Specify number of MySQL instances to be used.')
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.')
parser.add_argument('--ent', help='Install LS Ent or OpenLiteSpeed')
parser.add_argument('--serial', help='Install LS Ent or OpenLiteSpeed')
parser.add_argument('--port', help='LSCPD Port')
2020-01-11 18:31:18 +05:00
parser.add_argument('--redis', help='vHosts on Redis - Requires LiteSpeed Enterprise')
2020-06-26 18:22:20 +05:00
parser.add_argument('--remotemysql', help='Opt to choose local or remote MySQL')
parser.add_argument('--mysqlhost', help='MySQL host if remote is chosen.')
2020-07-05 14:39:57 +05:00
parser.add_argument('--mysqldb', help='MySQL DB if remote is chosen.')
2020-06-26 18:22:20 +05:00
parser.add_argument('--mysqluser', help='MySQL user if remote is chosen.')
parser.add_argument('--mysqlpassword', help='MySQL password if remote is chosen.')
parser.add_argument('--mysqlport', help='MySQL port if remote is chosen.')
2019-12-12 13:54:25 +05:00
args = parser.parse_args()
logging.InstallLog.writeToFile("Starting CyberPanel installation..")
preFlightsChecks.stdOut("Starting CyberPanel installation..")
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)
## Writing public IP
try:
os.mkdir("/etc/cyberpanel")
except:
pass
machineIP = open("/etc/cyberpanel/machineIP", "w")
machineIP.writelines(args.publicip)
machineIP.close()
cwd = os.getcwd()
2020-06-26 18:44:32 +05:00
if args.remotemysql == 'ON':
2020-06-26 18:22:20 +05:00
remotemysql = args.remotemysql
mysqlhost = args.mysqlhost
mysqluser = args.mysqluser
mysqlpassword = args.mysqlpassword
mysqlport = args.mysqlport
2020-07-05 14:39:57 +05:00
mysqldb = args.mysqldb
2020-07-05 13:26:46 +05:00
if preFlightsChecks.debug:
2020-07-05 14:39:57 +05:00
print('mysqlhost: %s, mysqldb: %s, mysqluser: %s, mysqlpassword: %s, mysqlport: %s' % (mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport))
2020-07-05 13:26:46 +05:00
time.sleep(10)
2020-06-26 18:22:20 +05:00
else:
remotemysql = args.remotemysql
mysqlhost = ''
mysqluser = ''
mysqlpassword = ''
mysqlport = ''
2020-07-05 14:39:57 +05:00
mysqldb = ''
2020-06-26 18:22:20 +05:00
2019-12-12 13:54:25 +05:00
distro = get_distro()
2020-07-05 14:39:57 +05:00
checks = preFlightsChecks("/usr/local/lsws/", args.publicip, "/usr/local", cwd, "/usr/local/CyberCP", distro, remotemysql, mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport)
2019-12-12 13:54:25 +05:00
checks.mountTemp()
if args.port == None:
port = "8090"
else:
port = args.port
if args.mysql == None:
mysql = 'One'
preFlightsChecks.stdOut("Single MySQL instance version will be installed.")
else:
mysql = args.mysql
preFlightsChecks.stdOut("Dobule MySQL instance version will be installed.")
checks.checkPythonVersion()
checks.setup_account_cyberpanel()
checks.installCyberPanelRepo()
import installCyberPanel
2020-06-26 18:22:20 +05:00
2019-12-12 13:54:25 +05:00
if ent == 0:
2020-07-05 14:39:57 +05:00
installCyberPanel.Main(cwd, mysql, distro, ent, None, port, args.ftp, args.powerdns, args.publicip, remotemysql, mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport)
2019-12-12 13:54:25 +05:00
else:
2020-07-05 14:39:57 +05:00
installCyberPanel.Main(cwd, mysql, distro, ent, serial, port, args.ftp, args.powerdns, args.publicip, remotemysql, mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport)
2019-12-12 13:54:25 +05:00
checks.setupPHPAndComposer()
checks.fix_selinux_issue()
checks.install_psmisc()
if args.postfix == None:
checks.install_postfix_davecot()
checks.setup_email_Passwords(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql)
checks.setup_postfix_davecot_config(mysql)
else:
2020-01-03 14:45:37 +05:00
if args.postfix == 'ON':
2019-12-12 13:54:25 +05:00
checks.install_postfix_davecot()
checks.setup_email_Passwords(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql)
checks.setup_postfix_davecot_config(mysql)
checks.install_unzip()
checks.install_zip()
checks.install_rsync()
checks.installFirewalld()
checks.install_default_keys()
checks.download_install_CyberPanel(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql)
checks.downoad_and_install_raindloop()
checks.download_install_phpmyadmin()
checks.setupCLI()
checks.setup_cron()
checks.installRestic()
checks.installAcme()
## Install and Configure OpenDKIM.
if args.postfix == None:
checks.installOpenDKIM()
checks.configureOpenDKIM()
else:
2020-01-03 14:45:37 +05:00
if args.postfix == 'ON':
2019-12-12 13:54:25 +05:00
checks.installOpenDKIM()
checks.configureOpenDKIM()
checks.modSecPreReqs()
checks.installLSCPD()
2019-12-18 16:37:12 +05:00
checks.setupPort()
checks.setupPythonWSGI()
2019-12-12 13:54:25 +05:00
checks.setupLSCPDDaemon()
2020-03-04 17:44:56 +05:00
if args.redis != None:
checks.installRedis()
2019-12-12 13:54:25 +05:00
checks.fixCyberPanelPermissions()
if args.postfix != None:
2020-01-03 14:39:22 +05:00
checks.enableDisableEmail(args.postfix.lower())
2019-12-12 13:54:25 +05:00
else:
preFlightsChecks.stdOut("Postfix will be installed and enabled.")
2020-01-03 14:39:22 +05:00
checks.enableDisableEmail('on')
2019-12-12 13:54:25 +05:00
if args.powerdns != None:
2020-01-03 14:39:22 +05:00
checks.enableDisableDNS(args.powerdns.lower())
2019-12-12 13:54:25 +05:00
else:
preFlightsChecks.stdOut("PowerDNS will be installed and enabled.")
2020-01-03 14:39:22 +05:00
checks.enableDisableDNS('on')
2019-12-12 13:54:25 +05:00
if args.ftp != None:
2020-01-03 14:39:22 +05:00
checks.enableDisableFTP(args.ftp.lower(), distro)
2019-12-12 13:54:25 +05:00
else:
preFlightsChecks.stdOut("Pure-FTPD will be installed and enabled.")
2020-01-03 14:39:22 +05:00
checks.enableDisableFTP('on', distro)
2019-12-28 18:01:12 +05:00
checks.installCLScripts()
2020-04-24 09:58:35 +05:00
#checks.disablePackegeUpdates()
2019-12-12 13:54:25 +05:00
logging.InstallLog.writeToFile("CyberPanel installation successfully completed!")
if __name__ == "__main__":
main()