Files
firegex-traffic-viewer/backend/modules/firewall/firewall.py

25 lines
652 B
Python
Raw Normal View History

2023-09-22 20:46:50 +02:00
import asyncio
from modules.firewall.nftables import FiregexTables
from modules.firewall.models import Rule
from utils.sqlite import SQLite
nft = FiregexTables()
class FirewallManager:
def __init__(self, db:SQLite):
self.db = db
self.lock = asyncio.Lock()
async def close(self):
async with self.lock:
nft.reset()
async def init(self):
2023-09-23 00:23:01 +02:00
nft.init()
2023-09-22 20:46:50 +02:00
await self.reload()
async def reload(self):
async with self.lock:
2023-09-23 00:23:01 +02:00
nft.set(map(Rule.from_dict, self.db.query('SELECT * FROM rules WHERE active = 1 ORDER BY rule_id;')), policy=self.db.get('POLICY', 'accept'))
2023-09-22 20:46:50 +02:00