Files
CyberPanel/plogical/applicationInstaller.py

1061 lines
40 KiB
Python
Raw Normal View History

2019-12-10 23:04:24 +05:00
#!/usr/local/CyberCP/bin/python
2019-11-07 09:37:06 +05:00
import os, sys
sys.path.append('/usr/local/CyberCP')
import django
2019-11-07 09:37:06 +05:00
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
django.setup()
import threading as multi
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
import subprocess
2019-12-11 10:40:35 +05:00
from .vhost import vhost
from websiteFunctions.models import ChildDomains, Websites
2019-12-12 08:46:07 +05:00
import randomPassword
2019-12-11 10:40:35 +05:00
from .mysqlUtilities import mysqlUtilities
from databases.models import Databases
2019-12-11 10:40:35 +05:00
from .installUtilities import installUtilities
import shutil
2018-07-26 23:13:02 +05:00
from plogical.mailUtilities import mailUtilities
2019-03-26 16:19:03 +05:00
from plogical.processUtilities import ProcessUtilities
2019-11-07 09:37:06 +05:00
class ApplicationInstaller(multi.Thread):
def __init__(self, installApp, extraArgs):
multi.Thread.__init__(self)
self.installApp = installApp
self.extraArgs = extraArgs
def run(self):
try:
if self.installApp == 'wordpress':
self.installWordPress()
2018-07-13 21:45:40 +05:00
elif self.installApp == 'joomla':
self.installJoomla()
2018-07-26 04:11:10 +05:00
elif self.installApp == 'git':
self.setupGit()
2018-07-26 23:13:02 +05:00
elif self.installApp == 'pull':
self.gitPull()
2018-07-28 01:25:51 +05:00
elif self.installApp == 'detach':
self.detachRepo()
elif self.installApp == 'changeBranch':
self.changeBranch()
2018-08-05 01:46:31 +05:00
elif self.installApp == 'prestashop':
self.installPrestaShop()
2019-11-07 09:37:06 +05:00
elif self.installApp == 'magento':
self.installMagento()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-11-07 09:37:06 +05:00
logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]')
def installWPCLI(self):
try:
command = 'sudo wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar'
2019-03-26 16:19:03 +05:00
ProcessUtilities.executioner(command)
command = 'sudo chmod +x wp-cli.phar'
2019-03-26 16:19:03 +05:00
ProcessUtilities.executioner(command)
command = 'sudo mv wp-cli.phar /usr/bin/wp'
2019-03-26 16:19:03 +05:00
ProcessUtilities.executioner(command)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-11-07 09:37:06 +05:00
logging.writeToFile(str(msg) + ' [ApplicationInstaller.installWPCLI]')
2018-11-10 16:05:40 +05:00
def dataLossCheck(self, finalPath, tempStatusPath):
dirFiles = os.listdir(finalPath)
if len(dirFiles) == 1:
if dirFiles[0] == ".well-known" or dirFiles[0] == 'index.html':
return 1
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Target directory should be empty before installation, otherwise data loss could occur." + " [404]")
statusFile.close()
return 0
elif len(dirFiles) == 2:
if ".well-known" in dirFiles and "index.html" in dirFiles:
return 1
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Target directory should be empty before installation, otherwise data loss could occur." + " [404]")
statusFile.close()
return 0
elif len(dirFiles) == 0:
return 1
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Target directory should be empty before installation, otherwise data loss could occur." + " [404]")
statusFile.close()
return 0
2018-07-26 23:13:02 +05:00
def installGit(self):
2018-07-26 04:11:10 +05:00
try:
2018-11-08 12:11:42 +05:00
if os.path.exists("/etc/lsb-release"):
command = 'apt -y install git'
2019-03-26 16:19:03 +05:00
ProcessUtilities.executioner(command)
2018-11-08 12:11:42 +05:00
else:
command = 'sudo yum -y install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm'
2019-03-26 16:19:03 +05:00
ProcessUtilities.executioner(command)
2018-11-08 12:11:42 +05:00
command = 'sudo yum install git -y'
2019-03-26 16:19:03 +05:00
ProcessUtilities.executioner(command)
2018-07-26 04:11:10 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-11-07 09:37:06 +05:00
logging.writeToFile(str(msg) + ' [ApplicationInstaller.installGit]')
2018-07-26 04:11:10 +05:00
2018-08-21 13:10:40 +05:00
def dbCreation(self, tempStatusPath, website):
try:
dbName = randomPassword.generate_pass()
dbUser = dbName
dbPassword = randomPassword.generate_pass()
## DB Creation
if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter(
dbUser=dbUser).exists():
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"This database or user is already taken." + " [404]")
statusFile.close()
return 0
result = mysqlUtilities.createDatabase(dbName, dbUser, dbPassword)
if result == 1:
pass
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Not able to create database." + " [404]")
statusFile.close()
return 0
db = Databases(website=website, dbName=dbName, dbUser=dbUser)
db.save()
return dbName, dbUser, dbPassword
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-08-21 13:10:40 +05:00
logging.writeToFile(str(msg) + '[ApplicationInstallerdbCreation]')
def installWordPress(self):
try:
admin = self.extraArgs['admin']
domainName = self.extraArgs['domainName']
home = self.extraArgs['home']
tempStatusPath = self.extraArgs['tempStatusPath']
blogTitle = self.extraArgs['blogTitle']
adminUser = self.extraArgs['adminUser']
adminPassword = self.extraArgs['adminPassword']
adminEmail = self.extraArgs['adminEmail']
2018-08-21 13:10:40 +05:00
FNULL = open(os.devnull, 'w')
### Check WP CLI
try:
command = 'sudo wp --info'
2019-04-01 15:19:54 +05:00
outout = ProcessUtilities.outputExecutioner(command)
2019-04-01 15:19:54 +05:00
if not outout.find('WP-CLI root dir:') > -1:
self.installWPCLI()
except subprocess.CalledProcessError:
self.installWPCLI()
## Open Status File
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up paths,0')
statusFile.close()
2018-08-21 13:10:40 +05:00
finalPath = ''
try:
website = ChildDomains.objects.get(domain=domainName)
externalApp = website.master.externalApp
2018-08-21 13:10:40 +05:00
if home == '0':
path = self.extraArgs['path']
finalPath = website.path.rstrip('/') + "/" + path + "/"
else:
finalPath = website.path
if website.master.package.dataBases > website.master.databases_set.all().count():
pass
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Maximum database limit reached for this website." + " [404]")
statusFile.close()
return 0
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up Database,20')
statusFile.close()
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master)
except:
website = Websites.objects.get(domain=domainName)
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
if home == '0':
path = self.extraArgs['path']
finalPath = "/home/" + domainName + "/public_html/" + path + "/"
else:
finalPath = "/home/" + domainName + "/public_html/"
2018-08-21 13:10:40 +05:00
if website.package.dataBases > website.databases_set.all().count():
pass
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
2019-11-07 09:37:06 +05:00
"Maximum database limit reached for this website." + " [404]")
2018-08-21 13:10:40 +05:00
statusFile.close()
return 0
2018-08-21 13:10:40 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up Database,20')
statusFile.close()
2018-08-21 13:10:40 +05:00
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website)
## Security Check
if finalPath.find("..") > -1:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Specified path must be inside virtual host home." + " [404]")
statusFile.close()
return 0
if not os.path.exists(finalPath):
2019-11-24 12:14:18 +05:00
command = 'mkdir -p ' + finalPath
ProcessUtilities.executioner(command, externalApp)
## checking for directories/files
2018-11-10 16:05:40 +05:00
if self.dataLossCheck(finalPath, tempStatusPath) == 0:
return 0
####
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Downloading WordPress Core,30')
statusFile.close()
2019-11-24 12:14:18 +05:00
command = "wp core download --allow-root --path=" + finalPath
ProcessUtilities.executioner(command, externalApp)
##
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Configuring the installation,40')
statusFile.close()
2019-11-24 12:14:18 +05:00
command = "wp core config --dbname=" + dbName + " --dbuser=" + dbUser + " --dbpass=" + dbPassword + " --dbhost=localhost --dbprefix=wp_ --allow-root --path=" + finalPath
ProcessUtilities.executioner(command, externalApp)
if home == '0':
path = self.extraArgs['path']
finalURL = domainName + '/' + path
else:
finalURL = domainName
2019-11-24 12:14:18 +05:00
command = 'wp core install --url="http://' + finalURL + '" --title="' + blogTitle + '" --admin_user="' + adminUser + '" --admin_password="' + adminPassword + '" --admin_email="' + adminEmail + '" --allow-root --path=' + finalPath
ProcessUtilities.executioner(command, externalApp)
##
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Installing LSCache Plugin,80')
statusFile.close()
2019-11-24 12:14:18 +05:00
command = "wp plugin install litespeed-cache --allow-root --path=" + finalPath
ProcessUtilities.executioner(command, externalApp)
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Activating LSCache Plugin,90')
statusFile.close()
2019-11-24 12:14:18 +05:00
command = "wp plugin activate litespeed-cache --allow-root --path=" + finalPath
ProcessUtilities.executioner(command, externalApp)
##
2019-11-24 12:14:18 +05:00
command = "chown -R " + externalApp + ":" + externalApp + " " + finalPath
ProcessUtilities.executioner(command, externalApp)
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Successfully Installed. [200]")
statusFile.close()
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-08-05 01:46:31 +05:00
# remove the downloaded files
2018-08-21 13:10:40 +05:00
FNULL = open(os.devnull, 'w')
2018-08-05 01:46:31 +05:00
homeDir = "/home/" + domainName + "/public_html"
if not os.path.exists(homeDir):
2019-11-24 12:14:18 +05:00
command = "chown -R " + externalApp + ":" + externalApp + " " + homeDir
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
try:
mysqlUtilities.deleteDatabase(dbName, dbUser)
db = Databases.objects.get(dbName=dbName)
db.delete()
except:
pass
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(str(msg) + " [404]")
statusFile.close()
return 0
def installPrestaShop(self):
try:
admin = self.extraArgs['admin']
domainName = self.extraArgs['domainName']
home = self.extraArgs['home']
shopName = self.extraArgs['shopName']
firstName = self.extraArgs['firstName']
lastName = self.extraArgs['lastName']
databasePrefix = self.extraArgs['databasePrefix']
email = self.extraArgs['email']
password = self.extraArgs['password']
tempStatusPath = self.extraArgs['tempStatusPath']
2018-08-21 13:10:40 +05:00
FNULL = open(os.devnull, 'w')
2018-08-05 01:46:31 +05:00
## Open Status File
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up paths,0')
statusFile.close()
2018-08-21 13:10:40 +05:00
finalPath = ''
2018-08-05 01:46:31 +05:00
try:
website = ChildDomains.objects.get(domain=domainName)
externalApp = website.master.externalApp
2018-08-21 13:10:40 +05:00
if home == '0':
path = self.extraArgs['path']
finalPath = website.path.rstrip('/') + "/" + path + "/"
else:
finalPath = website.path + "/"
if website.master.package.dataBases > website.master.databases_set.all().count():
pass
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Maximum database limit reached for this website." + " [404]")
statusFile.close()
return 0
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up Database,20')
statusFile.close()
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master)
2018-08-05 01:46:31 +05:00
except:
website = Websites.objects.get(domain=domainName)
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
if home == '0':
path = self.extraArgs['path']
finalPath = "/home/" + domainName + "/public_html/" + path + "/"
else:
finalPath = "/home/" + domainName + "/public_html/"
2018-08-05 01:46:31 +05:00
2018-08-21 13:10:40 +05:00
if website.package.dataBases > website.databases_set.all().count():
pass
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
2019-11-07 09:37:06 +05:00
"Maximum database limit reached for this website." + " [404]")
2018-08-21 13:10:40 +05:00
statusFile.close()
return 0
2018-08-05 01:46:31 +05:00
2018-08-21 13:10:40 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up Database,20')
statusFile.close()
2018-08-05 01:46:31 +05:00
2018-08-21 13:10:40 +05:00
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website)
2018-08-05 01:46:31 +05:00
## Security Check
if finalPath.find("..") > -1:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Specified path must be inside virtual host home." + " [404]")
statusFile.close()
return 0
if not os.path.exists(finalPath):
command = 'sudo mkdir -p ' + finalPath
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
## checking for directories/files
2018-11-10 16:05:40 +05:00
if self.dataLossCheck(finalPath, tempStatusPath) == 0:
2018-08-05 01:46:31 +05:00
return 0
####
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Downloading and extracting PrestaShop Core..,30')
statusFile.close()
2019-11-07 09:37:06 +05:00
command = "sudo wget https://download.prestashop.com/download/releases/prestashop_1.7.4.2.zip -P %s" % (
finalPath)
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
command = "sudo unzip -o %sprestashop_1.7.4.2.zip -d " % (finalPath) + finalPath
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
command = "sudo unzip -o %sprestashop.zip -d " % (finalPath) + finalPath
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
##
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Configuring the installation,40')
statusFile.close()
if home == '0':
path = self.extraArgs['path']
2019-11-07 09:37:06 +05:00
# finalURL = domainName + '/' + path
finalURL = domainName
2018-08-05 01:46:31 +05:00
else:
finalURL = domainName
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Installing and configuring PrestaShop..,60')
statusFile.close()
command = "sudo php " + finalPath + "install/index_cli.php --domain=" + finalURL + \
" --db_server=localhost --db_name=" + dbName + " --db_user=" + dbUser + " --db_password=" + dbPassword \
+ " --name='" + shopName + "' --firstname=" + firstName + " --lastname=" + lastName + \
" --email=" + email + " --password=" + password
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
##
2018-08-21 13:10:40 +05:00
command = "sudo rm -rf " + finalPath + "install"
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
##
2018-08-21 13:10:40 +05:00
command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
command = "sudo rm -f prestashop_1.7.4.2.zip"
ProcessUtilities.executioner(command, externalApp)
2018-08-05 01:46:31 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Successfully Installed. [200]")
statusFile.close()
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
# remove the downloaded files
homeDir = "/home/" + domainName + "/public_html"
if not os.path.exists(homeDir):
command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir
ProcessUtilities.executioner(command, externalApp)
try:
mysqlUtilities.deleteDatabase(dbName, dbUser)
db = Databases.objects.get(dbName=dbName)
db.delete()
except:
pass
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(str(msg) + " [404]")
statusFile.close()
return 0
2018-07-13 21:45:40 +05:00
2018-07-26 04:11:10 +05:00
def setupGit(self):
try:
admin = self.extraArgs['admin']
domainName = self.extraArgs['domainName']
username = self.extraArgs['username']
reponame = self.extraArgs['reponame']
branch = self.extraArgs['branch']
tempStatusPath = self.extraArgs['tempStatusPath']
2018-07-27 04:13:10 +05:00
defaultProvider = self.extraArgs['defaultProvider']
2018-07-26 04:11:10 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Checking if GIT installed..,0')
statusFile.close()
### Check git
try:
2018-07-26 23:13:02 +05:00
command = 'sudo git --help'
2019-04-15 15:54:23 +05:00
output = ProcessUtilities.outputExecutioner(command)
2018-07-26 04:11:10 +05:00
2019-04-15 15:54:23 +05:00
if output.find('command not found') > -1:
2018-07-26 04:11:10 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Installing GIT..,0')
statusFile.close()
2018-07-26 23:13:02 +05:00
self.installGit()
2018-07-26 04:11:10 +05:00
statusFile = open(tempStatusPath, 'w')
2018-07-26 23:13:02 +05:00
statusFile.writelines('GIT successfully installed,20')
2018-07-26 04:11:10 +05:00
statusFile.close()
except subprocess.CalledProcessError:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Installing GIT..,0')
statusFile.close()
2018-07-26 23:13:02 +05:00
self.installGit()
2018-07-26 04:11:10 +05:00
statusFile = open(tempStatusPath, 'w')
2018-07-26 23:13:02 +05:00
statusFile.writelines('GIT successfully installed.,20')
2018-07-26 04:11:10 +05:00
statusFile.close()
## Open Status File
statusFile = open(tempStatusPath, 'w')
2018-07-26 23:13:02 +05:00
statusFile.writelines('Setting up directories..,20')
2018-07-26 04:11:10 +05:00
statusFile.close()
try:
website = ChildDomains.objects.get(domain=domainName)
externalApp = website.master.externalApp
2018-08-21 13:10:40 +05:00
finalPath = website.path
2018-07-26 04:11:10 +05:00
except:
website = Websites.objects.get(domain=domainName)
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
finalPath = "/home/" + domainName + "/public_html/"
2018-07-26 04:11:10 +05:00
## Security Check
if finalPath.find("..") > -1:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Specified path must be inside virtual host home." + " [404]")
statusFile.close()
return 0
command = 'sudo mkdir -p ' + finalPath
ProcessUtilities.executioner(command, externalApp)
2018-07-26 04:11:10 +05:00
## checking for directories/files
2018-11-10 16:05:40 +05:00
if self.dataLossCheck(finalPath, tempStatusPath) == 0:
2018-07-26 04:11:10 +05:00
return 0
####
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Cloning the repo..,40')
statusFile.close()
try:
2019-11-07 09:37:06 +05:00
command = 'git clone --depth 1 --no-single-branch git@' + defaultProvider + '.com:' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath
ProcessUtilities.executioner(command, externalApp)
2019-12-10 15:09:10 +05:00
except subprocess.CalledProcessError as msg:
2018-07-26 04:11:10 +05:00
statusFile = open(tempStatusPath, 'w')
2019-11-07 09:37:06 +05:00
statusFile.writelines(
'Failed to clone repository, make sure you deployed your key to repository. [404]')
2018-07-26 04:11:10 +05:00
statusFile.close()
return 0
##
command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath
ProcessUtilities.executioner(command, externalApp)
2018-07-26 04:11:10 +05:00
vhost.addRewriteRules(domainName)
installUtilities.reStartLiteSpeed()
2018-07-26 23:13:02 +05:00
mailUtilities.checkHome()
gitPath = '/home/cyberpanel/' + domainName + '.git'
writeToFile = open(gitPath, 'w')
writeToFile.write(username + ':' + reponame)
writeToFile.close()
2018-07-26 04:11:10 +05:00
statusFile = open(tempStatusPath, 'w')
2018-07-26 23:13:02 +05:00
statusFile.writelines("GIT Repository successfully attached. [200]")
2018-07-26 04:11:10 +05:00
statusFile.close()
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-07-26 23:13:02 +05:00
os.remove('/home/cyberpanel/' + domainName + '.git')
2018-07-26 04:11:10 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(str(msg) + " [404]")
statusFile.close()
return 0
2018-07-26 23:13:02 +05:00
def gitPull(self):
try:
domain = self.extraArgs['domain']
2018-08-21 13:10:40 +05:00
try:
website = Websites.objects.get(domain=domain)
finalPath = "/home/" + domain + "/public_html/"
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
except:
childDomain = ChildDomains.objects.get(domain=domain)
finalPath = childDomain.path
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
2018-07-29 01:20:46 +05:00
path = '/home/cyberpanel/' + domain + '.git'
if not os.path.exists(path):
logging.writeToFile('Git is not setup for this website.')
return 0
2019-11-07 09:37:06 +05:00
command = 'sudo git --git-dir=' + finalPath + '.git --work-tree=' + finalPath + ' pull'
ProcessUtilities.executioner(command, externalApp)
2018-07-26 23:13:02 +05:00
2018-11-12 18:39:04 +05:00
##
2018-07-26 23:13:02 +05:00
website = Websites.objects.get(domain=domain)
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath
ProcessUtilities.executioner(command, externalApp)
2018-07-26 23:13:02 +05:00
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-11-07 09:37:06 +05:00
logging.writeToFile(str(msg) + " [ApplicationInstaller.gitPull]")
2018-07-26 23:13:02 +05:00
return 0
2018-07-26 04:11:10 +05:00
2018-07-28 01:25:51 +05:00
def detachRepo(self):
try:
domain = self.extraArgs['domainName']
2018-07-29 01:20:46 +05:00
admin = self.extraArgs['admin']
try:
website = ChildDomains.objects.get(domain=domain)
externalApp = website.master.externalApp
except:
website = Websites.objects.get(domain=domain)
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
try:
website = Websites.objects.get(domain=domain)
finalPath = "/home/" + domain + "/public_html/"
except:
childDomain = ChildDomains.objects.get(domain=domain)
finalPath = childDomain.path
2018-07-29 01:20:46 +05:00
2018-08-21 13:10:40 +05:00
command = 'sudo rm -rf ' + finalPath
ProcessUtilities.executioner(command, website.externalApp)
2018-07-28 01:25:51 +05:00
2018-08-21 13:10:40 +05:00
command = 'sudo mkdir ' + finalPath
ProcessUtilities.executioner(command, website.externalApp)
2018-07-28 01:25:51 +05:00
##
2018-08-21 13:10:40 +05:00
command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath
ProcessUtilities.executioner(command, website.externalApp)
2018-07-28 01:25:51 +05:00
gitPath = '/home/cyberpanel/' + domain + '.git'
os.remove(gitPath)
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-11-07 09:37:06 +05:00
logging.writeToFile(str(msg) + " [ApplicationInstaller.gitPull]")
2018-07-28 01:25:51 +05:00
return 0
2018-07-13 21:45:40 +05:00
def installJoomla(self):
try:
domainName = self.extraArgs['domainName']
finalPath = self.extraArgs['finalPath']
virtualHostUser = self.extraArgs['virtualHostUser']
dbName = self.extraArgs['dbName']
dbUser = self.extraArgs['dbUser']
dbPassword = self.extraArgs['dbPassword']
username = self.extraArgs['username']
password = self.extraArgs['password']
prefix = self.extraArgs['prefix']
sitename = self.extraArgs['sitename']
tempStatusPath = self.extraArgs['tempStatusPath']
FNULL = open(os.devnull, 'w')
if not os.path.exists(finalPath):
os.makedirs(finalPath)
## checking for directories/files
2018-11-10 16:05:40 +05:00
if self.dataLossCheck(finalPath, tempStatusPath) == 0:
2018-07-13 21:45:40 +05:00
return 0
## Get Joomla
os.chdir(finalPath)
if not os.path.exists("staging.zip"):
command = 'wget --no-check-certificate https://github.com/joomla/joomla-cms/archive/staging.zip -P ' + finalPath
2019-11-24 12:14:18 +05:00
ProcessUtilities.executioner(command, virtualHostUser)
2018-07-13 21:45:40 +05:00
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("File already exists." + " [404]")
statusFile.close()
return 0
command = 'unzip ' + finalPath + 'staging.zip -d ' + finalPath
2019-11-24 12:14:18 +05:00
ProcessUtilities.executioner(command, virtualHostUser)
2018-07-13 21:45:40 +05:00
2019-11-24 12:14:18 +05:00
command = 'rm -f %s' % (finalPath + 'staging.zip')
ProcessUtilities.executioner(command, virtualHostUser)
2018-07-13 21:45:40 +05:00
command = 'cp -r ' + finalPath + 'joomla-cms-staging/. ' + finalPath
2019-11-24 12:14:18 +05:00
ProcessUtilities.executioner(command, virtualHostUser)
command = 'chown -R cyberpanel:cyberpanel %s' % (finalPath)
ProcessUtilities.executioner(command)
2018-07-13 21:45:40 +05:00
shutil.rmtree(finalPath + "joomla-cms-staging")
os.rename(finalPath + "installation/configuration.php-dist", finalPath + "configuration.php")
os.rename(finalPath + "robots.txt.dist", finalPath + "robots.txt")
os.rename(finalPath + "htaccess.txt", finalPath + ".htaccess")
## edit config file
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Creating configuration files.,40')
statusFile.close()
configfile = finalPath + "configuration.php"
data = open(configfile, "r").readlines()
writeDataToFile = open(configfile, "w")
secret = randomPassword.generate_pass()
defDBName = " public $user = '" + dbName + "';" + "\n"
defDBUser = " public $db = '" + dbUser + "';" + "\n"
defDBPassword = " public $password = '" + dbPassword + "';" + "\n"
secretKey = " public $secret = '" + secret + "';" + "\n"
logPath = " public $log_path = '" + finalPath + "administrator/logs';" + "\n"
tmpPath = " public $tmp_path = '" + finalPath + "administrator/tmp';" + "\n"
dbprefix = " public $dbprefix = '" + prefix + "';" + "\n"
sitename = " public $sitename = '" + sitename + "';" + "\n"
for items in data:
if items.find("public $user ") > -1:
writeDataToFile.writelines(defDBUser)
elif items.find("public $password ") > -1:
writeDataToFile.writelines(defDBPassword)
elif items.find("public $db ") > -1:
writeDataToFile.writelines(defDBName)
elif items.find("public $log_path ") > -1:
writeDataToFile.writelines(logPath)
elif items.find("public $tmp_path ") > -1:
writeDataToFile.writelines(tmpPath)
elif items.find("public $secret ") > -1:
writeDataToFile.writelines(secretKey)
elif items.find("public $dbprefix ") > -1:
writeDataToFile.writelines(dbprefix)
elif items.find("public $sitename ") > -1:
writeDataToFile.writelines(sitename)
elif items.find("/*") > -1:
pass
elif items.find(" *") > -1:
pass
else:
writeDataToFile.writelines(items)
writeDataToFile.close()
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Creating default user..,70')
statusFile.close()
# Rename SQL db prefix
f1 = open(finalPath + 'installation/sql/mysql/joomla.sql', 'r')
2019-11-24 12:14:18 +05:00
f2 = open(finalPath + 'installation/sql/mysql/joomlaInstall.sql', 'w')
2018-07-13 21:45:40 +05:00
for line in f1:
f2.write(line.replace('#__', prefix))
f1.close()
f2.close()
# Restore SQL
2019-03-26 16:19:03 +05:00
proc = subprocess.Popen(["mysql", "--user=%s" % dbUser, "--password=%s" % dbPassword, dbName],
2018-07-13 21:45:40 +05:00
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
usercreation = """INSERT INTO `%susers`
(`name`, `username`, `password`, `params`)
VALUES ('Administrator', '%s',
'%s', '');
INSERT INTO `%suser_usergroup_map` (`user_id`,`group_id`)
VALUES (LAST_INSERT_ID(),'8');""" % (prefix, username, password, prefix)
out, err = proc.communicate(
file(finalPath + 'installation/sql/mysql/joomlaInstall.sql').read() + "\n" + usercreation)
shutil.rmtree(finalPath + "installation")
2019-11-24 12:14:18 +05:00
command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + finalPath
ProcessUtilities.executioner(command)
2018-07-13 21:45:40 +05:00
vhost.addRewriteRules(domainName)
2019-11-24 12:14:18 +05:00
installUtilities.reStartLiteSpeedSocket()
2018-07-13 21:45:40 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Successfully Installed. [200]")
statusFile.close()
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-07-13 21:45:40 +05:00
# remove the downloaded files
homeDir = "/home/" + domainName + "/public_html"
if not os.path.exists(homeDir):
2019-11-24 12:14:18 +05:00
command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir
2019-03-26 16:19:03 +05:00
ProcessUtilities.executioner(command)
2018-07-13 21:45:40 +05:00
2018-08-21 13:10:40 +05:00
try:
mysqlUtilities.deleteDatabase(dbName, dbUser)
db = Databases.objects.get(dbName=dbName)
db.delete()
except:
pass
2018-07-13 21:45:40 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(str(msg) + " [404]")
statusFile.close()
logging.writeToFile(str(msg))
2018-07-13 21:45:40 +05:00
return 0
2018-07-28 01:25:51 +05:00
def changeBranch(self):
try:
domainName = self.extraArgs['domainName']
githubBranch = self.extraArgs['githubBranch']
2018-07-29 01:20:46 +05:00
admin = self.extraArgs['admin']
2018-08-21 13:10:40 +05:00
try:
2018-07-29 01:20:46 +05:00
website = Websites.objects.get(domain=domainName)
2018-08-21 13:10:40 +05:00
finalPath = "/home/" + domainName + "/public_html/"
externalApp = website.externalApp
2018-08-21 13:10:40 +05:00
except:
childDomain = ChildDomains.objects.get(domain=domainName)
finalPath = childDomain.path
externalApp = childDomain.master.externalApp
2018-07-28 01:25:51 +05:00
try:
2019-02-21 17:19:04 +05:00
command = 'sudo git --git-dir=' + finalPath + '/.git checkout -b ' + githubBranch
ProcessUtilities.executioner(command, externalApp)
2019-02-21 17:19:04 +05:00
except:
try:
command = 'sudo git --git-dir=' + finalPath + '/.git checkout ' + githubBranch
ProcessUtilities.executioner(command, externalApp)
2019-12-10 15:09:10 +05:00
except subprocess.CalledProcessError as msg:
2019-11-07 09:37:06 +05:00
logging.writeToFile('Failed to change branch: ' + str(msg))
2019-02-21 17:19:04 +05:00
return 0
2018-07-28 01:25:51 +05:00
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-02-21 17:19:04 +05:00
logging.writeToFile('Failed to change branch: ' + str(msg))
2018-07-28 01:25:51 +05:00
return 0
2019-11-07 09:37:06 +05:00
def installMagento(self):
try:
username = self.extraArgs['username']
domainName = self.extraArgs['domainName']
home = self.extraArgs['home']
firstName = self.extraArgs['firstName']
lastName = self.extraArgs['lastName']
email = self.extraArgs['email']
password = self.extraArgs['password']
tempStatusPath = self.extraArgs['tempStatusPath']
sampleData = self.extraArgs['sampleData']
FNULL = open(os.devnull, 'w')
## Open Status File
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up paths,0')
statusFile.close()
finalPath = ''
try:
website = ChildDomains.objects.get(domain=domainName)
externalApp = website.master.externalApp
if home == '0':
path = self.extraArgs['path']
finalPath = website.path.rstrip('/') + "/" + path + "/"
else:
finalPath = website.path + "/"
if website.master.package.dataBases > website.master.databases_set.all().count():
pass
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Maximum database limit reached for this website." + " [404]")
statusFile.close()
return 0
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up Database,20')
statusFile.close()
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master)
except:
website = Websites.objects.get(domain=domainName)
externalApp = website.externalApp
if home == '0':
path = self.extraArgs['path']
finalPath = "/home/" + domainName + "/public_html/" + path + "/"
else:
finalPath = "/home/" + domainName + "/public_html/"
if website.package.dataBases > website.databases_set.all().count():
pass
else:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(
"Maximum database limit reached for this website." + " [404]")
statusFile.close()
return 0
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up Database,20')
statusFile.close()
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website)
## Security Check
if finalPath.find("..") > -1:
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Specified path must be inside virtual host home." + " [404]")
statusFile.close()
return 0
if not os.path.exists(finalPath):
command = 'sudo mkdir -p ' + finalPath
ProcessUtilities.executioner(command, externalApp)
## checking for directories/files
if self.dataLossCheck(finalPath, tempStatusPath) == 0:
return 0
####
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Downloading and extracting Magento Core..,30')
statusFile.close()
if sampleData:
command = "sudo wget http://cyberpanelsh.b-cdn.net/latest-sample.tar.gz -P %s" % (finalPath)
else:
command = "sudo wget http://cyberpanelsh.b-cdn.net/latest.tar.gz -P %s" % (finalPath)
ProcessUtilities.executioner(command, externalApp)
if sampleData:
command = 'tar -xf %slatest-sample.tar.gz --directory %s' % (finalPath, finalPath)
else:
command = 'tar -xf %slatest.tar.gz --directory %s' % (finalPath, finalPath)
ProcessUtilities.executioner(command, externalApp)
##
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Configuring the installation,40')
statusFile.close()
if home == '0':
path = self.extraArgs['path']
# finalURL = domainName + '/' + path
finalURL = domainName
else:
finalURL = domainName
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Installing and configuring Magento..,60')
statusFile.close()
command = '/usr/local/lsws/lsphp72/bin/php -d memory_limit=512M %sbin/magento setup:install --backend-frontname="admin" ' \
'--db-host="localhost" --db-name="%s" --db-user="%s" --db-password="%s" ' \
'--base-url="http://%s" --base-url-secure="https://%s/" --admin-user="%s" ' \
'--admin-password="%s" --admin-email="%s" --admin-firstname="%s" --admin-lastname="%s"' \
% (finalPath, dbName, dbUser, dbPassword, finalURL, finalURL, username, password, email, firstName, lastName)
result = ProcessUtilities.outputExecutioner(command, externalApp)
logging.writeToFile(result)
##
if sampleData:
command = 'rm -rf %slatest-sample.tar.gz' % (finalPath)
else:
command = 'rm -rf %slatest.tar.gz' % (finalPath)
ProcessUtilities.executioner(command, externalApp)
##
command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath
ProcessUtilities.executioner(command, externalApp)
2019-11-15 22:57:03 +05:00
installUtilities.reStartLiteSpeed()
2019-11-07 09:37:06 +05:00
statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Successfully Installed. [200]")
statusFile.close()
return 0
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-11-07 09:37:06 +05:00
# remove the downloaded files
homeDir = "/home/" + domainName + "/public_html"
if not os.path.exists(homeDir):
command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir
ProcessUtilities.executioner(command, externalApp)
try:
mysqlUtilities.deleteDatabase(dbName, dbUser)
db = Databases.objects.get(dbName=dbName)
db.delete()
except:
pass
statusFile = open(tempStatusPath, 'w')
statusFile.writelines(str(msg) + " [404]")
statusFile.close()
return 0