From fd1fc2f222cd628731582a8a2c41065f2ba5c0e6 Mon Sep 17 00:00:00 2001 From: Morgana Date: Mon, 5 Oct 2026 13:42:50 -0500 Subject: Refactor config & captcha presets --- app.py | 117 ++++++++----------------------------------------------------- presets.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 103 deletions(-) create mode 100644 presets.py diff --git a/app.py b/app.py index af687e4..95d1025 100644 --- a/app.py +++ b/app.py @@ -17,107 +17,11 @@ from flask import ( from werkzeug.exceptions import HTTPException from captcha import Captcha +from presets import GUEST_CAPTCHA, GUIDE_CAPTCHAS SCRYPT_PARAMS = {"n": 16384, "r": 8, "p": 1} HEX_CHARS = set("0123456789ABCDEF") -GUEST_CAPTCHA = Captcha.from_string( - 5, "m...cena....m...ebneb.clm", ".........................", True -) - -GUIDE_CAPTCHAS = { - "Layer 01": [ - Captcha.from_string(2, "a...", "...."), - Captcha.from_string(2, "aaa.", "01.."), - Captcha.from_string(2, "aaaa", "...."), - ], - "Layer 02": [ - Captcha.from_string(2, "b...", "...."), - Captcha.from_string(2, "b.b.", "0.1."), - Captcha.from_string(2, "bbbb", "00.."), - ], - "Layer 03": [ - Captcha.from_string(2, "c...", "...."), - Captcha.from_string(2, "c...", ".11."), - Captcha.from_string(2, "c.c.", "1.1."), - ], - "Layer 04": [ - Captcha.from_string(2, "ac..", "01.."), - Captcha.from_string(2, "ab..", "...."), - Captcha.from_string(2, "bba.", "...."), - ], - "Layer 05": [ - Captcha.from_string(2, "d...", "1..."), - Captcha.from_string(2, "d...", "..1."), - Captcha.from_string(2, "d..d", "...1"), - ], - "Layer 06": [ - Captcha.from_string(3, "c.c.c.c.c", "........."), - Captcha.from_string(3, "c.b...b.a", "........."), - Captcha.from_string(3, "d...d...d", "........."), - ], - "Layer 11": [ - Captcha.from_string(3, "m.m......", "10.10.00."), - Captcha.from_string(3, "m.......m", "10.10.01."), - Captcha.from_string(3, "m.m...m.m", "1.1...2.2"), - ], - "Layer 12": [ - Captcha.from_string(3, "m.m...n.n", "1.1...2.2"), - Captcha.from_string(3, "m.n...n.m", "1.1...2.2"), - Captcha.from_string(3, "m.m...n.n", "1.2....0."), - ], - "Layer 13": [ - Captcha.from_string(4, "m....m..........", "11..10.........."), - Captcha.from_string(4, "mmnn......cc...c", "01230...0...0..."), - Captcha.from_string(4, "mn............nm", "1...11.........."), - Captcha.from_string(4, "mn..nm........nm", "................"), - ], - "Layer 14": [ - Captcha.from_string(4, "m..a.m.........d", "11..10.......0.."), - Captcha.from_string(4, "m..a.m.........d", "11..10.......2.."), - Captcha.from_string(4, "m..a.md........d", "11..10.......0.."), - Captcha.from_string(4, "m.bn.mc.....n..d", "11..10.......2.."), - ], - "Layer 21": [ - Captcha.from_string(3, "....v....", "0101.10.0"), - Captcha.from_string(3, "....v....", "1101.10.0"), - Captcha.from_string(3, "v.......v", "1101020.."), - ], - "Layer 22": [ - Captcha.from_string(3, "v....v.v.", "0......1."), - Captcha.from_string(3, "vm.....m.", ".1.....0."), - Captcha.from_string(3, "v..m.m.v.", ".....1.0."), - ], - "Layer 23": [ - Captcha.from_string(3, "....l....", "...010..."), - Captcha.from_string(3, ".l..l..l.", ".1..0..1."), - Captcha.from_string(3, "..l.l.l..", ".1011...."), - ], - "Layer 24": [ - Captcha.from_string(3, "...cl...d", "....1...."), - Captcha.from_string(3, "l...d...l", "........."), - Captcha.from_string(3, "l...a.b.l", "........."), - ], - "Layer 31": [ - Captcha.from_string(3, "r...c...r", "31.312.1."), - Captcha.from_string(3, "r.b.c.b.r", "........."), - Captcha.from_string(3, "raa.d.a.r", "........."), - ], - "Layer 32": [ - Captcha.from_string(3, "....e....", "0001020.0"), - Captcha.from_string(3, "....e....", "....2...."), - Captcha.from_string(3, "e.e...e.e", "........."), - ], - "Layer 33": [ - Captcha.from_string(3, "ebebb.e.e", ".1.23...."), - Captcha.from_string(3, "eaeac.e.e", "........."), - Captcha.from_string(3, "eaebede.e", "........."), - ], - "Layer 34": [ - Captcha.from_string(4, "er...em..me.dbre", "................"), - ], -} - def get_db(): if "db" not in g: @@ -143,13 +47,20 @@ def add_captcha(captcha_id): session.modified = True -app = Flask(__name__) -with open("./config.json", "r", encoding="utf-8") as file: - config = json.load(file) - app.config["SECRET_KEY"] = config["fsk"] - LIGHT_URL = f"http://192.168.1.10/api/{config['light']}" - del config +def make_app(): + global LIGHT_URL + app = Flask(__name__) + with sqlite3.connect("akasha.db", detect_types=sqlite3.PARSE_DECLTYPES) as temp_db: + cur = temp_db.cursor() + cur.execute("SELECT value FROM config WHERE key='fsk'") + app.config["SECRET_KEY"] = cur.fetchone()[0] + cur.execute("SELECT value FROM config WHERE key='light'") + LIGHT_URL = f"http://192.168.1.10/api/{cur.fetchone()[0]}" app.teardown_appcontext(teardown) + return app + + +app = make_app() @app.context_processor diff --git a/presets.py b/presets.py new file mode 100644 index 0000000..1aedf78 --- /dev/null +++ b/presets.py @@ -0,0 +1,98 @@ +from captcha import Captcha + +GUEST_CAPTCHA = Captcha.from_string( + 5, "m...cena....m...ebneb.clm", ".........................", True +) + +GUIDE_CAPTCHAS = { + "Layer 01": [ + Captcha.from_string(2, "a...", "...."), + Captcha.from_string(2, "aaa.", "01.."), + Captcha.from_string(2, "aaaa", "...."), + ], + "Layer 02": [ + Captcha.from_string(2, "b...", "...."), + Captcha.from_string(2, "b.b.", "0.1."), + Captcha.from_string(2, "bbbb", "00.."), + ], + "Layer 03": [ + Captcha.from_string(2, "c...", "...."), + Captcha.from_string(2, "c...", ".11."), + Captcha.from_string(2, "c.c.", "1.1."), + ], + "Layer 04": [ + Captcha.from_string(2, "ac..", "01.."), + Captcha.from_string(2, "ab..", "...."), + Captcha.from_string(2, "bba.", "...."), + ], + "Layer 05": [ + Captcha.from_string(2, "d...", "1..."), + Captcha.from_string(2, "d...", "..1."), + Captcha.from_string(2, "d..d", "...1"), + ], + "Layer 06": [ + Captcha.from_string(3, "c.c.c.c.c", "........."), + Captcha.from_string(3, "c.b...b.a", "........."), + Captcha.from_string(3, "d...d...d", "........."), + ], + "Layer 11": [ + Captcha.from_string(3, "m.m......", "10.10.00."), + Captcha.from_string(3, "m.......m", "10.10.01."), + Captcha.from_string(3, "m.m...m.m", "1.1...2.2"), + ], + "Layer 12": [ + Captcha.from_string(3, "m.m...n.n", "1.1...2.2"), + Captcha.from_string(3, "m.n...n.m", "1.1...2.2"), + Captcha.from_string(3, "m.m...n.n", "1.2....0."), + ], + "Layer 13": [ + Captcha.from_string(4, "m....m..........", "11..10.........."), + Captcha.from_string(4, "mmnn......cc...c", "01230...0...0..."), + Captcha.from_string(4, "mn............nm", "1...11.........."), + Captcha.from_string(4, "mn..nm........nm", "................"), + ], + "Layer 14": [ + Captcha.from_string(4, "m..a.m.........d", "11..10.......0.."), + Captcha.from_string(4, "m..a.m.........d", "11..10.......2.."), + Captcha.from_string(4, "m..a.md........d", "11..10.......0.."), + Captcha.from_string(4, "m.bn.mc.....n..d", "11..10.......2.."), + ], + "Layer 21": [ + Captcha.from_string(3, "....v....", "0101.10.0"), + Captcha.from_string(3, "....v....", "1101.10.0"), + Captcha.from_string(3, "v.......v", "1101020.."), + ], + "Layer 22": [ + Captcha.from_string(3, "v....v.v.", "0......1."), + Captcha.from_string(3, "vm.....m.", ".1.....0."), + Captcha.from_string(3, "v..m.m.v.", ".....1.0."), + ], + "Layer 23": [ + Captcha.from_string(3, "....l....", "...010..."), + Captcha.from_string(3, ".l..l..l.", ".1..0..1."), + Captcha.from_string(3, "..l.l.l..", ".1011...."), + ], + "Layer 24": [ + Captcha.from_string(3, "...cl...d", "....1...."), + Captcha.from_string(3, "l...d...l", "........."), + Captcha.from_string(3, "l...a.b.l", "........."), + ], + "Layer 31": [ + Captcha.from_string(3, "r...c...r", "31.312.1."), + Captcha.from_string(3, "r.b.c.b.r", "........."), + Captcha.from_string(3, "raa.d.a.r", "........."), + ], + "Layer 32": [ + Captcha.from_string(3, "....e....", "0001020.0"), + Captcha.from_string(3, "....e....", "....2...."), + Captcha.from_string(3, "e.e...e.e", "........."), + ], + "Layer 33": [ + Captcha.from_string(3, "ebebb.e.e", ".1.23...."), + Captcha.from_string(3, "eaeac.e.e", "........."), + Captcha.from_string(3, "eaebede.e", "........."), + ], + "Layer 34": [ + Captcha.from_string(4, "er...em..me.dbre", "................"), + ], +} -- cgit v1.3.1