@@ -10,7 +10,7 @@ function getCookie(name) {
1010 if ( document . cookie && document . cookie !== '' ) {
1111 var cookies = document . cookie . split ( ';' ) ;
1212 for ( var i = 0 ; i < cookies . length ; i ++ ) {
13- var cookie = jQuery . trim ( cookies [ i ] ) ;
13+ var cookie = ( cookies [ i ] || '' ) . replace ( / ^ \s + | \s + $ / g , '' ) ;
1414 // Does this cookie string begin with the name we want?
1515 if ( cookie . substring ( 0 , name . length + 1 ) === ( name + '=' ) ) {
1616 cookieValue = decodeURIComponent ( cookie . substring ( name . length + 1 ) ) ;
@@ -39,6 +39,77 @@ function randomPassword(length) {
3939window . app = angular . module ( 'CyberCP' , [ ] ) ;
4040var app = window . app ; // Local reference for this file
4141
42+ // MUST be first: register dashboard controller before any other setup (avoids ctrlreg when CDN/Tracking Prevention blocks scripts)
43+ app . controller ( 'dashboardStatsController' , [ '$scope' , '$http' , '$timeout' , function ( $scope , $http , $timeout ) {
44+ $scope . cpuUsage = 0 ; $scope . ramUsage = 0 ; $scope . diskUsage = 0 ; $scope . cpuCores = 0 ;
45+ $scope . ramTotalMB = 0 ; $scope . diskTotalGB = 0 ; $scope . diskFreeGB = 0 ;
46+ $scope . totalUsers = 0 ; $scope . totalSites = 0 ; $scope . totalWPSites = 0 ;
47+ $scope . totalDBs = 0 ; $scope . totalEmails = 0 ; $scope . totalFTPUsers = 0 ;
48+ $scope . topProcesses = [ ] ; $scope . sshLogins = [ ] ; $scope . sshLogs = [ ] ;
49+ $scope . loadingTopProcesses = true ; $scope . loadingSSHLogins = true ; $scope . loadingSSHLogs = true ;
50+ $scope . blockedIPs = { } ; $scope . blockingIP = null ; $scope . securityAlerts = [ ] ;
51+ var opts = { headers : { 'X-CSRFToken' : ( typeof getCookie === 'function' ) ? getCookie ( 'csrftoken' ) : '' } } ;
52+ try {
53+ $http . get ( '/base/getSystemStatus' , opts ) . then ( function ( r ) {
54+ if ( r && r . data && r . data . status === 1 ) {
55+ $scope . cpuUsage = r . data . cpuUsage || 0 ; $scope . ramUsage = r . data . ramUsage || 0 ;
56+ $scope . diskUsage = r . data . diskUsage || 0 ; $scope . cpuCores = r . data . cpuCores || 0 ;
57+ $scope . ramTotalMB = r . data . ramTotalMB || 0 ; $scope . diskTotalGB = r . data . diskTotalGB || 0 ;
58+ $scope . diskFreeGB = r . data . diskFreeGB || 0 ;
59+ }
60+ } ) ;
61+ $http . get ( '/base/getDashboardStats' , opts ) . then ( function ( r ) {
62+ if ( r && r . data && r . data . status === 1 ) {
63+ $scope . totalUsers = r . data . total_users || 0 ; $scope . totalSites = r . data . total_sites || 0 ;
64+ $scope . totalWPSites = r . data . total_wp_sites || 0 ; $scope . totalDBs = r . data . total_dbs || 0 ;
65+ $scope . totalEmails = r . data . total_emails || 0 ; $scope . totalFTPUsers = r . data . total_ftp_users || 0 ;
66+ }
67+ } ) ;
68+ $http . get ( '/base/getRecentSSHLogins' , opts ) . then ( function ( r ) {
69+ $scope . loadingSSHLogins = false ;
70+ $scope . sshLogins = ( r && r . data && r . data . logins ) ? r . data . logins : [ ] ;
71+ } , function ( ) { $scope . loadingSSHLogins = false ; $scope . sshLogins = [ ] ; } ) ;
72+ $http . get ( '/base/getRecentSSHLogs' , opts ) . then ( function ( r ) {
73+ $scope . loadingSSHLogs = false ;
74+ $scope . sshLogs = ( r && r . data && r . data . logs ) ? r . data . logs : [ ] ;
75+ } , function ( ) { $scope . loadingSSHLogs = false ; $scope . sshLogs = [ ] ; } ) ;
76+ $http . get ( '/base/getTopProcesses' , opts ) . then ( function ( r ) {
77+ $scope . loadingTopProcesses = false ;
78+ $scope . topProcesses = ( r && r . data && r . data . status === 1 && r . data . processes ) ? r . data . processes : [ ] ;
79+ } , function ( ) { $scope . loadingTopProcesses = false ; $scope . topProcesses = [ ] ; } ) ;
80+ if ( typeof $timeout === 'function' ) { $timeout ( function ( ) { /* refresh */ } , 10000 ) ; }
81+ } catch ( e ) { /* ignore */ }
82+ } ] ) ;
83+
84+ // Overview CPU/RAM/Disk cards use systemStatusInfo – register early so data loads even if later script fails
85+ app . controller ( 'systemStatusInfo' , [ '$scope' , '$http' , '$timeout' , function ( $scope , $http , $timeout ) {
86+ $scope . uptimeLoaded = false ;
87+ $scope . uptime = 'Loading...' ;
88+ $scope . cpuUsage = 0 ; $scope . ramUsage = 0 ; $scope . diskUsage = 0 ;
89+ $scope . cpuCores = 0 ; $scope . ramTotalMB = 0 ; $scope . diskTotalGB = 0 ; $scope . diskFreeGB = 0 ;
90+ $scope . getSystemStatus = function ( ) { fetchStatus ( ) ; } ;
91+ function fetchStatus ( ) {
92+ try {
93+ var csrf = ( typeof getCookie === 'function' ) ? getCookie ( 'csrftoken' ) : '' ;
94+ $http . get ( '/base/getSystemStatus' , { headers : { 'X-CSRFToken' : csrf } } ) . then ( function ( r ) {
95+ if ( r && r . data && r . data . status === 1 ) {
96+ $scope . cpuUsage = r . data . cpuUsage != null ? r . data . cpuUsage : 0 ;
97+ $scope . ramUsage = r . data . ramUsage != null ? r . data . ramUsage : 0 ;
98+ $scope . diskUsage = r . data . diskUsage != null ? r . data . diskUsage : 0 ;
99+ $scope . cpuCores = r . data . cpuCores != null ? r . data . cpuCores : 0 ;
100+ $scope . ramTotalMB = r . data . ramTotalMB != null ? r . data . ramTotalMB : 0 ;
101+ $scope . diskTotalGB = r . data . diskTotalGB != null ? r . data . diskTotalGB : 0 ;
102+ $scope . diskFreeGB = r . data . diskFreeGB != null ? r . data . diskFreeGB : 0 ;
103+ $scope . uptime = r . data . uptime || 'N/A' ;
104+ }
105+ $scope . uptimeLoaded = true ;
106+ } , function ( ) { $scope . uptime = 'Unavailable' ; $scope . uptimeLoaded = true ; } ) ;
107+ if ( typeof $timeout === 'function' ) { $timeout ( fetchStatus , 60000 ) ; }
108+ } catch ( e ) { $scope . uptimeLoaded = true ; }
109+ }
110+ fetchStatus ( ) ;
111+ } ] ) ;
112+
42113var globalScope ;
43114
44115function GlobalRespSuccess ( response ) {
@@ -566,15 +637,18 @@ app.controller('homePageStatus', function ($scope, $http, $timeout) {
566637////////////
567638
568639function increment ( ) {
569- $ ( '.box' ) . hide ( ) ;
640+ var boxes = document . querySelectorAll ? document . querySelectorAll ( '.box' ) : [ ] ;
641+ for ( var i = 0 ; i < boxes . length ; i ++ ) boxes [ i ] . style . display = 'none' ;
570642 setTimeout ( function ( ) {
571- $ ( '.box' ) . show ( ) ;
643+ for ( var j = 0 ; j < boxes . length ; j ++ ) boxes [ j ] . style . display = '' ;
572644 } , 100 ) ;
573-
574-
575645}
576646
577- increment ( ) ;
647+ if ( document . readyState === 'loading' ) {
648+ document . addEventListener ( 'DOMContentLoaded' , increment ) ;
649+ } else {
650+ increment ( ) ;
651+ }
578652
579653////////////
580654
@@ -932,7 +1006,8 @@ var dashboardStatsControllerFn = function ($scope, $http, $timeout) {
9321006 $scope . errorTopProcesses = '' ;
9331007 $scope . refreshTopProcesses = function ( ) {
9341008 $scope . loadingTopProcesses = true ;
935- $http . get ( '/base/getTopProcesses' ) . then ( function ( response ) {
1009+ var h = { headers : { 'X-CSRFToken' : ( typeof getCookie === 'function' ) ? getCookie ( 'csrftoken' ) : '' } } ;
1010+ $http . get ( '/base/getTopProcesses' , h ) . then ( function ( response ) {
9361011 $scope . loadingTopProcesses = false ;
9371012 if ( response . data && response . data . status === 1 && response . data . processes ) {
9381013 $scope . topProcesses = response . data . processes ;
@@ -951,7 +1026,8 @@ var dashboardStatsControllerFn = function ($scope, $http, $timeout) {
9511026 $scope . errorSSHLogins = '' ;
9521027 $scope . refreshSSHLogins = function ( ) {
9531028 $scope . loadingSSHLogins = true ;
954- $http . get ( '/base/getRecentSSHLogins' ) . then ( function ( response ) {
1029+ var h = { headers : { 'X-CSRFToken' : ( typeof getCookie === 'function' ) ? getCookie ( 'csrftoken' ) : '' } } ;
1030+ $http . get ( '/base/getRecentSSHLogins' , h ) . then ( function ( response ) {
9551031 $scope . loadingSSHLogins = false ;
9561032 if ( response . data && response . data . logins ) {
9571033 $scope . sshLogins = response . data . logins ;
@@ -979,7 +1055,8 @@ var dashboardStatsControllerFn = function ($scope, $http, $timeout) {
9791055 $scope . loadingSecurityAnalysis = false ;
9801056 $scope . refreshSSHLogs = function ( ) {
9811057 $scope . loadingSSHLogs = true ;
982- $http . get ( '/base/getRecentSSHLogs' ) . then ( function ( response ) {
1058+ var h = { headers : { 'X-CSRFToken' : ( typeof getCookie === 'function' ) ? getCookie ( 'csrftoken' ) : '' } } ;
1059+ $http . get ( '/base/getRecentSSHLogs' , h ) . then ( function ( response ) {
9831060 $scope . loadingSSHLogs = false ;
9841061 if ( response . data && response . data . logs ) {
9851062 $scope . sshLogs = response . data . logs ;
0 commit comments