From 6369bc67382626d3da5c969463c3addc96bc042f Mon Sep 17 00:00:00 2001 From: Blackwhitebear8 Date: Wed, 13 Aug 2025 16:26:17 +0200 Subject: [PATCH] Add modules/firewall.py --- modules/firewall.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 modules/firewall.py diff --git a/modules/firewall.py b/modules/firewall.py new file mode 100644 index 0000000..d362126 --- /dev/null +++ b/modules/firewall.py @@ -0,0 +1,42 @@ +import re + +def parse_firewall_data(raw_json): + if not raw_json.get("success") or not raw_json.get("data"): + return [] + + text_data = raw_json["data"] + lines = text_data.strip().split('\n') + + rulesets = [] + current_ruleset = None + + for line in lines: + header_match = re.search(r'Firewall "([^"]+)"', line) + if header_match: + ruleset_name = header_match.group(1) + current_ruleset = { + "name": ruleset_name, + "rules": [] + } + rulesets.append(current_ruleset) + continue + + if not current_ruleset or not line.strip() or line.startswith('---') or "Rule Action" in line: + continue + + parts = line.split() + if len(parts) >= 5: + try: + rule_data = { + "rule": parts[0], + "action": parts[1], + "protocol": parts[2], + "packets": parts[3], + "bytes": parts[4], + "conditions": ' '.join(parts[5:]) + } + current_ruleset["rules"].append(rule_data) + except IndexError: + continue + + return rulesets \ No newline at end of file