joomla installer: auto install with lscache

This commit is contained in:
Usman Nasir
2020-10-08 12:18:51 +05:00
parent c6c37af35b
commit 38be1c9985
7 changed files with 143 additions and 242 deletions

BIN
install/lscache-1.3.1.zip Normal file

Binary file not shown.

View File

@@ -9,15 +9,14 @@ django.setup()
import threading as multi import threading as multi
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
import subprocess import subprocess
from plogical.vhost import vhost
from websiteFunctions.models import ChildDomains, Websites from websiteFunctions.models import ChildDomains, Websites
from plogical import randomPassword from plogical import randomPassword
from plogical.mysqlUtilities import mysqlUtilities from plogical.mysqlUtilities import mysqlUtilities
from databases.models import Databases from databases.models import Databases
from plogical.installUtilities import installUtilities from plogical.installUtilities import installUtilities
import shutil
from plogical.processUtilities import ProcessUtilities from plogical.processUtilities import ProcessUtilities
from random import randint from random import randint
import hashlib
class ApplicationInstaller(multi.Thread): class ApplicationInstaller(multi.Thread):
@@ -828,16 +827,10 @@ $parameters = array(
try: try:
domainName = self.extraArgs['domainName'] domainName = self.extraArgs['domain']
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'] password = self.extraArgs['password']
prefix = self.extraArgs['prefix'] prefix = self.extraArgs['prefix']
sitename = self.extraArgs['sitename'] home = self.extraArgs['home']
tempStatusPath = self.extraArgs['tempStatusPath'] tempStatusPath = self.extraArgs['tempStatusPath']
self.tempStatusPath = tempStatusPath self.tempStatusPath = tempStatusPath
@@ -847,135 +840,153 @@ $parameters = array(
command = 'chmod 755 %s' % (permPath) command = 'chmod 755 %s' % (permPath)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
if not os.path.exists(finalPath): ## Get Joomla
os.makedirs(finalPath)
## checking for directories/files try:
website = ChildDomains.objects.get(domain=domainName)
externalApp = website.master.externalApp
self.masterDomain = website.master.domain
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:
raise BaseException("Maximum database limit reached for this website.")
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Setting up Database,20')
statusFile.close()
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master)
self.permPath = website.path
except:
website = Websites.objects.get(domain=domainName)
externalApp = website.externalApp
self.masterDomain = website.domain
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:
raise BaseException("Maximum database limit reached for this website.")
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Installing Joomla Console..,30')
statusFile.close()
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website)
self.permPath = '/home/%s/public_html' % (website.domain)
## Dataloss check
command = 'ls -la %s' % (finalPath)
result = ProcessUtilities.outputExecutioner(command, externalApp)
if result.find('No such file or directory') > -1:
command = 'mkdir %s' % (finalPath)
ProcessUtilities.executioner(command, externalApp)
if self.dataLossCheck(finalPath, tempStatusPath) == 0: if self.dataLossCheck(finalPath, tempStatusPath) == 0:
raise BaseException('Directory is not empty.') raise BaseException('Directory is not empty.')
## Get Joomla command = 'composer global require joomlatools/console'
ProcessUtilities.outputExecutioner(command, externalApp, None, self.permPath)
os.chdir(finalPath) ## Run the install command
if not os.path.exists("staging.zip"):
command = 'wget --no-check-certificate https://github.com/joomla/joomla-cms/archive/staging.zip -P ' + finalPath
ProcessUtilities.executioner(command, virtualHostUser)
else:
raise BaseException('File already exists.')
command = 'unzip ' + finalPath + 'staging.zip -d ' + finalPath
ProcessUtilities.executioner(command, virtualHostUser)
command = 'rm -f %s' % (finalPath + 'staging.zip')
ProcessUtilities.executioner(command, virtualHostUser)
command = 'cp -r ' + finalPath + 'joomla-cms-staging/. ' + finalPath
ProcessUtilities.executioner(command, virtualHostUser)
command = 'chown -R cyberpanel:cyberpanel %s' % (finalPath)
ProcessUtilities.executioner(command)
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 = open(tempStatusPath, 'w')
statusFile.writelines('Creating configuration files.,40') statusFile.writelines('Installing Joomla..,40')
statusFile.close() statusFile.close()
configfile = finalPath + "configuration.php" command = '/home/%s/.composer/vendor/bin/joomla site:create %s --mysql-login %s:%s --mysql-database %s --mysql_db_prefix=%s --www %s --sample-data=blog --skip-create-statement' % (self.masterDomain, dbUser, dbUser, dbPassword, dbName, prefix , finalPath)
data = open(configfile, "r").readlines() result = ProcessUtilities.outputExecutioner(command, externalApp)
writeDataToFile = open(configfile, "w") if result.find('admin/admin') == -1:
raise BaseException(result)
secret = randomPassword.generate_pass() ### Update password as per user requirments
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 = open(tempStatusPath, 'w')
statusFile.writelines('Creating default user..,70') statusFile.writelines('Updating admin password..,70')
statusFile.close() statusFile.close()
# Rename SQL db prefix try:
f1 = open(finalPath + 'installation/sql/mysql/joomla.sql', 'r') salt = randomPassword.generate_pass(32)
f2 = open(finalPath + 'installation/sql/mysql/joomlaInstall.sql', 'w') # return salt
for line in f1: password_hash = hashlib.md5((password + salt).encode('utf-8')).hexdigest()
f2.write(line.replace('#__', prefix)) password = password_hash + ":" + salt
f1.close()
f2.close()
# Restore SQL import MySQLdb.cursors as cursors
proc = subprocess.Popen(["mysql", "--user=%s" % dbUser, "--password=%s" % dbPassword, dbName], import MySQLdb as mysql
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
usercreation = """INSERT INTO `%susers` conn = mysql.connect(host='localhost', user=dbUser, passwd=dbPassword, port=3306,
(`name`, `username`, `password`, `params`) cursorclass=cursors.SSCursor)
VALUES ('Administrator', '%s', cursor = conn.cursor()
'%s', '');
INSERT INTO `%suser_usergroup_map` (`user_id`,`group_id`)
VALUES (LAST_INSERT_ID(),'8');""" % (prefix, username, password, prefix)
out, err = proc.communicate( cursor.execute("use %s;UPDATE j_users SET password = '%s' where username = 'admin';FLUSH PRIVILEGES;" % (dbName, password))
open(finalPath + 'installation/sql/mysql/joomlaInstall.sql', 'rb').read() + ("\n" + usercreation).encode('utf-8'))
shutil.rmtree(finalPath + "installation") conn.close()
except BaseException as msg:
logging.writeToFile(str(msg))
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: try:
groupName = 'nobody' os.remove('/usr/local/CyberCP/joomla.zip')
else: os.remove('/usr/local/CyberCP/lscache_plugin.zip')
groupName = 'nogroup' os.remove('/usr/local/CyberCP/com_lscache.zip')
except:
pass
command = "chown -R " + virtualHostUser + ":" + groupName + " " + finalPath statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Installing LiteSpeed Cache Joomla plugin..,80')
statusFile.close()
command = 'wget https://raw.githubusercontent.com/litespeedtech/lscache-joomla/master/package/lscache-1.3.1.zip -O /usr/local/CyberCP/joomla.zip'
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
vhost.addRewriteRules(domainName) command = 'unzip /usr/local/CyberCP/joomla.zip -d /usr/local/CyberCP/'
ProcessUtilities.executioner(command)
command = '/home/%s/.composer/vendor/bin/joomla extension:installfile %s --www %s /usr/local/CyberCP/lscache_plugin.zip' % (self.masterDomain, dbUser, finalPath)
ProcessUtilities.executioner(command)
command = '/home/%s/.composer/vendor/bin/joomla extension:installfile %s --www %s /usr/local/CyberCP/com_lscache.zip' % (self.masterDomain, dbUser, finalPath)
ProcessUtilities.executioner(command)
command = '/home/%s/.composer/vendor/bin/joomla extension:enable %s --www %s lscache' % (self.masterDomain, dbUser, finalPath)
ProcessUtilities.executioner(command)
command = 'mv %s%s/* %s' % (finalPath, dbUser, finalPath)
ProcessUtilities.executioner(command)
command = 'mv %s%s/.[^.]* %s' % (finalPath, dbUser, finalPath)
ProcessUtilities.executioner(command)
command = "sed -i 's|$debug = 1|$debug = 0|g' %sconfiguration.php" % (finalPath)
ProcessUtilities.executioner(command)
##
from filemanager.filemanager import FileManager
fm = FileManager(None, None)
fm.fixPermissions(self.masterDomain)
installUtilities.reStartLiteSpeedSocket() installUtilities.reStartLiteSpeedSocket()
permPath = '/home/%s/public_html' % (domainName)
command = 'chmod 750 %s' % (permPath)
ProcessUtilities.executioner(command)
statusFile = open(tempStatusPath, 'w') statusFile = open(tempStatusPath, 'w')
statusFile.writelines("Successfully Installed. [200]") statusFile.writelines("Successfully Installed. [200]")
statusFile.close() statusFile.close()
@@ -984,16 +995,10 @@ $parameters = array(
except BaseException as msg: except BaseException as msg:
# remove the downloaded files # remove the downloaded files
homeDir = "/home/" + domainName + "/public_html" from filemanager.filemanager import FileManager
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: fm = FileManager(None, None)
groupName = 'nobody' fm.fixPermissions(self.masterDomain)
else:
groupName = 'nogroup'
if not os.path.exists(homeDir):
command = "chown -R " + virtualHostUser + ":" + groupName + " " + homeDir
ProcessUtilities.executioner(command)
try: try:
mysqlUtilities.deleteDatabase(dbName, dbUser) mysqlUtilities.deleteDatabase(dbName, dbUser)

View File

@@ -1723,8 +1723,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) {
var domain = $("#domainNamePage").text(); var domain = $("#domainNamePage").text();
var path = $scope.installPath; var path = $scope.installPath;
var sitename = $scope.sitename; var username = 'admin';
var username = $scope.username;
var password = $scope.password; var password = $scope.password;
var prefix = $scope.prefix; var prefix = $scope.prefix;
@@ -1742,8 +1741,6 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) {
domain: domain, domain: domain,
home: home, home: home,
path: path, path: path,
sitename: sitename,
username: username,
password: password, password: password,
prefix: prefix, prefix: prefix,
}; };

