Files
CyberPanel/cloudAPI/cloudManager.py

2811 lines
106 KiB
Python
Raw Normal View History

2021-04-01 11:47:47 +05:00
import sys
2019-03-13 23:05:22 +05:00
import userManagment.views as um
from backup.backupManager import BackupManager
2018-11-08 13:19:36 +05:00
from databases.databaseManager import DatabaseManager
from dns.dnsManager import DNSManager
2019-03-13 23:05:22 +05:00
from firewall.firewallManager import FirewallManager
2018-11-08 13:19:36 +05:00
from ftp.ftpManager import FTPManager
2019-03-13 23:05:22 +05:00
from highAvailability.haManager import HAManager
from loginSystem.models import Administrator
from mailServer.mailserverManager import MailServerManager
2018-11-26 02:32:30 +05:00
from manageSSL.views import issueSSL, obtainHostNameSSL, obtainMailServerSSL
2018-11-16 14:41:40 +05:00
from packages.packagesManager import PackagesManager
2019-03-13 23:05:22 +05:00
from plogical.mysqlUtilities import mysqlUtilities
from plogical.virtualHostUtilities import virtualHostUtilities
2019-08-03 14:53:31 +05:00
from websiteFunctions.website import WebsiteManager
2018-12-13 04:23:08 +05:00
from s3Backups.s3Backups import S3Backups
2019-03-13 23:05:22 +05:00
from serverLogs.views import getLogsFromFile
2019-06-08 21:41:43 +00:00
from serverStatus.views import topProcessesStatus, killProcess, switchTOLSWSStatus
2019-04-22 03:38:40 +05:00
from plogical import hashPassword
from loginSystem.models import ACL
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
2019-06-08 21:41:43 +00:00
from managePHP.phpManager import PHPManager
from managePHP.views import submitExtensionRequest, getRequestStatusApache
from containerization.views import *
2021-04-01 11:47:47 +05:00
sys.path.append('/usr/local/CyberCP')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
2018-11-08 13:19:36 +05:00
class CloudManager:
2020-12-22 12:12:41 +05:00
def __init__(self, data=None, admin=None):
2018-11-08 13:19:36 +05:00
self.data = data
2018-11-20 15:43:43 +05:00
self.admin = admin
2018-11-08 13:19:36 +05:00
def ajaxPre(self, status, errorMessage):
final_dic = {'status': status, 'error_message': errorMessage}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
2018-11-20 15:43:43 +05:00
def verifyLogin(self, request):
2018-11-08 13:19:36 +05:00
try:
2018-11-20 15:43:43 +05:00
if request.META['HTTP_AUTHORIZATION'] == self.admin.token:
return 1, self.ajaxPre(1, None)
2018-11-08 13:19:36 +05:00
else:
2018-11-20 15:43:43 +05:00
return 0, self.ajaxPre(0, 'Invalid login information.')
2018-11-08 13:19:36 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchWebsites(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.getFurtherAccounts(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitWebsiteDeletion(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
return wm.submitWebsiteDeletion(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitWebsiteCreation(self):
try:
2019-04-22 03:38:40 +05:00
try:
2020-09-15 09:35:55 +05:00
2019-04-22 03:38:40 +05:00
UserAccountName = self.data['UserAccountName']
UserPassword = self.data['UserPassword']
FullName = self.data['FullName']
token = hashPassword.generateToken(UserAccountName, UserPassword)
password = hashPassword.hash_password(UserPassword)
2020-09-15 09:35:55 +05:00
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
2019-04-22 03:38:40 +05:00
try:
newAdmin = Administrator(firstName=FullName,
lastName="",
email=self.data['adminEmail'],
type=3,
userName=UserAccountName,
password=password,
2020-09-15 09:35:55 +05:00
initWebsitesLimit=initWebsitesLimit,
2019-04-22 03:38:40 +05:00
owner=1,
acl=selectedACL,
2020-09-15 09:35:55 +05:00
token=token,
api=apiAccess
2019-04-22 03:38:40 +05:00
)
newAdmin.save()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-04-22 03:38:40 +05:00
logging.writeToFile(str(msg))
admin = Administrator.objects.get(userName=UserAccountName)
admin.token = token
admin.password = password
admin.save()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-04-22 03:38:40 +05:00
logging.writeToFile(str(msg))
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.submitWebsiteCreation(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchWebsiteDataJSON(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.fetchWebsiteDataJSON(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchWebsiteData(self):
try:
2018-11-20 15:43:43 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
website = Websites.objects.get(domain=self.data['domainName'])
admin = Administrator.objects.get(pk=self.admin.pk)
2018-11-08 13:19:36 +05:00
2018-11-20 15:43:43 +05:00
if ACLManager.checkOwnership(self.data['domainName'], admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
2018-11-08 13:19:36 +05:00
2018-11-20 15:43:43 +05:00
Data = {}
2018-11-08 13:19:36 +05:00
2018-11-20 15:43:43 +05:00
Data['ftpAllowed'] = website.package.ftpAccounts
Data['ftpUsed'] = website.users_set.all().count()
2018-11-08 13:19:36 +05:00
2018-11-20 15:43:43 +05:00
Data['dbUsed'] = website.databases_set.all().count()
Data['dbAllowed'] = website.package.dataBases
2018-11-08 13:19:36 +05:00
DiskUsage, DiskUsagePercentage, bwInMB, bwUsage = virtualHostUtilities.FindStats(website)
2018-11-08 13:19:36 +05:00
2018-11-20 15:43:43 +05:00
## bw usage calculations
2018-11-08 13:19:36 +05:00
Data['bwInMBTotal'] = website.package.bandwidth
Data['bwInMB'] = bwInMB
Data['bwUsage'] = bwUsage
2018-11-08 13:19:36 +05:00
if DiskUsagePercentage > 100:
DiskUsagePercentage = 100
2018-11-08 13:19:36 +05:00
Data['diskUsage'] = DiskUsagePercentage
Data['diskInMB'] = DiskUsage
Data['diskInMBTotal'] = website.package.diskSpace
##
2018-11-20 15:43:43 +05:00
Data['status'] = 1
final_json = json.dumps(Data)
return HttpResponse(final_json)
2018-11-08 13:19:36 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchModifyData(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.submitWebsiteModify(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def saveModifications(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.saveWebsiteChanges(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitDBCreation(self):
try:
2018-11-20 15:43:43 +05:00
dm = DatabaseManager()
return dm.submitDBCreation(self.admin.pk, self.data, 1)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchDatabases(self):
try:
2018-11-20 15:43:43 +05:00
dm = DatabaseManager()
return dm.fetchDatabases(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitDatabaseDeletion(self):
try:
2018-11-20 15:43:43 +05:00
dm = DatabaseManager()
return dm.submitDatabaseDeletion(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def changePassword(self):
try:
2018-11-20 15:43:43 +05:00
dm = DatabaseManager()
return dm.changePassword(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def getCurrentRecordsForDomain(self):
try:
2018-11-20 15:43:43 +05:00
dm = DNSManager()
return dm.getCurrentRecordsForDomain(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def deleteDNSRecord(self):
try:
2018-11-20 15:43:43 +05:00
dm = DNSManager()
return dm.deleteDNSRecord(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def addDNSRecord(self):
try:
2018-11-20 15:43:43 +05:00
dm = DNSManager()
return dm.addDNSRecord(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitEmailCreation(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitEmailCreation()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def getEmailsForDomain(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.getEmailsForDomain()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitEmailDeletion(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitEmailDeletion()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitPasswordChange(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitPasswordChange()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchCurrentForwardings(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.fetchCurrentForwardings()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitForwardDeletion(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitForwardDeletion()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitEmailForwardingCreation(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.submitEmailForwardingCreation()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchDKIMKeys(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.fetchDKIMKeys()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def generateDKIMKeys(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
msm = MailServerManager(request)
return msm.generateDKIMKeys()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitFTPCreation(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.submitFTPCreation()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def getAllFTPAccounts(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.getAllFTPAccounts()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitFTPDelete(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.submitFTPDelete()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def changeFTPPassword(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
fm = FTPManager(request)
return fm.changePassword()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def issueSSL(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return issueSSL(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def statusFunc(self):
try:
statusFile = self.data['statusFile']
statusData = open(statusFile, 'r').readlines()
2020-11-06 12:07:39 +05:00
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..'}
2018-11-08 13:19:36 +05:00
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
2018-11-08 13:19:36 +05:00
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def submitDomainCreation(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.submitDomainCreation(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def fetchDomains(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.fetchDomains(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def submitDomainDeletion(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.submitDomainDeletion(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def changeOpenBasedir(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.changeOpenBasedir(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def changePHP(self):
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.changePHP(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def backupStatusFunc(self):
try:
2018-11-20 15:43:43 +05:00
bm = BackupManager()
return bm.backupStatus(self.admin.pk, self.data)
2018-11-08 13:19:36 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
2018-11-08 13:19:36 +05:00
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def submitBackupCreation(self):
try:
2018-11-20 15:43:43 +05:00
bm = BackupManager()
return bm.submitBackupCreation(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def getCurrentBackups(self):
try:
2018-11-20 15:43:43 +05:00
bm = BackupManager()
return bm.getCurrentBackups(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
def deleteBackup(self):
try:
2018-11-20 15:43:43 +05:00
bm = BackupManager()
return bm.deleteBackup(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-08 13:19:36 +05:00
return self.ajaxPre(0, str(msg))
2018-11-16 14:41:40 +05:00
def fetchACLs(self):
try:
2018-11-20 15:43:43 +05:00
userID = self.admin.pk
currentACL = ACLManager.loadedACL(userID)
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
if currentACL['admin'] == 1:
aclNames = ACLManager.unFileteredACLs()
elif currentACL['changeUserACL'] == 1:
aclNames = ACLManager.unFileteredACLs()
elif currentACL['createNewUser'] == 1:
aclNames = ['user']
else:
return ACLManager.loadError()
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
json_data = "["
checker = 0
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
for items in aclNames:
dic = {'acl': items}
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
2018-11-16 14:41:40 +05:00
else:
2018-11-20 15:43:43 +05:00
json_data = json_data + ',' + json.dumps(dic)
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
2018-11-16 14:41:40 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def submitUserCreation(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return um.submitUserCreation(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def fetchUsers(self):
try:
2018-11-20 15:43:43 +05:00
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)
2018-11-16 14:41:40 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def submitUserDeletion(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return um.submitUserDeletion(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def saveModificationsUser(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return um.saveModifications(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def userWithResellerPriv(self):
try:
2018-11-20 15:43:43 +05:00
userID = self.admin.pk
allUsers = ACLManager.userWithResellerPriv(userID)
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
json_data = "["
checker = 0
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
for user in allUsers:
dic = {
"userName": user,
}
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def saveResellerChanges(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return um.saveResellerChanges(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def changeACLFunc(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return um.changeACLFunc(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def createACLFunc(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return um.createACLFunc(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def findAllACLs(self, request):
try:
2018-11-20 15:43:43 +05:00
userID = self.admin.pk
currentACL = ACLManager.loadedACL(userID)
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
if currentACL['admin'] == 1:
aclNames = ACLManager.findAllACLs()
else:
return ACLManager.loadErrorJson()
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
json_data = "["
checker = 0
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
for items in aclNames:
dic = {'acl': items}
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
2018-11-16 14:41:40 +05:00
else:
2018-11-20 15:43:43 +05:00
json_data = json_data + ',' + json.dumps(dic)
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
return HttpResponse(final_json)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
def deleteACLFunc(self, request):
try:
2018-11-20 15:43:43 +05:00
request.session['userID'] = self.admin.pk
return um.deleteACLFunc(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
return self.ajaxPre(0, str(msg))
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
def fetchACLDetails(self, request):
try:
request.session['userID'] = self.admin.pk
return um.fetchACLDetails(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
return self.ajaxPre(0, str(msg))
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
def submitACLModifications(self, request):
try:
request.session['userID'] = self.admin.pk
return um.submitACLModifications(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
return self.ajaxPre(0, str(msg))
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
def submitPackage(self, request):
try:
request.session['userID'] = self.admin.pk
pm = PackagesManager(request)
return pm.submitPackage()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
2018-11-20 15:43:43 +05:00
def fetchPackages(self, request):
2018-11-16 14:41:40 +05:00
try:
2018-11-20 15:43:43 +05:00
userID = self.admin.pk
currentACL = ACLManager.loadedACL(userID)
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
if ACLManager.currentContextPermission(currentACL, 'deletePackage') == 0:
return ACLManager.loadError()
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
packageList = ACLManager.loadPackageObjects(userID, currentACL)
json_data = "["
checker = 0
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
2018-11-20 15:43:43 +05:00
def submitPackageDelete(self, request):
2018-11-16 14:41:40 +05:00
try:
2019-04-22 03:38:40 +05:00
request.session['userID'] = self.admin.pk
2018-11-20 15:43:43 +05:00
pm = PackagesManager(request)
return pm.submitDelete()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
return self.ajaxPre(0, str(msg))
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
def submitPackageModify(self, request):
try:
2019-04-22 03:38:40 +05:00
request.session['userID'] = self.admin.pk
2018-11-20 15:43:43 +05:00
pm = PackagesManager(request)
return pm.saveChanges()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
return self.ajaxPre(0, str(msg))
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
def getDataFromLogFile(self, request):
try:
wm = WebsiteManager()
return wm.getDataFromLogFile(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
2018-11-20 15:43:43 +05:00
def fetchErrorLogs(self, request):
2018-11-16 14:41:40 +05:00
try:
2018-11-20 15:43:43 +05:00
wm = WebsiteManager()
return wm.fetchErrorLogs(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
return self.ajaxPre(0, str(msg))
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
def submitApplicationInstall(self, request):
try:
request.session['userID'] = self.admin.pk
wm = WebsiteManager()
2018-11-16 14:41:40 +05:00
2018-11-20 15:43:43 +05:00
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)
2018-11-16 14:41:40 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-16 14:41:40 +05:00
return self.ajaxPre(0, str(msg))
2018-11-20 15:43:43 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-20 15:43:43 +05:00
return self.ajaxPre(0, str(msg))
2018-11-21 14:50:27 +05:00
def getSSHConfigs(self):
try:
fm = FirewallManager()
return fm.getSSHConfigs(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
def saveSSHConfigs(self):
try:
fm = FirewallManager()
return fm.saveSSHConfigs(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
def deleteSSHKey(self):
try:
fm = FirewallManager()
return fm.deleteSSHKey(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
def addSSHKey(self):
try:
fm = FirewallManager()
return fm.addSSHKey(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
def getCurrentRules(self):
try:
fm = FirewallManager()
return fm.getCurrentRules(self.admin.pk)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
def addRule(self):
try:
fm = FirewallManager()
return fm.addRule(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
def deleteRule(self):
try:
fm = FirewallManager()
return fm.deleteRule(self.admin.pk, self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
def getLogsFromFile(self, request):
try:
request.session['userID'] = self.admin.pk
return getLogsFromFile(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-21 14:50:27 +05:00
return self.ajaxPre(0, str(msg))
2018-11-26 02:32:30 +05:00
def serverSSL(self, request):
try:
request.session['userID'] = self.admin.pk
if self.data['type'] == 'hostname':
return obtainHostNameSSL(request)
else:
return obtainMailServerSSL(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-26 02:32:30 +05:00
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)
2019-12-10 15:09:10 +05:00
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()
2019-12-10 15:09:10 +05:00
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()
2019-12-10 15:09:10 +05:00
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
2019-03-21 23:26:42 +05:00
data = ProcessUtilities.outputExecutioner(execPath)
data_ret = {
'status': 1,
'error_message': "None",
'pubKey': data
}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2019-12-10 15:09:10 +05:00
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)
2019-12-10 15:09:10 +05:00
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()
2019-12-10 15:09:10 +05:00
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()
2019-12-10 15:09:10 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
return self.ajaxPre(0, str(msg))
2018-12-13 04:23:08 +05:00
def connectAccount(self, request):
try:
request.session['userID'] = self.admin.pk
s3 = S3Backups(request, self.data, 'connectAccount')
return s3.connectAccount()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
return self.ajaxPre(0, str(msg))
def forceRunAWSBackup(self, request):
try:
2020-12-08 07:35:30 +05:00
2018-12-13 04:23:08 +05:00
request.session['userID'] = self.admin.pk
2020-12-08 07:35:30 +05:00
2020-12-22 12:12:41 +05:00
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/IncScheduler.py forceRunAWSBackup --planName %s" % (
self.data['planName'])
2020-12-08 07:35:30 +05:00
ProcessUtilities.popenExecutioner(execPath)
2018-12-13 04:23:08 +05:00
return self.ajaxPre(1, None)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-13 04:23:08 +05:00
return self.ajaxPre(0, str(msg))
2018-12-24 20:21:14 +05:00
def systemStatus(self, request):
try:
2020-04-08 16:54:50 +05:00
request.session['userID'] = self.admin.pk
2018-12-24 20:21:14 +05:00
return topProcessesStatus(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-24 20:21:14 +05:00
return self.ajaxPre(0, str(msg))
def killProcess(self, request):
try:
request.session['userID'] = self.admin.pk
return killProcess(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
return self.ajaxPre(0, str(msg))
def showStatus(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2018-12-31 22:55:17 +05:00
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.showStatus()
finalData = json.dumps(finalData)
return HttpResponse(finalData)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
return self.ajaxPre(0, str(msg))
def fetchRam(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2018-12-31 22:55:17 +05:00
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
2020-12-22 12:12:41 +05:00
# if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
2019-01-13 23:58:09 +05:00
# return self.ajaxPre(0, 'This feature is currently only available on CentOS.')
2019-01-01 20:16:54 +05:00
2018-12-31 22:55:17 +05:00
from psutil import virtual_memory
import math
finalData = {}
mem = virtual_memory()
2020-12-22 12:12:41 +05:00
inGB = math.ceil(float(mem.total) / float(1024 * 1024 * 1024))
2018-12-31 22:55:17 +05:00
finalData['ramInGB'] = inGB
2019-01-01 20:16:54 +05:00
2020-05-24 10:51:14 +01:00
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
2019-03-26 16:19:03 +05:00
finalData['conf'] = ProcessUtilities.outputExecutioner('sudo cat /etc/my.cnf')
2019-01-01 20:16:54 +05:00
else:
2019-03-26 16:19:03 +05:00
finalData['conf'] = ProcessUtilities.outputExecutioner('sudo cat /etc/mysql/my.cnf')
2019-01-01 20:16:54 +05:00
2018-12-31 22:55:17 +05:00
finalData['status'] = 1
finalData = json.dumps(finalData)
return HttpResponse(finalData)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-12-31 22:55:17 +05:00
return self.ajaxPre(0, str(msg))
def applyMySQLChanges(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2018-12-31 22:55:17 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-01 20:16:54 +05:00
return self.ajaxPre(0, str(msg))
def restartMySQL(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2019-01-01 20:16:54 +05:00
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.restartMySQL()
2019-01-08 22:38:33 +05:00
finalData = json.dumps(finalData)
return HttpResponse(finalData)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-08 22:38:33 +05:00
return self.ajaxPre(0, str(msg))
def fetchDatabasesMYSQL(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2019-01-08 22:38:33 +05:00
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.fetchDatabases()
finalData = json.dumps(finalData)
return HttpResponse(finalData)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-08 22:38:33 +05:00
return self.ajaxPre(0, str(msg))
def fetchTables(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2019-01-08 22:38:33 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-08 22:38:33 +05:00
return self.ajaxPre(0, str(msg))
def deleteTable(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2019-01-08 22:38:33 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-08 22:38:33 +05:00
return self.ajaxPre(0, str(msg))
def fetchTableData(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2019-01-08 22:38:33 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-08 22:38:33 +05:00
return self.ajaxPre(0, str(msg))
def fetchStructure(self, request):
try:
request.session['userID'] = self.admin.pk
2020-12-22 12:12:41 +05:00
currentACL = ACLManager.loadedACL(self.admin.pk)
2019-01-08 22:38:33 +05:00
if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
finalData = mysqlUtilities.fetchStructure(self.data)
2019-01-01 20:16:54 +05:00
finalData = json.dumps(finalData)
return HttpResponse(finalData)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-01-16 15:08:41 +05:00
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()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-04-22 03:38:40 +05:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def getCurrentPHPConfig(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.getCurrentPHPConfig(self.data['phpSelection'])
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def savePHPConfigBasic(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.savePHPConfigBasic(self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def fetchPHPSettingsAdvance(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.fetchPHPSettingsAdvance(self.data['phpSelection'])
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def savePHPConfigAdvance(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.savePHPConfigAdvance(self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def fetchPHPExtensions(self, request):
try:
request.session['userID'] = self.admin.pk
return PHPManager.fetchPHPExtensions(self.data)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def submitExtensionRequest(self, request):
try:
request.session['userID'] = self.admin.pk
submitExtensionRequest(request)
return self.ajaxPre(1, 'None')
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def getRequestStatus(self, request):
try:
request.session['userID'] = self.admin.pk
return getRequestStatusApache(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
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)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def switchTOLSWSStatus(self, request):
try:
request.session['userID'] = self.admin.pk
return switchTOLSWSStatus(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def fetchWebsiteLimits(self, request):
try:
request.session['userID'] = self.admin.pk
return fetchWebsiteLimits(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def saveWebsiteLimits(self, request):
try:
request.session['userID'] = self.admin.pk
return saveWebsiteLimits(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-06-08 21:41:43 +00:00
return self.ajaxPre(0, str(msg))
def getUsageData(self, request):
try:
request.session['userID'] = self.admin.pk
return getUsageData(request)
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2020-11-06 12:07:39 +05:00
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))
2020-11-26 18:13:05 +05:00
def SubmitCloudBackup(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
2020-12-08 21:19:23 +05:00
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'
2020-12-31 22:54:07 +05:00
try:
port = str(self.data['port'])
except:
port = '0'
try:
ip = str(self.data['ip'])
except:
ip = '0'
try:
destinationDomain = self.data['destinationDomain']
except:
2021-01-02 00:45:29 +05:00
destinationDomain = 'None'
2020-12-31 22:54:07 +05:00
import time
2021-03-22 20:13:57 +05:00
BackupPath = '/home/cyberpanel/backups/%s/backup-' % (self.data['domain']) + self.data[
'domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
2020-12-31 22:54:07 +05:00
2020-11-26 18:13:05 +05:00
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
2020-12-31 22:54:07 +05:00
execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s " \
"--path %s --port %s --ip %s --destinationDomain %s" % (
2021-03-22 20:13:57 +05:00
self.data['domain'], data, emails, databases, tempStatusPath, BackupPath, port, ip,
destinationDomain)
2020-11-26 18:13:05 +05:00
ProcessUtilities.popenExecutioner(execPath)
2020-12-31 22:54:07 +05:00
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath, 'path': '%s.tar.gz' % (BackupPath)}
2020-11-26 18:13:05 +05:00
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)
2020-12-06 14:10:09 +05:00
try:
backups = os.listdir(backupsPath)
backups.reverse()
except:
backups = []
2020-11-26 18:13:05 +05:00
json_data = "["
checker = 0
counter = 1
for items in backups:
2020-12-22 12:12:41 +05:00
size = str(int(int(os.path.getsize('%s/%s' % (backupsPath, items))) / int(1048576)))
2020-11-26 18:13:05 +05:00
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)
2020-12-06 14:10:09 +05:00
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()
2020-12-31 22:54:07 +05:00
try:
sourceDomain = self.data['sourceDomain']
except:
sourceDomain = 'None'
2020-12-06 14:10:09 +05:00
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
2020-12-31 22:54:07 +05:00
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --sourceDomain %s --tempStoragePath %s" % (
2021-03-22 20:13:57 +05:00
self.data['domain'], self.data['backupFile'], sourceDomain, tempStatusPath)
2020-12-06 14:10:09 +05:00
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))
2020-12-11 23:07:15 +05:00
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()
2020-12-14 15:33:59 +05:00
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,
)
2020-12-11 23:07:15 +05:00
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()
2020-12-14 15:33:59 +05:00
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,
2020-12-22 12:12:41 +05:00
endpoint_url=region
2020-12-14 15:33:59 +05:00
)
else:
s3 = boto3.resource(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
)
2020-12-11 23:07:15 +05:00
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"
2020-12-22 12:12:41 +05:00
execPath = execPath + " SubmitS3BackupRestore --backupDomain %s --backupFile '%s' --tempStoragePath %s --planName %s" % (
self.data['domain'], self.data['backupFile'], tempStatusPath, self.data['planName'])
2020-12-11 23:07:15 +05:00
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
2020-12-22 12:12:41 +05:00
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' " \
2021-01-12 17:56:36 +05:00
"--version '%s' --createSite %s" % (
2020-12-29 13:56:22 +05:00
tempStatusPath, self.data['appsSet'], self.data['domain'], self.data['email'],
2021-03-14 00:15:09 +05:00
self.data['passwordByPass'],
2020-12-29 13:56:22 +05:00
self.data['pluginUpdates'], self.data['themeUpdates'], self.data['title'],
self.data['updates'],
2021-01-12 17:56:36 +05:00
self.data['userName'], self.data['version'], str(self.data['createSite']))
2020-12-22 12:12:41 +05:00
2020-12-23 19:06:42 +05:00
try:
execPath = '%s --path %s' % (execPath, self.data['path'])
except:
pass
2020-12-22 12:12:41 +05:00
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))
2020-12-29 13:56:22 +05:00
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)
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2021-03-26 23:28:24 +05:00
command = 'wp core version --skip-plugins --skip-themes --path=%s' % (path)
finalDic['version'] = str(ProcessUtilities.outputExecutioner(command, website.externalApp))
2020-12-29 13:56:22 +05:00
## LSCache
2021-03-26 23:28:24 +05:00
command = 'wp plugin status litespeed-cache --skip-plugins --skip-themes --path=%s' % (path)
result = str(ProcessUtilities.outputExecutioner(command, website.externalApp))
2020-12-29 13:56:22 +05:00
if result.find('Status: Active') > -1:
finalDic['lscache'] = 1
else:
finalDic['lscache'] = 0
## Debug
2021-03-26 23:28:24 +05:00
try:
command = 'wp config list --skip-plugins --skip-themes --path=%s' % (path)
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
except BaseException as msg:
finalDic['debugging'] = 0
logging.writeToFile('Error fetching WordPress debug mode for %s. [404]' % (website.domain))
2020-12-29 13:56:22 +05:00
## Search index
2021-03-26 23:28:24 +05:00
try:
command = 'wp option get blog_public --skip-plugins --skip-themes --path=%s' % (path)
finalDic['searchIndex'] = int(ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()[-1])
except BaseException as msg:
logging.writeToFile('Error fetching WordPress searchIndex mode for %s. [404]' % (website.domain))
finalDic['searchIndex'] = 0
2020-12-29 13:56:22 +05:00
## Maintenece mode
2021-03-26 23:28:24 +05:00
try:
command = 'wp maintenance-mode status --skip-plugins --skip-themes --path=%s' % (path)
result = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()[-1]
2020-12-29 13:56:22 +05:00
2021-03-26 23:28:24 +05:00
if result.find('not active') > -1:
finalDic['maintenanceMode'] = 0
else:
finalDic['maintenanceMode'] = 1
except BaseException as msg:
logging.writeToFile('Error fetching WordPress maintenanceMode mode for %s. [404]' % (website.domain))
2020-12-29 13:56:22 +05:00
finalDic['maintenanceMode'] = 0
## Get title
2021-03-26 23:28:24 +05:00
try:
command = 'wp option get blogname --skip-plugins --skip-themes --path=%s' % (path)
finalDic['title'] = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()[-1]
except:
logging.writeToFile('Error fetching WordPress Title for %s. [404]' % (website.domain))
finalDic['title'] = 'CyberPanel'
2020-12-29 13:56:22 +05:00
##
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2020-12-29 13:56:22 +05:00
## Get title
import plogical.randomPassword as randomPassword
password = randomPassword.generate_pass(32)
2021-03-26 23:28:24 +05:00
command = 'wp user create cyberpanel support@cyberpanel.cloud --role=administrator --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (
2021-03-22 20:13:57 +05:00
password, path)
2020-12-29 13:56:22 +05:00
ProcessUtilities.executioner(command, website.externalApp)
2021-03-26 23:28:24 +05:00
command = 'wp user update cyberpanel --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (password, path)
2020-12-29 13:56:22 +05:00
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']
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2020-12-29 13:56:22 +05:00
if self.data['setting'] == 'lscache':
2021-03-22 20:13:57 +05:00
if self.data['settingValue']:
2020-12-29 13:56:22 +05:00
2021-03-26 23:28:24 +05:00
command = "wp plugin install litespeed-cache --path=%s --skip-plugins --skip-themes" % (path)
2021-03-22 20:13:57 +05:00
ProcessUtilities.executioner(command, website.externalApp)
2020-12-29 13:56:22 +05:00
2021-03-26 23:28:24 +05:00
command = "wp plugin activate litespeed-cache --path=%s --skip-plugins --skip-themes" % (path)
2021-03-22 20:13:57 +05:00
ProcessUtilities.executioner(command, website.externalApp)
2020-12-29 13:56:22 +05:00
2021-03-22 20:13:57 +05:00
final_dic = {'status': 1, 'message': 'LSCache successfully installed and activated.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
2021-03-26 23:28:24 +05:00
command = 'wp plugin deactivate litespeed-cache --path=%s --skip-plugins --skip-themes' % (path)
2020-12-29 13:56:22 +05:00
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':
2021-03-26 23:28:24 +05:00
command = "wp litespeed-purge all --path=%s --skip-plugins --skip-themes" % (path)
ProcessUtilities.executioner(command, website.externalApp)
2020-12-29 13:56:22 +05:00
if self.data['settingValue']:
2021-03-26 23:28:24 +05:00
command = "wp config set WP_DEBUG true --path=%s --skip-plugins --skip-themes" % (path)
2020-12-29 13:56:22 +05:00
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:
2021-03-26 23:28:24 +05:00
command = "wp config set WP_DEBUG false --path=%s --skip-plugins --skip-themes" % (path)
2020-12-29 13:56:22 +05:00
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':
2021-03-26 23:28:24 +05:00
command = "wp litespeed-purge all --path=%s --skip-plugins --skip-themes" % (path)
ProcessUtilities.executioner(command, website.externalApp)
2020-12-29 13:56:22 +05:00
if self.data['settingValue']:
2021-03-26 23:28:24 +05:00
command = "wp option update blog_public 1 --path=%s --skip-plugins --skip-themes" % (path)
2020-12-29 13:56:22 +05:00
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:
2021-03-26 23:28:24 +05:00
command = "wp option update blog_public 0 --path=%s --skip-plugins --skip-themes" % (path)
2020-12-29 13:56:22 +05:00
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':
2021-03-26 23:28:24 +05:00
command = "wp litespeed-purge all --path=%s --skip-plugins --skip-themes" % (path)
ProcessUtilities.executioner(command, website.externalApp)
2020-12-29 13:56:22 +05:00
if self.data['settingValue']:
2021-03-26 23:28:24 +05:00
command = "wp maintenance-mode activate --path=%s --skip-plugins --skip-themes" % (path)
2020-12-29 13:56:22 +05:00
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:
2021-03-26 23:28:24 +05:00
command = "wp maintenance-mode deactivate --path=%s --skip-plugins --skip-themes" % (path)
2020-12-29 13:56:22 +05:00
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2021-03-26 23:28:24 +05:00
command = 'wp plugin list --skip-plugins --skip-themes --format=json --path=%s' % (path)
2021-03-19 22:41:31 +05:00
json_data = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()[-1]
2020-12-29 13:56:22 +05:00
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data})
2020-12-29 13:56:22 +05:00
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2020-12-29 13:56:22 +05:00
if self.data['plugin'] == 'all':
2021-03-26 23:28:24 +05:00
command = 'wp plugin update --all --skip-plugins --skip-themes --path=%s' % (path)
2020-12-29 13:56:22 +05:00
ProcessUtilities.popenExecutioner(command, website.externalApp)
2021-03-22 20:13:57 +05:00
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin updates started in the background."})
2020-12-29 13:56:22 +05:00
return HttpResponse(final_json)
elif self.data['plugin'] == 'selected':
if self.data['allPluginsChecked']:
2021-03-26 23:28:24 +05:00
command = 'wp plugin update --all --skip-plugins --skip-themes --path=%s' % (path)
2020-12-29 13:56:22 +05:00
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)
2021-03-26 23:28:24 +05:00
command = 'wp plugin update %s --skip-plugins --skip-themes --path=%s' % (pluginsList, path)
2020-12-29 13:56:22 +05:00
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:
2021-03-26 23:28:24 +05:00
command = 'wp plugin update %s --skip-plugins --skip-themes --path=%s' % (self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2021-03-26 23:28:24 +05:00
command = 'wp plugin status %s --skip-plugins --skip-themes --path=%s' % (self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
result = ProcessUtilities.outputExecutioner(command, website.externalApp)
if result.find('Status: Active') > -1:
2021-03-26 23:28:24 +05:00
command = 'wp plugin deactivate %s --skip-plugins --skip-themes --path=%s' % (self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Plugin successfully deactivated."})
return HttpResponse(final_json)
else:
2021-03-26 23:28:24 +05:00
command = 'wp plugin activate %s --skip-plugins --skip-themes --path=%s' % (
2021-03-22 20:13:57 +05:00
self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2020-12-29 13:56:22 +05:00
if self.data['plugin'] == 'selected':
pluginsList = ''
for plugin in self.data['plugins']:
pluginsList = '%s %s' % (pluginsList, plugin)
2021-03-26 23:28:24 +05:00
command = 'wp plugin delete %s --skip-plugins --skip-themes --path=%s' % (pluginsList, path)
2020-12-29 13:56:22 +05:00
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:
2021-03-26 23:28:24 +05:00
command = 'wp plugin delete %s --skip-plugins --skip-themes --path=%s' % (self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
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:
2020-12-29 13:56:22 +05:00
website = Websites.objects.get(domain=self.data['domain'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2021-03-26 23:28:24 +05:00
command = 'wp theme list --skip-plugins --skip-themes --format=json --path=%s' % (path)
2021-03-19 22:41:31 +05:00
json_data = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()[-1]
2020-12-29 13:56:22 +05:00
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2020-12-29 13:56:22 +05:00
if self.data['plugin'] == 'all':
2021-03-26 23:28:24 +05:00
command = 'wp theme update --all --skip-plugins --skip-themes --path=%s' % (path)
2020-12-29 13:56:22 +05:00
ProcessUtilities.popenExecutioner(command, website.externalApp)
2021-03-22 20:13:57 +05:00
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme updates started in the background."})
2020-12-29 13:56:22 +05:00
return HttpResponse(final_json)
elif self.data['plugin'] == 'selected':
if self.data['allPluginsChecked']:
2021-03-26 23:28:24 +05:00
command = 'wp theme update --all --skip-plugins --skip-themes --path=%s' % (path)
2020-12-29 13:56:22 +05:00
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)
2021-03-26 23:28:24 +05:00
command = 'wp theme update %s --skip-plugins --skip-themes --path=%s' % (pluginsList, path)
2020-12-29 13:56:22 +05:00
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:
2021-03-26 23:28:24 +05:00
command = 'wp theme update %s --skip-plugins --skip-themes --path=%s' % (self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2021-03-26 23:28:24 +05:00
command = 'wp theme status %s --skip-plugins --skip-themes --path=%s' % (self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
result = ProcessUtilities.outputExecutioner(command, website.externalApp)
if result.find('Status: Active') > -1:
2021-03-26 23:28:24 +05:00
command = 'wp theme deactivate %s --skip-plugins --skip-themes --path=%s' % (
self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
{'status': 1, 'fetchStatus': 1, 'message': "Theme successfully deactivated."})
return HttpResponse(final_json)
else:
2021-03-26 23:28:24 +05:00
command = 'wp theme activate %s --skip-plugins --skip-themes --path=%s' % (
2021-03-22 20:13:57 +05:00
self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
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'])
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2020-12-29 13:56:22 +05:00
if self.data['plugin'] == 'selected':
pluginsList = ''
for plugin in self.data['plugins']:
pluginsList = '%s %s' % (pluginsList, plugin)
2021-03-26 23:28:24 +05:00
command = 'wp theme delete %s --skip-plugins --skip-themes --path=%s' % (pluginsList, path)
2020-12-29 13:56:22 +05:00
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:
2021-03-26 23:28:24 +05:00
command = 'wp theme delete %s --skip-plugins --skip-themes --path=%s' % (self.data['plugin'], path)
2020-12-29 13:56:22 +05:00
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)
2020-12-31 22:54:07 +05:00
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)
2021-03-30 16:16:59 +05:00
## Create backup path so that file can be sent here later. If just submitting the key, no need to create backup folder domain.
2020-12-31 22:54:07 +05:00
2021-03-30 16:16:59 +05:00
try:
BackupPath = '/home/cyberpanel/backups/%s' % (self.data['domain'])
command = 'mkdir -p %s' % (BackupPath)
ProcessUtilities.executioner(command, 'cyberpanel')
except:
pass
2020-12-31 22:54:07 +05:00
###
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:
2021-01-02 00:45:29 +05:00
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
2021-02-05 18:33:20 +05:00
try:
wpd = WPDeployments.objects.get(owner=website)
config = json.loads(wpd.config)
except:
wpd = WPDeployments(owner=website)
config = {}
try:
from cloudAPI.models import WPDeployments
wpd = WPDeployments.objects.get(owner=website)
path = json.loads(wpd.config)['path']
path = '/home/%s/public_html/%s' % (self.data['domain'], path)
except:
path = '/home/%s/public_html' % (self.data['domain'])
2021-01-02 00:45:29 +05:00
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':
2021-03-26 23:28:24 +05:00
command = "wp config set WP_AUTO_UPDATE_CORE false --skip-plugins --skip-themes --raw --path=%s" % (path)
2021-01-02 00:45:29 +05:00
ProcessUtilities.executioner(command, website.externalApp)
elif self.data['wpCore'] == 'Minor and Security Updates':
2021-03-26 23:28:24 +05:00
command = "wp config set WP_AUTO_UPDATE_CORE minor --skip-plugins --skip-themes --allow-root --path=%s" % (path)
2021-01-02 00:45:29 +05:00
ProcessUtilities.executioner(command, website.externalApp)
else:
command = "wp config set WP_AUTO_UPDATE_CORE true --raw --allow-root --path=%s" % (path)
2021-01-02 00:45:29 +05:00
ProcessUtilities.executioner(command, website.externalApp)
final_json = json.dumps(
2021-03-22 20:13:57 +05:00
{'status': 1, 'message': "Autoupdates configured."})
2021-01-02 00:45:29 +05:00
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(
2021-03-22 20:13:57 +05:00
{'status': 1, 'cliVersion': cliVersion, 'finalCron': finalCron})
2021-01-02 00:45:29 +05:00
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)
2021-01-12 17:56:36 +05:00
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'])
2021-03-26 23:28:24 +05:00
command = 'wp core version --allow-root --skip-plugins --skip-themes --path=%s' % (path)
2021-01-12 17:56:36 +05:00
result = ProcessUtilities.outputExecutioner(command)
if result.find('Error:') > -1:
2021-03-22 20:13:57 +05:00
final_dic = {'status': 0, 'fetchStatus': 0,
'error_message': 'This does not seem to be a WordPress installation'}
2021-01-12 17:56:36 +05:00
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
final_json = json.dumps({'status': 1})
return HttpResponse(final_json)
2021-03-22 13:06:05 +05:00
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 SubmitCyberPanelUpgrade(self):
try:
2021-03-22 20:13:57 +05:00
try:
mail = str(int(self.data['mail']))
except:
mail = '0'
try:
dns = str(int(self.data['dns']))
except:
dns = '0'
try:
ftp = str(int(self.data['ftp']))
except:
ftp = '0'
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/CyberPanelUpgrade.py --branch %s --mail %s --dns %s --ftp %s" % (
self.data['CyberPanelBranch'], mail, dns, ftp)
2021-03-22 13:06:05 +05:00
ProcessUtilities.popenExecutioner(execPath)
final_json = json.dumps({'status': 1})
return HttpResponse(final_json)
2021-01-02 00:45:29 +05:00
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
2021-03-22 20:13:57 +05:00
return HttpResponse(final_json)
2021-03-29 17:23:18 +05:00
def DetachCluster(self):
try:
type = self.data['type']
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function %s --type %s" % ('DetachCluster', type)
2021-04-01 11:47:47 +05:00
ProcessUtilities.executioner(execPath)
2021-03-29 17:23:18 +05:00
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)
2021-03-30 16:16:59 +05:00
def SetupCluster(self):
try:
ClusterConfigPath = '/home/cyberpanel/cluster'
writeToFile = open(ClusterConfigPath, 'w')
writeToFile.write(json.dumps(self.data))
writeToFile.close()
2021-04-01 11:47:47 +05:00
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function SetupCluster --type %s" % (self.data['type'])
ProcessUtilities.executioner(execPath)
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 FetchMasterBootStrapStatus(self):
try:
from CyberCP import settings
data = {}
data['status'] = 1
## CyberPanel DB Creds
data['dbName'] = settings.DATABASES['default']['NAME']
data['dbUser'] = settings.DATABASES['default']['USER']
data['password'] = settings.DATABASES['default']['PASSWORD']
data['host'] = settings.DATABASES['default']['HOST']
data['port'] = settings.DATABASES['default']['PORT']
## Root DB Creds
data['rootdbName'] = settings.DATABASES['rootdb']['NAME']
data['rootdbdbUser'] = settings.DATABASES['rootdb']['USER']
data['rootdbpassword'] = settings.DATABASES['rootdb']['PASSWORD']
command = 'cat /var/lib/mysql/grastate.dat'
output = ProcessUtilities.outputExecutioner(command)
if output.find('No such file or directory') > -1:
data['safe'] = 1
elif output.find('safe_to_bootstrap: 1') > -1:
data['safe'] = 1
else:
data['safe'] = 0
final_json = json.dumps(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 FetchChildBootStrapStatus(self):
try:
data = {}
data['status'] = 1
command = 'cat /var/lib/mysql/grastate.dat'
output = ProcessUtilities.outputExecutioner(command)
if output.find('No such file or directory') > -1:
data['safe'] = 1
elif output.find('safe_to_bootstrap: 0') > -1:
data['safe'] = 1
else:
data['safe'] = 0
final_json = json.dumps(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 BootMaster(self):
try:
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function BootMaster --type Master"
ProcessUtilities.executioner(execPath)
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 BootChild(self):
try:
ChildData = '/home/cyberpanel/childaata'
writeToFile = open(ChildData, 'w')
writeToFile.write(json.dumps(self.data))
writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function BootChild --type Child"
ProcessUtilities.executioner(execPath)
2021-03-30 16:16:59 +05:00
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)