Fixing eviltwin. Lots of changes.
This commit is contained in:
@@ -9,6 +9,7 @@ from ..config import Configuration
|
||||
|
||||
class Dnsmasq(Dependency):
|
||||
'''Wrapper for dnsmasq program.'''
|
||||
|
||||
dependency_required = False
|
||||
dependency_name = 'dnsmasq'
|
||||
dependency_url = 'apt-get install dnsmasq'
|
||||
@@ -16,14 +17,15 @@ class Dnsmasq(Dependency):
|
||||
def __init__(self, interface):
|
||||
self.interface = interface
|
||||
self.pid = None
|
||||
self.config_file = None
|
||||
|
||||
|
||||
def create_config_file(self):
|
||||
config_file = os.path.join(Configuration.temp(), 'dnsmasq.conf')
|
||||
if os.path.exists(config_file):
|
||||
os.remove(config_file)
|
||||
self.config_file = os.path.join(Configuration.temp(), 'dnsmasq.conf')
|
||||
if os.path.exists(self.config_file):
|
||||
os.remove(self.config_file)
|
||||
|
||||
with open(config_file, 'w') as config:
|
||||
with open(self.config_file, 'w') as config:
|
||||
config.write('interface={}\n'.format(self.interface))
|
||||
config.write('dhcp-range=10.0.0.10,10.0.0.100,8h\n')
|
||||
config.write('dhcp-option=3,10.0.0.1\n')
|
||||
@@ -31,11 +33,10 @@ class Dnsmasq(Dependency):
|
||||
config.write('server=8.8.8.8\n')
|
||||
config.write('log-queries\n')
|
||||
config.write('log-dhcp\n')
|
||||
return config_file
|
||||
|
||||
|
||||
def start(self):
|
||||
config_file = self.create_config_file()
|
||||
self.create_config_file()
|
||||
|
||||
# Stop already-running dnsmasq process
|
||||
self.killall()
|
||||
@@ -43,25 +44,28 @@ class Dnsmasq(Dependency):
|
||||
# Start new dnsmasq process
|
||||
self.pid = Process([
|
||||
'dnsmasq',
|
||||
'-C', config_file
|
||||
'-C', self.config_file
|
||||
])
|
||||
|
||||
|
||||
def stop(self):
|
||||
# Kill dnsmasq process
|
||||
if self.pid:
|
||||
if self.pid and self.pid.poll() is not None:
|
||||
self.pid.interrupt()
|
||||
|
||||
self.killall()
|
||||
# TODO: Wait until dnsmasq is completely stopped.
|
||||
|
||||
|
||||
def check(self):
|
||||
# TODO: Check if dnsmasq is still running, if there's any errors in the logs, etc.
|
||||
if self.pid.poll() is not None:
|
||||
# Process stopped
|
||||
pass
|
||||
if self.config_file and os.path.exists(self.config_file):
|
||||
os.remove(self.config_file)
|
||||
|
||||
|
||||
def killall(self):
|
||||
Process(['killall', 'dnsmasq']).wait()
|
||||
# TODO: Wait until dnsmasq is completely stopped.
|
||||
|
||||
|
||||
def check(self):
|
||||
if self.pid.poll() is not None:
|
||||
raise Exception('dnsmasq stopped running, exit code: %d, output: %s' % (self.pid.poll(), self.pid.stdout()))
|
||||
# TODO: Check logs/output for problems
|
||||
|
||||
|
||||
Reference in New Issue
Block a user