Correct multiple issues with DHCP and add firewall control logic
This commit is contained in:
@ -23,6 +23,8 @@
|
||||
import subprocess
|
||||
import threading
|
||||
import signal
|
||||
import os
|
||||
import time
|
||||
|
||||
import daemon_lib.ansiiprint as ansiiprint
|
||||
|
||||
@ -38,7 +40,8 @@ class OSDaemon(object):
|
||||
def signal(self, sent_signal):
|
||||
signal_map = {
|
||||
'hup': signal.SIGHUP,
|
||||
'int': signal.SIGINT
|
||||
'int': signal.SIGINT,
|
||||
'term': signal.SIGTERM
|
||||
}
|
||||
self.proc.send_signal(signal_map[sent_signal])
|
||||
|
||||
@ -52,7 +55,7 @@ def run_os_command(command_string, background=False, environment=None):
|
||||
command = command_string.split()
|
||||
if background:
|
||||
def runcmd():
|
||||
subprocess.Popen(
|
||||
subprocess.run(
|
||||
command,
|
||||
env=environment,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -60,12 +63,20 @@ def run_os_command(command_string, background=False, environment=None):
|
||||
)
|
||||
thread = threading.Thread(target=runcmd, args=())
|
||||
thread.start()
|
||||
return 0
|
||||
return 0, None, None
|
||||
else:
|
||||
command_output = subprocess.Popen(
|
||||
command_output = subprocess.run(
|
||||
command,
|
||||
env=environment,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
return command_output.returncode
|
||||
return command_output.returncode, command_output.stdout.decode('ascii'), command_output.stderr.decode('ascii')
|
||||
|
||||
# Reload the firewall rules of the system
|
||||
def reload_firewall_rules(rules_dir):
|
||||
ansiiprint.echo('Updating firewall rules', '', 'o')
|
||||
rules_file = '{}/base.nft'.format(rules_dir)
|
||||
retcode, stdout, stderr = run_os_command('/usr/sbin/nft -f {}'.format(rules_file))
|
||||
if retcode != 0:
|
||||
ansiiprint.echo('Failed to reload rules: {}'.format(stderr), '', 'e')
|
||||
|
Reference in New Issue
Block a user