GUI editor to tame mod_security rules

⌈⌋ ⎇ branch:  modseccfg


Artifact [b96dfd1dcd]

Artifact b96dfd1dcd1480a76be1f664f5be756ea98461585aa28fa74f00922dd7f202b1:

  • Executable file logfmt1/fmt2md — part of check-in [36388dbafb] at 2020-12-17 16:37:01 on branch trunk — logfmt1: Add update/nginx support (untested), fmt2md, #doc and #src comments in .fmt/json files, add logopen.names() to list named groups in regex, fix single backlash in rx_sub() (user: mario size: 1514)

#!/usr/bin/env python3
# description: show patterns in markdown
#
# 
#

import re, json, os, sys

fn = sys.argv[1]
f = open(fn, "r", encoding="utf-8")
fmt = json.loads(f.read())

# doc urls
search = {
    "strftime": "[strftime(3)](https://www.man7.org/linux/man-pages/man3/strftime.3.html#:~:text={})",
    "grok": "[grok formats](https://duckduckgo.com/?q=grok+format+{})",
    "apache generic": "[mod_log_config.c/log_io.c](https://github.com/apache/httpd/search?q={})",
    "else": "[???](https://duckduckgo.com/?q={})",
}
url = search.get(fmt["class"]) or search["else"]

# table head
print(f"\n\n## {fmt['class']}\n")
print("| placeholder \t | id \t | regex \t \t | grok/fmt-recursion \t | description/reference \t |")
print("-------------------------------------------------------------------------------------------")

# fields
for name, opt in fmt.get("fields", {}).items():
    id = opt.get("id")
    rx = opt.get('rx')
    if rx:
        rx = rx.replace("|", "¦")
    grok = opt.get('grok') or "-"
    desc = opt.get('desc') or url.format(id) 
    print(f"| {name} \t | {id} \t | `{rx}` \t | {grok} \t | {desc} |")

for name, opt in fmt.get("expand", {}).items():
    id = opt.get("id")
    rx = opt.get('rx') or opt.get("record")
    if rx and len(rx) >= 50:
        rx = rx[0:50] + "…"
    if rx:
        rx = rx.replace("|", "¦")
    grok = opt.get('grok') or opt.get("class")
    desc = opt.get('desc') or url.format(id) 
    print(f"| {name} \t | {id} \t | `{rx}` \t | {grok} \t | {desc} |")