backuprestore0.1

This commit is contained in:
Hassan Hashmi
2022-06-12 12:05:51 +05:00
parent 24436156f5
commit 0ae63f53e9
2 changed files with 44 additions and 554 deletions

View File

@@ -1728,9 +1728,6 @@ $parameters = array(
statusFile.writelines('Installing WordPress....,30') statusFile.writelines('Installing WordPress....,30')
statusFile.close() statusFile.close()
logging.writeToFile("Pluginbucket ....... %s" % str(self.data['pluginbucket']))
## Install WordPress ## Install WordPress
## get save pluginbucket ## get save pluginbucket
@@ -1777,6 +1774,7 @@ $parameters = array(
webobj = Websites.objects.get(domain= self.extraArgs['domainName']) webobj = Websites.objects.get(domain= self.extraArgs['domainName'])
if self.extraArgs['home'] == '0': if self.extraArgs['home'] == '0':
path = self.extraArgs['path'] path = self.extraArgs['path']
finalPath = "/home/" + self.extraArgs['domainName'] + "/public_html/" + path + "/" finalPath = "/home/" + self.extraArgs['domainName'] + "/public_html/" + path + "/"
@@ -1785,6 +1783,7 @@ $parameters = array(
finalPath = "/home/" + self.extraArgs['domainName'] + "/public_html/" finalPath = "/home/" + self.extraArgs['domainName'] + "/public_html/"
Finalurl = (self.extraArgs['domainName']) Finalurl = (self.extraArgs['domainName'])
wpobj = WPSites(owner=webobj, title=self.extraArgs['blogTitle'], path=finalPath, FinalURL=Finalurl, wpobj = WPSites(owner=webobj, title=self.extraArgs['blogTitle'], path=finalPath, FinalURL=Finalurl,
AutoUpdates=(self.extraArgs['updates']), PluginUpdates=(self.extraArgs['Plugins']), AutoUpdates=(self.extraArgs['updates']), PluginUpdates=(self.extraArgs['Plugins']),
ThemeUpdates=(self.extraArgs['Themes']),) ThemeUpdates=(self.extraArgs['Themes']),)
@@ -2454,6 +2453,15 @@ $parameters = array(
newurl = wpsite.FinalURL newurl = wpsite.FinalURL
#### Check If sub dir in web site
try:
abc = newWPpath.split("/")
newpath = abc[4]
home = "0"
except BaseException as msg:
home = "1"
### get WPsite Database name and usr ### get WPsite Database name and usr
php = PHPManager.getPHPString(PhpVersion) php = PHPManager.getPHPString(PhpVersion)
@@ -2508,7 +2516,10 @@ $parameters = array(
logging.statusWriter(self.tempStatusPath, 'Copying Data File...,50') logging.statusWriter(self.tempStatusPath, 'Copying Data File...,50')
###Copy backup content to newsite ###Copy backup content to newsite
unzippath ="%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/"%(self.tempPath, oldtemppath) if home == "0":
unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath)
else:
unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath)
command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath)
result = ProcessUtilities.outputExecutioner(command) result = ProcessUtilities.outputExecutioner(command)
@@ -2567,6 +2578,22 @@ $parameters = array(
DataToPass['Themes'] = config['WPThemeUpdates'] DataToPass['Themes'] = config['WPThemeUpdates']
DataToPass['websiteOwner'] = WebOwner DataToPass['websiteOwner'] = WebOwner
DataToPass['package'] = packegs DataToPass['package'] = packegs
try:
oldpath = config['WPsitepath']
logging.writeToFile("old path..:%s"%oldpath)
abc = oldpath.split("/")
newpath = abc[4]
newurl = "%s/%s"%(DomainName,newpath)
home = "0"
except BaseException as msg:
logging.writeToFile("path error: %s"%msg)
newpath = ""
newurl = DomainName
home = "1"
DataToPass['path'] = newpath
DataToPass['home'] = home
try: try:
website = Websites.objects.get(domain=DomainName) website = Websites.objects.get(domain=DomainName)
@@ -2590,11 +2617,11 @@ $parameters = array(
time.sleep(2) time.sleep(2)
logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30')
NewWPsite =WPSites.objects.get(FinalURL=DomainName) NewWPsite =WPSites.objects.get(FinalURL=newurl)
VHuser = NewWPsite.owner.externalApp VHuser = NewWPsite.owner.externalApp
PhpVersion = NewWPsite.owner.phpSelection PhpVersion = NewWPsite.owner.phpSelection
newWPpath = NewWPsite.path newWPpath = NewWPsite.path
newurl = NewWPsite.FinalURL
###### Same code already used in Existing site ###### Same code already used in Existing site
@@ -2653,7 +2680,11 @@ $parameters = array(
logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60')
###Copy backup content to newsite ###Copy backup content to newsite
if home == "0":
unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath)
else:
unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath) unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath)
command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath)
result = ProcessUtilities.outputExecutioner(command) result = ProcessUtilities.outputExecutioner(command)

View File

@@ -1,548 +1,7 @@
# -*- coding: utf-8 -*- a = "/home/newweb2.com/public_html/newweb2/"
from django.test import TestCase DomainName ="newweb3.com"
import json abc = a.split("/")
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging wpexpath = abc[4]
import requests newpath = '/home/%s/public_html/%s' % (DomainName, wpexpath)
import time
from plogical.processUtilities import ProcessUtilities
import urllib3
urllib3.disable_warnings()
# Create your tests here.
class TestWebsiteManagement(TestCase):
httpClient = requests.Session()
def MakeRequest(self, endPoint, data):
json_data = json.dumps(data)
path = 'https://cyberpanel.xyz:8090/%s' % (endPoint)
result = TestWebsiteManagement.httpClient.post(path, data=json_data, verify=False)
return json.loads(result.text)
def MakeRequestRaw(self, path):
result = requests.get(path)
return str(result.text)
def setUp(self):
## Verify login
data_ret = {'username': 'admin', 'password': '1234567'}
response = self.MakeRequest('verifyLogin', data_ret)
self.assertEqual(response['loginStatus'], 1)
def test_submitWebsiteCreation(self):
## Login
data_ret = {'domainName': 'hello.cyberpanel.xyz', 'adminEmail': 'usman@cyberpersons.com' , 'phpSelection': 'PHP 7.1',
'package': 'Default', 'websiteOwner': 'admin', 'ssl': 0, 'dkimCheck': 0, 'openBasedir': 0}
response = self.MakeRequest('websites/submitWebsiteCreation', data_ret)
time.sleep(10)
self.assertEqual(response['status'], 1)
exists = 0
if self.MakeRequestRaw('http://hello.cyberpanel.xyz').find('CyberPanel') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_submitWebsiteDeletion(self):
## Login
data_ret = {'websiteName': 'hello.cyberpanel.xyz'}
response = self.MakeRequest('websites/submitWebsiteDeletion', data_ret)
time.sleep(10)
self.assertEqual(response['status'], 1)
def test_submitWebsiteModify(self):
data_ret = {'domainName': 'hey.cyberpanel.xyz', 'adminEmail': 'usman@cyberpersons.com',
'phpSelection': 'PHP 7.1',
'package': 'Default', 'websiteOwner': 'admin', 'ssl': 0, 'dkimCheck': 0, 'openBasedir': 0}
self.MakeRequest('websites/submitWebsiteCreation', data_ret)
time.sleep(10)
##
data_ret = {'domain': 'hey.cyberpanel.xyz', 'email': 'usman@cyberpersons.com' , 'phpVersion': 'PHP 7.3',
'packForWeb': 'Default', 'admin': 'admin'}
response = self.MakeRequest('websites/saveWebsiteChanges', data_ret)
time.sleep(5)
self.assertEqual(response['status'], 1)
phpInfoPath = '/home/hey.cyberpanel.xyz/public_html/info.php'
content = """<?php
phpinfo();
?>
"""
writeToFile = open(phpInfoPath, 'w')
writeToFile.write(content)
writeToFile.close()
exists = 0
if self.MakeRequestRaw('http://hey.cyberpanel.xyz/info.php').find('lsphp73') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_submitWebsiteStatus(self):
data_ret = {'domainName': 'suspend.cyberpanel.xyz', 'adminEmail': 'usman@cyberpersons.com',
'phpSelection': 'PHP 7.1',
'package': 'Default', 'websiteOwner': 'admin', 'ssl': 0, 'dkimCheck': 0, 'openBasedir': 0}
self.MakeRequest('websites/submitWebsiteCreation', data_ret)
## Suspend check
data_ret = {'websiteName': 'suspend.cyberpanel.xyz', 'state': 'Suspend'}
response = self.MakeRequest('websites/submitWebsiteStatus', data_ret)
time.sleep(5)
self.assertEqual(response['websiteStatus'], 1)
exists = 0
if self.MakeRequestRaw('http://suspend.cyberpanel.xyz').find('404') > -1 or self.MakeRequestRaw('http://suspend.cyberpanel.xyz').find('Access to this resource on the server is denied!') > -1:
exists = 1
self.assertEqual(exists, 1)
suspend = 0
import os
if os.path.exists('/usr/local/lsws/conf/vhosts/suspend.cyberpanel.xyz-suspended'):
suspend = 1
self.assertEqual(suspend, 1)
## Unsuspend check
data_ret = {'websiteName': 'suspend.cyberpanel.xyz', 'state': 'Unsuspend'}
response = self.MakeRequest('websites/submitWebsiteStatus', data_ret)
time.sleep(5)
self.assertEqual(response['websiteStatus'], 1)
exists = 0
if self.MakeRequestRaw('http://suspend.cyberpanel.xyz').find('CyberPanel') > -1:
exists = 1
self.assertEqual(exists, 1)
suspend = 0
import os
if os.path.exists('/usr/local/lsws/conf/vhosts/suspend.cyberpanel.xyz'):
suspend = 1
self.assertEqual(suspend, 1)
def test_installWordpress(self):
command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
## Suspend check
data_ret = {'domain': 'cyberpanel.xyz', 'home': '1', 'blogTitle': 'Unit Test', 'adminUser': 'cyberpanel',
'passwordByPass': 'helloworld', 'adminEmail': 'usman@cyberpersons.com'}
response = self.MakeRequest('websites/installWordpress', data_ret)
time.sleep(2)
self.assertEqual(response['status'], 1)
tempStatusPath = response['tempStatusPath']
## Wait for install to complete
data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'}
while True:
response = self.MakeRequest('websites/installWordpressStatus', data_ret)
if response['abort'] == 1:
if response['installStatus']:
break
else:
logging.writeToFile(response['error_message'])
break
exists = 0
if self.MakeRequestRaw('http://cyberpanel.xyz').find('Unit Test') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_installJoomla(self):
command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
## Suspend check
data_ret = {'domain': 'cyberpanel.xyz', 'home': '1', 'sitename': 'Unit Test Joomla', 'username': 'cyberpanel',
'passwordByPass': 'helloworld', 'prefix': 'db_'}
response = self.MakeRequest('websites/installJoomla', data_ret)
time.sleep(2)
self.assertEqual(response['status'], 1)
tempStatusPath = response['tempStatusPath']
## Wait for install to complete
data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'}
while True:
response = self.MakeRequest('websites/installWordpressStatus', data_ret)
time.sleep(1)
if response['abort'] == 1:
if response['installStatus'] == 1:
break
else:
logging.writeToFile(response['error_message'])
break
exists = 0
if self.MakeRequestRaw('http://cyberpanel.xyz').find('Unit Test Joomla') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_prestaShopInstall(self):
command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
## Suspend check
data_ret = {'domain': 'cyberpanel.xyz', 'home': '1', 'shopName': 'Unit Test PrestaShop', 'firstName': 'Usman', 'lastName': 'Nasir',
'passwordByPass': 'helloworld', 'databasePrefix': 'db_', 'email': 'usman@cyberpersons.com'}
response = self.MakeRequest('websites/prestaShopInstall', data_ret)
time.sleep(2)
self.assertEqual(response['status'], 1)
tempStatusPath = response['tempStatusPath']
## Wait for install to complete
data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'}
while True:
response = self.MakeRequest('websites/installWordpressStatus', data_ret)
time.sleep(1)
if response['abort'] == 1:
if response['installStatus'] == 1:
break
else:
logging.writeToFile(response['error_message'])
break
exists = 0
if self.MakeRequestRaw('http://cyberpanel.xyz').find('Unit Test PrestaShop') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_magentoInstall(self):
command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz')
ProcessUtilities.normalExecutioner(command)
## Suspend check
data_ret = {'domain': 'cyberpanel.xyz', 'home': '1','firstName': 'Usman', 'lastName': 'Nasir',
'passwordByPass': 'helloworld1234', 'sampleData': False, 'email': 'usman@cyberpersons.com', 'username': 'usman'}
response = self.MakeRequest('websites/magentoInstall', data_ret)
logging.writeToFile('ps: ' + str(response))
time.sleep(2)
self.assertEqual(response['status'], 1)
tempStatusPath = response['tempStatusPath']
## Wait for install to complete
data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'}
while True:
response = self.MakeRequest('websites/installWordpressStatus', data_ret)
time.sleep(1)
if response['abort'] == 1:
if response['installStatus'] == 1:
break
else:
logging.writeToFile(response['error_message'])
break
exists = 0
if self.MakeRequestRaw('http://cyberpanel.xyz').find('Magento') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_checkConfigFile(self):
##
data_ret = {'virtualHost': 'cyberpanel.xyz'}
response = self.MakeRequest('websites/getDataFromConfigFile', data_ret)
self.assertEqual(response['status'], 1)
exists = 0
if response['configData'].find('phpIniOverride') > -1:
exists = 1
self.assertEqual(exists, 1)
## Inserting something in config file
data_ret = {'virtualHost': 'cyberpanel.xyz', 'configData': response['configData'] + '\nhello world'}
response = self.MakeRequest('websites/saveConfigsToFile', data_ret)
self.assertEqual(response['configstatus'], 1)
## Check again
data_ret = {'virtualHost': 'cyberpanel.xyz'}
response = self.MakeRequest('websites/getDataFromConfigFile', data_ret)
self.assertEqual(response['status'], 1)
exists = 0
if response['configData'].find('hello world') > -1:
exists = 1
self.assertEqual(exists, 1)
## Inserting again
## Inserting something in config file
data_ret = {'virtualHost': 'cyberpanel.xyz', 'configData': response['configData']}
response = self.MakeRequest('websites/saveConfigsToFile', data_ret)
self.assertEqual(response['configstatus'], 1)
def test_checkRewriteFile(self):
## Inserting something in rewrite file
data_ret = {'virtualHost': 'cyberpanel.xyz', 'rewriteRules': 'hello world'}
response = self.MakeRequest('websites/saveRewriteRules', data_ret)
self.assertEqual(response['rewriteStatus'], 1)
## Check again
data_ret = {'virtualHost': 'cyberpanel.xyz'}
response = self.MakeRequest('websites/getRewriteRules', data_ret)
self.assertEqual(response['rewriteStatus'], 1)
exists = 0
if response['rewriteRules'].find('hello world') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_saveSSL(self):
## Inserting something in rewrite file
data_ret = {'virtualHost': 'hey.cyberpanel.xyz', 'key': 'hello world', 'cert': 'hello world'}
response = self.MakeRequest('websites/saveSSL', data_ret)
self.assertEqual(response['sslStatus'], 1)
## Check again
certPath = '/etc/letsencrypt/live/hey.cyberpanel.xyz/fullchain.pem'
keyPath = '/etc/letsencrypt/live/hey.cyberpanel.xyz/privkey.pem'
self.assertGreater(open(certPath, 'r').read().find('hello world'), -1)
self.assertGreater(open(keyPath, 'r').read().find('hello world'), -1)
def test_changePHP(self):
data_ret = {'childDomain': 'hey.cyberpanel.xyz', 'phpSelection': 'PHP 7.0',}
response = self.MakeRequest('websites/changePHP', data_ret)
self.assertEqual(response['status'], 1)
phpInfoPath = '/home/hey.cyberpanel.xyz/public_html/info.php'
content = "<?php phpinfo(); ?>"
writeToFile = open(phpInfoPath, 'w')
writeToFile.write(content)
writeToFile.close()
time.sleep(2)
exists = 0
if self.MakeRequestRaw('http://hey.cyberpanel.xyz/info.php').find('lsphp70') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_changeOpenBasedir(self):
## Check enable
data_ret = {'domainName': 'hey.cyberpanel.xyz', 'openBasedirValue': 'Enable'}
response = self.MakeRequest('websites/changeOpenBasedir', data_ret)
self.assertEqual(response['status'], 1)
time.sleep(3)
completePathToConfigFile = '/usr/local/lsws/conf/vhosts/%s/vhost.conf' % ('hey.cyberpanel.xyz')
exists = 0
if open(completePathToConfigFile, 'r').read().find('open_basedir') > -1:
exists = 1
self.assertEqual(exists, 1)
## Check disable
data_ret = {'domainName': 'hey.cyberpanel.xyz', 'openBasedirValue': 'Disable'}
response = self.MakeRequest('websites/changeOpenBasedir', data_ret)
self.assertEqual(response['status'], 1)
time.sleep(3)
completePathToConfigFile = '/usr/local/lsws/conf/vhosts/%s/vhost.conf' % ('hey.cyberpanel.xyz')
exists = 0
if open(completePathToConfigFile, 'r').read().find('open_basedir') > -1:
exists = 1
self.assertEqual(exists, 0)
def test_submitDomainCreation(self):
## Check creation
data_ret = {'masterDomain': 'cyberpanel.xyz', 'domainName': 'child.cyberpanel.xyz' , 'phpSelection': 'PHP 7.1', 'ssl': 0, 'dkimCheck': 0, 'openBasedir': 0, 'path': ''}
response = self.MakeRequest('websites/submitDomainCreation', data_ret)
time.sleep(10)
self.assertEqual(response['status'], 1)
exists = 0
if self.MakeRequestRaw('http://child.cyberpanel.xyz').find('CyberPanel') > -1:
exists = 1
self.assertEqual(exists, 1)
## Check deletion
data_ret = {'websiteName': 'child.cyberpanel.xyz'}
response = self.MakeRequest('websites/submitDomainDeletion', data_ret)
time.sleep(10)
self.assertEqual(response['status'], 1)
exists = 0
if self.MakeRequestRaw('http://child.cyberpanel.xyz').find('404') > -1:
exists = 1
self.assertEqual(exists, 1)
def test_addNewCron(self):
## Check cron creation
data_ret = {'domain': 'cyberpanel.xyz', 'cronCommand': 'touch /home/cyberpanel.xyz/cron.txt' , 'hour': '*', 'minute': '*', 'month': '*', 'monthday': '*', 'weekday': '*'}
response = self.MakeRequest('websites/addNewCron', data_ret)
time.sleep(65)
self.assertEqual(response['addNewCron'], 1)
import os
self.assertEqual(os.path.exists('/home/cyberpanel.xyz/cron.txt'), True)
##
data_ret = {'domain': 'cyberpanel.xyz', 'line': 1}
response = self.MakeRequest('websites/remCronbyLine', data_ret)
self.assertEqual(response['remCronbyLine'], 1)
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
cronPath = "/var/spool/cron/cyberpa"
else:
cronPath = "/var/spool/cron/crontabs/cyberpa"
exists = 0
if open(cronPath, 'r').read().find('cron.txt') > -1:
exists = 1
self.assertEqual(exists, 0)
print(newpath)