def deleteVirtualHostConfigurations(virtualHostName, numberOfSites): try: ## Deleting master conf vhost.deleteCoreConf(virtualHostName, numberOfSites) delWebsite = Websites.objects.get(domain=virtualHostName) databases = Databases.objects.filter(website=delWebsite) childDomains = delWebsite.childdomains_set.all() ## Deleting child domains for items in childDomains: numberOfSites = Websites.objects.count( ) + ChildDomains.objects.count() vhost.deleteCoreConf(items.domain, numberOfSites) for items in databases: mysqlUtilities.deleteDatabase(items.dbName, items.dbUser) delWebsite.delete() ## Deleting DNS Zone if there is any. DNS.deleteDNSZone(virtualHostName) installUtilities.installUtilities.reStartLiteSpeed() ## Delete mail accounts command = "sudo rm -rf /home/vmail/" + virtualHostName subprocess.call(shlex.split(command)) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + " [Not able to remove virtual host configuration from main configuration file.]" ) return 0
homeDir = "/home/" + domainName + "/public_html" if not os.path.exists(homeDir): FNULL = open(os.devnull, 'w') command = 'sudo mkdir ' + homeDir subprocess.call(shlex.split(command)) command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir cmd = shlex.split(command) res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) 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 installJoomla(self): try: domainName = self.extraArgs['domainName']
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="******" --db-password="******" ' \ '--base-url="http://%s" --base-url-secure="https://%s/" --admin-user="******" ' \ '--admin-password="******" --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) installUtilities.reStartLiteSpeed() statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") statusFile.close() return 0 except BaseException, 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
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 if self.dataLossCheck(finalPath, tempStatusPath) == 0: 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 ProcessUtilities.executioner(command, virtualHostUser) else: statusFile = open(tempStatusPath, 'w') statusFile.writelines("File already exists." + " [404]") statusFile.close() return 0 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.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 = '******';" + "\n" defDBUser = "******" + dbUser + "';" + "\n" defDBPassword = "******" + 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') f2 = open(finalPath + 'installation/sql/mysql/joomlaInstall.sql', 'w') for line in f1: f2.write(line.replace('#__', prefix)) f1.close() f2.close() # Restore SQL proc = subprocess.Popen([ "mysql", "--user=%s" % dbUser, "--password=%s" % dbPassword, dbName ], 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") command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + finalPath ProcessUtilities.executioner(command) vhost.addRewriteRules(domainName) installUtilities.reStartLiteSpeedSocket() statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") statusFile.close() return 0 except BaseException, msg: # remove the downloaded files homeDir = "/home/" + domainName + "/public_html" if not os.path.exists(homeDir): command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir ProcessUtilities.executioner(command) 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() logging.writeToFile(str(msg)) 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'] 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 PrestaShop Core..,30') statusFile.close() command = "sudo wget https://download.prestashop.com/download/releases/prestashop_1.7.4.2.zip -P %s" % ( finalPath) ProcessUtilities.executioner(command, externalApp) command = "sudo unzip -o %sprestashop_1.7.4.2.zip -d " % ( finalPath) + finalPath ProcessUtilities.executioner(command, externalApp) command = "sudo unzip -o %sprestashop.zip -d " % ( 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 PrestaShop..,60') statusFile.close() command = "sudo php " + finalPath + "install/index_cli.php --domain=" + finalURL + \ " --db_server=localhost --db_name=" + dbName + " --db_user="******" --db_password="******" --name='" + shopName + "' --firstname=" + firstName + " --lastname=" + lastName + \ " --email=" + email + " --password="******"sudo rm -rf " + finalPath + "install" ProcessUtilities.executioner(command, externalApp) ## command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath ProcessUtilities.executioner(command, externalApp) command = "sudo rm -f prestashop_1.7.4.2.zip" ProcessUtilities.executioner(command, externalApp) statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") statusFile.close() return 0 except BaseException, 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
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'] FNULL = open(os.devnull, 'w') ### Check WP CLI try: command = 'sudo wp --info' outout = ProcessUtilities.outputExecutioner(command) 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() 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 = '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 WordPress Core,30') statusFile.close() command = "wp core download --allow-root --path=" + finalPath ProcessUtilities.executioner(command, externalApp) ## statusFile = open(tempStatusPath, 'w') statusFile.writelines('Configuring the installation,40') statusFile.close() command = "wp core config --dbname=" + dbName + " --dbuser="******" --dbpass="******" --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 command = 'wp core install --url="http://' + finalURL + '" --title="' + blogTitle + '" --admin_user="******" --admin_password="******" --admin_email="' + adminEmail + '" --allow-root --path=' + finalPath ProcessUtilities.executioner(command, externalApp) ## statusFile = open(tempStatusPath, 'w') statusFile.writelines('Installing LSCache Plugin,80') statusFile.close() 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() command = "wp plugin activate litespeed-cache --allow-root --path=" + finalPath ProcessUtilities.executioner(command, externalApp) ## command = "chown -R " + externalApp + ":" + externalApp + " " + finalPath ProcessUtilities.executioner(command, externalApp) statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") statusFile.close() return 0 except BaseException, msg: # remove the downloaded files FNULL = open(os.devnull, 'w') homeDir = "/home/" + domainName + "/public_html" if not os.path.exists(homeDir): command = "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