Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Integrate firewall management into Security page

Juan Denisd4b44b582f31
diff --git a/ROADMAP.md b/ROADMAP.md
index ae08e4a1..58bcd22f 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -107,12 +107,13 @@ This document outlines the development roadmap for ServerKit. Features are organ
---
-## Phase 9: Firewall Management (Completed)
+## Phase 9: Firewall Management (Completed - Merged into Security)
- [x] UFW firewall integration
- [x] Visual rule management
- [x] Common port presets
- [x] Rule enable/disable
+- [x] Consolidated into Security page for unified security management
---
@@ -133,13 +134,13 @@ This document outlines the development roadmap for ServerKit. Features are organ
**Priority: High**
-- [ ] GitHub/GitLab webhook integration
-- [ ] Automatic deployment on push
-- [ ] Branch selection for deployment
-- [ ] Rollback to previous deployments
-- [ ] Deployment history and logs
-- [ ] Pre/post deployment scripts
-- [ ] Zero-downtime deployments
+- [x] GitHub/GitLab webhook integration
+- [x] Automatic deployment on push
+- [x] Branch selection for deployment
+- [x] Rollback to previous deployments
+- [x] Deployment history and logs
+- [x] Pre/post deployment scripts
+- [x] Zero-downtime deployments
---
@@ -209,10 +210,12 @@ This document outlines the development roadmap for ServerKit. Features are organ
---
-## Phase 17: Advanced Security (Planned)
+## Phase 17: Advanced Security (In Progress)
**Priority: High**
+- [x] Unified Security page with all security features
+- [x] Firewall tab with UFW/firewalld management
- [ ] Fail2ban integration
- [ ] SSH key management
- [ ] IP allowlist/blocklist
diff --git a/backend/app/services/firewall_service.py b/backend/app/services/firewall_service.py
index d04b28ec..f14d95fd 100644
--- a/backend/app/services/firewall_service.py
+++ b/backend/app/services/firewall_service.py
@@ -1,5 +1,6 @@
"""Firewall management service for firewalld and ufw."""
+import os
import subprocess
import re
from typing import Dict, List, Optional
@@ -37,9 +38,23 @@ class FirewallService:
def _check_firewalld(cls) -> Dict:
"""Check firewalld status."""
try:
- # Check if installed
- result = subprocess.run(['which', 'firewall-cmd'], capture_output=True, text=True)
- installed = result.returncode == 0
+ # Check if installed using dpkg or by checking common paths
+ installed = False
+
+ # Try dpkg first (Debian/Ubuntu)
+ result = subprocess.run(
+ ['dpkg', '-s', 'firewalld'],
+ capture_output=True, text=True
+ )
+ if result.returncode == 0 and 'Status: install ok installed' in result.stdout:
+ installed = True
+
+ # Also check if binary exists at common paths
+ if not installed:
+ for path in ['/usr/bin/firewall-cmd', '/usr/sbin/firewall-cmd']:
+ if os.path.exists(path):
+ installed = True
+ break
running = False
default_zone = None
@@ -72,9 +87,23 @@ class FirewallService:
def _check_ufw(cls) -> Dict:
"""Check ufw status."""
try:
- # Check if installed
- result = subprocess.run(['which', 'ufw'], capture_output=True, text=True)
- installed = result.returncode == 0
+ # Check if installed using dpkg or by checking common paths
+ installed = False
+
+ # Try dpkg first (Debian/Ubuntu)
+ result = subprocess.run(
+ ['dpkg', '-s', 'ufw'],
+ capture_output=True, text=True
+ )
+ if result.returncode == 0 and 'Status: install ok installed' in result.stdout:
+ installed = True
+
+ # Also check if binary exists at common paths
+ if not installed:
+ for path in ['/usr/sbin/ufw', '/usr/bin/ufw']:
+ if os.path.exists(path):
+ installed = True
+ break
active = False
if installed:
diff --git a/frontend/dist/index.html b/frontend/dist/index.html
index a03bc7f4..314918a7 100644
--- a/frontend/dist/index.html
+++ b/frontend/dist/index.html
@@ -6,8 +6,8 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Dashboard Template</title>
- <script type="module" crossorigin src="/assets/index-DrutglRQ.js"></script>
- <link rel="stylesheet" crossorigin href="/assets/index-B06xC2dW.css">
+ <script type="module" crossorigin src="/assets/index-C430V7gN.js"></script>
+ <link rel="stylesheet" crossorigin href="/assets/index-CIITacjz.css">
</head>
<body>
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 40891ca5..714100ee 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -19,7 +19,7 @@ import Terminal from './pages/Terminal';
import Settings from './pages/Settings';
import FileManager from './pages/FileManager';
import FTPServer from './pages/FTPServer';
-import Firewall from './pages/Firewall';
+// Firewall is now part of Security page
import Git from './pages/Git';
import CronJobs from './pages/CronJobs';
import Security from './pages/Security';
@@ -107,7 +107,7 @@ function AppRoutes() {
<Route path="databases" element={<Databases />} />
<Route path="ssl" element={<div className="page">SSL Certificates</div>} />
<Route path="docker" element={<Docker />} />
- <Route path="firewall" element={<Firewall />} />
+ <Route path="firewall" element={<Navigate to="/security" replace />} />
<Route path="git" element={<Git />} />
<Route path="files" element={<FileManager />} />
<Route path="ftp" element={<FTPServer />} />
diff --git a/frontend/src/components/Sidebar.jsx b/frontend/src/components/Sidebar.jsx
index 7767385b..4112184c 100644
--- a/frontend/src/components/Sidebar.jsx
+++ b/frontend/src/components/Sidebar.jsx
@@ -93,12 +93,6 @@ const Sidebar = () => {
</svg>
Docker
</NavLink>
- <NavLink to="/firewall" className={({ isActive }) => `nav-item ${isActive ? 'active' : ''}`}>
- <svg viewBox="0 0 24 24">
- <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
- </svg>
- Firewall
- </NavLink>
<NavLink to="/git" className={({ isActive }) => `nav-item ${isActive ? 'active' : ''}`}>
<svg viewBox="0 0 24 24">
<circle cx="18" cy="18" r="3"/>
diff --git a/frontend/src/pages/Security.jsx b/frontend/src/pages/Security.jsx
index 3a886a5f..a134cfe7 100644
--- a/frontend/src/pages/Security.jsx
+++ b/frontend/src/pages/Security.jsx
@@ -1,6 +1,8 @@
import React, { useState, useEffect, useCallback } from 'react';
import { useAuth } from '../contexts/AuthContext';
import api from '../services/api';
+import ConfirmDialog from '../components/ConfirmDialog';
+import { useToast } from '../contexts/ToastContext';
const Security = () => {
const { isAdmin } = useAuth();
@@ -32,7 +34,7 @@ const Security = () => {
<div className="page-header">
<div>
<h1>Security</h1>
- <p className="page-subtitle">Malware scanning, file integrity monitoring, and security alerts</p>
+ <p className="page-subtitle">Firewall, malware scanning, file integrity, and security alerts</p>
</div>
</div>
@@ -40,6 +42,9 @@ const Security = () => {
<button className={`tab-btn ${activeTab === 'overview' ? 'active' : ''}`} onClick={() => setActiveTab('overview')}>
Overview
</button>
+ <button className={`tab-btn ${activeTab === 'firewall' ? 'active' : ''}`} onClick={() => setActiveTab('firewall')}>
+ Firewall
+ </button>
<button className={`tab-btn ${activeTab === 'scanner' ? 'active' : ''}`} onClick={() => setActiveTab('scanner')}>
Malware Scanner
</button>
@@ -59,6 +64,7 @@ const Security = () => {
<div className="tab-content">
{activeTab === 'overview' && <OverviewTab status={status} onRefresh={loadStatus} />}
+ {activeTab === 'firewall' && <FirewallTab />}
{activeTab === 'scanner' && <ScannerTab />}
{activeTab === 'quarantine' && <QuarantineTab />}
{activeTab === 'integrity' && <IntegrityTab />}
@@ -258,6 +264,552 @@ const InstallClamAVButton = ({ onInstalled }) => {
);
};
+const FirewallTab = () => {
+ const [status, setStatus] = useState(null);
+ const [rules, setRules] = useState([]);
+ const [blockedIPs, setBlockedIPs] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [activeSubTab, setActiveSubTab] = useState('status');
+ const [showBlockIPModal, setShowBlockIPModal] = useState(false);
+ const [showPortModal, setShowPortModal] = useState(false);
+ const [showInstallModal, setShowInstallModal] = useState(false);
+ const [blockIP, setBlockIP] = useState('');
+ const [newPort, setNewPort] = useState({ port: '', protocol: 'tcp' });
+ const [selectedFirewall, setSelectedFirewall] = useState('ufw');
+ const [actionLoading, setActionLoading] = useState(false);
+ const [confirmDialog, setConfirmDialog] = useState(null);
+ const toast = useToast();
+
+ const commonPorts = [
+ { port: 22, name: 'SSH', protocol: 'tcp' },
+ { port: 80, name: 'HTTP', protocol: 'tcp' },
+ { port: 443, name: 'HTTPS', protocol: 'tcp' },
+ { port: 21, name: 'FTP', protocol: 'tcp' },
+ { port: 25, name: 'SMTP', protocol: 'tcp' },
+ { port: 3306, name: 'MySQL', protocol: 'tcp' },
+ { port: 5432, name: 'PostgreSQL', protocol: 'tcp' },
+ { port: 6379, name: 'Redis', protocol: 'tcp' },
+ { port: 27017, name: 'MongoDB', protocol: 'tcp' },
+ ];
+
+ useEffect(() => {
+ loadData();
+ }, []);
+
+ const loadData = async () => {
+ setLoading(true);
+ try {
+ await Promise.all([loadStatus(), loadRules(), loadBlockedIPs()]);
+ } catch (error) {
+ console.error('Failed to load firewall data:', error);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ const loadStatus = async () => {
+ try {
+ const data = await api.getFirewallStatus();
+ setStatus(data);
+ } catch (error) {
+ console.error('Failed to load status:', error);
+ }
+ };
+
+ const loadRules = async () => {
+ try {
+ const data = await api.getFirewallRules();
+ setRules(data.rules || []);
+ } catch (error) {
+ console.error('Failed to load rules:', error);
+ }
+ };
+
+ const loadBlockedIPs = async () => {
+ try {
+ const data = await api.getBlockedIPs();
+ setBlockedIPs(data.blocked_ips || []);
+ } catch (error) {
+ console.error('Failed to load blocked IPs:', error);
+ }
+ };
+
+ const handleEnable = async () => {
+ setActionLoading(true);
+ try {
+ await api.enableFirewall();
+ toast.success('Firewall enabled');
+ await loadStatus();
+ } catch (error) {
+ toast.error(`Failed to enable firewall: ${error.message}`);
+ } finally {
+ setActionLoading(false);
+ }
+ };
+
+ const handleDisable = async () => {
+ setConfirmDialog({
+ title: 'Disable Firewall',
+ message: 'Are you sure you want to disable the firewall? This will leave your server unprotected.',
+ confirmText: 'Disable',
+ variant: 'danger',
+ onConfirm: async () => {
+ setActionLoading(true);
+ try {
+ await api.disableFirewall();
+ toast.success('Firewall disabled');
+ await loadStatus();
+ } catch (error) {
+ toast.error(`Failed to disable firewall: ${error.message}`);
+ } finally {
+ setActionLoading(false);
+ setConfirmDialog(null);
+ }
+ },
+ onCancel: () => setConfirmDialog(null)
+ });
+ };
+
+ const handleBlockIP = async () => {
+ if (!blockIP.trim()) return;
+ setActionLoading(true);
+ try {
+ await api.blockIP(blockIP);
+ toast.success(`IP ${blockIP} blocked`);
+ setShowBlockIPModal(false);
+ setBlockIP('');
+ await loadBlockedIPs();
+ await loadRules();
+ } catch (error) {
+ toast.error(`Failed to block IP: ${error.message}`);
+ } finally {
+ setActionLoading(false);
+ }
+ };
+
+ const handleUnblockIP = async (ip) => {
+ setConfirmDialog({
+ title: 'Unblock IP',
+ message: `Are you sure you want to unblock ${ip}?`,
+ confirmText: 'Unblock',
+ variant: 'warning',
+ onConfirm: async () => {
+ try {
+ await api.unblockIP(ip);
+ toast.success(`IP ${ip} unblocked`);
+ await loadBlockedIPs();
+ await loadRules();
+ } catch (error) {
+ toast.error(`Failed to unblock IP: ${error.message}`);
+ }
+ setConfirmDialog(null);
+ },
+ onCancel: () => setConfirmDialog(null)
+ });
+ };
+
+ const handleAllowPort = async () => {
+ if (!newPort.port) return;
+ setActionLoading(true);
+ try {
+ await api.allowPort(parseInt(newPort.port), newPort.protocol);
+ toast.success(`Port ${newPort.port}/${newPort.protocol} allowed`);
+ setShowPortModal(false);
+ setNewPort({ port: '', protocol: 'tcp' });
+ await loadRules();
+ } catch (error) {
+ toast.error(`Failed to allow port: ${error.message}`);
+ } finally {
+ setActionLoading(false);
+ }
+ };
+
+ const handleQuickAllowPort = async (port, protocol) => {
+ setActionLoading(true);
+ try {
+ await api.allowPort(port, protocol);
+ toast.success(`Port ${port}/${protocol} allowed`);
+ await loadRules();
+ } catch (error) {
+ toast.error(`Failed to allow port: ${error.message}`);
+ } finally {
+ setActionLoading(false);
+ }
+ };
+
+ const handleRemovePort = async (port, protocol) => {
+ setConfirmDialog({
+ title: 'Remove Port Rule',
+ message: `Are you sure you want to remove the rule for port ${port}/${protocol}?`,
+ confirmText: 'Remove',
+ variant: 'danger',
+ onConfirm: async () => {
+ try {
+ await api.denyPort(parseInt(port), protocol);
+ toast.success(`Port ${port}/${protocol} rule removed`);
+ await loadRules();
+ } catch (error) {
+ toast.error(`Failed to remove port: ${error.message}`);
+ }
+ setConfirmDialog(null);
+ },
+ onCancel: () => setConfirmDialog(null)
+ });
+ };
+
+ const handleInstall = async () => {
+ setActionLoading(true);
+ try {
+ await api.installFirewall(selectedFirewall);
+ toast.success(`${selectedFirewall.toUpperCase()} installed successfully`);
+ setShowInstallModal(false);
+ await loadData();
+ } catch (error) {
+ toast.error(`Failed to install firewall: ${error.message}`);
+ } finally {
+ setActionLoading(false);
+ }
+ };
+
+ const isActive = status?.any_active;
+ const activeFirewall = status?.active_firewall;
+
+ if (loading) {
+ return <div className="loading-sm">Loading firewall status...</div>;
+ }
+
+ return (
+ <div className="firewall-tab">
+ {!status?.any_installed ? (
+ <div className="empty-state">
+ <svg viewBox="0 0 24 24" width="48" height="48" stroke="currentColor" fill="none" strokeWidth="1">
+ <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
+ </svg>
+ <h3>No Firewall Installed</h3>
+ <p>Install a firewall to protect your server from unauthorized access.</p>
+ <button className="btn btn-primary" onClick={() => setShowInstallModal(true)}>
+ Install Firewall
+ </button>
+ </div>
+ ) : (
+ <>
+ <div className="firewall-header">
+ <div className="firewall-status-row">
+ <div className={`status-indicator ${isActive ? 'active' : 'inactive'}`}>
+ <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" fill="none" strokeWidth="2">
+ <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
+ </svg>
+ <span>{isActive ? 'Firewall Active' : 'Firewall Inactive'}</span>
+ <span className="firewall-type">({activeFirewall?.toUpperCase()})</span>
+ </div>
+ <div className="firewall-actions">
+ <button className="btn btn-sm btn-secondary" onClick={() => setShowBlockIPModal(true)}>
+ Block IP
+ </button>
+ <button className="btn btn-sm btn-secondary" onClick={() => setShowPortModal(true)}>
+ Allow Port
+ </button>
+ {isActive ? (
+ <button className="btn btn-sm btn-danger" onClick={handleDisable} disabled={actionLoading}>
+ Disable
+ </button>
+ ) : (
+ <button className="btn btn-sm btn-success" onClick={handleEnable} disabled={actionLoading}>
+ Enable
+ </button>
+ )}
+ </div>
+ </div>
+ </div>
+
+ <div className="firewall-stats">
+ <div className="stat-mini">
+ <span className="stat-value">{rules.length}</span>
+ <span className="stat-label">Rules</span>
+ </div>
+ <div className="stat-mini">
+ <span className="stat-value">{blockedIPs.length}</span>
+ <span className="stat-label">Blocked IPs</span>
+ </div>
+ <div className="stat-mini">
+ <span className="stat-value">{rules.filter(r => r.type === 'port' || r.port).length}</span>
+ <span className="stat-label">Ports Open</span>
+ </div>
+ </div>
+
+ <div className="subtabs">
+ <button className={`subtab ${activeSubTab === 'status' ? 'active' : ''}`} onClick={() => setActiveSubTab('status')}>
+ Status
+ </button>
+ <button className={`subtab ${activeSubTab === 'rules' ? 'active' : ''}`} onClick={() => setActiveSubTab('rules')}>
+ Rules
+ </button>
+ <button className={`subtab ${activeSubTab === 'blocked' ? 'active' : ''}`} onClick={() => setActiveSubTab('blocked')}>
+ Blocked IPs
+ </button>
+ <button className={`subtab ${activeSubTab === 'quick' ? 'active' : ''}`} onClick={() => setActiveSubTab('quick')}>
+ Quick Ports
+ </button>
+ </div>
+
+ {activeSubTab === 'status' && (
+ <div className="card">
+ <div className="card-header">
+ <h3>Firewall Information</h3>
+ <button className="btn btn-sm btn-secondary" onClick={loadData}>Refresh</button>
+ </div>
+ <div className="card-body">
+ <div className="info-list">
+ <div className="info-item">
+ <span className="info-label">Type</span>
+ <span className="info-value">{activeFirewall?.toUpperCase()}</span>
+ </div>
+ <div className="info-item">
+ <span className="info-label">Status</span>
+ <span className={`badge ${isActive ? 'badge-success' : 'badge-danger'}`}>
+ {isActive ? 'Active' : 'Inactive'}
+ </span>
+ </div>
+ {activeFirewall === 'firewalld' && status?.firewalld?.default_zone && (
+ <div className="info-item">
+ <span className="info-label">Default Zone</span>
+ <span className="info-value">{status.firewalld.default_zone}</span>
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+ )}
+
+ {activeSubTab === 'rules' && (
+ <div className="card">
+ <div className="card-header">
+ <h3>Firewall Rules</h3>
+ <button className="btn btn-sm btn-primary" onClick={() => setShowPortModal(true)}>Add Rule</button>
+ </div>
+ <div className="card-body">
+ {rules.length === 0 ? (
+ <p className="text-muted">No rules configured</p>
+ ) : (
+ <table className="table">
+ <thead>
+ <tr>
+ <th>Type</th>
+ <th>Target</th>
+ <th>Protocol</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ {rules.map((rule, index) => (
+ <tr key={index}>
+ <td><span className="badge badge-info">{rule.type}</span></td>
+ <td>
+ {rule.type === 'service' && rule.service}
+ {rule.type === 'port' && rule.port}
+ {rule.type === 'rich' && <code>{rule.rule}</code>}
+ </td>
+ <td>{rule.protocol || '-'}</td>
+ <td>
+ {rule.type === 'port' && (
+ <button className="btn btn-sm btn-danger" onClick={() => handleRemovePort(rule.port, rule.protocol)}>
+ Remove
+ </button>
+ )}
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ )}
+ </div>
+ </div>
+ )}
+
+ {activeSubTab === 'blocked' && (
+ <div className="card">
+ <div className="card-header">
+ <h3>Blocked IP Addresses</h3>
+ <button className="btn btn-sm btn-primary" onClick={() => setShowBlockIPModal(true)}>Block IP</button>
+ </div>
+ <div className="card-body">
+ {blockedIPs.length === 0 ? (
+ <div className="empty-state-sm">
+ <p>No blocked IPs</p>
+ </div>
+ ) : (
+ <div className="blocked-list">
+ {blockedIPs.map((item, index) => (
+ <div key={index} className="blocked-item">
+ <div className="blocked-info">
+ <span className="blocked-ip">{item.ip}</span>
+ </div>
+ <button className="btn btn-sm btn-warning" onClick={() => handleUnblockIP(item.ip)}>
+ Unblock
+ </button>
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ </div>
+ )}
+
+ {activeSubTab === 'quick' && (
+ <div className="card">
+ <div className="card-header">
+ <h3>Quick Port Access</h3>
+ </div>
+ <div className="card-body">
+ <p className="text-muted" style={{ marginBottom: '1rem' }}>One-click enable/disable common service ports</p>
+ <div className="quick-ports-grid">
+ {commonPorts.map(({ port, name, protocol }) => {
+ const isAllowed = rules.some(r =>
+ (r.port === String(port) || r.port === port) && r.protocol === protocol
+ );
+ return (
+ <div key={port} className="quick-port-card">
+ <div className="port-info">
+ <span className="port-name">{name}</span>
+ <span className="port-number">{port}/{protocol}</span>
+ </div>
+ {isAllowed ? (
+ <button className="btn btn-sm btn-danger" onClick={() => handleRemovePort(port, protocol)} disabled={actionLoading}>
+ Block
+ </button>
+ ) : (
+ <button className="btn btn-sm btn-success" onClick={() => handleQuickAllowPort(port, protocol)} disabled={actionLoading}>
+ Allow
+ </button>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+
+ {/* Block IP Modal */}
+ {showBlockIPModal && (
+ <div className="modal-overlay" onClick={() => setShowBlockIPModal(false)}>
+ <div className="modal" onClick={(e) => e.stopPropagation()}>
+ <div className="modal-header">
+ <h2>Block IP Address</h2>
+ <button className="btn btn-icon" onClick={() => setShowBlockIPModal(false)}>×</button>
+ </div>
+ <div className="modal-body">
+ <div className="form-group">
+ <label>IP Address</label>
+ <input
+ type="text"
+ value={blockIP}
+ onChange={(e) => setBlockIP(e.target.value)}
+ placeholder="192.168.1.100 or 10.0.0.0/24"
+ />
+ </div>
+ <p className="text-muted">You can block a single IP or a range using CIDR notation.</p>
+ </div>
+ <div className="modal-footer">
+ <button className="btn btn-secondary" onClick={() => setShowBlockIPModal(false)}>Cancel</button>
+ <button className="btn btn-danger" onClick={handleBlockIP} disabled={actionLoading || !blockIP.trim()}>
+ {actionLoading ? 'Blocking...' : 'Block IP'}
+ </button>
+ </div>
+ </div>
+ </div>
+ )}
+
+ {/* Allow Port Modal */}
+ {showPortModal && (
+ <div className="modal-overlay" onClick={() => setShowPortModal(false)}>
+ <div className="modal" onClick={(e) => e.stopPropagation()}>
+ <div className="modal-header">
+ <h2>Allow Port</h2>
+ <button className="btn btn-icon" onClick={() => setShowPortModal(false)}>×</button>
+ </div>
+ <div className="modal-body">
+ <div className="form-row">
+ <div className="form-group">
+ <label>Port Number</label>
+ <input
+ type="number"
+ value={newPort.port}
+ onChange={(e) => setNewPort({ ...newPort, port: e.target.value })}
+ placeholder="8080"
+ min="1"
+ max="65535"
+ />
+ </div>
+ <div className="form-group">
+ <label>Protocol</label>
+ <select value={newPort.protocol} onChange={(e) => setNewPort({ ...newPort, protocol: e.target.value })}>
+ <option value="tcp">TCP</option>
+ <option value="udp">UDP</option>
+ </select>
+ </div>
+ </div>
+ </div>
+ <div className="modal-footer">
+ <button className="btn btn-secondary" onClick={() => setShowPortModal(false)}>Cancel</button>
+ <button className="btn btn-primary" onClick={handleAllowPort} disabled={actionLoading || !newPort.port}>
+ {actionLoading ? 'Adding...' : 'Allow Port'}
+ </button>
+ </div>
+ </div>
+ </div>
+ )}
+
+ {/* Install Firewall Modal */}
+ {showInstallModal && (
+ <div className="modal-overlay" onClick={() => setShowInstallModal(false)}>
+ <div className="modal" onClick={(e) => e.stopPropagation()}>
+ <div className="modal-header">
+ <h2>Install Firewall</h2>
+ <button className="btn btn-icon" onClick={() => setShowInstallModal(false)}>×</button>
+ </div>
+ <div className="modal-body">
+ <div className="form-group">
+ <label>Select Firewall</label>
+ <select value={selectedFirewall} onChange={(e) => setSelectedFirewall(e.target.value)}>
+ <option value="ufw">UFW (Recommended for Ubuntu)</option>
+ <option value="firewalld">firewalld (CentOS/RHEL)</option>
+ </select>
+ </div>
+ <div className="install-info">
+ {selectedFirewall === 'ufw' ? (
+ <p><strong>UFW (Uncomplicated Firewall)</strong> is simple and easy to use for Ubuntu/Debian systems.</p>
+ ) : (
+ <p><strong>firewalld</strong> is a dynamically managed firewall with zone-based configuration for CentOS/RHEL.</p>
+ )}
+ </div>
+ </div>
+ <div className="modal-footer">
+ <button className="btn btn-secondary" onClick={() => setShowInstallModal(false)}>Cancel</button>
+ <button className="btn btn-primary" onClick={handleInstall} disabled={actionLoading}>
+ {actionLoading ? 'Installing...' : 'Install'}
+ </button>
+ </div>
+ </div>
+ </div>
+ )}
+
+ {confirmDialog && (
+ <ConfirmDialog
+ title={confirmDialog.title}
+ message={confirmDialog.message}
+ confirmText={confirmDialog.confirmText}
+ variant={confirmDialog.variant}
+ onConfirm={confirmDialog.onConfirm}
+ onCancel={confirmDialog.onCancel}
+ />
+ )}
+ </div>
+ );
+};
+
const ScannerTab = () => {
const [scanStatus, setScanStatus] = useState({ status: 'idle' });
const [scanPath, setScanPath] = useState('/var/www');
diff --git a/frontend/src/styles/pages/_security.less b/frontend/src/styles/pages/_security.less
index 03969451..87af78ff 100644
--- a/frontend/src/styles/pages/_security.less
+++ b/frontend/src/styles/pages/_security.less
@@ -408,3 +408,169 @@
font-size: @font-size-sm;
padding: @space-4;
}
+
+// Firewall Tab
+.firewall-tab {
+ .firewall-header {
+ margin-bottom: @space-6;
+ }
+
+ .firewall-status-row {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: @space-4;
+ background: @bg-card;
+ border-radius: @radius-lg;
+ border: 1px solid @border-subtle;
+ }
+
+ .status-indicator {
+ display: flex;
+ align-items: center;
+ gap: @space-2;
+ font-weight: 600;
+
+ &.active {
+ color: @success;
+ }
+
+ &.inactive {
+ color: @danger;
+ }
+
+ .firewall-type {
+ color: @text-tertiary;
+ font-weight: 400;
+ }
+ }
+
+ .firewall-actions {
+ display: flex;
+ gap: @space-2;
+ }
+
+ .firewall-stats {
+ display: flex;
+ gap: @space-4;
+ margin-bottom: @space-6;
+ }
+
+ .stat-mini {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: @space-4 @space-6;
+ background: @bg-card;
+ border-radius: @radius-md;
+ border: 1px solid @border-subtle;
+ min-width: 100px;
+
+ .stat-value {
+ font-size: @font-size-xl;
+ font-weight: 700;
+ }
+
+ .stat-label {
+ color: @text-tertiary;
+ font-size: @font-size-sm;
+ }
+ }
+
+ .subtabs {
+ display: flex;
+ gap: @space-1;
+ margin-bottom: @space-4;
+ border-bottom: 1px solid @border-subtle;
+ padding-bottom: @space-2;
+
+ .subtab {
+ padding: @space-2 @space-3;
+ border: none;
+ background: none;
+ color: @text-secondary;
+ cursor: pointer;
+ border-radius: @radius-sm;
+ font-size: @font-size-sm;
+ transition: all 0.2s;
+
+ &:hover {
+ background: @bg-hover;
+ color: @text-primary;
+ }
+
+ &.active {
+ background: @bg-hover;
+ color: @accent-primary;
+ }
+ }
+ }
+
+ .quick-ports-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
+ gap: @space-3;
+ }
+
+ .quick-port-card {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: @space-3 @space-4;
+ background: @bg-hover;
+ border-radius: @radius-md;
+
+ .port-info {
+ display: flex;
+ flex-direction: column;
+
+ .port-name {
+ font-weight: 500;
+ }
+
+ .port-number {
+ color: @text-tertiary;
+ font-size: @font-size-sm;
+ font-family: @font-mono;
+ }
+ }
+ }
+
+ .blocked-list {
+ display: flex;
+ flex-direction: column;
+ gap: @space-2;
+ }
+
+ .blocked-item {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: @space-3 @space-4;
+ background: @bg-hover;
+ border-radius: @radius-md;
+
+ .blocked-ip {
+ font-family: @font-mono;
+ font-weight: 500;
+ }
+ }
+
+ .empty-state-sm {
+ text-align: center;
+ padding: @space-6;
+ color: @text-secondary;
+ }
+
+ .install-info {
+ margin-top: @space-4;
+ padding: @space-4;
+ background: @bg-hover;
+ border-radius: @radius-md;
+
+ p {
+ margin: 0;
+ font-size: @font-size-sm;
+ }
+ }
+}