GUI editor to tame mod_security rules

⌈⌋ ⎇ branch:  modseccfg


Check-in [de9d870142]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add File→Install menu for *.deb packages or scripts.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: de9d870142e90b6eb27b847082ed2a6fc4988b39e70af17c0dedd04f1d5846e9
User & Date: mario 2020-12-02 06:33:02
Context
2020-12-02
22:32
Remove stale infos, add project meta block check-in: 0fcb10b69d user: mario tags: trunk
06:33
Add File→Install menu for *.deb packages or scripts. check-in: de9d870142 user: mario tags: trunk
06:32
Introduce module/plugin lookup for .add_menu()/.has()/.show() and raw_event in mainwindow handler (for literal menu string lookups). check-in: 92ff15a9ff user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to dev/Makefile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SHELL   := /bin/bash #(for brace expansion)

all:	deb
deb:	flame

flame:
	echo $(DESC)
	cd modsec-flameeyes-main && \
	fpm -f -t deb -s dir -n modsec-flameeyes -v 2020.06.13 -a all	\
		--description "mod_security rules againt rogue bots"	\
		--url "https://github.com/Flameeyes/modsec-flameeyes/"	\
		--vendor "Diego Elio Pettenò <flameeyes@flameeyes.eu>"	\
		--depends libapache2-mod-security2 --license Apache-2.0 \
		rules/=/usr/share/modsecurity-flameeyes/rules/ 		\
		optional/=/usr/share/modsecurity-flameeyes/optional/ 	\
		README.md=//usr/share/doc/modsec-flameeyes/		\
		../flameeyes.conf=/etc/apache2/mods-enabled/flameeyes.conf
	mv modsec-flameeyes-main/modsec-flameeyes*.deb .

down:
	wget https://github.com/Flameeyes/modsec-flameeyes/archive/main.zip
	unzip main.zip












|











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SHELL   := /bin/bash #(for brace expansion)

all:	deb
deb:	flame

flame:
	echo $(DESC)
	cd modsec-flameeyes-main && \
	fpm -f -t deb -s dir -n modsec-flameeyes -v 2020.06.13 -a all	\
		--description "mod_security rules againt rogue bots"	\
		--url "https://github.com/Flameeyes/modsec-flameeyes/"	\
		--vendor "Diego Elio Pettenò <flameeyes@flameeyes.com>"	\
		--depends libapache2-mod-security2 --license Apache-2.0 \
		rules/=/usr/share/modsecurity-flameeyes/rules/ 		\
		optional/=/usr/share/modsecurity-flameeyes/optional/ 	\
		README.md=//usr/share/doc/modsec-flameeyes/		\
		../flameeyes.conf=/etc/apache2/mods-enabled/flameeyes.conf
	mv modsec-flameeyes-main/modsec-flameeyes*.deb .

down:
	wget https://github.com/Flameeyes/modsec-flameeyes/archive/main.zip
	unzip main.zip

Added modseccfg/install/__init__.py.



















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# api: modseccfg
# encoding: utf-8
# title: Install packages
# descriptions: addon packages
# version: 0.1
# type: handler
# category: setup
#
# Mirrors files from install/ dir into File→Install menu.
# Allows to install packages (locally or onto srvroot).
#

import os, re, glob, subprocess, traceback
from modseccfg import writer
from modseccfg.utils import srvroot, conf
import PySimpleGUI as sg

dir = re.sub("[^/]+$", "", __file__)


# hook: mainwindow.add_menu
def add_menu(menu):
    print("\n")
    m = menu[0][1] # File
    i = 5 # m.index("Test")
    m.insert(i, ls())
    m.insert(i, "Install")
    
# find files
def ls():
    ls = [re.sub("^.+/", "", fn) for fn in glob.glob(f"{dir}/*.*")]
    ls = [fn for fn in ls if not fn.startswith("_")]
    return ls

# File→Install check
def has(event):
    return event in ls()

# actual invocation
def show(raw_event=None, mainwindow=None, **kwargs):

    cmd = raw_event
    if re.search("\.deb$", cmd):
        cmd = f"dpkg -i ./{cmd}"
    elif re.search("\.rpm$", cmd):
        cmd = f"rpm -i ./{cmd}"
    elif os.access(f"{dir}/{cmd}", os.X_OK):
        cmd = f"./{cmd}"
    if srvroot.srv:
        cmd = re.sub('\./', '/root/', cmd)
        cmd = f"scp  ./{cmd}  {srvroot.srv}root/\nssh {srvroot.srvname}  {cmd}"
        
    layout = [
       [sg.Multiline(cmd, size=(100,22), background_color="#331111", text_color="white", font=("Monospace", 13), key="cmd")],
       [sg.Button("Exec", key="Exec"), sg.Button("Cancel")]
    ]
    execwin(
        sg.Window(layout=layout, title="install"),
        mainwindow
    )

# event handler    
class execwin:
    def __init__(self, w, mainwindow):
        self.w = w
        self.cmd = w["cmd"]
        w.read(timeout=1)
        self.w["cmd"].Widget.config(insertbackground="yellow")
        mainwindow.win_register(w, self.event)

    def event(self, event, data):
        if event=="Exec":
            self.w["Exec"].update(disabled=1, visible=0)
            self.run(data["cmd"])
        elif event=="Cancel":
            self.w.close()

    # iterate over cmd lines, and run each
    def run(self, cmds):
        os.chdir(dir)
        self.cmd.update("")
        for line in cmds.split("\n"):
            if not re.match("^\s*[\w.]", line):
                self.cmd.print(line, text_color="gray")
                continue
            self.cmd.print(f"> {line}\n", text_color="lightgreen")
            args = re.split("\s+", line)
            try:
                r = subprocess.run(args, capture_output=True)
            except Exception as e:
                self.cmd.print(str(e), text_color="red", background_color="#553311")
                break
            if r.stdout:
                self.cmd.print(str(r.stdout.decode("utf-8")))
            if r.returncode:
                self.cmd.print(f"ERRNO {r.returncode}", background_color="yellow", text_color="red", end="")
                self.cmd.print("")
            if r.stderr:
                self.cmd.print(str(r.stderr.decode("utf-8")), text_color="red")
                self.cmd.print("")
            if r.returncode:
                break
        #sg.popup("Completed?")
        self.w.read(timeout=7000)
        self.w.close()

Added modseccfg/install/modsec-flameeyes_2020.06.13_all.deb.

cannot compute difference between binary files

Added modseccfg/install/test.sh.







>
>
>
1
2
3
#!/bin/sh
ls -l
echo test $@