Skip to content

Commit 68e59cc

Browse files
authored
Merge pull request #1705 from master3395/v2.5.5-dev
V2.5.5 dev
2 parents 5c44048 + ea05bb1 commit 68e59cc

File tree

44 files changed

+4562
-1002
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4562
-1002
lines changed

CyberCP/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140
'baseTemplate.context_processors.version_context',
141141
'baseTemplate.context_processors.cosmetic_context',
142142
'baseTemplate.context_processors.notification_preferences_context',
143+
'baseTemplate.context_processors.firewall_static_context',
144+
'baseTemplate.context_processors.dns_static_context',
143145
],
144146
},
145147
},

baseTemplate/context_processors.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,51 @@ def notification_preferences_context(request):
5555
}
5656

5757
def firewall_static_context(request):
58-
"""Expose a cache-busting token for firewall static assets."""
59-
firewall_js_path = '/usr/local/CyberCP/static/firewall/firewall.js'
58+
"""Expose a cache-busting token for firewall static assets (bumps when firewall.js changes)."""
6059
try:
61-
version = int(os.path.getmtime(firewall_js_path))
62-
except OSError:
60+
from django.conf import settings
61+
base = settings.BASE_DIR
62+
# Check both app static and repo static so version updates when either is updated
63+
paths = [
64+
os.path.join(base, 'firewall', 'static', 'firewall', 'firewall.js'),
65+
os.path.join(base, 'static', 'firewall', 'firewall.js'),
66+
os.path.join(base, 'public', 'static', 'firewall', 'firewall.js'),
67+
]
68+
version = 0
69+
for p in paths:
70+
try:
71+
version = max(version, int(os.path.getmtime(p)))
72+
except (OSError, TypeError):
73+
pass
74+
if version <= 0:
75+
version = int(time.time())
76+
except (OSError, AttributeError):
6377
version = int(time.time())
6478
return {
6579
'FIREWALL_STATIC_VERSION': version
80+
}
81+
82+
83+
def dns_static_context(request):
84+
"""Cache-busting for DNS static assets (bumps when dns.js changes). Avoids stale JS/layout."""
85+
try:
86+
from django.conf import settings
87+
base = settings.BASE_DIR
88+
paths = [
89+
os.path.join(base, 'dns', 'static', 'dns', 'dns.js'),
90+
os.path.join(base, 'static', 'dns', 'dns.js'),
91+
os.path.join(base, 'public', 'static', 'dns', 'dns.js'),
92+
]
93+
version = 0
94+
for p in paths:
95+
try:
96+
version = max(version, int(os.path.getmtime(p)))
97+
except (OSError, TypeError):
98+
pass
99+
if version <= 0:
100+
version = int(time.time())
101+
except (OSError, AttributeError):
102+
version = int(time.time())
103+
return {
104+
'DNS_STATIC_VERSION': version
66105
}

baseTemplate/static/baseTemplate/custom-js/system-status.js

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
3939
window.app = angular.module('CyberCP', []);
4040
var 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+
42113
var globalScope;
43114

44115
function GlobalRespSuccess(response) {
@@ -566,15 +637,18 @@ app.controller('homePageStatus', function ($scope, $http, $timeout) {
566637
////////////
567638

568639
function 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;

baseTemplate/static/baseTemplate/vendor/select2/select2.full.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)