Add modules/firewall.py
This commit is contained in:
parent
8b4cc6c467
commit
6369bc6738
1 changed files with 42 additions and 0 deletions
42
modules/firewall.py
Normal file
42
modules/firewall.py
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue