Merge pull request from dadav/fix/bt-tet-loaded-msg

More bt-tether fixes
This commit is contained in:
evilsocket 2019-11-05 10:48:19 +01:00 committed by GitHub
commit bdf585afe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -434,7 +434,7 @@ class BTTether(plugins.Plugin):
'max_tries', 'share_internet', 'mac', 'ip', 'max_tries', 'share_internet', 'mac', 'ip',
'netmask', 'interval']: 'netmask', 'interval']:
if device_opt not in options or (device_opt in options and options[device_opt] is None): if device_opt not in options or (device_opt in options and options[device_opt] is None):
logging.error("BT-TET: Pleace specify the %s for device %s.", logging.error("BT-TETHER: Please specify the %s for device %s.",
device_opt, device) device_opt, device)
break break
else: else:
@ -445,22 +445,23 @@ class BTTether(plugins.Plugin):
if 'mac' in self.options: if 'mac' in self.options:
for opt in ['share_internet', 'mac', 'ip', 'netmask', 'interval']: for opt in ['share_internet', 'mac', 'ip', 'netmask', 'interval']:
if opt not in self.options or (opt in self.options and self.options[opt] is None): if opt not in self.options or (opt in self.options and self.options[opt] is None):
logging.error("BT-TET: Please specify the %s in your config.yml.", opt) logging.error("BT-TETHER: Please specify the %s in your config.yml.", opt)
return return
self.devices['legacy'] = Device(name='legacy', **self.options) self.devices['legacy'] = Device(name='legacy', **self.options)
if not self.devices: if not self.devices:
logging.error("BT-TET: No valid devices found") logging.error("BT-TETHER: No valid devices found")
return return
# ensure bluetooth is running # ensure bluetooth is running
bt_unit = SystemdUnitWrapper('bluetooth.service') bt_unit = SystemdUnitWrapper('bluetooth.service')
if not bt_unit.is_active(): if not bt_unit.is_active():
if not bt_unit.start(): if not bt_unit.start():
logging.error("BT-TET: Can't start bluetooth.service") logging.error("BT-TETHER: Can't start bluetooth.service")
return return
logging.info("BT-TETHER: Sussessfully loaded ...")
self.ready = True self.ready = True
def on_ui_setup(self, ui): def on_ui_setup(self, ui):
@ -518,14 +519,21 @@ class BTTether(plugins.Plugin):
logging.debug('BT-TETHER: Try to create nap connection with %s ...', device.name) logging.debug('BT-TETHER: Try to create nap connection with %s ...', device.name)
device.network, success = BTNap.nap(dev_remote) device.network, success = BTNap.nap(dev_remote)
interface = None
if success: if success:
if device.interface() is None: try:
interface = device.interface()
except Exception:
logging.debug('BT-TETHER: Could not establish nap connection with %s', device.name)
continue
if interface is None:
ui.set('bluetooth', 'BE') ui.set('bluetooth', 'BE')
logging.debug('BT-TETHER: Could not establish nap connection with %s', device.name) logging.debug('BT-TETHER: Could not establish nap connection with %s', device.name)
continue continue
logging.debug('BT-TETHER: Created interface (%s)', device.interface()) logging.debug('BT-TETHER: Created interface (%s)', interface)
ui.set('bluetooth', 'C') ui.set('bluetooth', 'C')
any_device_connected = True any_device_connected = True
device.tries = 0 # reset tries device.tries = 0 # reset tries
@ -534,7 +542,6 @@ class BTTether(plugins.Plugin):
ui.set('bluetooth', 'NF') ui.set('bluetooth', 'NF')
continue continue
interface = device.interface()
addr = f"{device.ip}/{device.netmask}" addr = f"{device.ip}/{device.netmask}"
gateway = ".".join(device.ip.split('.')[:-1] + ['1']) gateway = ".".join(device.ip.split('.')[:-1] + ['1'])