Files
CyberPanel/cloudAPI/cloudManager.py
2021-01-18 14:01:26 +05:00

2496 lines
94 KiB
Python
Executable File

import userManagment.views as um
from backup.backupManager import BackupManager
from databases.databaseManager import DatabaseManager
from dns.dnsManager import DNSManager
from firewall.firewallManager import FirewallManager
from ftp.ftpManager import FTPManager
from highAvailability.haManager import HAManager
from loginSystem.models import Administrator
from mailServer.mailserverManager import MailServerManager
from manageSSL.views import issueSSL, obtainHostNameSSL, obtainMailServerSSL
from packages.packagesManager import PackagesManager
from plogical.mysqlUtilities import mysqlUtilities
from plogical.virtualHostUtilities import virtualHostUtilities
from websiteFunctions.website import WebsiteManager
from s3Backups.s3Backups import S3Backups
from serverLogs.views import getLogsFromFile
from serverStatus.views import topProcessesStatus, killProcess, switchTOLSWSStatus
from plogical import hashPassword
from loginSystem.models import ACL
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
from managePHP.phpManager import PHPManager
from managePHP.views import submitExtensionRequest, getRequestStatusApache
from containerization.views import *
class CloudManager:
def __init__(self, data=None, admin=None):
self.data = data
self.admin = admin
def ajaxPre(self, status, errorMessage):
final_dic = {'status': status, 'error_message': errorMessage}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def verifyLogin(self, request):
try:
if request.META['HTTP_AUTHORIZATION'] == self.admin.token:
return 1, self.ajaxPre(1, None)
else:
return 0, self.ajaxPre(0, 'Invalid login information.')
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchWebsites(self):
try:
wm = WebsiteManager()
return wm.getFurtherAccounts(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitWebsiteDeletion(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.submitWebsiteDeletion(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitWebsiteCreation(self):
try:
try:
UserAccountName = self.data['UserAccountName']
UserPassword = self.data['UserPassword']
FullName = self.data['FullName']
token = hashPassword.generateToken(UserAccountName, UserPassword)
password = hashPassword.hash_password(UserPassword)
try:
initWebsitesLimit = int(self.data['websitesLimit'])
except:
initWebsitesLimit = 10
try:
acl = self.data['acl']
selectedACL = ACL.objects.get(name=acl)
except:
selectedACL = ACL.objects.get(name='user')
try:
apiAccess = int(self.data['api'])
except:
apiAccess = 10
try:
newAdmin = Administrator(firstName=FullName,
lastName="",
email=self.data['adminEmail'],
type=3,
userName=UserAccountName,
password=password,
initWebsitesLimit=initWebsitesLimit,
owner=1,
acl=selectedACL,
token=token,
api=apiAccess
)
newAdmin.save()
except BaseException as msg:
logging.writeToFile(str(msg))
admin = Administrator.objects.get(userName=UserAccountName)
admin.token = token
admin.password = password
admin.save()
except BaseException as msg:
logging.writeToFile(str(msg))
wm = WebsiteManager()
return wm.submitWebsiteCreation(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchWebsiteDataJSON(self):
try:
wm = WebsiteManager()
return wm.fetchWebsiteDataJSON(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchWebsiteData(self):
try:
currentACL = ACLManager.loadedACL(self.admin.pk)
website = Websites.objects.get(domain=self.data['domainName'])
admin = Administrator.objects.get(pk=self.admin.pk)
if ACLManager.checkOwnership(self.data['domainName'], admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
Data = {}
Data['ftpAllowed'] = website.package.ftpAccounts
Data['ftpUsed'] = website.users_set.all().count()
Data['dbUsed'] = website.databases_set.all().count()
Data['dbAllowed'] = website.package.dataBases
DiskUsage, DiskUsagePercentage, bwInMB, bwUsage = virtualHostUtilities.FindStats(website)
## bw usage calculations
Data['bwInMBTotal'] = website.package.bandwidth
Data['bwInMB'] = bwInMB
Data['bwUsage'] = bwUsage
if DiskUsagePercentage > 100:
DiskUsagePercentage = 100
Data['diskUsage'] = DiskUsagePercentage
Data['diskInMB'] = DiskUsage
Data['diskInMBTotal'] = website.package.diskSpace
##
Data['status'] = 1
final_json = json.dumps(Data)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchModifyData(self):
try:
wm = WebsiteManager()
return wm.submitWebsiteModify(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def saveModifications(self):
try:
wm = WebsiteManager()
return wm.saveWebsiteChanges(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitDBCreation(self):
try:
dm = DatabaseManager()
return dm.submitDBCreation(self.admin.pk, self.data, 1)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchDatabases(self):
try:
dm = DatabaseManager()
return dm.fetchDatabases(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitDatabaseDeletion(self):
try:
dm = DatabaseManager()
return dm.submitDatabaseDeletion(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def changePassword(self):
try:
dm = DatabaseManager()
return dm.changePassword(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getCurrentRecordsForDomain(self):
try:
dm = DNSManager()
return dm.getCurrentRecordsForDomain(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteDNSRecord(self):
try:
dm = DNSManager()
return dm.deleteDNSRecord(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def addDNSRecord(self):
try:
dm = DNSManager()
return dm.addDNSRecord(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitEmailCreation(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitEmailCreation()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getEmailsForDomain(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.getEmailsForDomain()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitEmailDeletion(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitEmailDeletion()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitPasswordChange(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitPasswordChange()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchCurrentForwardings(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.fetchCurrentForwardings()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitForwardDeletion(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitForwardDeletion()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitEmailForwardingCreation(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitEmailForwardingCreation()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchDKIMKeys(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.fetchDKIMKeys()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def generateDKIMKeys(self, request):
try:
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.generateDKIMKeys()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitFTPCreation(self, request):
try:
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.submitFTPCreation()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getAllFTPAccounts(self, request):
try:
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.getAllFTPAccounts()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitFTPDelete(self, request):
try:
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.submitFTPDelete()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def changeFTPPassword(self, request):
try:
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.changePassword()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def issueSSL(self, request):
try:
request.session['userID'] = self.admin.pk
return issueSSL(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def statusFunc(self):
try:
statusFile = self.data['statusFile']
statusData = open(statusFile, 'r').readlines()
try:
lastLine = statusData[-1]
if lastLine.find('[200]') > -1:
command = 'rm -f ' + statusFile
ProcessUtilities.executioner(command)
data_ret = {'status': 1, 'abort': 1, 'installationProgress': "100", 'currentStatus': lastLine}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
elif lastLine.find('[404]') > -1:
data_ret = {'status': 0, 'abort': 1, 'installationProgress': "0", 'error_message': lastLine}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
progress = lastLine.split(',')
currentStatus = progress[0]
try:
installationProgress = progress[1].rstrip('\n')
except:
installationProgress = 0
data_ret = {'status': 1, 'abort': 0, 'installationProgress': installationProgress,
'currentStatus': currentStatus}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except IndexError:
data_ret = {'status': 1, 'abort': 0, 'installationProgress': 0,
'currentStatus': 'Working..'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def submitDomainCreation(self):
try:
wm = WebsiteManager()
return wm.submitDomainCreation(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchDomains(self):
try:
wm = WebsiteManager()
return wm.fetchDomains(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitDomainDeletion(self):
try:
wm = WebsiteManager()
return wm.submitDomainDeletion(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def changeOpenBasedir(self):
try:
wm = WebsiteManager()
return wm.changeOpenBasedir(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def changePHP(self):
try:
wm = WebsiteManager()
return wm.changePHP(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def backupStatusFunc(self):
try:
bm = BackupManager()
return bm.backupStatus(self.admin.pk, self.data)
except BaseException as msg:
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def submitBackupCreation(self):
try:
bm = BackupManager()
return bm.submitBackupCreation(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getCurrentBackups(self):
try:
bm = BackupManager()
return bm.getCurrentBackups(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteBackup(self):
try:
bm = BackupManager()
return bm.deleteBackup(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchACLs(self):
try:
userID = self.admin.pk
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
aclNames = ACLManager.unFileteredACLs()
elif currentACL['changeUserACL'] == 1:
aclNames = ACLManager.unFileteredACLs()
elif currentACL['createNewUser'] == 1:
aclNames = ['user']
else:
return ACLManager.loadError()
json_data = "["
checker = 0
for items in aclNames:
dic = {'acl': items}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitUserCreation(self, request):
try:
request.session['userID'] = self.admin.pk
return um.submitUserCreation(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchUsers(self):
try:
userID = self.admin.pk
allUsers = ACLManager.loadUserObjects(userID)
json_data = "["
checker = 0
for user in allUsers:
dic = {
"id": user.id,
"userName": user.userName,
"firstName": user.firstName,
"lastName": user.lastName,
"email": user.email,
"acl": user.acl.name,
"websitesLimit": user.initWebsitesLimit
}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitUserDeletion(self, request):
try:
request.session['userID'] = self.admin.pk
return um.submitUserDeletion(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def saveModificationsUser(self, request):
try:
request.session['userID'] = self.admin.pk
return um.saveModifications(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def userWithResellerPriv(self):
try:
userID = self.admin.pk
allUsers = ACLManager.userWithResellerPriv(userID)
json_data = "["
checker = 0
for user in allUsers:
dic = {
"userName": user,
}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def saveResellerChanges(self, request):
try:
request.session['userID'] = self.admin.pk
return um.saveResellerChanges(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def changeACLFunc(self, request):
try:
request.session['userID'] = self.admin.pk
return um.changeACLFunc(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def createACLFunc(self, request):
try:
request.session['userID'] = self.admin.pk
return um.createACLFunc(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def findAllACLs(self, request):
try:
userID = self.admin.pk
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
aclNames = ACLManager.findAllACLs()
else:
return ACLManager.loadErrorJson()
json_data = "["
checker = 0
for items in aclNames:
dic = {'acl': items}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteACLFunc(self, request):
try:
request.session['userID'] = self.admin.pk
return um.deleteACLFunc(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchACLDetails(self, request):
try:
request.session['userID'] = self.admin.pk
return um.fetchACLDetails(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitACLModifications(self, request):
try:
request.session['userID'] = self.admin.pk
return um.submitACLModifications(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitPackage(self, request):
try:
request.session['userID'] = self.admin.pk
pm = PackagesManager(request)
return pm.submitPackage()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchPackages(self, request):
try:
userID = self.admin.pk
currentACL = ACLManager.loadedACL(userID)
if ACLManager.currentContextPermission(currentACL, 'deletePackage') == 0:
return ACLManager.loadError()
packageList = ACLManager.loadPackageObjects(userID, currentACL)
json_data = "["
checker = 0
for items in packageList:
dic = {
'packageName': items.packageName,
'allowedDomains': items.allowedDomains,
'diskSpace': items.diskSpace,
'bandwidth': items.bandwidth,
'emailAccounts': items.emailAccounts,
'dataBases': items.dataBases,
'ftpAccounts': items.ftpAccounts,
}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitPackageDelete(self, request):
try:
request.session['userID'] = self.admin.pk
pm = PackagesManager(request)
return pm.submitDelete()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitPackageModify(self, request):
try:
request.session['userID'] = self.admin.pk
pm = PackagesManager(request)
return pm.saveChanges()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getDataFromLogFile(self, request):
try:
wm = WebsiteManager()
return wm.getDataFromLogFile(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchErrorLogs(self, request):
try:
wm = WebsiteManager()
return wm.fetchErrorLogs(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitApplicationInstall(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
if self.data['selectedApplication'] == 'WordPress with LSCache':
return wm.installWordpress(self.admin.pk, self.data)
elif self.data['selectedApplication'] == 'Prestashop':
return wm.prestaShopInstall(self.admin.pk, self.data)
elif self.data['selectedApplication'] == 'Joomla':
return wm.installJoomla(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def obtainServer(self, request):
try:
request.session['userID'] = self.admin.pk
data_ret = {'status': 1, 'serverStatus': ProcessUtilities.decideServer()}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getSSHConfigs(self):
try:
fm = FirewallManager()
return fm.getSSHConfigs(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def saveSSHConfigs(self):
try:
fm = FirewallManager()
return fm.saveSSHConfigs(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteSSHKey(self):
try:
fm = FirewallManager()
return fm.deleteSSHKey(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def addSSHKey(self):
try:
fm = FirewallManager()
return fm.addSSHKey(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getCurrentRules(self):
try:
fm = FirewallManager()
return fm.getCurrentRules(self.admin.pk)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def addRule(self):
try:
fm = FirewallManager()
return fm.addRule(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteRule(self):
try:
fm = FirewallManager()
return fm.deleteRule(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getLogsFromFile(self, request):
try:
request.session['userID'] = self.admin.pk
return getLogsFromFile(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def serverSSL(self, request):
try:
request.session['userID'] = self.admin.pk
if self.data['type'] == 'hostname':
return obtainHostNameSSL(request)
else:
return obtainMailServerSSL(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def setupManager(self, request):
try:
request.session['userID'] = self.admin.pk
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
self.data['tempStatusPath'] = tempStatusPath
ham = HAManager(request, self.data, 'setupNode')
ham.start()
data = {}
data['tempStatusPath'] = tempStatusPath
proc = httpProc(request, None)
return proc.ajax(1, None, data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchManagerTokens(self, request):
try:
request.session['userID'] = self.admin.pk
ham = HAManager(request, self.data, 'fetchManagerTokens')
return ham.fetchManagerTokens()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def addWorker(self, request):
try:
request.session['userID'] = self.admin.pk
ham = HAManager(request, self.data, 'fetchManagerTokens')
return ham.addWorker()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchSSHKey(self, request):
try:
pubKey = os.path.join("/root", ".ssh", 'cyberpanel.pub')
execPath = "sudo cat " + pubKey
data = ProcessUtilities.outputExecutioner(execPath)
data_ret = {
'status': 1,
'error_message': "None",
'pubKey': data
}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def putSSHkeyFunc(self, request):
try:
fm = FirewallManager(request)
return fm.addSSHKey(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def leaveSwarm(self, request):
try:
request.session['userID'] = self.admin.pk
ham = HAManager(request, self.data, 'leaveSwarm')
return ham.leaveSwarm()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def setUpDataNode(self, request):
try:
request.session['userID'] = self.admin.pk
ham = HAManager(request, self.data, 'setUpDataNode')
return ham.setUpDataNode()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitEditCluster(self, request):
try:
request.session['userID'] = self.admin.pk
ham = HAManager(request, self.data, 'submitEditCluster')
return ham.submitEditCluster()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def connectAccount(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'connectAccount')
return s3.connectAccount()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBuckets(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBuckets')
return s3.fetchBuckets()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def createPlan(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'createPlan')
return s3.createPlan()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBackupPlans(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBackupPlans')
return s3.fetchBackupPlans()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deletePlan(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'deletePlan')
return s3.deletePlan()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchWebsitesInPlan(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchWebsitesInPlan')
return s3.fetchWebsitesInPlan()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteDomainFromPlan(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'deleteDomainFromPlan')
return s3.deleteDomainFromPlan()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def savePlanChanges(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'savePlanChanges')
return s3.savePlanChanges()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBackupLogs(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBackupLogs')
return s3.fetchBackupLogs()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def forceRunAWSBackup(self, request):
try:
request.session['userID'] = self.admin.pk
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/IncScheduler.py forceRunAWSBackup --planName %s" % (
self.data['planName'])
ProcessUtilities.popenExecutioner(execPath)
return self.ajaxPre(1, None)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def systemStatus(self, request):
try:
request.session['userID'] = self.admin.pk
return topProcessesStatus(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def killProcess(self, request):
try:
request.session['userID'] = self.admin.pk
return killProcess(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def connectAccountDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'connectAccountDO')
return s3.connectAccountDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBucketsDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBucketsDO')
return s3.fetchBucketsDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def createPlanDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'createPlanDO')
return s3.createPlanDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBackupPlansDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBackupPlansDO')
return s3.fetchBackupPlansDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deletePlanDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'deletePlanDO')
return s3.deletePlanDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchWebsitesInPlanDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchWebsitesInPlanDO')
return s3.fetchWebsitesInPlanDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBackupLogsDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBackupLogsDO')
return s3.fetchBackupLogsDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteDomainFromPlanDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'deleteDomainFromPlanDO')
return s3.deleteDomainFromPlanDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def savePlanChangesDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'savePlanChangesDO')
return s3.savePlanChangesDO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def forceRunAWSBackupDO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'forceRunAWSBackupDO')
s3.start()
return self.ajaxPre(1, None)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def showStatus(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.showStatus()
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchRam(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
# if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
# return self.ajaxPre(0, 'This feature is currently only available on CentOS.')
from psutil import virtual_memory
import math
finalData = {}
mem = virtual_memory()
inGB = math.ceil(float(mem.total) / float(1024 * 1024 * 1024))
finalData['ramInGB'] = inGB
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
finalData['conf'] = ProcessUtilities.outputExecutioner('sudo cat /etc/my.cnf')
else:
finalData['conf'] = ProcessUtilities.outputExecutioner('sudo cat /etc/mysql/my.cnf')
finalData['status'] = 1
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def applyMySQLChanges(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
result = mysqlUtilities.applyMySQLChanges(self.data)
if result[0] == 0:
return self.ajaxPre(0, result[1])
else:
return self.ajaxPre(1, None)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def restartMySQL(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.restartMySQL()
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchDatabasesMYSQL(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.fetchDatabases()
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchTables(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.fetchTables(self.data)
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteTable(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.deleteTable(self.data)
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchTableData(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.fetchTableData(self.data)
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchStructure(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.fetchStructure(self.data)
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def addMINIONode(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'addMINIONode')
return s3.addMINIONode()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchMINIONodes(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchMINIONodes')
return s3.fetchMINIONodes()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteMINIONode(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'deleteMINIONode')
return s3.deleteMINIONode()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def createPlanMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'createPlanMINIO')
return s3.createPlanMINIO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBackupPlansMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBackupPlansMINIO')
return s3.fetchBackupPlansMINIO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deletePlanMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'deletePlanMINIO')
return s3.deletePlanMINIO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def savePlanChangesMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'savePlanChangesMINIO')
return s3.savePlanChangesMINIO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def forceRunAWSBackupMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'forceRunAWSBackupMINIO')
s3.start()
return self.ajaxPre(1, None)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchWebsitesInPlanMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchWebsitesInPlanMINIO')
return s3.fetchWebsitesInPlanMINIO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchBackupLogsMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'fetchBackupLogsMINIO')
return s3.fetchBackupLogsMINIO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def deleteDomainFromPlanMINIO(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'deleteDomainFromPlanMINIO')
return s3.deleteDomainFromPlanMINIO()
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitWebsiteStatus(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.submitWebsiteStatus(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitChangePHP(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.changePHP(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getSwitchStatus(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.getSwitchStatus(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def switchServer(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.switchServer(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def tuneSettings(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.tuneSettings(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getCurrentPHPConfig(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.getCurrentPHPConfig(self.data['phpSelection'])
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def savePHPConfigBasic(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.savePHPConfigBasic(self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchPHPSettingsAdvance(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.fetchPHPSettingsAdvance(self.data['phpSelection'])
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def savePHPConfigAdvance(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.savePHPConfigAdvance(self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchPHPExtensions(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.fetchPHPExtensions(self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitExtensionRequest(self, request):
try:
request.session['userID'] = self.admin.pk
submitExtensionRequest(request)
return self.ajaxPre(1, 'None')
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getRequestStatus(self, request):
try:
request.session['userID'] = self.admin.pk
return getRequestStatusApache(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getContainerizationStatus(self, request):
try:
request.session['userID'] = self.admin.pk
finalData = {}
finalData['status'] = 1
if not ProcessUtilities.containerCheck():
finalData['notInstalled'] = 1
else:
finalData['notInstalled'] = 0
finalData = json.dumps(finalData)
return HttpResponse(finalData)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def submitContainerInstall(self, request):
try:
request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson()
c = ContainerManager(request, None, 'submitContainerInstall')
c.start()
data_ret = {'status': 1, 'error_message': 'None'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def switchTOLSWSStatus(self, request):
try:
request.session['userID'] = self.admin.pk
return switchTOLSWSStatus(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchWebsiteLimits(self, request):
try:
request.session['userID'] = self.admin.pk
return fetchWebsiteLimits(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def saveWebsiteLimits(self, request):
try:
request.session['userID'] = self.admin.pk
return saveWebsiteLimits(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getUsageData(self, request):
try:
request.session['userID'] = self.admin.pk
return getUsageData(request)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def RunServerLevelEmailChecks(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
reportFile = "/home/cyberpanel/" + str(randint(1000, 9999))
extraArgs = {'tempStatusPath': tempStatusPath, 'reportFile': reportFile}
background = MailServerManager(None, 'RunServerLevelEmailChecks', extraArgs)
background.start()
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath, 'reportFile': reportFile}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def ReadReport(self):
try:
reportFile = self.data['reportFile']
reportContent = open(reportFile, 'r').read()
data_ret = {'status': 1, 'reportContent': reportContent}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def ResetEmailConfigurations(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/mailServer/mailserverManager.py"
execPath = execPath + ' ResetEmailConfigurations --tempStatusPath %s' % (tempStatusPath)
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchAllSites(self):
try:
currentACL = ACLManager.loadedACL(self.admin.pk)
websites = ACLManager.findAllWebsites(currentACL, self.admin.pk)
final_dic = {'status': 1, 'websites': websites}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def debugEmailForSite(self):
try:
websiteName = self.data['websiteName']
result = MailServerManager(None, 'debugEmailForSite', None).debugEmailForSite(websiteName)
if result[0]:
final_dic = {'error_message': result[1], 'status': 1}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
final_dic = {'error_message': result[1], 'status': 0}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fixMailSSL(self, request):
try:
request.session['userID'] = self.admin.pk
msM = MailServerManager(request)
return msM.fixMailSSL(self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def ReadReportFTP(self):
try:
command = 'ps aux'
result = ProcessUtilities.outputExecutioner(command)
FTP = 1
if result.find('pure-ftpd') == -1:
FTP = 0
data_ret = {'status': 1, 'FTP': FTP}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def ResetFTPConfigurations(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/ftp/ftpManager.py"
execPath = execPath + ' ResetFTPConfigurations --tempStatusPath %s' % (tempStatusPath)
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def ReadReportDNS(self):
try:
command = 'ps aux'
result = ProcessUtilities.outputExecutioner(command)
DNS = 1
if result.find('pdns_server --guardian=no') == -1:
DNS = 0
data_ret = {'status': 1, 'DNS': DNS}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def ResetDNSConfigurations(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/dns/dnsManager.py"
execPath = execPath + ' ResetDNSConfigurations --tempStatusPath %s' % (tempStatusPath)
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def SubmitCloudBackup(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
try:
data = str(int(self.data['data']))
except:
data = '0'
try:
emails = str(int(self.data['emails']))
except:
emails = '0'
try:
databases = str(int(self.data['databases']))
except:
databases = '0'
try:
port = str(self.data['port'])
except:
port = '0'
try:
ip = str(self.data['ip'])
except:
ip = '0'
try:
destinationDomain = self.data['destinationDomain']
except:
destinationDomain = 'None'
import time
BackupPath = '/home/cyberpanel/backups/%s/backup-' % (self.data['domain']) + self.data['domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s " \
"--path %s --port %s --ip %s --destinationDomain %s" % (
self.data['domain'], data, emails, databases, tempStatusPath, BackupPath, port, ip, destinationDomain)
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath, 'path': '%s.tar.gz' % (BackupPath)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def getCurrentCloudBackups(self):
try:
backupDomain = self.data['domainName']
backupsPath = '/home/cyberpanel/backups/%s/' % (backupDomain)
try:
backups = os.listdir(backupsPath)
backups.reverse()
except:
backups = []
json_data = "["
checker = 0
counter = 1
for items in backups:
size = str(int(int(os.path.getsize('%s/%s' % (backupsPath, items))) / int(1048576)))
dic = {'id': counter,
'file': items,
'size': '%s MBs' % (size),
}
counter = counter + 1
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def fetchCloudBackupSettings(self):
try:
from plogical.backupUtilities import backupUtilities
if os.path.exists(backupUtilities.CloudBackupConfigPath):
result = json.loads(open(backupUtilities.CloudBackupConfigPath, 'r').read())
self.nice = result['nice']
self.cpu = result['cpu']
self.time = result['time']
else:
self.nice = backupUtilities.NiceDefault
self.cpu = backupUtilities.CPUDefault
self.time = backupUtilities.time
data_ret = {'status': 1, 'nice': self.nice, 'cpu': self.cpu, 'time': self.time}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def saveCloudBackupSettings(self):
try:
from plogical.backupUtilities import backupUtilities
writeToFile = open(backupUtilities.CloudBackupConfigPath, 'w')
writeToFile.write(json.dumps(self.data))
writeToFile.close()
data_ret = {'status': 1}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def deleteCloudBackup(self):
try:
backupDomain = self.data['domainName']
backupFile = self.data['backupFile']
backupsPathComplete = '/home/cyberpanel/backups/%s/%s' % (backupDomain, backupFile)
command = 'rm -f %s' % (backupsPathComplete)
ProcessUtilities.executioner(command)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def SubmitCloudBackupRestore(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
try:
sourceDomain = self.data['sourceDomain']
except:
sourceDomain = 'None'
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --sourceDomain %s --tempStoragePath %s" % (
self.data['domain'], self.data['backupFile'],sourceDomain, tempStatusPath)
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def fetchAWSKeys(self):
path = '/home/cyberpanel/.aws'
credentials = path + '/credentials'
data = open(credentials, 'r').readlines()
aws_access_key_id = data[1].split(' ')[2].strip(' ').strip('\n')
aws_secret_access_key = data[2].split(' ')[2].strip(' ').strip('\n')
region = data[3].split(' ')[2].strip(' ').strip('\n')
return aws_access_key_id, aws_secret_access_key, region
def getCurrentS3Backups(self):
try:
import boto3
from s3Backups.models import BackupPlan, BackupLogs
plan = BackupPlan.objects.get(name=self.data['planName'])
aws_access_key_id, aws_secret_access_key, region = self.fetchAWSKeys()
if region.find('http') > -1:
s3 = boto3.resource(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
endpoint_url=region
)
else:
s3 = boto3.resource(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
)
bucket = s3.Bucket(plan.bucket)
key = '%s/%s/' % (plan.name, self.data['domainName'])
backups = []
for file in bucket.objects.filter(Prefix=key):
backups.append({'key': file.key, 'size': file.size})
json_data = "["
checker = 0
counter = 1
for items in backups:
dic = {'id': counter,
'file': items['key'],
'size': items['size'],
}
counter = counter + 1
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def deleteS3Backup(self):
try:
import boto3
from s3Backups.models import BackupPlan, BackupLogs
plan = BackupPlan.objects.get(name=self.data['planName'])
aws_access_key_id, aws_secret_access_key, region = self.fetchAWSKeys()
if region.find('http') > -1:
s3 = boto3.resource(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
endpoint_url=region
)
else:
s3 = boto3.resource(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
)
s3.Object(plan.bucket, self.data['backupFile']).delete()
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def SubmitS3BackupRestore(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " SubmitS3BackupRestore --backupDomain %s --backupFile '%s' --tempStoragePath %s --planName %s" % (
self.data['domain'], self.data['backupFile'], tempStatusPath, self.data['planName'])
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def DeployWordPress(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/applicationInstaller.py"
execPath = execPath + " DeployWordPress --tempStatusPath %s --appsSet '%s' --domain '%s' --email '%s' --password '%s' " \
"--pluginUpdates '%s' --themeUpdates '%s' --title '%s' --updates '%s' --userName '%s' " \
"--version '%s' --createSite %s" % (
tempStatusPath, self.data['appsSet'], self.data['domain'], self.data['email'],
self.data['password'],
self.data['pluginUpdates'], self.data['themeUpdates'], self.data['title'],
self.data['updates'],
self.data['userName'], self.data['version'], str(self.data['createSite']))
try:
execPath = '%s --path %s' % (execPath, self.data['path'])
except:
pass
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def FetchWordPressDetails(self):
try:
finalDic = {}
domain = self.data['domain']
finalDic['status'] = 1
finalDic['maintenanceMode'] = 1
finalDic['php'] = '7.4'
## Get versopm
website = Websites.objects.get(domain=domain)
command = 'wp core version --path=/home/%s/public_html' % (domain)
finalDic['version'] = ProcessUtilities.outputExecutioner(command, website.externalApp)
## LSCache
command = 'wp plugin status litespeed-cache --path=/home/%s/public_html' % (domain)
result = ProcessUtilities.outputExecutioner(command, website.externalApp)
if result.find('Status: Active') > -1:
finalDic['lscache'] = 1
else:
finalDic['lscache'] = 0
## Debug
command = 'wp config list --path=/home/%s/public_html' % (domain)
result = ProcessUtilities.outputExecutioner(command, website.externalApp).split('\n')
finalDic['debugging'] = 0
for items in result:
if items.find('WP_DEBUG') > -1 and items.find('1') > - 1:
finalDic['debugging'] = 1
break
## Search index
command = 'wp option get blog_public --path=/home/%s/public_html' % (domain)
finalDic['searchIndex'] = int(ProcessUtilities.outputExecutioner(command, website.externalApp).rstrip('\n'))
## Maintenece mode
command = 'wp maintenance-mode status --path=/home/%s/public_html' % (domain)
result = ProcessUtilities.outputExecutioner(command, website.externalApp)
if result.find('not active') > -1:
finalDic['maintenanceMode'] = 0
else:
finalDic['maintenanceMode'] = 1
## Get title
command = 'wp option get blogname --path=/home/%s/public_html' % (domain)
finalDic['title'] = ProcessUtilities.outputExecutioner(command, website.externalApp)
##
final_json = json.dumps(finalDic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def AutoLogin(self):
try:
## Get versopm
website = Websites.objects.get(domain=self.data['domain'])
## Get title
import plogical.randomPassword as randomPassword
password = randomPassword.generate_pass(32)
command = 'wp user create cyberpanel support@cyberpanel.cloud --role=administrator --user_pass="%s" --path=/home/%s/public_html' % (password, self.data['domain'])
ProcessUtilities.executioner(command, website.externalApp)
command = 'wp user update cyberpanel --user_pass="%s" --path=/home/%s/public_html' % (password, self.data['domain'])
ProcessUtilities.executioner(command, website.externalApp)
finalDic = {'status': 1, 'password': password}
final_json = json.dumps(finalDic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def UpdateWPSettings(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
domain = self.data['domain']
if self.data['setting'] == 'lscache':
if self.data['settingValue']:
command = "wp plugin install litespeed-cache --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
command = "wp plugin activate litespeed-cache --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'LSCache successfully installed and activated.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
command = 'wp plugin deactivate litespeed-cache --path=/home/%s/public_html' % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'LSCache successfully deactivated.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
elif self.data['setting'] == 'debugging':
if self.data['settingValue']:
command = "wp config set WP_DEBUG true --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'WordPress is now in debug mode.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
command = "wp config set WP_DEBUG false --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'WordPress debug mode turned off.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
elif self.data['setting'] == 'searchIndex':
if self.data['settingValue']:
command = "wp option update blog_public 1 --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'Search Engine Indexing enabled.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
command = "wp option update blog_public 0 --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'Search Engine Indexing disabled.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
elif self.data['setting'] == 'maintenanceMode':
if self.data['settingValue']:
command = "wp maintenance-mode activate --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'WordPress Maintenance mode turned on.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
command = "wp maintenance-mode deactivate --path=/home/%s/public_html" % (domain)
ProcessUtilities.executioner(command, website.externalApp)
final_dic = {'status': 1, 'message': 'WordPress Maintenance mode turned off.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def GetCurrentPlugins(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
command = 'wp plugin list --format=json --path=/home/%s/public_html' % (self.data['domain'])
json_data = ProcessUtilities.outputExecutioner(command, website.externalApp)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def UpdatePlugins(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
if self.data['plugin'] == 'all':
command = 'wp plugin update --all --path=/home/%s/public_html' % (self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'message': "Plugin updates started in the background."})
return HttpResponse(final_json)
elif self.data['plugin'] == 'selected':
if self.data['allPluginsChecked']:
command = 'wp plugin update --all --path=/home/%s/public_html' % (self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin updates started in the background."})
return HttpResponse(final_json)
else:
pluginsList = ''
for plugin in self.data['plugins']:
pluginsList = '%s %s' % (pluginsList, plugin)
command = 'wp plugin update %s --path=/home/%s/public_html' % (pluginsList, self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin updates started in the background."})
return HttpResponse(final_json)
else:
command = 'wp plugin update %s --path=/home/%s/public_html' % (self.data['plugin'], self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin updates started in the background."})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def ChangeState(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
command = 'wp plugin status %s --path=/home/%s/public_html' % (self.data['plugin'], self.data['domain'])
result = ProcessUtilities.outputExecutioner(command, website.externalApp)
if result.find('Status: Active') > -1:
command = 'wp plugin deactivate %s --path=/home/%s/public_html' % (
self.data['plugin'], self.data['domain'])
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin successfully deactivated."})
return HttpResponse(final_json)
else:
command = 'wp plugin activate %s --path=/home/%s/public_html' % (
self.data['plugin'], self.data['domain'])
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin successfully activated."})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def DeletePlugins(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
if self.data['plugin'] == 'selected':
pluginsList = ''
for plugin in self.data['plugins']:
pluginsList = '%s %s' % (pluginsList, plugin)
command = 'wp plugin delete %s --path=/home/%s/public_html' % (pluginsList, self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin deletion started in the background."})
return HttpResponse(final_json)
else:
command = 'wp plugin delete %s --path=/home/%s/public_html' % (self.data['plugin'], self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin deletion started in the background."})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def GetCurrentThemes(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
command = 'wp theme list --format=json --path=/home/%s/public_html' % (self.data['domain'])
json_data = ProcessUtilities.outputExecutioner(command, website.externalApp)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def UpdateThemes(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
if self.data['plugin'] == 'all':
command = 'wp theme update --all --path=/home/%s/public_html' % (self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'message': "Theme updates started in the background."})
return HttpResponse(final_json)
elif self.data['plugin'] == 'selected':
if self.data['allPluginsChecked']:
command = 'wp theme update --all --path=/home/%s/public_html' % (self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme updates started in the background."})
return HttpResponse(final_json)
else:
pluginsList = ''
for plugin in self.data['plugins']:
pluginsList = '%s %s' % (pluginsList, plugin)
command = 'wp theme update %s --path=/home/%s/public_html' % (pluginsList, self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme updates started in the background."})
return HttpResponse(final_json)
else:
command = 'wp theme update %s --path=/home/%s/public_html' % (self.data['plugin'], self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme updates started in the background."})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def ChangeStateThemes(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
command = 'wp theme status %s --path=/home/%s/public_html' % (self.data['plugin'], self.data['domain'])
result = ProcessUtilities.outputExecutioner(command, website.externalApp)
if result.find('Status: Active') > -1:
command = 'wp theme deactivate %s --path=/home/%s/public_html' % (
self.data['plugin'], self.data['domain'])
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme successfully deactivated."})
return HttpResponse(final_json)
else:
command = 'wp theme activate %s --path=/home/%s/public_html' % (
self.data['plugin'], self.data['domain'])
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme successfully activated."})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def DeleteThemes(self):
try:
website = Websites.objects.get(domain=self.data['domain'])
if self.data['plugin'] == 'selected':
pluginsList = ''
for plugin in self.data['plugins']:
pluginsList = '%s %s' % (pluginsList, plugin)
command = 'wp theme delete %s --path=/home/%s/public_html' % (pluginsList, self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin Theme started in the background."})
return HttpResponse(final_json)
else:
command = 'wp theme delete %s --path=/home/%s/public_html' % (self.data['plugin'], self.data['domain'])
ProcessUtilities.popenExecutioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme deletion started in the background."})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def GetServerPublicSSHkey(self):
try:
path = '/root/.ssh/cyberpanel.pub'
command = 'cat %s' % (path)
key = ProcessUtilities.outputExecutioner(command)
final_dic = {'status': 1, 'key': key}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def SubmitPublicKey(self):
try:
fm = FirewallManager()
fm.addSSHKey(self.admin.pk, self.data)
## Create backup path so that file can be sent here later.
BackupPath = '/home/cyberpanel/backups/%s' % (self.data['domain'])
command = 'mkdir -p %s' % (BackupPath)
ProcessUtilities.executioner(command, 'cyberpanel')
###
from WebTerminal.CPWebSocket import SSHServer
SSHServer.findSSHPort()
final_dic = {'status': 1, 'port': SSHServer.DEFAULT_PORT}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def CreateStaging(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.startCloning(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def startSync(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.startSync(self.admin.pk, self.data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def SaveAutoUpdateSettings(self):
try:
website = Websites.objects.get(domain=self.data['domainName'])
domainName = self.data['domainName']
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
config = json.loads(wpd.config)
config['updates'] = self.data['wpCore']
config['pluginUpdates'] = self.data['plugins']
config['themeUpdates'] = self.data['themes']
wpd.config = json.dumps(config)
wpd.save()
if self.data['wpCore'] == 'Disabled':
command = "wp config set WP_AUTO_UPDATE_CORE false --raw --path=/home/%s/public_html" % (domainName)
ProcessUtilities.executioner(command, website.externalApp)
elif self.data['wpCore'] == 'Minor and Security Updates':
command = "wp config set WP_AUTO_UPDATE_CORE minor --allow-root --path=/home/%s/public_html" % (domainName)
ProcessUtilities.executioner(command, website.externalApp)
else:
command = "wp config set WP_AUTO_UPDATE_CORE true --raw --allow-root --path=/home/%s/public_html" % (domainName)
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'message': "Autoupdates configured."})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def fetchWPSettings(self):
try:
cliVersion = ProcessUtilities.outputExecutioner('wp --version --allow-root')
if cliVersion.find('not found') > -1:
cliVersion = 'WP CLI Not installed.'
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
localCronPath = "/var/spool/cron/root"
else:
localCronPath = "/var/spool/cron/crontabs/root"
cronData = ProcessUtilities.outputExecutioner('cat %s' % (localCronPath)).split('\n')
finalCron = ''
for cronLine in cronData:
if cronLine.find('WPAutoUpdates.py') > -1:
finalCron = cronLine
if finalCron.find('WPAutoUpdates.py') == -1:
finalCron = 'Not Set'
final_json = json.dumps(
{'status': 1, 'cliVersion': cliVersion, 'finalCron': finalCron})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def updateWPCLI(self):
try:
command = 'wp cli update'
ProcessUtilities.executioner(command)
final_json = json.dumps({'status': 1})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def saveWPSettings(self):
try:
command = 'wp cli update'
ProcessUtilities.executioner(command)
final_json = json.dumps({'status': 1})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def WPScan(self):
try:
path = '/home/%s/public_html' % (self.data['domainName'])
command = 'wp core version --allow-root --path=%s' % (path)
result = ProcessUtilities.outputExecutioner(command)
if result.find('Error:') > -1:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': 'This does not seem to be a WordPress installation'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
final_json = json.dumps({'status': 1})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)