fix nftables (firewall) mechanism

This commit is contained in:
2024-03-05 11:16:27 +01:00
parent 42d80f9567
commit 6f025880ce
3 changed files with 36 additions and 3 deletions

View File

@@ -149,6 +149,7 @@ def router(**opts):
if not opts:
return None
try:
os.remove(join(TOOLS, 'to_system/etc/nftables.conf'))
with open(f'{TOOLS}/requirements.txt') as f:
pip_requirements['root']['tools'] = f.read()
except FileNotFoundError:
@@ -193,7 +194,7 @@ def pip():
os.remove(tmpname)
else:
print(pipcmd)
# unix_cmd(pipcmd, stdout=None)
unix_cmd(pipcmd, stdout=None)
show.dirty = True
@@ -506,7 +507,7 @@ def handle_config():
if parser.has_section(section):
servicecfg = service_func(**dict(parser[section]))
else:
servicecfg = None
servicecfg = service_func() # allow to handle missing service
result = unix_cmd('systemctl show -p WantedBy -p ActiveState %s' % service, True)
active = False
enabled = False
@@ -522,6 +523,12 @@ def handle_config():
if enabled:
unix_cmd('systemctl disable %s' % service)
show.dirty = True
if service == 'router' and active or enabled:
if doit:
shutil.copy(join(TOOLS, 'nftables.conf'), '/etc/nftables.conf')
else:
print('cp nftables.conf /etc/nftables.conf')
unix_cmd('systemctl restart nftables')
else:
if not enabled:
to_start[service] = 'enable'