mirror of
https://github.com/fabriziosalmi/patterns.git
synced 2025-12-17 09:45:34 +00:00
Update json2apache.py
This commit is contained in:
parent
4c01d419de
commit
ed0c2e736e
@ -5,6 +5,7 @@ import logging
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Set, Tuple, Optional
|
||||
from functools import lru_cache
|
||||
from collections import defaultdict # Import defaultdict
|
||||
|
||||
# --- Configuration ---
|
||||
LOG_LEVEL = logging.INFO # Adjust as needed (DEBUG, INFO, WARNING, ERROR)
|
||||
@ -96,7 +97,15 @@ def generate_apache_waf(rules: List[Dict]) -> None:
|
||||
if not isinstance(rule_id, int): # check if is an int
|
||||
# Extract ID from rule and convert to an integer
|
||||
match = re.search(r'id:(\d+)', rule_id)
|
||||
rule_id = int(match.group(1)) if match else rule_id_counter
|
||||
if match:
|
||||
try:
|
||||
rule_id = int(match.group(1))
|
||||
except ValueError:
|
||||
logger.warning(f"Invalid rule ID '{match.group(1)}' in rule: {rule}. Using generated ID.")
|
||||
rule_id = rule_id_counter
|
||||
rule_id_counter += 1
|
||||
else:
|
||||
rule_id = rule_id_counter
|
||||
rule_id_counter += 1
|
||||
|
||||
category = rule.get("category", "generic").lower()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user