mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-06-04 21:54:10 +02:00
Merge branch 'v2.3.3-dev' of github.com:usmannasir/cyberpanel into v2.3.3-dev
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#!/usr/local/CyberCP/bin/python
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
import django
|
||||
|
||||
django.setup()
|
||||
from IncBackups.IncBackupsControl import IncJobs
|
||||
from IncBackups.models import BackupJob
|
||||
@@ -22,6 +24,7 @@ import requests
|
||||
import socket
|
||||
from websiteFunctions.models import NormalBackupJobs, NormalBackupJobLogs
|
||||
from boto3.s3.transfer import TransferConfig
|
||||
|
||||
try:
|
||||
from s3Backups.models import BackupPlan, BackupLogs
|
||||
import boto3
|
||||
@@ -63,7 +66,7 @@ class IncScheduler(multi.Thread):
|
||||
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
for job in BackupJob.objects.all():
|
||||
logging.statusWriter(IncScheduler.logPath, 'Job Description:\n\n Destination: %s, Frequency: %s.\n ' % (
|
||||
job.destination, job.frequency), 1)
|
||||
job.destination, job.frequency), 1)
|
||||
if job.frequency == type:
|
||||
for web in job.jobsites_set.all():
|
||||
logging.statusWriter(IncScheduler.logPath, 'Backing up %s.' % (web.website), 1)
|
||||
@@ -129,7 +132,7 @@ class IncScheduler(multi.Thread):
|
||||
web = Websites.objects.get(domain=website)
|
||||
|
||||
message = '[%s Cron] Checking if %s has any pending commits on %s.' % (
|
||||
type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
|
||||
type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
|
||||
finalText = '%s\n' % (message)
|
||||
GitLogs(owner=web, type='INFO', message=message).save()
|
||||
|
||||
@@ -148,7 +151,7 @@ class IncScheduler(multi.Thread):
|
||||
data['domain'] = gitConf['domain']
|
||||
data['folder'] = gitConf['folder']
|
||||
data['commitMessage'] = 'Auto commit by CyberPanel %s cron on %s' % (
|
||||
type, time.strftime('%m-%d-%Y_%H-%M-%S'))
|
||||
type, time.strftime('%m-%d-%Y_%H-%M-%S'))
|
||||
|
||||
if gitConf['autoCommit'] == type:
|
||||
|
||||
@@ -182,7 +185,7 @@ class IncScheduler(multi.Thread):
|
||||
finalText = '%s\n%s' % (finalText, message)
|
||||
|
||||
message = '[%s Cron] Finished checking for %s on %s.' % (
|
||||
type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
|
||||
type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
|
||||
finalText = '%s\n%s' % (finalText, message)
|
||||
logging.SendEmail(web.adminEmail, web.adminEmail, finalText, 'Git report for %s.' % (web.domain))
|
||||
GitLogs(owner=web, type='INFO', message=message).save()
|
||||
@@ -333,7 +336,7 @@ class IncScheduler(multi.Thread):
|
||||
if retValues[0] == 0:
|
||||
GDriveJobLogs(owner=items, status=backupSchedule.ERROR,
|
||||
message='[ERROR] Backup failed for %s, error: %s moving on..' % (
|
||||
website.domain, retValues[1])).save()
|
||||
website.domain, retValues[1])).save()
|
||||
continue
|
||||
|
||||
completeFileToSend = retValues[1] + ".tar.gz"
|
||||
@@ -378,12 +381,9 @@ class IncScheduler(multi.Thread):
|
||||
GDriveJobLogs(owner=items, status=backupSchedule.INFO,
|
||||
message='Job Completed').save()
|
||||
|
||||
|
||||
print("job com[leted")
|
||||
|
||||
#logging.writeToFile('job completed')
|
||||
|
||||
|
||||
# logging.writeToFile('job completed')
|
||||
|
||||
url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission"
|
||||
data = {
|
||||
@@ -400,67 +400,67 @@ class IncScheduler(multi.Thread):
|
||||
|
||||
page_token = None
|
||||
while True:
|
||||
response = drive.files().list(q="name='%s-%s'" % (items.name,ipAddress),
|
||||
spaces='drive',
|
||||
response = drive.files().list(q="name='%s-%s'" % (items.name, ipAddress),
|
||||
spaces='drive',
|
||||
fields='nextPageToken, files(id, name)',
|
||||
pageToken=page_token).execute()
|
||||
for file in response.get('files', []):
|
||||
# Process change
|
||||
#print('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id')))
|
||||
#logging.writeToFile('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id')))
|
||||
mainfolder_id= file.get('id')
|
||||
# print('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id')))
|
||||
# logging.writeToFile('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id')))
|
||||
mainfolder_id = file.get('id')
|
||||
page_token = response.get('nextPageToken', None)
|
||||
if page_token is None:
|
||||
break
|
||||
#print("new job started ")
|
||||
# print("new job started ")
|
||||
try:
|
||||
page_token = None
|
||||
while True:
|
||||
response = drive.files().list(q="'%s' in parents"%(mainfolder_id),
|
||||
spaces='drive',
|
||||
fields='nextPageToken, files(id, name, createdTime)',
|
||||
pageToken=page_token).execute()
|
||||
response = drive.files().list(q="'%s' in parents" % (mainfolder_id),
|
||||
spaces='drive',
|
||||
fields='nextPageToken, files(id, name, createdTime)',
|
||||
pageToken=page_token).execute()
|
||||
for file in response.get('files', []):
|
||||
# Process change
|
||||
#print('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'), file.get('createdTime')))
|
||||
#logging.writeToFile('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'),file.get('createdTime')))
|
||||
# print('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'), file.get('createdTime')))
|
||||
# logging.writeToFile('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'),file.get('createdTime')))
|
||||
ab = file.get('createdTime')[:10]
|
||||
filename = file.get('name')
|
||||
fileDeleteID = file.get('id')
|
||||
timestamp = time.mktime(datetime.datetime.strptime(ab,"%Y-%m-%d").timetuple())
|
||||
timestamp = time.mktime(datetime.datetime.strptime(ab, "%Y-%m-%d").timetuple())
|
||||
CUrrenttimestamp = time.time()
|
||||
timerrtention = gDriveData['FileRetentiontime']
|
||||
if(timerrtention == '1d'):
|
||||
if (timerrtention == '1d'):
|
||||
new = CUrrenttimestamp - float(86400)
|
||||
if(new>=timestamp):
|
||||
resp=drive.files().delete(fileId=fileDeleteID).execute()
|
||||
logging.writeToFile('Delete file %s '%filename)
|
||||
elif(timerrtention == '1w'):
|
||||
if (new >= timestamp):
|
||||
resp = drive.files().delete(fileId=fileDeleteID).execute()
|
||||
logging.writeToFile('Delete file %s ' % filename)
|
||||
elif (timerrtention == '1w'):
|
||||
new = CUrrenttimestamp - float(604800)
|
||||
if (new >= timestamp):
|
||||
resp = drive.files().delete(fileId=fileDeleteID).execute()
|
||||
logging.writeToFile('Delete file %s '%filename)
|
||||
logging.writeToFile('Delete file %s ' % filename)
|
||||
elif (timerrtention == '1m'):
|
||||
new = CUrrenttimestamp - float(2592000)
|
||||
if (new >= timestamp):
|
||||
resp = drive.files().delete(fileId=fileDeleteID).execute()
|
||||
logging.writeToFile('Delete file %s '%filename)
|
||||
logging.writeToFile('Delete file %s ' % filename)
|
||||
elif (timerrtention == '6m'):
|
||||
new = CUrrenttimestamp - float(15552000)
|
||||
if (new >= timestamp):
|
||||
resp = drive.files().delete(fileId=fileDeleteID).execute()
|
||||
logging.writeToFile('Delete file %s '%filename)
|
||||
logging.writeToFile('Delete file %s ' % filename)
|
||||
page_token = response.get('nextPageToken', None)
|
||||
if page_token is None:
|
||||
break
|
||||
|
||||
# logging.writeToFile('Createtime list - %s'%Createtime)
|
||||
# logging.writeToFile('Createtime list - %s'%Createtime)
|
||||
|
||||
except BaseException as msg:
|
||||
print('An error occurred fetch child: %s' % msg)
|
||||
logging.writeToFile('An error occurred fetch child: %s' % msg)
|
||||
print('An error occurred fetch child: %s' % msg)
|
||||
logging.writeToFile('An error occurred fetch child: %s' % msg)
|
||||
except BaseException as msg:
|
||||
logging.writeToFile('job not completed [ERROR:]..%s'%msg)
|
||||
logging.writeToFile('job not completed [ERROR:]..%s' % msg)
|
||||
|
||||
except BaseException as msg:
|
||||
GDriveJobLogs(owner=items, status=backupSchedule.ERROR,
|
||||
@@ -523,7 +523,7 @@ class IncScheduler(multi.Thread):
|
||||
NormalBackupJobLogs.objects.filter(owner=backupjob).delete()
|
||||
NormalBackupJobLogs(owner=backupjob, status=backupSchedule.INFO,
|
||||
message='Starting %s backup on %s..' % (
|
||||
type, time.strftime("%m.%d.%Y_%H-%M-%S"))).save()
|
||||
type, time.strftime("%m.%d.%Y_%H-%M-%S"))).save()
|
||||
|
||||
if oldJobContinue:
|
||||
NormalBackupJobLogs(owner=backupjob, status=backupSchedule.INFO,
|
||||
@@ -886,8 +886,7 @@ Automatic backup failed for %s on %s.
|
||||
emailPath = '/home/vmail/%s/%s' % (website.domain, email.email.split('@')[0])
|
||||
email.DiskUsage = virtualHostUtilities.getDiskUsageofPath(emailPath)
|
||||
email.save()
|
||||
print('Disk Usage of %s is %s' % (email.email,email.DiskUsage))
|
||||
|
||||
print('Disk Usage of %s is %s' % (email.email, email.DiskUsage))
|
||||
|
||||
config['DiskUsage'], config['DiskUsagePercentage'] = virtualHostUtilities.getDiskUsage(
|
||||
"/home/" + website.domain, website.package.diskSpace)
|
||||
@@ -947,14 +946,14 @@ Automatic backup failed for %s on %s.
|
||||
|
||||
if config['pluginUpdates'] == 'Enabled':
|
||||
command = 'wp plugin update --all --minor --allow-root --path=/home/%s/public_html' % (
|
||||
config['domainName'])
|
||||
config['domainName'])
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
### Themes, for plugins we will do minor updates only.
|
||||
|
||||
if config['themeUpdates'] == 'Enabled':
|
||||
command = 'wp theme update --all --minor --allow-root --path=/home/%s/public_html' % (
|
||||
config['domainName'])
|
||||
config['domainName'])
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
except BaseException as msg:
|
||||
@@ -970,7 +969,7 @@ Automatic backup failed for %s on %s.
|
||||
from plogical.applicationInstaller import ApplicationInstaller
|
||||
for config in RemoteBackupSchedule.objects.all():
|
||||
try:
|
||||
configbakup=json.loads(config.config)
|
||||
configbakup = json.loads(config.config)
|
||||
backuptype = configbakup['BackupType']
|
||||
if backuptype == 'Only DataBase':
|
||||
Backuptype = "3"
|
||||
@@ -983,119 +982,231 @@ Automatic backup failed for %s on %s.
|
||||
try:
|
||||
allRemoteBackupsiteobj = RemoteBackupsites.objects.filter(owner=config.pk)
|
||||
for i in allRemoteBackupsiteobj:
|
||||
backupsiteID=i.WPsites
|
||||
wpsite=WPSites.objects.get(pk=backupsiteID)
|
||||
AdminID=wpsite.owner.admin_id
|
||||
backupsiteID = i.WPsites
|
||||
wpsite = WPSites.objects.get(pk=backupsiteID)
|
||||
AdminID = wpsite.owner.admin_id
|
||||
Admin = Administrator.objects.get(pk=AdminID)
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = "SFTP"
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
Lastrun = config.lastrun
|
||||
Currenttime = float(time.time())
|
||||
if config.timeintervel == "30 Minutes":
|
||||
al = float(Currenttime) - float(1800)
|
||||
if float(al) >= float(Lastrun):
|
||||
# if 1 == 1:
|
||||
#if 1 == 1:
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = config.RemoteBackupConfig.configtype
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
background = ApplicationInstaller('WPCreateBackup', extraArgs)
|
||||
status, msg = background.WPCreateBackup()
|
||||
status, msg, backupID = background.WPCreateBackup()
|
||||
if status == 1:
|
||||
filename = msg
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
if config.RemoteBackupConfig.configtype == "SFTP":
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.RemoteBackupConfig.configtype == "S3":
|
||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, config.id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.timeintervel == "1 Hour":
|
||||
al = float(Currenttime) - float(3600)
|
||||
if float(al) >= float(Lastrun):
|
||||
# if 1 == 1:
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = config.RemoteBackupConfig.configtype
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
background = ApplicationInstaller('WPCreateBackup', extraArgs)
|
||||
status, msg = background.WPCreateBackup()
|
||||
status, msg, backupID = background.WPCreateBackup()
|
||||
if status == 1:
|
||||
filename = msg
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
if config.RemoteBackupConfig.configtype == "SFTP":
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.RemoteBackupConfig.configtype == "S3":
|
||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||
config.id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.timeintervel == "6 Hours":
|
||||
al = float(Currenttime) - float(21600)
|
||||
if float(al) >= float(Lastrun):
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = "SFTP"
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
background = ApplicationInstaller('WPCreateBackup', extraArgs)
|
||||
status, msg = background.WPCreateBackup()
|
||||
status, msg, backupID = background.WPCreateBackup()
|
||||
if status == 1:
|
||||
filename = msg
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
if config.RemoteBackupConfig.configtype == "SFTP":
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.RemoteBackupConfig.configtype == "S3":
|
||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||
config.id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.timeintervel == "12 Hours":
|
||||
al = float(Currenttime) - float(43200)
|
||||
if float(al) >= float(Lastrun):
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = "SFTP"
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
background = ApplicationInstaller('WPCreateBackup', extraArgs)
|
||||
status, msg = background.WPCreateBackup()
|
||||
status, msg, backupID = background.WPCreateBackup()
|
||||
if status == 1:
|
||||
filename = msg
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
if config.RemoteBackupConfig.configtype == "SFTP":
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.RemoteBackupConfig.configtype == "S3":
|
||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||
config.id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.timeintervel == "1 Day":
|
||||
al = float(Currenttime) - float(86400)
|
||||
if float(al) >= float(Lastrun):
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = "SFTP"
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
background = ApplicationInstaller('WPCreateBackup', extraArgs)
|
||||
status, msg = background.WPCreateBackup()
|
||||
status, msg, backupID = background.WPCreateBackup()
|
||||
if status == 1:
|
||||
filename = msg
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
if config.RemoteBackupConfig.configtype == "SFTP":
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.RemoteBackupConfig.configtype == "S3":
|
||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||
config.id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.timeintervel == "3 Days":
|
||||
al = float(Currenttime) - float(259200)
|
||||
if float(al) >= float(Lastrun):
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = "SFTP"
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
background = ApplicationInstaller('WPCreateBackup', extraArgs)
|
||||
status, msg = background.WPCreateBackup()
|
||||
status, msg, backupID = background.WPCreateBackup()
|
||||
if status == 1:
|
||||
filename = msg
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
if config.RemoteBackupConfig.configtype == "SFTP":
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.RemoteBackupConfig.configtype == "S3":
|
||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||
config.id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.timeintervel == "1 Week":
|
||||
al = float(Currenttime) - float(604800)
|
||||
if float(al) >= float(Lastrun):
|
||||
extraArgs = {}
|
||||
extraArgs['adminID'] = Admin.pk
|
||||
extraArgs['WPid'] = wpsite.pk
|
||||
extraArgs['Backuptype'] = Backuptype
|
||||
extraArgs['BackupDestination'] = "SFTP"
|
||||
extraArgs['SFTPID'] = config.RemoteBackupConfig_id
|
||||
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
background = ApplicationInstaller('WPCreateBackup', extraArgs)
|
||||
status, msg = background.WPCreateBackup()
|
||||
status, msg, backupID = background.WPCreateBackup()
|
||||
if status == 1:
|
||||
filename = msg
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
if config.RemoteBackupConfig.configtype == "SFTP":
|
||||
IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
elif config.RemoteBackupConfig.configtype == "S3":
|
||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||
config.id)
|
||||
command = f"rm -r {filename}"
|
||||
ProcessUtilities.executioner(command)
|
||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||
obj.lastrun = time.time()
|
||||
obj.save()
|
||||
except BaseException as msg:
|
||||
print("Error in Sites:%s" % str(msg))
|
||||
continue
|
||||
except BaseException as msg:
|
||||
print("Error: [RemoteBackup]: %s"%str(msg))
|
||||
print("Error: [RemoteBackup]: %s" % str(msg))
|
||||
logging.writeToFile('%s. [RemoteBackup]' % (str(msg)))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def SendTORemote(FileName, RemoteBackupID):
|
||||
import pysftp
|
||||
@@ -1117,7 +1228,6 @@ Automatic backup failed for %s on %s.
|
||||
with pysftp.Connection(HostName, username=Username, password=Password, cnopts=cnopts) as sftp:
|
||||
print("Connection succesfully stablished ... ")
|
||||
|
||||
|
||||
try:
|
||||
with sftp.cd(Path):
|
||||
sftp.put(FileName)
|
||||
@@ -1131,6 +1241,109 @@ Automatic backup failed for %s on %s.
|
||||
except BaseException as msg:
|
||||
logging.writeToFile('%s. [SendTORemote]' % (str(msg)))
|
||||
|
||||
@staticmethod
|
||||
def SendToS3Cloud(FileName, RemoteBackupCofigID, backupID, scheduleID):
|
||||
import boto3
|
||||
import json
|
||||
import time
|
||||
from websiteFunctions.models import RemoteBackupConfig, WPSitesBackup, RemoteBackupSchedule
|
||||
import plogical.randomPassword as randomPassword
|
||||
try:
|
||||
print("UPloading to S3")
|
||||
Backupobj = WPSitesBackup.objects.get(pk=backupID)
|
||||
backupConfig = json.loads(Backupobj.config)
|
||||
websitedomain = backupConfig['WebDomain']
|
||||
RemoteBackupOBJ = RemoteBackupConfig.objects.get(pk=RemoteBackupCofigID)
|
||||
config = json.loads(RemoteBackupOBJ.config)
|
||||
provider = config['Provider']
|
||||
if provider == "Backblaze":
|
||||
EndURl = config['EndUrl']
|
||||
elif provider == "Amazon":
|
||||
EndURl = "https://s3.us-east-1.amazonaws.com"
|
||||
elif provider == "Wasabi":
|
||||
EndURl = "https://s3.wasabisys.com"
|
||||
|
||||
AccessKey = config['AccessKey']
|
||||
SecertKey = config['SecertKey']
|
||||
|
||||
session = boto3.session.Session()
|
||||
|
||||
client = session.client(
|
||||
's3',
|
||||
endpoint_url=EndURl,
|
||||
aws_access_key_id=AccessKey,
|
||||
aws_secret_access_key=SecertKey,
|
||||
verify=False
|
||||
)
|
||||
|
||||
# ############Creating Bucket
|
||||
# BucketName = randomPassword.generate_pass().lower()
|
||||
# print("BucketName...%s"%BucketName)
|
||||
#
|
||||
# try:
|
||||
# client.create_bucket(Bucket=BucketName)
|
||||
# except BaseException as msg:
|
||||
# print("Error in Creating bucket...: %s" % str(msg))
|
||||
# logging.writeToFile("Create bucket error---%s:" % str(msg))
|
||||
|
||||
|
||||
####getting Bucket from backup schedule
|
||||
Scheduleobj = RemoteBackupSchedule.objects.get(pk=scheduleID)
|
||||
Scheduleconfig = json.loads(Scheduleobj.config)
|
||||
BucketName = Scheduleconfig['BucketName']
|
||||
#####Uploading File
|
||||
|
||||
uploadfilename = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
|
||||
print("uploadfilename....%s"%uploadfilename)
|
||||
|
||||
try:
|
||||
res = client.upload_file(Filename=FileName, Bucket=BucketName, Key=uploadfilename)
|
||||
print("res of Uploading...: %s" % res)
|
||||
|
||||
except BaseException as msg:
|
||||
print("Error in Uploading...: %s" % msg)
|
||||
|
||||
###################### version id, this only applied to blackbaze
|
||||
try:
|
||||
|
||||
s3 = boto3.resource(
|
||||
's3',
|
||||
endpoint_url=EndURl,
|
||||
aws_access_key_id=AccessKey,
|
||||
aws_secret_access_key=SecertKey,
|
||||
)
|
||||
|
||||
bucket = BucketName
|
||||
key = uploadfilename
|
||||
versions = s3.Bucket(bucket).object_versions.filter(Prefix=key)
|
||||
data = {}
|
||||
|
||||
for version in versions:
|
||||
obj = version.get()
|
||||
print("VersionId---%s:" % obj.get('VersionId'))
|
||||
data['backupVersionId'] = obj.get('VersionId')
|
||||
|
||||
ab = os.path.getsize(FileName)
|
||||
filesize = float(ab) / 1024.0
|
||||
|
||||
backupConfig['uploadfilename'] = uploadfilename
|
||||
backupConfig['backupVersionId'] = data['backupVersionId']
|
||||
backupConfig['BucketName'] = BucketName
|
||||
backupConfig['Uplaodingfilesize'] = filesize
|
||||
Backupobj.config = json.dumps(backupConfig)
|
||||
Backupobj.save()
|
||||
|
||||
except BaseException as msg:
|
||||
print("Version ID Error: %s"%str(msg))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
except BaseException as msg:
|
||||
print('%s. [SendToS3Cloud]' % (str(msg)))
|
||||
logging.writeToFile('%s. [SendToS3Cloud]' % (str(msg)))
|
||||
|
||||
|
||||
def main():
|
||||
@@ -1151,7 +1364,6 @@ def main():
|
||||
ib = IncScheduler('startBackup', {'freq': args.function})
|
||||
ib.start()
|
||||
|
||||
|
||||
###
|
||||
|
||||
IncScheduler.startBackup(args.function)
|
||||
@@ -1166,4 +1378,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
config= {
|
||||
"name": "habi",
|
||||
"dev": "python"
|
||||
}
|
||||
|
||||
print(config)
|
||||
config['klm'] ="tls"
|
||||
|
||||
print(config)
|
||||
@@ -1961,9 +1961,11 @@ app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) {
|
||||
function DeleteBackupConfigNow(url) {
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
function DeleteRemoteBackupsiteNow(url) {
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
function DeleteBackupfileConfigNow(url) {
|
||||
window.location.href = url;
|
||||
}
|
||||
@@ -1972,15 +1974,47 @@ function DeleteBackupfileConfigNow(url) {
|
||||
app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window) {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
$scope.SFTPBackUpdiv = true;
|
||||
$scope.S3backupdiv = true;
|
||||
|
||||
$scope.EndpointURLdiv = true;
|
||||
$scope.Selectprovider = true;
|
||||
$scope.S3keyNamediv = true;
|
||||
$scope.Accesskeydiv = true;
|
||||
$scope.SecretKeydiv = true;
|
||||
$scope.SelectRemoteBackuptype = function () {
|
||||
var val = $scope.RemoteBackuptype;
|
||||
if (val == "SFTP") {
|
||||
$scope.SFTPBackUpdiv = false;
|
||||
$scope.S3backupdiv = true;
|
||||
} else {
|
||||
$scope.S3backupdiv = false;
|
||||
$scope.EndpointURLdiv = true;
|
||||
$scope.Selectprovider = true;
|
||||
$scope.S3keyNamediv = true;
|
||||
$scope.Accesskeydiv = true;
|
||||
$scope.SecretKeydiv = true;
|
||||
} else if (val == "S3") {
|
||||
$scope.EndpointURLdiv = true;
|
||||
$scope.Selectprovider = false;
|
||||
$scope.S3keyNamediv = false;
|
||||
$scope.Accesskeydiv = false;
|
||||
$scope.SecretKeydiv = false;
|
||||
$scope.SFTPBackUpdiv = true;
|
||||
} else {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
$scope.SFTPBackUpdiv = true;
|
||||
|
||||
$scope.EndpointURLdiv = true;
|
||||
$scope.Selectprovider = true;
|
||||
$scope.S3keyNamediv = true;
|
||||
$scope.Accesskeydiv = true;
|
||||
$scope.SecretKeydiv = true;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.SelectProvidertype = function () {
|
||||
$scope.EndpointURLdiv = true;
|
||||
var provider = $scope.Providervalue
|
||||
if (provider == 'Backblaze') {
|
||||
$scope.EndpointURLdiv = false;
|
||||
} else {
|
||||
$scope.EndpointURLdiv = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1991,65 +2025,87 @@ app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window)
|
||||
var Passwd = $scope.Password;
|
||||
var path = $scope.path;
|
||||
var type = $scope.RemoteBackuptype;
|
||||
|
||||
var Providervalue = $scope.Providervalue;
|
||||
var data;
|
||||
if (type == "SFTP") {
|
||||
|
||||
var data = {
|
||||
data = {
|
||||
Hname: Hname,
|
||||
Uname: Uname,
|
||||
Passwd: Passwd,
|
||||
path: path,
|
||||
type: type
|
||||
}
|
||||
var url = "/websites/SaveBackupConfig";
|
||||
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
} else if (type == "S3") {
|
||||
if (Providervalue == "Backblaze") {
|
||||
data = {
|
||||
S3keyname: $scope.S3keyName,
|
||||
Provider: Providervalue,
|
||||
AccessKey: $scope.Accesskey,
|
||||
SecertKey: $scope.SecretKey,
|
||||
EndUrl: $scope.EndpointURL,
|
||||
type: type
|
||||
}
|
||||
};
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success!',
|
||||
text: 'Successfully Saved!.',
|
||||
type: 'success'
|
||||
});
|
||||
location.reload();
|
||||
|
||||
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
} else {
|
||||
data = {
|
||||
S3keyname: $scope.S3keyName,
|
||||
Provider: Providervalue,
|
||||
AccessKey: $scope.Accesskey,
|
||||
SecertKey: $scope.SecretKey,
|
||||
type: type
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
}
|
||||
var url = "/websites/SaveBackupConfig";
|
||||
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
title: 'Success!',
|
||||
text: 'Successfully Saved!.',
|
||||
type: 'success'
|
||||
});
|
||||
location.reload();
|
||||
|
||||
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
var UpdatescheduleID;
|
||||
app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) {
|
||||
$scope.BackupScheduleLoading = true;
|
||||
$scope.SaveBackupSchedule = function () {
|
||||
@@ -2062,7 +2118,7 @@ app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) {
|
||||
FileRetention: FileRetention,
|
||||
Backfrequency: Backfrequency,
|
||||
ScheduleName: $scope.ScheduleName,
|
||||
RemoteConfigID : $('#RemoteConfigID').html(),
|
||||
RemoteConfigID: $('#RemoteConfigID').html(),
|
||||
BackupType: $scope.BackupType
|
||||
}
|
||||
var url = "/websites/SaveBackupSchedule";
|
||||
@@ -2108,17 +2164,73 @@ app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) {
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
$scope.getupdateid = function (ID) {
|
||||
UpdatescheduleID = ID;
|
||||
}
|
||||
|
||||
$scope.UpdateRemoteschedules = function () {
|
||||
$scope.RemoteBackupLoading = false;
|
||||
var Frequency = $scope.RemoteFrequency;
|
||||
var fretention = $scope.RemoteFileretention;
|
||||
|
||||
var data = {
|
||||
ScheduleID: UpdatescheduleID,
|
||||
Frequency: Frequency,
|
||||
FileRetention: fretention
|
||||
}
|
||||
var url = "/websites/UpdateRemoteschedules";
|
||||
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success!',
|
||||
text: 'Successfully Updated!.',
|
||||
type: 'success'
|
||||
});
|
||||
location.reload();
|
||||
|
||||
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.RemoteBackupLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
$scope.AddWPsiteforRemoteBackup = function () {
|
||||
$scope.RemoteBackupLoading = false;
|
||||
|
||||
|
||||
|
||||
var data = {
|
||||
WpsiteID: $('#Wpsite').val(),
|
||||
RemoteScheduleID : $('#RemoteScheduleID').html()
|
||||
WpsiteID: $('#Wpsite').val(),
|
||||
RemoteScheduleID: $('#RemoteScheduleID').html()
|
||||
}
|
||||
var url = "/websites/AddWPsiteforRemoteBackup";
|
||||
|
||||
@@ -2163,7 +2275,7 @@ app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
});
|
||||
/* Java script code to create account */
|
||||
app.controller('createWebsite', function ($scope, $http, $timeout, $window) {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<input name="Hostname" type="text" class="form-control" ng-model="ScheduleName"
|
||||
required>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<span style="display: none" id="RemoteConfigID"> {{ RemoteConfigID }}</span>
|
||||
|
||||
@@ -86,6 +87,10 @@
|
||||
<tr>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">ID</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Schedule Name</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Backup Frequency</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Backup File Retention
|
||||
</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Last Run</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Remote Configuration
|
||||
</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Action</th>
|
||||
@@ -97,6 +102,9 @@
|
||||
<tr>
|
||||
<td style="padding: 13px;">{{ sub.id }}</td>
|
||||
<td style="padding: 13px;">{{ sub.Name }}</td>
|
||||
<td style="padding: 13px;">{{ sub.Frequency }}</td>
|
||||
<td style="padding: 13px;">{{ sub.Retention }}</td>
|
||||
<td style="padding: 13px;">{{ sub.LastRun }}</td>
|
||||
<td style="padding: 13px;">{{ sub.RemoteConfiguration }}</td>
|
||||
<td style="padding: 13px;">
|
||||
<button
|
||||
@@ -105,9 +113,14 @@
|
||||
type="button" class="btn btn-border btn-alt border-red btn-link font-red">
|
||||
Delete
|
||||
</button>
|
||||
<button ng-click="getupdateid({{ sub.id }})" data-toggle="modal" data-target="#EidtRemoteShedule"
|
||||
aria-label=""
|
||||
type="button" class="btn btn-border btn-alt border-yellow btn-link font-yellow">
|
||||
Eidt
|
||||
</button>
|
||||
<a href="{% url 'AddRemoteBackupsite' %}?ID={{ sub.id }}"
|
||||
aria-label=""
|
||||
|
||||
style="margin-top: 5px;"
|
||||
type="button" class="btn btn-border btn-alt border-green btn-link font-green">
|
||||
Add WordPress Sites
|
||||
</a>
|
||||
@@ -117,6 +130,68 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div id="EidtRemoteShedule" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title">Update Remote Backup Schedules
|
||||
<img id="containerSettingLoading" src="/static/images/loading.gif"
|
||||
style="display: none;">
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
<form name="containerSettingsForm" action="/" class="form-horizontal">
|
||||
<div ng-hide="installationDetailsForm" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Backup Frequency" %}</label>
|
||||
<div class="col-sm-6">
|
||||
|
||||
<select ng-model="RemoteFrequency"
|
||||
class="form-control">
|
||||
<option>30 Minutes</option>
|
||||
<option>1 Hour</option>
|
||||
<option>6 Hours</option>
|
||||
<option>12 Hours</option>
|
||||
<option>1 Day</option>
|
||||
<option>3 Days</option>
|
||||
<option>1 Week</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div ng-hide="installationDetailsForm" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Backup File Retention" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-model="RemoteFileretention"
|
||||
class="form-control">
|
||||
<option>3 Days</option>
|
||||
<option>1 Week</option>
|
||||
<option>3 Weeks</option>
|
||||
<option>1 Month</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" ng-disabled="savingSettings" class="btn btn-primary"
|
||||
ng-click="UpdateRemoteschedules()">Save
|
||||
</button>
|
||||
<button type="button" ng-disabled="savingSettings" class="btn btn-default"
|
||||
data-dismiss="modal">
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<select ng-model="RemoteBackuptype" ng-change="SelectRemoteBackuptype()"
|
||||
class="form-control">
|
||||
<option>SFTP</option>
|
||||
<option>S3</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -68,8 +69,45 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div ng-hide="S3backupdiv">
|
||||
<span>S3 BAckups</span>
|
||||
|
||||
<div ng-hide="Selectprovider" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Choose Provider" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-model="Providervalue" ng-change="SelectProvidertype()"
|
||||
class="form-control">
|
||||
<option selected="selected">Amazon</option>
|
||||
<option>Wasabi</option>
|
||||
<option>Backblaze</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-hide="S3keyNamediv" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Name" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="S3keyName" type="text" class="form-control" ng-model="S3keyName"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-hide="EndpointURLdiv" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Endpoint URL" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="EndpointURL" type="text" class="form-control" ng-model="EndpointURL"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-hide="Accesskeydiv" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Access Key" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="Accesskey" type="text" class="form-control" ng-model="Accesskey"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-hide="SecretKeydiv" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Secret Key" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="SecretKey" type="password" class="form-control" ng-model="SecretKey"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -93,30 +131,31 @@
|
||||
<tr>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Backup Type</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">HostName</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Path</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Path / Key Name</th>
|
||||
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody >
|
||||
<tbody>
|
||||
{% for sub in backupconfigs %}
|
||||
<tr>
|
||||
<td style="padding: 13px;">{{ sub.Type }}</td>
|
||||
<td style="padding: 13px;">{{ sub.HostName }}</td>
|
||||
<td style="padding: 13px;">{{ sub.Path }}</td>
|
||||
<td style="padding: 13px;"> <button
|
||||
aria-label=""
|
||||
onclick="DeleteBackupConfigNow('{% url 'RemoteBackupConfig' %}?DeleteID={{ sub.id }}')"
|
||||
type="button" class="btn btn-border btn-alt border-red btn-link font-red">
|
||||
Delete
|
||||
</button>
|
||||
<a href="{% url 'BackupfileConfig' %}?ID={{ sub.id }}"
|
||||
aria-label=""
|
||||
<tr>
|
||||
<td style="padding: 13px;">{{ sub.Type }}</td>
|
||||
<td style="padding: 13px;">{{ sub.HostName }}</td>
|
||||
<td style="padding: 13px;">{{ sub.Path }}</td>
|
||||
<td style="padding: 13px;">
|
||||
<button
|
||||
aria-label=""
|
||||
onclick="DeleteBackupConfigNow('{% url 'RemoteBackupConfig' %}?DeleteID={{ sub.id }}')"
|
||||
type="button" class="btn btn-border btn-alt border-red btn-link font-red">
|
||||
Delete
|
||||
</button>
|
||||
<a href="{% url 'BackupfileConfig' %}?ID={{ sub.id }}"
|
||||
aria-label=""
|
||||
|
||||
type="button" class="btn btn-border btn-alt border-green btn-link font-green">
|
||||
Schedule Backups
|
||||
</a></td>
|
||||
</tr>
|
||||
type="button" class="btn btn-border btn-alt border-green btn-link font-green">
|
||||
Schedule Backups
|
||||
</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -124,7 +163,6 @@
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ urlpatterns = [
|
||||
url(r'^SaveBackupConfig', views.SaveBackupConfig, name='SaveBackupConfig'),
|
||||
url(r'^SaveBackupSchedule', views.SaveBackupSchedule, name='SaveBackupSchedule'),
|
||||
url(r'^AddWPsiteforRemoteBackup', views.AddWPsiteforRemoteBackup, name='AddWPsiteforRemoteBackup'),
|
||||
url(r'^UpdateRemoteschedules', views.UpdateRemoteschedules, name='UpdateRemoteschedules'),
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -502,6 +502,27 @@ def AddWPsiteforRemoteBackup(request):
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def UpdateRemoteschedules(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
result = pluginManager.preWebsiteCreation(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
wm = WebsiteManager()
|
||||
coreResult = wm.UpdateRemoteschedules(userID, json.loads(request.body))
|
||||
|
||||
result = pluginManager.postWebsiteCreation(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
return coreResult
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def installwpcore(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
@@ -25,6 +25,7 @@ from plogical.mailUtilities import mailUtilities
|
||||
from random import randint
|
||||
import time
|
||||
import re
|
||||
import boto3
|
||||
from plogical.childDomain import ChildDomainManager
|
||||
from math import ceil
|
||||
from plogical.alias import AliasManager
|
||||
@@ -222,12 +223,30 @@ class WebsiteManager:
|
||||
Data['backupconfigs'] =[]
|
||||
for i in allcon:
|
||||
configr = json.loads(i.config)
|
||||
Data['backupconfigs'].append({
|
||||
'id':i.pk,
|
||||
'Type': i.configtype,
|
||||
'HostName': configr['Hostname'],
|
||||
'Path': configr['Path']
|
||||
})
|
||||
if i.configtype == "SFTP":
|
||||
Data['backupconfigs'].append({
|
||||
'id': i.pk,
|
||||
'Type': i.configtype,
|
||||
'HostName': configr['Hostname'],
|
||||
'Path': configr['Path']
|
||||
})
|
||||
elif i.configtype == "S3":
|
||||
Provider = configr['Provider']
|
||||
if Provider == "Backblaze":
|
||||
Data['backupconfigs'].append({
|
||||
'id': i.pk,
|
||||
'Type': i.configtype,
|
||||
'HostName': Provider,
|
||||
'Path': configr['S3keyname']
|
||||
})
|
||||
else:
|
||||
Data['backupconfigs'].append({
|
||||
'id': i.pk,
|
||||
'Type': i.configtype,
|
||||
'HostName': Provider,
|
||||
'Path': configr['S3keyname']
|
||||
})
|
||||
|
||||
proc = httpProc(request, 'websiteFunctions/RemoteBackupConfig.html',
|
||||
Data, 'createWebsite')
|
||||
return proc.render()
|
||||
@@ -254,10 +273,15 @@ class WebsiteManager:
|
||||
allsechedule = RemoteBackupSchedule.objects.filter(RemoteBackupConfig=RemoteConfigobj)
|
||||
Data['Backupschedule'] = []
|
||||
for i in allsechedule:
|
||||
lastrun = i.lastrun
|
||||
LastRun = time.strftime('%Y-%m-%d', time.localtime(float(lastrun)))
|
||||
Data['Backupschedule'].append({
|
||||
'id': i.pk,
|
||||
'Name': i.Name,
|
||||
'RemoteConfiguration': i.RemoteBackupConfig.configtype
|
||||
'RemoteConfiguration': i.RemoteBackupConfig.configtype,
|
||||
'Retention': i.fileretention,
|
||||
'Frequency': i.timeintervel,
|
||||
'LastRun': LastRun
|
||||
})
|
||||
proc = httpProc(request, 'websiteFunctions/BackupfileConfig.html',
|
||||
Data, 'createWebsite')
|
||||
@@ -1148,8 +1172,37 @@ class WebsiteManager:
|
||||
"Password": Passwd,
|
||||
"Path": path
|
||||
}
|
||||
mkobj = RemoteBackupConfig(owner=admin, configtype=ConfigType, config=json.dumps(config))
|
||||
mkobj.save()
|
||||
elif ConfigType == "S3":
|
||||
Provider = data['Provider']
|
||||
if Provider == "Backblaze":
|
||||
S3keyname = data['S3keyname']
|
||||
SecertKey = data['SecertKey']
|
||||
AccessKey = data['AccessKey']
|
||||
EndUrl = data['EndUrl']
|
||||
config = {
|
||||
"Provider": Provider,
|
||||
"S3keyname": S3keyname,
|
||||
"SecertKey": SecertKey,
|
||||
"AccessKey": AccessKey,
|
||||
"EndUrl": EndUrl
|
||||
|
||||
}
|
||||
else:
|
||||
S3keyname = data['S3keyname']
|
||||
SecertKey = data['SecertKey']
|
||||
AccessKey = data['AccessKey']
|
||||
config = {
|
||||
"Provider": Provider,
|
||||
"S3keyname": S3keyname,
|
||||
"SecertKey": SecertKey,
|
||||
"AccessKey": AccessKey,
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
mkobj = RemoteBackupConfig(owner=admin, configtype=ConfigType, config=json.dumps(config))
|
||||
mkobj.save()
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
@@ -1174,11 +1227,46 @@ class WebsiteManager:
|
||||
ScheduleName = data['ScheduleName']
|
||||
RemoteConfigID = data['RemoteConfigID']
|
||||
BackupType = data['BackupType']
|
||||
config = {
|
||||
'BackupType': BackupType
|
||||
}
|
||||
|
||||
|
||||
RemoteBackupConfigobj = RemoteBackupConfig.objects.get(pk=RemoteConfigID)
|
||||
Rconfig = json.loads(RemoteBackupConfigobj.config)
|
||||
provider = Rconfig['Provider']
|
||||
if provider == "Backblaze":
|
||||
EndURl = Rconfig['EndUrl']
|
||||
elif provider == "Amazon":
|
||||
EndURl = "https://s3.us-east-1.amazonaws.com"
|
||||
elif provider == "Wasabi":
|
||||
EndURl = "https://s3.wasabisys.com"
|
||||
|
||||
AccessKey = Rconfig['AccessKey']
|
||||
SecertKey = Rconfig['SecertKey']
|
||||
|
||||
session = boto3.session.Session()
|
||||
|
||||
client = session.client(
|
||||
's3',
|
||||
endpoint_url=EndURl,
|
||||
aws_access_key_id=AccessKey,
|
||||
aws_secret_access_key=SecertKey,
|
||||
verify=False
|
||||
)
|
||||
|
||||
############Creating Bucket
|
||||
BucketName = randomPassword.generate_pass().lower()
|
||||
|
||||
try:
|
||||
client.create_bucket(Bucket=BucketName)
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile("Creating Bucket Error: %s"%str(msg))
|
||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
config = {
|
||||
'BackupType': BackupType,
|
||||
'BucketName': BucketName
|
||||
}
|
||||
|
||||
svobj = RemoteBackupSchedule( RemoteBackupConfig=RemoteBackupConfigobj, Name=ScheduleName,
|
||||
timeintervel=Backfrequency, fileretention=FileRetention, config=json.dumps(config),
|
||||
@@ -1241,6 +1329,30 @@ class WebsiteManager:
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
def UpdateRemoteschedules(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
ScheduleID = data['ScheduleID']
|
||||
Frequency = data['Frequency']
|
||||
FileRetention = data['FileRetention']
|
||||
|
||||
scheduleobj = RemoteBackupSchedule.objects.get(pk=ScheduleID)
|
||||
scheduleobj.timeintervel = Frequency
|
||||
scheduleobj.fileretention = FileRetention
|
||||
scheduleobj.save()
|
||||
|
||||
data_ret = {'status': 1, 'error_message': 'None',}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except BaseException as msg:
|
||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
|
||||
def installwpcore(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user