nfqueue to hyperscan and stream match, removed proxyregex
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import asyncio
|
||||
from ipaddress import ip_address, ip_interface
|
||||
import os, socket, psutil, sys, nftables
|
||||
import os
|
||||
import socket
|
||||
import psutil
|
||||
import sys
|
||||
import nftables
|
||||
from fastapi_socketio import SocketManager
|
||||
from fastapi import Path
|
||||
from typing import Annotated
|
||||
import json
|
||||
|
||||
LOCALHOST_IP = socket.gethostbyname(os.getenv("LOCALHOST_IP","127.0.0.1"))
|
||||
|
||||
@@ -31,7 +34,8 @@ async def socketio_emit(elements:list[str]):
|
||||
|
||||
def refactor_name(name:str):
|
||||
name = name.strip()
|
||||
while " " in name: name = name.replace(" "," ")
|
||||
while " " in name:
|
||||
name = name.replace(" "," ")
|
||||
return name
|
||||
|
||||
class SysctlManager:
|
||||
@@ -125,8 +129,10 @@ class NFTableManager(Singleton):
|
||||
|
||||
def cmd(self, *cmds):
|
||||
code, out, err = self.raw_cmd(*cmds)
|
||||
if code == 0: return out
|
||||
else: raise Exception(err)
|
||||
if code == 0:
|
||||
return out
|
||||
else:
|
||||
raise Exception(err)
|
||||
|
||||
def init(self):
|
||||
self.reset()
|
||||
@@ -138,8 +144,10 @@ class NFTableManager(Singleton):
|
||||
|
||||
def list_rules(self, tables = None, chains = None):
|
||||
for filter in [ele["rule"] for ele in self.raw_list() if "rule" in ele ]:
|
||||
if tables and filter["table"] not in tables: continue
|
||||
if chains and filter["chain"] not in chains: continue
|
||||
if tables and filter["table"] not in tables:
|
||||
continue
|
||||
if chains and filter["chain"] not in chains:
|
||||
continue
|
||||
yield filter
|
||||
|
||||
def raw_list(self):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
import os, httpx
|
||||
import os
|
||||
import httpx
|
||||
from typing import Callable
|
||||
from fastapi import APIRouter
|
||||
from starlette.responses import StreamingResponse
|
||||
@@ -31,7 +32,8 @@ def frontend_deploy(app):
|
||||
return await frontend_debug_proxy(full_path)
|
||||
except Exception:
|
||||
return {"details":"Frontend not started at "+f"http://127.0.0.1:{os.getenv('F_PORT','5173')}"}
|
||||
else: return await react_deploy(full_path)
|
||||
else:
|
||||
return await react_deploy(full_path)
|
||||
|
||||
def list_routers():
|
||||
return [ele[:-3] for ele in list_files(ROUTERS_DIR) if ele != "__init__.py" and " " not in ele and ele.endswith(".py")]
|
||||
@@ -79,9 +81,12 @@ def load_routers(app):
|
||||
if router.shutdown:
|
||||
shutdowns.append(router.shutdown)
|
||||
async def reset(reset_option:ResetRequest):
|
||||
for func in resets: await run_func(func, reset_option)
|
||||
for func in resets:
|
||||
await run_func(func, reset_option)
|
||||
async def startup():
|
||||
for func in startups: await run_func(func)
|
||||
for func in startups:
|
||||
await run_func(func)
|
||||
async def shutdown():
|
||||
for func in shutdowns: await run_func(func)
|
||||
for func in shutdowns:
|
||||
await run_func(func)
|
||||
return reset, startup, shutdown
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import json, sqlite3, os
|
||||
import json
|
||||
import sqlite3
|
||||
import os
|
||||
from hashlib import md5
|
||||
|
||||
class SQLite():
|
||||
@@ -15,8 +17,10 @@ class SQLite():
|
||||
self.conn = sqlite3.connect(self.db_name, check_same_thread = False)
|
||||
except Exception:
|
||||
path_name = os.path.dirname(self.db_name)
|
||||
if not os.path.exists(path_name): os.makedirs(path_name)
|
||||
with open(self.db_name, 'x'): pass
|
||||
if not os.path.exists(path_name):
|
||||
os.makedirs(path_name)
|
||||
with open(self.db_name, 'x'):
|
||||
pass
|
||||
self.conn = sqlite3.connect(self.db_name, check_same_thread = False)
|
||||
def dict_factory(cursor, row):
|
||||
d = {}
|
||||
@@ -36,13 +40,15 @@ class SQLite():
|
||||
with open(self.db_name, "wb") as f:
|
||||
f.write(self.__backup)
|
||||
self.__backup = None
|
||||
if were_active: self.connect()
|
||||
if were_active:
|
||||
self.connect()
|
||||
|
||||
def delete_backup(self):
|
||||
self.__backup = None
|
||||
|
||||
def disconnect(self) -> None:
|
||||
if self.conn: self.conn.close()
|
||||
if self.conn:
|
||||
self.conn.close()
|
||||
self.conn = None
|
||||
|
||||
def create_schema(self, tables = {}) -> None:
|
||||
@@ -50,9 +56,11 @@ class SQLite():
|
||||
cur = self.conn.cursor()
|
||||
cur.execute("CREATE TABLE IF NOT EXISTS main.keys_values(key VARCHAR(100) PRIMARY KEY, value VARCHAR(100) NOT NULL);")
|
||||
for t in tables:
|
||||
if t == "QUERY": continue
|
||||
if t == "QUERY":
|
||||
continue
|
||||
cur.execute('CREATE TABLE IF NOT EXISTS main.{}({});'.format(t, ''.join([(c + ' ' + tables[t][c] + ', ') for c in tables[t]])[:-2]))
|
||||
if "QUERY" in tables: [cur.execute(qry) for qry in tables["QUERY"]]
|
||||
if "QUERY" in tables:
|
||||
[cur.execute(qry) for qry in tables["QUERY"]]
|
||||
cur.close()
|
||||
|
||||
def query(self, query, *values):
|
||||
@@ -82,8 +90,10 @@ class SQLite():
|
||||
raise e
|
||||
finally:
|
||||
cur.close()
|
||||
try: self.conn.commit()
|
||||
except Exception: pass
|
||||
try:
|
||||
self.conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def delete(self):
|
||||
self.disconnect()
|
||||
@@ -92,7 +102,8 @@ class SQLite():
|
||||
def init(self):
|
||||
self.connect()
|
||||
try:
|
||||
if self.get('DB_VERSION') != self.DB_VER: raise Exception("DB_VERSION is not correct")
|
||||
if self.get('DB_VERSION') != self.DB_VER:
|
||||
raise Exception("DB_VERSION is not correct")
|
||||
except Exception:
|
||||
self.delete()
|
||||
self.connect()
|
||||
|
||||
Reference in New Issue
Block a user