in tools/paranoia_level_classifier.py [0:0]
def find_paranoia_level_line(lines = [], paranoia_level = 0):
# find start
start_pos = 0
if paranoia_level > 0:
start_pattern = re.compile(r"^\s*SecRule.*PARANOIA_LEVEL\D+" + str(paranoia_level) + r".*$")
while start_pos < len(lines):
if start_pattern.match(lines[start_pos]):
break
start_pos += 1
# find end
end_pattern = re.compile(r"^\s*SecRule.*PARANOIA_LEVEL\D+(\d+).*$")
end_pos = start_pos + 1
while end_pos < len(lines):
result = end_pattern.match(lines[end_pos])
if result and int(result.group(1)) > paranoia_level:
break
end_pos += 1
if end_pos > start_pos and start_pos < len(lines):
if end_pos > len(lines):
end_pos = len(lines)
return lines[start_pos + 1: end_pos]
return []