file structure and comments unified
Some checks failed
Build and Deploy MITM Webserver / build (push) Failing after 3s
Some checks failed
Build and Deploy MITM Webserver / build (push) Failing after 3s
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// src/components/FirewallTables.tsx
|
||||
import { ArrowDownOutlined, DeleteOutlined, ReloadOutlined } from '@ant-design/icons';
|
||||
import { Alert, Button, Card, Divider, Modal, notification, Space, Spin, Table, Typography } from 'antd';
|
||||
import { ColumnsType } from 'antd/lib/table';
|
||||
@@ -10,7 +9,6 @@ import FirewallAddTableModal from './FireWallAddTableModal';
|
||||
|
||||
const { Paragraph, Text, Title } = Typography;
|
||||
|
||||
/* ---------- Helpers ---------- */
|
||||
|
||||
function renderRuleFriendly(rule: RuleOut | any): string {
|
||||
if (rule?.text && typeof rule.text === 'string' && rule.text.trim() !== '') return rule.text;
|
||||
@@ -103,7 +101,6 @@ function renderRuleFriendly(rule: RuleOut | any): string {
|
||||
try {
|
||||
return JSON.stringify(rule.expr, (_k, v) => (v === undefined ? null : v)).slice(0, 500);
|
||||
} catch {
|
||||
// fallthrough
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,22 +117,18 @@ function isSuccessRc(out?: ExecResult | null): boolean {
|
||||
return out.rc === 0 || out.rc === -1;
|
||||
}
|
||||
|
||||
/* ---------- Props ---------- */
|
||||
type Props = {
|
||||
tables: TableOut[]; // passed from parent
|
||||
error?: Error | null;
|
||||
refreshRules: () => Promise<void>; // trigger to re-fetch ruleset
|
||||
};
|
||||
|
||||
/* ---------- Component ---------- */
|
||||
|
||||
export default function FirewallTables({ tables, error, refreshRules: refresh }: Props): ReactElement {
|
||||
// local UI state, non-persistent
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [isOpenTableCreatorModal, setIsOpenTableCreatorModal] = useState(false);
|
||||
const [isOpenChainCreatorModal, setIsOpenChainCreatorModal] = useState(false);
|
||||
|
||||
// run raw nft commands sequentially and collect results (used for delete ops etc.)
|
||||
const runCommands = useCallback(async (cmds: string[]) => {
|
||||
const acc: CmdResult[] = [];
|
||||
for (const cmd of cmds) {
|
||||
@@ -150,7 +143,6 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
// Delete rule
|
||||
const handleDeleteRule = useCallback(
|
||||
async (family: string | null | undefined, table: string, chain: string, handle: number | string) => {
|
||||
const cmd = `delete rule ${family ?? 'inet'} ${table} ${chain} handle ${handle}`;
|
||||
@@ -175,12 +167,9 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
} catch (err: any) {
|
||||
notification.error({ message: 'Delete failed', description: err?.message ?? String(err) });
|
||||
} finally {
|
||||
// auto-refresh after change (no refresh notification shown here)
|
||||
try {
|
||||
await refresh();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
} catch
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -188,7 +177,6 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
[runCommands, refresh],
|
||||
);
|
||||
|
||||
// Delete chain
|
||||
const handleDeleteChain = useCallback(
|
||||
async (family: string | null | undefined, table: string, chain: string) => {
|
||||
const cmd = `delete chain ${family ?? 'inet'} ${table} ${chain}`;
|
||||
@@ -215,12 +203,9 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
} catch (err: any) {
|
||||
notification.error({ message: 'Chain deletion failed', description: err?.message ?? String(err) });
|
||||
} finally {
|
||||
// auto-refresh after change (no notification)
|
||||
try {
|
||||
await refresh();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
} catch
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -228,7 +213,6 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
[runCommands, refresh],
|
||||
);
|
||||
|
||||
// Delete table
|
||||
const handleDeleteTable = useCallback(
|
||||
async (family: string | null | undefined, table: string) => {
|
||||
const cmd = `delete table ${family ?? 'inet'} ${table}`;
|
||||
@@ -255,12 +239,9 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
} catch (err: any) {
|
||||
notification.error({ message: 'Table deletion failed', description: err?.message ?? String(err) });
|
||||
} finally {
|
||||
// auto-refresh after change (no notification)
|
||||
try {
|
||||
await refresh();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
} catch
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -268,12 +249,10 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
[runCommands, refresh],
|
||||
);
|
||||
|
||||
// manual refresh trigger (exposed to UI)
|
||||
const handleRefresh = useCallback(async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await refresh();
|
||||
// Only show notification when user pressed the refresh button
|
||||
notification.success({ message: 'Ruleset refreshed' });
|
||||
} catch (err: any) {
|
||||
notification.error({ message: 'Refresh failed', description: err?.message ?? String(err) });
|
||||
@@ -289,14 +268,12 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Pass onClose that accepts optional 'created' boolean. If the modal
|
||||
calls onClose(true) we will auto-refresh (no refresh notification). */}
|
||||
|
||||
<FirewallAddTableModal
|
||||
open={isOpenTableCreatorModal}
|
||||
onClose={(created?: boolean) => {
|
||||
setIsOpenTableCreatorModal(false);
|
||||
if (created) {
|
||||
// auto-refresh after create (no notification)
|
||||
void refresh().catch(() => {});
|
||||
}
|
||||
}}
|
||||
@@ -361,7 +338,7 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{/* Chain modal: same optional 'created' signal */}
|
||||
|
||||
<FirewallAddChainModal
|
||||
open={isOpenChainCreatorModal}
|
||||
onClose={(created?: boolean) => {
|
||||
|
||||
Reference in New Issue
Block a user