Add storage stats, last backup info, and error logs to ManageOCBackups page

- Add comprehensive backup account overview with visual stats cards
- Display storage usage (total, used, available, percentage) from platform API
- Show last backup run timestamp and status (success/failed)
- Display total backups count and failed backups count
- Add recent backup error logs table with timestamp, website, and error message
- Fetch all stats from platform.cyberpersons.com/Billing/GetBackupStats endpoint
- Beautiful gradient cards for visual presentation of stats
- Progress bar for storage usage visualization
- Conditional display of error logs (only shown if errors exist)
- Add account info card showing SFTP user and plan name
- Graceful fallback to N/A if platform API is unavailable
- Comprehensive error logging for API failures
This commit is contained in:
usmannasir
2025-10-14 19:11:38 +05:00
parent fb02243245
commit b6f20a6a5e
2 changed files with 157 additions and 4 deletions

View File

@@ -2119,8 +2119,53 @@ class BackupManager:
websitesName = ACLManager.findAllSites(currentACL, userID)
proc = httpProc(request, 'backup/OneClickBackupSchedule.html', {'destination': NormalBackupDests.objects.get(name=ocb.sftpUser).name, 'websites': websitesName},
'scheduleBackups')
# Fetch storage stats and backup info from platform API
storage_info = {
'total_storage': 'N/A',
'used_storage': 'N/A',
'available_storage': 'N/A',
'usage_percentage': 0,
'last_backup_run': 'Never',
'last_backup_status': 'N/A',
'total_backups': 0,
'failed_backups': 0,
'error_logs': []
}
try:
import requests
url = 'https://platform.cyberpersons.com/Billing/GetBackupStats'
payload = {
'sub': ocb.subscription,
'sftpUser': ocb.sftpUser,
'serverIP': ACLManager.fetchIP()
}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=30)
if response.status_code == 200:
api_data = response.json()
if api_data.get('status') == 1:
storage_info = api_data.get('data', storage_info)
logging.CyberCPLogFileWriter.writeToFile(f'Successfully fetched backup stats for {ocb.sftpUser} [ManageOCBackups]')
else:
logging.CyberCPLogFileWriter.writeToFile(f'Platform API returned error: {api_data.get("error_message")} [ManageOCBackups]')
else:
logging.CyberCPLogFileWriter.writeToFile(f'Platform API returned HTTP {response.status_code} [ManageOCBackups]')
except Exception as e:
logging.CyberCPLogFileWriter.writeToFile(f'Failed to fetch backup stats: {str(e)} [ManageOCBackups]')
context = {
'destination': NormalBackupDests.objects.get(name=ocb.sftpUser).name,
'websites': websitesName,
'storage_info': storage_info,
'ocb_subscription': ocb.subscription,
'ocb_plan_name': ocb.planName,
'ocb_sftp_user': ocb.sftpUser
}
proc = httpProc(request, 'backup/OneClickBackupSchedule.html', context, 'scheduleBackups')
return proc.render()
def RestoreOCBackups(self, request=None, userID=None, data=None):