diff --git a/backend/example_scripts/hello_nfqueue.py b/backend/example_scripts/hello_nfqueue.py index 1169a95..0d019bc 100644 --- a/backend/example_scripts/hello_nfqueue.py +++ b/backend/example_scripts/hello_nfqueue.py @@ -1,42 +1,29 @@ #!/usr/bin/env python3 -"""Minimal NFQUEUE example script. +"""Minimal NFQUEUE example: accept every packet from a queue.""" -Expected argv: - argv[1] = queue number -Any extra args are optional. -""" - -import logging import signal import sys -from typing import Optional try: from netfilterqueue import NetfilterQueue -except Exception as exc: # pragma: no cover +except Exception as exc: print(f"Failed to import netfilterqueue: {exc}", file=sys.stderr) sys.exit(2) -logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s") -logger = logging.getLogger("hello-nfqueue") - -_running = True - - -def _stop(_sig: int, _frame: Optional[object]) -> None: - global _running - _running = False +nfq = NetfilterQueue() def _handle_packet(packet) -> None: - # This demo accepts all packets and logs basic metadata. - logger.info("packet id=%s len=%s", packet.get_id(), len(packet.get_payload())) packet.accept() +def _stop(_sig, _frame) -> None: + raise SystemExit(0) + + def main() -> int: - if len(sys.argv) < 2: - print("Usage: hello_nfqueue.py [extra args...]", file=sys.stderr) + if len(sys.argv) != 2: + print("Usage: hello_nfqueue.py ", file=sys.stderr) return 1 try: @@ -48,19 +35,13 @@ def main() -> int: signal.signal(signal.SIGINT, _stop) signal.signal(signal.SIGTERM, _stop) - nfq = NetfilterQueue() - logger.info("Binding to NFQUEUE %d", qnum) nfq.bind(qnum, _handle_packet) - try: - while _running: - nfq.run(block=True) + nfq.run() except KeyboardInterrupt: pass finally: - logger.info("Unbinding NFQUEUE %d", qnum) nfq.unbind() - return 0 diff --git a/backend/src/api/packet_scripting_api.py b/backend/src/api/packet_scripting_api.py index 7f84648..9c10adf 100644 --- a/backend/src/api/packet_scripting_api.py +++ b/backend/src/api/packet_scripting_api.py @@ -376,6 +376,7 @@ Type=simple ExecStart={exec_start} Restart=always RestartSec=2 +TimeoutStopSec=10 StandardOutput=syslog StandardError=syslog diff --git a/frontend/src/components/ScriptManager.tsx b/frontend/src/components/ScriptManager.tsx index 583cf37..0bcd4af 100644 --- a/frontend/src/components/ScriptManager.tsx +++ b/frontend/src/components/ScriptManager.tsx @@ -166,8 +166,7 @@ export default function ScriptsManager({ onOpenInEditor }: { onOpenInEditor?: (c const val = ta.value ?? ''; ta.setSelectionRange(val.length, val.length); } - } catch { - } + } catch {} }, 80); }, []); @@ -489,7 +488,10 @@ export default function ScriptsManager({ onOpenInEditor }: { onOpenInEditor?: (c return ; }, []); - const isScriptActive = useCallback((record: ScriptWithStatus) => record.mappings.some((mapping) => mapping.active), []); + const isScriptActive = useCallback( + (record: ScriptWithStatus) => record.mappings.some((mapping) => mapping.active), + [], + ); const saveAddRequirements = useCallback(async () => { if (!addReqTarget) return; @@ -539,7 +541,6 @@ export default function ScriptsManager({ onOpenInEditor }: { onOpenInEditor?: (c render: (_: unknown, record: ScriptWithStatus) => ( {record.name} - {record.is_protected_example ? : null} ), }, @@ -741,7 +742,6 @@ export default function ScriptsManager({ onOpenInEditor }: { onOpenInEditor?: (c expandable={expandable} /> - - - - - -