import React from "react"; import { Shield, ShieldOff, ShieldCheck, ChevronDown } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { ServerMetrics } from "@/main-axios.ts"; import type { FirewallMetrics, FirewallChain, FirewallRule, } from "@/types/stats-widgets"; import { SectionCard } from "@/components/section-card"; interface FirewallWidgetProps { metrics: ServerMetrics | null; metricsHistory: ServerMetrics[]; } function RuleRow({ rule }: { rule: FirewallRule }) { const { t } = useTranslation(); const targetClass = rule.target.toUpperCase() === "ACCEPT" ? "text-accent-brand" : rule.target.toUpperCase() === "DROP" ? "text-destructive" : rule.target.toUpperCase() === "REJECT" ? "text-yellow-500" : "text-muted-foreground"; const src = rule.interface ?? rule.state ?? (rule.source === "0.0.0.0/0" ? t("serverStats.firewall.anywhere") : rule.source); return (
{rule.target} {rule.protocol.toUpperCase()} {rule.dport ?? "—"} {src}
); } function ChainSection({ chain }: { chain: FirewallChain }) { const { t } = useTranslation(); const [open, setOpen] = React.useState(true); const policyClass = chain.policy.toUpperCase() === "ACCEPT" ? "text-accent-brand" : chain.policy.toUpperCase() === "DROP" ? "text-destructive" : "text-yellow-500"; return (
{open && chain.rules.length > 0 && (
{t("serverStats.firewall.action")} {t("serverStats.firewall.protocol")} {t("serverStats.firewall.port")} {t("serverStats.firewall.source")}
{chain.rules.map((rule, i) => ( ))}
)}
); } export function FirewallWidget({ metrics }: FirewallWidgetProps) { const { t } = useTranslation(); const firewall = (metrics as ServerMetrics & { firewall?: FirewallMetrics }) ?.firewall; const statusIcon = !firewall || firewall.type === "none" ? ( ) : firewall.status === "active" ? ( ) : ( ); const statusBadge = firewall?.status === "active" ? ( ACTIVE ) : ( {t("serverStats.firewall.inactive").toUpperCase()} ); return (
{t("serverStats.firewall.title")} {statusBadge}
{firewall?.type && firewall.type !== "none" && ( {firewall.type} )} {firewall && firewall.chains.length > 0 ? (
{firewall.chains.map((chain) => ( ))}
) : ( {t("serverStats.firewall.noData")} )}
); }