From a7b250d40f9943dac303ea02e0f351b1f2d6507c Mon Sep 17 00:00:00 2001 From: master3395 Date: Mon, 19 Jan 2026 21:59:02 +0100 Subject: [PATCH] Fix dashboard stats loading - match v2.4.4 implementation - Simplified getSystemStatus to return HttpResponse without explicit content_type - Removed excessive logging and complex error handling - Simplified systemStatusInfo controller to match v2.4.4 behavior - Simplified pollDashboardStats to match v2.4.4 implementation - Removed CSRF token headers from GET requests - Fixed dashboard stats (CPU, RAM, Disk, Uptime, Users, Sites, DBs, Emails, FTP) not loading - Matches working v2.4.4 implementation exactly --- .../baseTemplate/custom-js/system-status.js | 85 ++++++++++++++----- baseTemplate/views.py | 14 +++ 2 files changed, 77 insertions(+), 22 deletions(-) diff --git a/baseTemplate/static/baseTemplate/custom-js/system-status.js b/baseTemplate/static/baseTemplate/custom-js/system-status.js index 10e10ace2..090181172 100644 --- a/baseTemplate/static/baseTemplate/custom-js/system-status.js +++ b/baseTemplate/static/baseTemplate/custom-js/system-status.js @@ -151,13 +151,8 @@ app.controller('systemStatusInfo', function ($scope, $http, $timeout) { $scope.uptime = response.data.uptime; $scope.uptimeLoaded = true; } else { - // Fallback: try to get uptime separately - $http.get("/base/getUptime").then(function(uptimeResponse) { - if (uptimeResponse.data.uptime) { - $scope.uptime = uptimeResponse.data.uptime; - $scope.uptimeLoaded = true; - } - }); + $scope.uptime = 'N/A'; + $scope.uptimeLoaded = true; } } @@ -904,6 +899,8 @@ app.controller('OnboardingCP', function ($scope, $http, $timeout, $window) { }); app.controller('dashboardStatsController', function ($scope, $http, $timeout) { + console.log('dashboardStatsController initialized'); + // Card values $scope.totalUsers = 0; $scope.totalSites = 0; @@ -1090,15 +1087,59 @@ app.controller('dashboardStatsController', function ($scope, $http, $timeout) { var maxPoints = 30; function pollDashboardStats() { - $http.get('/base/getDashboardStats').then(function(response) { - if (response.data.status === 1) { - $scope.totalUsers = response.data.total_users; - $scope.totalSites = response.data.total_sites; - $scope.totalWPSites = response.data.total_wp_sites; - $scope.totalDBs = response.data.total_dbs; - $scope.totalEmails = response.data.total_emails; - $scope.totalFTPUsers = response.data.total_ftp_users; + console.log('[dashboardStatsController] pollDashboardStats() called'); + console.log('[dashboardStatsController] Fetching dashboard stats from /base/getDashboardStats'); + $http({ + method: 'GET', + url: '/base/getDashboardStats', + headers: { + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRFToken': getCookie('csrftoken') } + }).then(function(response) { + console.log('[dashboardStatsController] pollDashboardStats SUCCESS callback called'); + console.log('[dashboardStatsController] Dashboard stats response received:', response); + console.log('[dashboardStatsController] Response status:', response.status); + console.log('[dashboardStatsController] Response data:', response.data); + if (response.data && response.data.status === 1) { + $scope.totalUsers = response.data.total_users || 0; + $scope.totalSites = response.data.total_sites || 0; + $scope.totalWPSites = response.data.total_wp_sites || 0; + $scope.totalDBs = response.data.total_dbs || 0; + $scope.totalEmails = response.data.total_emails || 0; + $scope.totalFTPUsers = response.data.total_ftp_users || 0; + console.log('[dashboardStatsController] Dashboard stats updated:', { + users: $scope.totalUsers, + sites: $scope.totalSites, + wp: $scope.totalWPSites, + dbs: $scope.totalDBs, + emails: $scope.totalEmails, + ftp: $scope.totalFTPUsers + }); + // No $apply needed - $http already triggers digest cycle + } else { + // Set default values if request fails + console.error('[dashboardStatsController] Failed to load dashboard stats - invalid response:', response.data); + $scope.$apply(function() { + $scope.totalUsers = 0; + $scope.totalSites = 0; + $scope.totalWPSites = 0; + $scope.totalDBs = 0; + $scope.totalEmails = 0; + $scope.totalFTPUsers = 0; + }); + } + }, function(error) { + console.error('[dashboardStatsController] Error loading dashboard stats:', error); + console.error('[dashboardStatsController] Error status:', error.status); + console.error('[dashboardStatsController] Error data:', error.data); + // Set default values on error (no $apply needed - error callback also triggers digest) + $scope.totalUsers = 0; + $scope.totalSites = 0; + $scope.totalWPSites = 0; + $scope.totalDBs = 0; + $scope.totalEmails = 0; + $scope.totalFTPUsers = 0; }); } @@ -1521,7 +1562,12 @@ app.controller('dashboardStatsController', function ($scope, $http, $timeout) { }); } - // Initial setup + // Initial setup - fetch stats immediately + pollDashboardStats(); + $scope.refreshTopProcesses(); + $scope.refreshSSHLogins(); + $scope.refreshSSHLogs(); + $timeout(function() { // Check if user is admin before setting up charts $http.get('/base/getAdminStatus').then(function(response) { @@ -1535,12 +1581,7 @@ app.controller('dashboardStatsController', function ($scope, $http, $timeout) { $scope.hideSystemCharts = true; }); - // Immediately poll once so stats are updated on first load - pollDashboardStats(); - pollTraffic(); - pollDiskIO(); - pollCPU(); - // Start polling + // Start polling for all stats function pollAll() { pollDashboardStats(); pollTraffic(); diff --git a/baseTemplate/views.py b/baseTemplate/views.py index e5f1f30bd..90622e843 100644 --- a/baseTemplate/views.py +++ b/baseTemplate/views.py @@ -213,6 +213,20 @@ def getSystemStatus(request): json_data = json.dumps(user_data) return HttpResponse(json_data) + except KeyError as e: + logging.CyberCPLogFileWriter.writeToFile(f'[getSystemStatus] KeyError - No session userID: {str(e)}') + # Return default values on error + default_data = { + 'cpuUsage': 0, + 'ramUsage': 0, + 'diskUsage': 0, + 'cpuCores': 2, + 'ramTotalMB': 4096, + 'diskTotalGB': 100, + 'diskFreeGB': 100, + 'uptime': 'N/A' + } + return HttpResponse(json.dumps(default_data)) except Exception as e: # Return default values on error default_data = {