mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-14 01:06:09 +01:00
add code to fetch existing backups
This commit is contained in:
@@ -2341,10 +2341,9 @@ class BackupManager:
|
|||||||
|
|
||||||
def ReconfigureSubscription(self, request=None, userID=None, data=None):
|
def ReconfigureSubscription(self, request=None, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
if not data:
|
||||||
admin = Administrator.objects.get(pk=userID)
|
return JsonResponse({'status': 0, 'error_message': 'No data provided'})
|
||||||
|
|
||||||
data = json.loads(request.body)
|
|
||||||
subscription_id = data['subscription_id']
|
subscription_id = data['subscription_id']
|
||||||
customer_id = data['customer_id']
|
customer_id = data['customer_id']
|
||||||
plan_name = data['plan_name']
|
plan_name = data['plan_name']
|
||||||
@@ -2372,13 +2371,13 @@ class BackupManager:
|
|||||||
# Create OneClickBackups record
|
# Create OneClickBackups record
|
||||||
from IncBackups.models import OneClickBackups
|
from IncBackups.models import OneClickBackups
|
||||||
backup_plan = OneClickBackups(
|
backup_plan = OneClickBackups(
|
||||||
owner=admin,
|
owner=Administrator.objects.get(pk=userID),
|
||||||
planName=plan_name,
|
planName=plan_name,
|
||||||
months='1' if interval == 'month' else '12',
|
months='1' if interval == 'month' else '12',
|
||||||
price=amount,
|
price=amount,
|
||||||
customer=customer_id,
|
customer=customer_id,
|
||||||
subscription=subscription_id,
|
subscription=subscription_id,
|
||||||
sftpUser=response_data.get('sftpUser'), # Get username from platform response
|
sftpUser=response_data.get('sftpUser'),
|
||||||
state=1 # Set as active since SFTP is already configured
|
state=1 # Set as active since SFTP is already configured
|
||||||
)
|
)
|
||||||
backup_plan.save()
|
backup_plan.save()
|
||||||
@@ -2388,10 +2387,10 @@ class BackupManager:
|
|||||||
'IPAddress': response_data.get('ipAddress'),
|
'IPAddress': response_data.get('ipAddress'),
|
||||||
'password': 'NOT-NEEDED',
|
'password': 'NOT-NEEDED',
|
||||||
'backupSSHPort': '22',
|
'backupSSHPort': '22',
|
||||||
'userName': response_data.get('sftpUser'), # Use username from platform
|
'userName': response_data.get('sftpUser'),
|
||||||
'type': 'SFTP',
|
'type': 'SFTP',
|
||||||
'path': 'cpbackups',
|
'path': 'cpbackups',
|
||||||
'name': response_data.get('sftpUser') # Use username from platform
|
'name': response_data.get('sftpUser')
|
||||||
}
|
}
|
||||||
|
|
||||||
wm = BackupManager()
|
wm = BackupManager()
|
||||||
@@ -2407,7 +2406,7 @@ class BackupManager:
|
|||||||
else:
|
else:
|
||||||
return JsonResponse({'status': 0, 'error_message': f'Platform API error: {response.text}'})
|
return JsonResponse({'status': 0, 'error_message': f'Platform API error: {response.text}'})
|
||||||
|
|
||||||
except BaseException as msg:
|
except Exception as e:
|
||||||
return JsonResponse({'status': 0, 'error_message': str(msg)})
|
return JsonResponse({'status': 0, 'error_message': str(e)})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -548,7 +548,8 @@ def ReconfigureSubscription(request):
|
|||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
bm = BackupManager()
|
bm = BackupManager()
|
||||||
return bm.ReconfigureSubscription(request, userID)
|
data = json.loads(request.body)
|
||||||
|
return bm.ReconfigureSubscription(request, userID, data)
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
|
|||||||
Reference in New Issue
Block a user