mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-07 01:36:18 +02:00
fix(firewall): banned IPs search, modify modal, export/import, Tracking Prevention
- Add searchBannedIPFilter for searching banned IPs by IP, reason, or status - Add openModifyModal, closeModifyModal, saveModifyBannedIP for modify modal - Add exportBannedIPs and importBannedIPs for export/import buttons - Wrap localStorage in try-catch in base template to handle Tracking Prevention (Firefox/Safari blocking storage access for cross-site context) - Fixes firewall banned IPs page search and functionality
This commit is contained in:
@@ -2440,12 +2440,13 @@
|
||||
// .htaccess Feature Notification Functions
|
||||
function checkHtaccessStatus() {
|
||||
// Check if user has dismissed the notification permanently (localStorage for longer persistence)
|
||||
if (localStorage.getItem('htaccessNotificationDismissed') === 'true') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (localStorage.getItem('htaccessNotificationDismissed') === 'true') return;
|
||||
} catch (e) { return; }
|
||||
|
||||
// Check if notification has been shown today
|
||||
const lastShown = localStorage.getItem('htaccessNotificationLastShown');
|
||||
var lastShown;
|
||||
try { lastShown = localStorage.getItem('htaccessNotificationLastShown'); } catch (e) { return; }
|
||||
const today = new Date().toDateString();
|
||||
|
||||
if (lastShown === today) {
|
||||
@@ -2454,7 +2455,7 @@
|
||||
|
||||
// Show the notification
|
||||
showHtaccessNotification();
|
||||
localStorage.setItem('htaccessNotificationLastShown', today);
|
||||
try { localStorage.setItem('htaccessNotificationLastShown', today); } catch (e) {}
|
||||
}
|
||||
|
||||
function showHtaccessNotification() {
|
||||
@@ -2470,7 +2471,7 @@
|
||||
banner.classList.remove('show');
|
||||
body.classList.remove('htaccess-shown');
|
||||
// Remember dismissal permanently
|
||||
localStorage.setItem('htaccessNotificationDismissed', 'true');
|
||||
try { localStorage.setItem('htaccessNotificationDismissed', 'true'); } catch (e) {}
|
||||
}
|
||||
|
||||
function isNotificationDismissed(notificationKey) {
|
||||
@@ -2481,7 +2482,7 @@
|
||||
return {% if ai_scanner_notification_dismissed %}true{% else %}false{% endif %};
|
||||
}
|
||||
if (notificationKey === 'htaccess-notification') {
|
||||
return localStorage.getItem('htaccessNotificationDismissed') === 'true';
|
||||
try { return localStorage.getItem('htaccessNotificationDismissed') === 'true'; } catch (e) { return false; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2604,10 +2605,12 @@
|
||||
|
||||
<!-- Dark Mode Toggle Script -->
|
||||
<script>
|
||||
// Theme switching functionality
|
||||
// Theme switching functionality (wrapped in try-catch for Tracking Prevention / private browsing)
|
||||
(function() {
|
||||
// Get saved theme from localStorage or default to light
|
||||
const savedTheme = localStorage.getItem('cyberPanelTheme') || 'light';
|
||||
var savedTheme = 'light';
|
||||
try {
|
||||
savedTheme = localStorage.getItem('cyberPanelTheme') || 'light';
|
||||
} catch (e) { /* Tracking Prevention or storage disabled */ }
|
||||
document.documentElement.setAttribute('data-theme', savedTheme);
|
||||
|
||||
// Update icon based on current theme
|
||||
@@ -2630,7 +2633,7 @@
|
||||
|
||||
// Update theme
|
||||
document.documentElement.setAttribute('data-theme', newTheme);
|
||||
localStorage.setItem('cyberPanelTheme', newTheme);
|
||||
try { localStorage.setItem('cyberPanelTheme', newTheme); } catch (e) { /* Tracking Prevention */ }
|
||||
|
||||
// Update icon
|
||||
updateThemeIcon(newTheme);
|
||||
|
||||
@@ -98,6 +98,59 @@ app.controller('firewallController', function ($scope, $http, $timeout) {
|
||||
$scope.banIP = '';
|
||||
$scope.banReason = '';
|
||||
$scope.banDuration = '24h';
|
||||
$scope.bannedIPSearch = '';
|
||||
|
||||
// Modify banned IP modal
|
||||
$scope.showModifyModal = false;
|
||||
$scope.modifyBannedIPData = { ip: '', reason: '', duration: '24h', id: null };
|
||||
|
||||
// Search filter for banned IPs (by IP, reason, or status)
|
||||
$scope.searchBannedIPFilter = function(item) {
|
||||
var q = ($scope.bannedIPSearch || '').toLowerCase().trim();
|
||||
if (!q) return true;
|
||||
var ip = (item.ip || '').toLowerCase();
|
||||
var reason = (item.reason || '').toLowerCase();
|
||||
var status = item.active ? 'active' : 'expired';
|
||||
return ip.indexOf(q) !== -1 || reason.indexOf(q) !== -1 || status.indexOf(q) !== -1;
|
||||
};
|
||||
|
||||
// Modify banned IP modal functions
|
||||
$scope.openModifyModal = function(bannedIP) {
|
||||
if (!bannedIP) return;
|
||||
$scope.modifyBannedIPData = {
|
||||
id: bannedIP.id,
|
||||
ip: bannedIP.ip,
|
||||
reason: bannedIP.reason || '',
|
||||
duration: bannedIP.duration || '24h'
|
||||
};
|
||||
$scope.showModifyModal = true;
|
||||
};
|
||||
$scope.closeModifyModal = function() { $scope.showModifyModal = false; };
|
||||
$scope.saveModifyBannedIP = function() {
|
||||
if (!$scope.modifyBannedIPData || !$scope.modifyBannedIPData.id) return;
|
||||
$scope.bannedIPsLoading = true;
|
||||
$http.post('/firewall/modifyBannedIP', {
|
||||
id: $scope.modifyBannedIPData.id,
|
||||
reason: $scope.modifyBannedIPData.reason,
|
||||
duration: $scope.modifyBannedIPData.duration
|
||||
}, { headers: { 'X-CSRFToken': getCookie('csrftoken') } }).then(
|
||||
function(response) {
|
||||
$scope.bannedIPsLoading = false;
|
||||
if (response.data && response.data.status === 1) {
|
||||
$scope.bannedIPActionSuccess = false;
|
||||
$scope.closeModifyModal();
|
||||
populateBannedIPs();
|
||||
} else {
|
||||
$scope.bannedIPActionFailed = false;
|
||||
$scope.bannedIPErrorMessage = (response.data && response.data.error_message) || 'Unknown error';
|
||||
}
|
||||
},
|
||||
function() {
|
||||
$scope.bannedIPsLoading = false;
|
||||
$scope.bannedIPCouldNotConnect = false;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
firewallStatus();
|
||||
|
||||
@@ -922,6 +975,58 @@ app.controller('firewallController', function ($scope, $http, $timeout) {
|
||||
});
|
||||
};
|
||||
|
||||
// Export banned IPs (triggers file download)
|
||||
$scope.exportBannedIPs = function() {
|
||||
var url = '/firewall/exportBannedIPs';
|
||||
var form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = url;
|
||||
form.style.display = 'none';
|
||||
var csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = 'csrfmiddlewaretoken';
|
||||
csrfInput.value = getCookie('csrftoken');
|
||||
form.appendChild(csrfInput);
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
document.body.removeChild(form);
|
||||
};
|
||||
|
||||
// Import banned IPs (file picker -> POST)
|
||||
$scope.importBannedIPs = function() {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = '.json';
|
||||
input.style.display = 'none';
|
||||
input.onchange = function(ev) {
|
||||
var file = ev.target && ev.target.files[0];
|
||||
if (!file) return;
|
||||
var formData = new FormData();
|
||||
formData.append('import_file', file);
|
||||
formData.append('csrfmiddlewaretoken', getCookie('csrftoken'));
|
||||
$scope.bannedIPsLoading = false;
|
||||
$http.post('/firewall/importBannedIPs', formData, {
|
||||
headers: { 'X-CSRFToken': getCookie('csrftoken'), 'Content-Type': undefined },
|
||||
transformRequest: angular.identity
|
||||
}).then(function(response) {
|
||||
$scope.bannedIPsLoading = true;
|
||||
if (response.data && response.data.importStatus === 1) {
|
||||
$scope.bannedIPActionSuccess = false;
|
||||
populateBannedIPs();
|
||||
} else {
|
||||
$scope.bannedIPActionFailed = false;
|
||||
$scope.bannedIPErrorMessage = (response.data && response.data.error_message) || 'Import failed';
|
||||
}
|
||||
}, function() {
|
||||
$scope.bannedIPsLoading = true;
|
||||
$scope.bannedIPCouldNotConnect = false;
|
||||
});
|
||||
};
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
document.body.removeChild(input);
|
||||
};
|
||||
|
||||
// Export/Import Firewall Rules Functions
|
||||
$scope.exportRules = function () {
|
||||
$scope.rulesLoading = false;
|
||||
|
||||
@@ -68,6 +68,111 @@ app.controller('firewallController', function ($scope, $http, $timeout) {
|
||||
$scope.banIP = '';
|
||||
$scope.banReason = '';
|
||||
$scope.banDuration = '24h';
|
||||
$scope.bannedIPSearch = '';
|
||||
|
||||
// Modify banned IP modal
|
||||
$scope.showModifyModal = false;
|
||||
$scope.modifyBannedIPData = { ip: '', reason: '', duration: '24h', id: null };
|
||||
|
||||
// Search filter for banned IPs (by IP, reason, or status)
|
||||
$scope.searchBannedIPFilter = function(item) {
|
||||
var q = ($scope.bannedIPSearch || '').toLowerCase().trim();
|
||||
if (!q) return true;
|
||||
var ip = (item.ip || '').toLowerCase();
|
||||
var reason = (item.reason || '').toLowerCase();
|
||||
var status = item.active ? 'active' : 'expired';
|
||||
return ip.indexOf(q) !== -1 || reason.indexOf(q) !== -1 || status.indexOf(q) !== -1;
|
||||
};
|
||||
|
||||
// Modify banned IP modal functions
|
||||
$scope.openModifyModal = function(bannedIP) {
|
||||
if (!bannedIP) return;
|
||||
$scope.modifyBannedIPData = {
|
||||
id: bannedIP.id,
|
||||
ip: bannedIP.ip,
|
||||
reason: bannedIP.reason || '',
|
||||
duration: bannedIP.duration || '24h'
|
||||
};
|
||||
$scope.showModifyModal = true;
|
||||
};
|
||||
$scope.closeModifyModal = function() { $scope.showModifyModal = false; };
|
||||
$scope.saveModifyBannedIP = function() {
|
||||
if (!$scope.modifyBannedIPData || !$scope.modifyBannedIPData.id) return;
|
||||
$scope.bannedIPsLoading = true;
|
||||
$http.post('/firewall/modifyBannedIP', {
|
||||
id: $scope.modifyBannedIPData.id,
|
||||
reason: $scope.modifyBannedIPData.reason,
|
||||
duration: $scope.modifyBannedIPData.duration
|
||||
}, { headers: { 'X-CSRFToken': getCookie('csrftoken') } }).then(
|
||||
function(response) {
|
||||
$scope.bannedIPsLoading = false;
|
||||
if (response.data && response.data.status === 1) {
|
||||
$scope.bannedIPActionSuccess = false;
|
||||
$scope.closeModifyModal();
|
||||
populateBannedIPs();
|
||||
} else {
|
||||
$scope.bannedIPActionFailed = false;
|
||||
$scope.bannedIPErrorMessage = (response.data && response.data.error_message) || 'Unknown error';
|
||||
}
|
||||
},
|
||||
function() {
|
||||
$scope.bannedIPsLoading = false;
|
||||
$scope.bannedIPCouldNotConnect = false;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Export banned IPs (triggers file download)
|
||||
$scope.exportBannedIPs = function() {
|
||||
var url = '/firewall/exportBannedIPs';
|
||||
var form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = url;
|
||||
form.style.display = 'none';
|
||||
var csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = 'csrfmiddlewaretoken';
|
||||
csrfInput.value = getCookie('csrftoken');
|
||||
form.appendChild(csrfInput);
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
document.body.removeChild(form);
|
||||
};
|
||||
|
||||
// Import banned IPs (file picker -> POST)
|
||||
$scope.importBannedIPs = function() {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = '.json';
|
||||
input.style.display = 'none';
|
||||
input.onchange = function(ev) {
|
||||
var file = ev.target && ev.target.files[0];
|
||||
if (!file) return;
|
||||
var formData = new FormData();
|
||||
formData.append('import_file', file);
|
||||
formData.append('csrfmiddlewaretoken', getCookie('csrftoken'));
|
||||
$scope.bannedIPsLoading = false;
|
||||
$http.post('/firewall/importBannedIPs', formData, {
|
||||
headers: { 'X-CSRFToken': getCookie('csrftoken'), 'Content-Type': undefined },
|
||||
transformRequest: angular.identity
|
||||
}).then(function(response) {
|
||||
$scope.bannedIPsLoading = true;
|
||||
if (response.data && response.data.importStatus === 1) {
|
||||
$scope.bannedIPActionSuccess = false;
|
||||
populateBannedIPs();
|
||||
} else {
|
||||
$scope.bannedIPActionFailed = false;
|
||||
$scope.bannedIPErrorMessage = (response.data && response.data.error_message) || 'Import failed';
|
||||
}
|
||||
}, function() {
|
||||
$scope.bannedIPsLoading = true;
|
||||
$scope.bannedIPCouldNotConnect = false;
|
||||
});
|
||||
};
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
document.body.removeChild(input);
|
||||
};
|
||||
|
||||
firewallStatus();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user