View File

@@ -1723,8 +1723,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) {
var domain = $("#domainNamePage").text(); var domain = $("#domainNamePage").text();
var path = $scope.installPath; var path = $scope.installPath;
var sitename = $scope.sitename; var username = 'admin';
var username = $scope.username;
var password = $scope.password; var password = $scope.password;
var prefix = $scope.prefix; var prefix = $scope.prefix;
@@ -1742,8 +1741,6 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) {
domain: domain, domain: domain,
home: home, home: home,
path: path, path: path,
sitename: sitename,
username: username,
password: password, password: password,
prefix: prefix, prefix: prefix,
}; };

View File

@@ -24,17 +24,10 @@
<form name="websiteCreationForm" action="/" id="createPackages" class="form-horizontal bordered-row"> <form name="websiteCreationForm" action="/" id="createPackages" class="form-horizontal bordered-row">
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Site Name" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" ng-model="blogTitle" required>
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group"> <div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Login User" %}</label> <label class="col-sm-3 control-label">{% trans "Login User" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">
<input type="text" class="form-control" ng-model="adminUser" required> <input placeholder="admin" type="text" class="form-control" ng-model="adminUser" readonly>
</div> </div>
</div> </div>
@@ -48,7 +41,7 @@
<div ng-hide="installationDetailsForm" class="form-group"> <div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Database Prefix" %}</label> <label class="col-sm-3 control-label">{% trans "Database Prefix" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">
<input type="text" class="form-control" ng-model="databasePrefix" required> <input type="text" class="form-control" ng-model="databasePrefix" readonly>
</div> </div>
</div> </div>

View File

@@ -688,7 +688,7 @@
</a> </a>
</div> </div>
<!--<div class="col-md-3 panel-body"> <div class="col-md-3 panel-body">
<a href="{$ joomlaInstallURL $}" target="_blank" <a href="{$ joomlaInstallURL $}" target="_blank"
title="{% trans 'Install Joomla with LSCache' %}"> title="{% trans 'Install Joomla with LSCache' %}">
@@ -698,7 +698,7 @@
title="{% trans 'Install Joomla with LSCache' %}"> title="{% trans 'Install Joomla with LSCache' %}">
<span class="h4">{% trans "Joomla" %}</span> <span class="h4">{% trans "Joomla" %}</span>
</a> </a>
</div>--> </div>
<div class="col-md-3 panel-body"> <div class="col-md-3 panel-body">
<a href="/websites/{{ childDomain }}/manageGIT" target="_blank" <a href="/websites/{{ childDomain }}/manageGIT" target="_blank"

View File

@@ -1925,117 +1925,26 @@ class WebsiteManager:
else: else:
return ACLManager.loadErrorJson('installStatus', 0) return ACLManager.loadErrorJson('installStatus', 0)
domainName = data['domain'] extraArgs = {}
home = data['home']
sitename = data['sitename'] extraArgs['password'] = data['passwordByPass']
username = data['username'] extraArgs['prefix'] = data['prefix']
password = data['passwordByPass'] extraArgs['domain'] = data['domain']
prefix = data['prefix'] extraArgs['home'] = data['home']
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
mailUtilities.checkHome() mailUtilities.checkHome()
tempStatusPath = "/tmp/" + str(randint(1000, 9999)) if data['home'] == '0':
extraArgs['path'] = data['path']
statusFile = open(tempStatusPath, 'w') background = ApplicationInstaller('joomla', extraArgs)
statusFile.writelines('Setting up paths,0') background.start()
statusFile.close()
os.chmod(tempStatusPath, 0o777)
finalPath = "" time.sleep(2)
admin = Administrator.objects.get(pk=userID) data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None',
'tempStatusPath': extraArgs['tempStatusPath']}
## DB Creation
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Creating database..,10')
statusFile.close()
dbName = randomPassword.generate_pass()
dbUser = dbName
dbPassword = randomPassword.generate_pass()
if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter(
dbUser=dbUser).exists():
data_ret = {'status': 0, 'installStatus': 0,
'error_message': "0,This database or user is already taken."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
result = mysqlUtilities.createDatabase(dbName, dbUser, dbPassword)
if result == 1:
pass
else:
data_ret = {'status': 0, 'installStatus': 0,
'error_message': "0,Not able to create database."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
##
try:
website = ChildDomains.objects.get(domain=domainName)
externalApp = website.master.externalApp
if website.master.package.dataBases > website.master.databases_set.all().count():
pass
else:
data_ret = {'status': 0, 'installStatus': 0,
'error_message': "0,Maximum database limit reached for this website."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
if home == '0':
path = data['path']
finalPath = website.path.rstrip('/') + "/" + path + "/"
else:
finalPath = website.path + "/"
db = Databases(website=website.master, dbName=dbName, dbUser=dbUser)
db.save()
except:
website = Websites.objects.get(domain=domainName)
externalApp = website.externalApp
if website.package.dataBases > website.databases_set.all().count():
pass
else:
data_ret = {'status': 0, 'installStatus': 0,
'error_message': "0,Maximum database limit reached for this website."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
if home == '0':
path = data['path']
finalPath = "/home/" + domainName + "/public_html/" + path + "/"
else:
finalPath = "/home/" + domainName + "/public_html/"
db = Databases(website=website, dbName=dbName, dbUser=dbUser)
db.save()
if finalPath.find("..") > -1:
data_ret = {'status': 0, 'installStatus': 0,
'error_message': "Specified path must be inside virtual host home!"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
## Installation
salt = randomPassword.generate_pass(32)
# return salt
password_hash = hashlib.md5((password + salt).encode('utf-8')).hexdigest()
password = password_hash + ":" + salt
statusFile = open(tempStatusPath, 'w')
statusFile.writelines('Downloading Joomla Core..,20')
statusFile.close()
virtualHostUtilities.installJoomla(domainName, finalPath, externalApp, dbName, dbUser, dbPassword, username, password, prefix, sitename, tempStatusPath)
data_ret = {'status': 1, "installStatus": 1, 'tempStatusPath': tempStatusPath}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)