From 9390551ebd111573f4c73db4c484781dc77f576b Mon Sep 17 00:00:00 2001 From: master3395 Date: Mon, 16 Feb 2026 03:16:18 +0100 Subject: [PATCH] Firewall: fix search bar, Search button, Modify centering, system-status $ error - Search input: add firewall-search-input class, blue focus instead of red (avoids read-only/error look) - Search button: use btn-search with round futuristic style (match Ban IP/Overview) - Actions column: center Modify/Unban/Delete in Firewall Rules and Banned IPs tables - system-status.js: increment() uses document.querySelectorAll (no jQuery), fixes $ is not defined - upgrade_modules/09_sync.sh: sync firewall static to public/static during upgrade - to-do/FIREWALL-LOAD-CHANGES.md: doc on file locations and deploy steps --- baseTemplate/context_processors.py | 22 +- .../baseTemplate/custom-js/system-status.js | 95 +- .../templates/baseTemplate/index.html | 20 +- firewall/firewallManager.py | 302 +++-- firewall/static/firewall/firewall.js | 443 ++++--- firewall/templates/firewall/firewall.html | 279 +++- firewall/views.py | 27 +- .../baseTemplate/custom-js/system-status.js | 13 +- public/static/firewall/firewall.js | 1055 ++++++++++++++- .../baseTemplate/custom-js/system-status.js | 214 ++- static/firewall/firewall.js | 1163 ++++++++++------- to-do/FIREWALL-LOAD-CHANGES.md | 64 + upgrade_modules/09_sync.sh | 6 + 13 files changed, 2851 insertions(+), 852 deletions(-) create mode 100644 to-do/FIREWALL-LOAD-CHANGES.md diff --git a/baseTemplate/context_processors.py b/baseTemplate/context_processors.py index b3122a0fe..db7aa8d90 100644 --- a/baseTemplate/context_processors.py +++ b/baseTemplate/context_processors.py @@ -55,11 +55,25 @@ def notification_preferences_context(request): } def firewall_static_context(request): - """Expose a cache-busting token for firewall static assets.""" - firewall_js_path = '/usr/local/CyberCP/static/firewall/firewall.js' + """Expose a cache-busting token for firewall static assets (bumps when firewall.js changes).""" try: - version = int(os.path.getmtime(firewall_js_path)) - except OSError: + from django.conf import settings + base = settings.BASE_DIR + # Check both app static and repo static so version updates when either is updated + paths = [ + os.path.join(base, 'firewall', 'static', 'firewall', 'firewall.js'), + os.path.join(base, 'static', 'firewall', 'firewall.js'), + os.path.join(base, 'public', 'static', 'firewall', 'firewall.js'), + ] + version = 0 + for p in paths: + try: + version = max(version, int(os.path.getmtime(p))) + except (OSError, TypeError): + pass + if version <= 0: + version = int(time.time()) + except (OSError, AttributeError): version = int(time.time()) return { 'FIREWALL_STATIC_VERSION': version diff --git a/baseTemplate/static/baseTemplate/custom-js/system-status.js b/baseTemplate/static/baseTemplate/custom-js/system-status.js index 4da778e02..9924462f9 100644 --- a/baseTemplate/static/baseTemplate/custom-js/system-status.js +++ b/baseTemplate/static/baseTemplate/custom-js/system-status.js @@ -10,7 +10,7 @@ function getCookie(name) { if (document.cookie && document.cookie !== '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { - var cookie = jQuery.trim(cookies[i]); + var cookie = (cookies[i] || '').replace(/^\s+|\s+$/g, ''); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) === (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); @@ -39,6 +39,77 @@ function randomPassword(length) { window.app = angular.module('CyberCP', []); var app = window.app; // Local reference for this file +// MUST be first: register dashboard controller before any other setup (avoids ctrlreg when CDN/Tracking Prevention blocks scripts) +app.controller('dashboardStatsController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { + $scope.cpuUsage = 0; $scope.ramUsage = 0; $scope.diskUsage = 0; $scope.cpuCores = 0; + $scope.ramTotalMB = 0; $scope.diskTotalGB = 0; $scope.diskFreeGB = 0; + $scope.totalUsers = 0; $scope.totalSites = 0; $scope.totalWPSites = 0; + $scope.totalDBs = 0; $scope.totalEmails = 0; $scope.totalFTPUsers = 0; + $scope.topProcesses = []; $scope.sshLogins = []; $scope.sshLogs = []; + $scope.loadingTopProcesses = true; $scope.loadingSSHLogins = true; $scope.loadingSSHLogs = true; + $scope.blockedIPs = {}; $scope.blockingIP = null; $scope.securityAlerts = []; + var opts = { headers: { 'X-CSRFToken': (typeof getCookie === 'function') ? getCookie('csrftoken') : '' } }; + try { + $http.get('/base/getSystemStatus', opts).then(function (r) { + if (r && r.data && r.data.status === 1) { + $scope.cpuUsage = r.data.cpuUsage || 0; $scope.ramUsage = r.data.ramUsage || 0; + $scope.diskUsage = r.data.diskUsage || 0; $scope.cpuCores = r.data.cpuCores || 0; + $scope.ramTotalMB = r.data.ramTotalMB || 0; $scope.diskTotalGB = r.data.diskTotalGB || 0; + $scope.diskFreeGB = r.data.diskFreeGB || 0; + } + }); + $http.get('/base/getDashboardStats', opts).then(function (r) { + if (r && r.data && r.data.status === 1) { + $scope.totalUsers = r.data.total_users || 0; $scope.totalSites = r.data.total_sites || 0; + $scope.totalWPSites = r.data.total_wp_sites || 0; $scope.totalDBs = r.data.total_dbs || 0; + $scope.totalEmails = r.data.total_emails || 0; $scope.totalFTPUsers = r.data.total_ftp_users || 0; + } + }); + $http.get('/base/getRecentSSHLogins', opts).then(function (r) { + $scope.loadingSSHLogins = false; + $scope.sshLogins = (r && r.data && r.data.logins) ? r.data.logins : []; + }, function () { $scope.loadingSSHLogins = false; $scope.sshLogins = []; }); + $http.get('/base/getRecentSSHLogs', opts).then(function (r) { + $scope.loadingSSHLogs = false; + $scope.sshLogs = (r && r.data && r.data.logs) ? r.data.logs : []; + }, function () { $scope.loadingSSHLogs = false; $scope.sshLogs = []; }); + $http.get('/base/getTopProcesses', opts).then(function (r) { + $scope.loadingTopProcesses = false; + $scope.topProcesses = (r && r.data && r.data.status === 1 && r.data.processes) ? r.data.processes : []; + }, function () { $scope.loadingTopProcesses = false; $scope.topProcesses = []; }); + if (typeof $timeout === 'function') { $timeout(function() { /* refresh */ }, 10000); } + } catch (e) { /* ignore */ } +}]); + +// Overview CPU/RAM/Disk cards use systemStatusInfo – register early so data loads even if later script fails +app.controller('systemStatusInfo', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { + $scope.uptimeLoaded = false; + $scope.uptime = 'Loading...'; + $scope.cpuUsage = 0; $scope.ramUsage = 0; $scope.diskUsage = 0; + $scope.cpuCores = 0; $scope.ramTotalMB = 0; $scope.diskTotalGB = 0; $scope.diskFreeGB = 0; + $scope.getSystemStatus = function() { fetchStatus(); }; + function fetchStatus() { + try { + var csrf = (typeof getCookie === 'function') ? getCookie('csrftoken') : ''; + $http.get('/base/getSystemStatus', { headers: { 'X-CSRFToken': csrf } }).then(function (r) { + if (r && r.data && r.data.status === 1) { + $scope.cpuUsage = r.data.cpuUsage != null ? r.data.cpuUsage : 0; + $scope.ramUsage = r.data.ramUsage != null ? r.data.ramUsage : 0; + $scope.diskUsage = r.data.diskUsage != null ? r.data.diskUsage : 0; + $scope.cpuCores = r.data.cpuCores != null ? r.data.cpuCores : 0; + $scope.ramTotalMB = r.data.ramTotalMB != null ? r.data.ramTotalMB : 0; + $scope.diskTotalGB = r.data.diskTotalGB != null ? r.data.diskTotalGB : 0; + $scope.diskFreeGB = r.data.diskFreeGB != null ? r.data.diskFreeGB : 0; + $scope.uptime = r.data.uptime || 'N/A'; + } + $scope.uptimeLoaded = true; + }, function() { $scope.uptime = 'Unavailable'; $scope.uptimeLoaded = true; }); + if (typeof $timeout === 'function') { $timeout(fetchStatus, 60000); } + } catch (e) { $scope.uptimeLoaded = true; } + } + fetchStatus(); +}]); + var globalScope; function GlobalRespSuccess(response) { @@ -566,15 +637,18 @@ app.controller('homePageStatus', function ($scope, $http, $timeout) { //////////// function increment() { - $('.box').hide(); + var boxes = document.querySelectorAll ? document.querySelectorAll('.box') : []; + for (var i = 0; i < boxes.length; i++) boxes[i].style.display = 'none'; setTimeout(function () { - $('.box').show(); + for (var j = 0; j < boxes.length; j++) boxes[j].style.display = ''; }, 100); - - } -increment(); +if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', increment); +} else { + increment(); +} //////////// @@ -932,7 +1006,8 @@ var dashboardStatsControllerFn = function ($scope, $http, $timeout) { $scope.errorTopProcesses = ''; $scope.refreshTopProcesses = function() { $scope.loadingTopProcesses = true; - $http.get('/base/getTopProcesses').then(function (response) { + var h = { headers: { 'X-CSRFToken': (typeof getCookie === 'function') ? getCookie('csrftoken') : '' } }; + $http.get('/base/getTopProcesses', h).then(function (response) { $scope.loadingTopProcesses = false; if (response.data && response.data.status === 1 && response.data.processes) { $scope.topProcesses = response.data.processes; @@ -951,7 +1026,8 @@ var dashboardStatsControllerFn = function ($scope, $http, $timeout) { $scope.errorSSHLogins = ''; $scope.refreshSSHLogins = function() { $scope.loadingSSHLogins = true; - $http.get('/base/getRecentSSHLogins').then(function (response) { + var h = { headers: { 'X-CSRFToken': (typeof getCookie === 'function') ? getCookie('csrftoken') : '' } }; + $http.get('/base/getRecentSSHLogins', h).then(function (response) { $scope.loadingSSHLogins = false; if (response.data && response.data.logins) { $scope.sshLogins = response.data.logins; @@ -979,7 +1055,8 @@ var dashboardStatsControllerFn = function ($scope, $http, $timeout) { $scope.loadingSecurityAnalysis = false; $scope.refreshSSHLogs = function() { $scope.loadingSSHLogs = true; - $http.get('/base/getRecentSSHLogs').then(function (response) { + var h = { headers: { 'X-CSRFToken': (typeof getCookie === 'function') ? getCookie('csrftoken') : '' } }; + $http.get('/base/getRecentSSHLogs', h).then(function (response) { $scope.loadingSSHLogs = false; if (response.data && response.data.logs) { $scope.sshLogs = response.data.logs; diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index bef27a093..41f04ac3b 100644 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -26,17 +26,14 @@ - + + - - - - @@ -45,9 +42,9 @@ - - - + + +