From 631326eeb794cf1417c2c1d9db92c51e54180889 Mon Sep 17 00:00:00 2001 From: nik012003 Date: Tue, 28 Jun 2022 13:36:17 +0200 Subject: [PATCH] fixed create_schema --- backend/app.py | 10 ++++++---- backend/utils.py | 9 ++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/backend/app.py b/backend/app.py index 9bd947e..47f9cd7 100644 --- a/backend/app.py +++ b/backend/app.py @@ -23,8 +23,7 @@ APP_STATUS = "init" REACT_BUILD_DIR = "../frontend/build/" if not ON_DOCKER else "../frontend/" REACT_HTML_PATH = os.path.join(REACT_BUILD_DIR,"index.html") -if not conf.get("password") is None: - APP_STATUS = "run" + def is_loggined(request: Request): return request.session.get("token", "") == SESSION_TOKEN @@ -294,7 +293,7 @@ async def catch_all(request: Request, full_path:str): if __name__ == '__main__': - db.check_integrity({ + db.create_schema({ 'services': { 'status': 'VARCHAR(100) NOT NULL', 'service_id': 'VARCHAR(100) PRIMARY KEY', @@ -307,7 +306,7 @@ if __name__ == '__main__': 'mode': 'VARCHAR(1) NOT NULL', 'service_id': 'VARCHAR(100) NOT NULL', 'is_blacklist': 'BOOLEAN NOT NULL CHECK (is_blacklist IN (0, 1))', - 'blocked_packets': 'INTEGER UNSIGNED NOT NULL async defAULT 0', + 'blocked_packets': 'INTEGER UNSIGNED NOT NULL DEFAULT 0', 'regex_id': 'INTEGER PRIMARY KEY', 'is_case_sensitive' : 'BOOLEAN NOT NULL CHECK (is_case_sensitive IN (0, 1))', 'FOREIGN KEY (service_id)':'REFERENCES services (service_id)', @@ -319,6 +318,9 @@ if __name__ == '__main__': }) db.query("CREATE UNIQUE INDEX IF NOT EXISTS unique_regex_service ON regexes (regex,service_id,is_blacklist,mode,is_case_sensitive);") + if not conf.get("password") is None: + APP_STATUS = "run" + firewall.reload() # os.environ {PORT = Backend Port (Main Port), F_PORT = Frontend Port} uvicorn.run( diff --git a/backend/utils.py b/backend/utils.py index aaeacfb..846f228 100755 --- a/backend/utils.py +++ b/backend/utils.py @@ -30,15 +30,10 @@ class SQLite(): def disconnect(self) -> None: self.conn.close() - def check_integrity(self, tables = {}) -> None: + def create_schema(self, tables = {}) -> None: cur = self.conn.cursor() for t in tables: - cur.execute(''' - SELECT name FROM sqlite_master WHERE type='table' AND name='{}'; - '''.format(t)) - - if len(cur.fetchall()) == 0: - cur.execute('''CREATE TABLE main.{}({});'''.format(t, ''.join([(c + ' ' + tables[t][c] + ', ') for c in tables[t]])[:-2])) + cur.execute('''CREATE TABLE IF NOT EXISTS main.{}({});'''.format(t, ''.join([(c + ' ' + tables[t][c] + ', ') for c in tables[t]])[:-2])) cur.close() def query(self, query, *values):