Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | 1x 1x 3x 1x 3x 1x 1x 1x 1x 1x 3x 1x 3x | import React, { useState } from "react";
import MainPage from "@/components/page/MainPage/MainPage";
import {
BrickWallFire,
Plus,
Shield,
ShieldOff,
Globe,
Server,
Info,
MoreHorizontal,
Trash,
CircleMinus,
} from "lucide-react";
// ─── Types ────────────────────────────────────────────────────────────────────
type RuleAction = "allow" | "deny";
type RuleDirection = "inbound" | "outbound";
interface FirewallRule {
id: string;
name: string;
direction: RuleDirection;
action: RuleAction;
source: string;
destination: string;
port: string;
enabled: boolean;
}
const PLACEHOLDER_RULES: FirewallRule[] = [
{
id: "r1",
name: "Allow HTTPS inbound",
direction: "inbound",
action: "allow",
source: "0.0.0.0/0",
destination: "api.internal",
port: "443",
enabled: true,
},
{
id: "r2",
name: "Block all other inbound",
direction: "inbound",
action: "deny",
source: "0.0.0.0/0",
destination: "*",
port: "*",
enabled: true,
},
{
id: "r3",
name: "Allow outbound to LLM providers",
direction: "outbound",
action: "allow",
source: "api.internal",
destination: "api.openai.com",
port: "443",
enabled: false,
},
];
// ─── Primitives ───────────────────────────────────────────────────────────────
const actionBadge = (action: RuleAction) =>
action === "allow"
? "bg-emerald-50 dark:bg-emerald-950/40 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-800"
: "bg-red-50 dark:bg-red-950/40 text-red-700 dark:text-red-300 border-red-200 dark:border-red-800";
const directionBadge = (dir: RuleDirection) =>
dir === "inbound"
? "bg-blue-50 dark:bg-blue-950/40 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800"
: "bg-violet-50 dark:bg-violet-950/40 text-violet-700 dark:text-violet-300 border-violet-200 dark:border-violet-800";
// ─── DeveloperFirewall ────────────────────────────────────────────────────────
const DeveloperFirewall: React.FC = () => {
const [rules, setRules] = useState<FirewallRule[]>(PLACEHOLDER_RULES);
const [openMenu, setOpenMenu] = useState<string | null>(null);
const toggleRule = (id: string) => {
setRules((prev) =>
prev.map((r) => (r.id === id ? { ...r, enabled: !r.enabled } : r)),
);
};
const deleteRule = (id: string) => {
setRules((prev) => prev.filter((r) => r.id !== id));
setOpenMenu(null);
};
const activeCount = rules.filter((r) => r.enabled).length;
return (
<MainPage
title="Firewall"
description="Custom network policies controlling inbound and outbound traffic on your endpoints."
links={[
<button
type="button"
disabled
className="flex items-center gap-1.5 px-3 py-2 rounded-lg bg-gray-900 dark:bg-white text-white dark:text-gray-900 text-sm font-medium opacity-40 cursor-not-allowed"
title="Coming soon"
>
<Plus className="size-4" />
New Rule
</button>,
]}
>
<div className="space-y-5">
{/* Info banner */}
<div className="flex items-start gap-3 px-4 py-3 rounded-xl bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800">
<Info className="size-4 text-blue-600 dark:text-blue-400 shrink-0 mt-0.5" />
<p className="text-sm text-blue-700 dark:text-blue-300">
Firewall rule management is coming soon. The rules below are for preview only.
Rules are evaluated top-to-bottom — the first matching rule wins.
</p>
</div>
{/* Summary */}
<div className="grid grid-cols-3 gap-4">
<div className="flex flex-col gap-1 p-4 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800">
<div className="flex items-center gap-1.5 text-xs text-gray-400 dark:text-gray-500">
<Shield className="size-3.5" />
Total Rules
</div>
<div className="text-2xl font-bold text-gray-900 dark:text-gray-100">{rules.length}</div>
</div>
<div className="flex flex-col gap-1 p-4 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800">
<div className="flex items-center gap-1.5 text-xs text-emerald-500">
<Shield className="size-3.5" />
Active
</div>
<div className="text-2xl font-bold text-gray-900 dark:text-gray-100">{activeCount}</div>
</div>
<div className="flex flex-col gap-1 p-4 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800">
<div className="flex items-center gap-1.5 text-xs text-gray-400 dark:text-gray-500">
<ShieldOff className="size-3.5" />
Disabled
</div>
<div className="text-2xl font-bold text-gray-900 dark:text-gray-100">
{rules.length - activeCount}
</div>
</div>
</div>
{/* Rules table */}
<div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm overflow-hidden">
<div className="flex items-center gap-2 px-5 py-3.5 border-b border-gray-100 dark:border-gray-700">
<BrickWallFire className="size-4 text-gray-400 dark:text-gray-500" />
<h3 className="text-sm font-semibold text-gray-700 dark:text-gray-300">Rules</h3>
<span className="ml-auto text-xs text-gray-400 dark:text-gray-500">
Evaluated top-to-bottom
</span>
</div>
{rules.length === 0 ? (
<div className="flex flex-col items-center justify-center py-16 text-center">
<div className="p-4 rounded-full bg-gray-100 dark:bg-gray-700 mb-4">
<BrickWallFire className="size-7 text-gray-400 dark:text-gray-500" />
</div>
<p className="text-sm font-medium text-gray-600 dark:text-gray-400">No rules configured.</p>
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">Add a rule to control traffic.</p>
</div>
) : (
<div className="divide-y divide-gray-50 dark:divide-gray-700/50">
{rules.map((rule, idx) => (
<div
key={rule.id}
className={`flex items-center gap-4 px-5 py-3.5 ${
!rule.enabled ? "opacity-50" : ""
}`}
>
{/* Order */}
<span className="text-xs font-mono text-gray-300 dark:text-gray-600 w-4 shrink-0 text-right">
{idx + 1}
</span>
{/* Toggle */}
<button
onClick={() => toggleRule(rule.id)}
className={`relative inline-flex h-4.5 w-8 shrink-0 items-center rounded-full transition-colors ${
rule.enabled
? "bg-gray-900 dark:bg-gray-100"
: "bg-gray-200 dark:bg-gray-600"
}`}
aria-label="Toggle rule"
>
<span
className={`inline-block size-3 rounded-full bg-white dark:bg-gray-900 shadow transition-transform ${
rule.enabled ? "translate-x-4" : "translate-x-0.5"
}`}
/>
</button>
{/* Badges */}
<div className="flex items-center gap-1.5 shrink-0">
<span
className={`text-xs px-2 py-0.5 rounded-full border font-medium capitalize ${actionBadge(rule.action)}`}
>
{rule.action}
</span>
<span
className={`text-xs px-2 py-0.5 rounded-full border font-medium capitalize ${directionBadge(rule.direction)}`}
>
{rule.direction}
</span>
</div>
{/* Name + endpoints */}
<div className="flex-1 min-w-0">
<div className="text-sm font-medium text-gray-800 dark:text-gray-200 truncate">
{rule.name}
</div>
<div className="flex items-center gap-2 mt-0.5 text-xs text-gray-400 dark:text-gray-500">
<Globe className="size-3 shrink-0" />
<code className="font-mono truncate">{rule.source}</code>
<span>→</span>
<Server className="size-3 shrink-0" />
<code className="font-mono truncate">{rule.destination}</code>
<span className="shrink-0">:{rule.port}</span>
</div>
</div>
{/* Actions */}
<div className="relative shrink-0">
<button
onClick={() => setOpenMenu(openMenu === rule.id ? null : rule.id)}
className="p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"
>
<MoreHorizontal className="size-4 text-gray-400" />
</button>
{openMenu === rule.id && (
<div className="absolute right-0 top-8 z-10 w-40 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 shadow-lg py-1">
<button
onClick={() => { toggleRule(rule.id); setOpenMenu(null); }}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700"
>
<CircleMinus className="size-3.5" />
{rule.enabled ? "Disable" : "Enable"}
</button>
<button
onClick={() => deleteRule(rule.id)}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/30"
>
<Trash className="size-3.5" />
Delete Rule
</button>
</div>
)}
</div>
</div>
))}
</div>
)}
</div>
</div>
</MainPage>
);
};
export default DeveloperFirewall;
|