From 5dbdf1e8ded95d1e1c3f76dffe8c1501f82e41d9 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 28 Dec 2024 15:32:22 +0100 Subject: [PATCH] Fix bt-tether to actually use IP set in config.toml Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/defaults.toml | 1 + pwnagotchi/plugins/default/bt-tether.py | 60 +++++++++---------------- 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml index 3e03f4d7..9fcd0fef 100644 --- a/pwnagotchi/defaults.toml +++ b/pwnagotchi/defaults.toml @@ -23,6 +23,7 @@ main.plugins.auto-update.install = false main.plugins.auto-update.interval = 1 main.plugins.bt-tether.enabled = false +main.plugins.bt-tether.phone-name = "" main.plugins.bt-tether.mac = "" main.plugins.bt-tether.phone = "" # android or ios main.plugins.bt-tether.ip = "" # 192.168.44.2 android / 172.20.10.2 ios diff --git a/pwnagotchi/plugins/default/bt-tether.py b/pwnagotchi/plugins/default/bt-tether.py index 7d5792a4..c0f6c378 100644 --- a/pwnagotchi/plugins/default/bt-tether.py +++ b/pwnagotchi/plugins/default/bt-tether.py @@ -7,7 +7,7 @@ from pwnagotchi.ui.view import BLACK class BTTether(plugins.Plugin): __author__ = 'Jayofelony' - __version__ = '1.0' + __version__ = '1.1' __license__ = 'GPL3' __description__ = 'A new BT-Tether plugin' @@ -19,45 +19,29 @@ class BTTether(plugins.Plugin): def on_loaded(self): logging.info("[BT-Tether] plugin loaded.") - def on_ready(self, agent): - ip = self.options['ip'] - if self.options['phone'].lower() == 'android': - address = f'{ip}/24,192.168.44.1' - route = '192.168.44.0/24,192.168.44.1' - elif self.options['phone'].lower() == 'ios': - address = f'{ip}/24,172.20.10.1' - route = '172.20.10.0/24,172.20.10.1' - file = f''' - [connection] - id=bluetooth - interface-name=bnep0 - type=bluetooth - autoconnect=yes - [bluetooth] - bdaddr={self.options['mac']} - type=panu - [ipv4] - address1={address} - route1={route} - dns=8.8.8.8;1.1.1.1; - method=manual - [ipv6] - addr-gen-mode=default - method=disabled - [proxy] - ''' + def on_config_changed(self, config): + ip = config['main']['plugins']['bt-tether']['ip'] + phone_name = config['main']['plugins']['bt-tether']['phone-name'] + ' Network' + if config['main']['plugins']['bt-tether']['phone'].lower() == 'android': + address = f'{ip}' + gateway = '192.168.44.1' + elif config['main']['plugins']['bt-tether']['phone'].lower() == 'ios': + address = f'{ip}' + gateway = '172.20.10.1' try: - file = '\n'.join(line.strip() for line in file.strip().splitlines() if line.strip()) - with open('/etc/NetworkManager/system-connections/bluetooth.nmconnection', 'w+') as bt_file: - bt_file.write(file) - subprocess.run(['chmod', '600', '/etc/NetworkManager/system-connections/bluetooth.nmconnection'], check=True) - try: - mac = self.options['mac'] - subprocess.run(['nmcli', 'device', 'connect', f'{mac}'], check=True) - except Exception as e: - logging.error(f"[BT-Tether] Failed to connect to device: {e}") + subprocess.run(['nmcli', 'connection', 'modify', f'{phone_name}', 'ipv4.addresses', f'{address}', 'ipv4.gateway',f'{gateway}'], check=True) + subprocess.run(['nmcli', 'connection', 'reload'], check=True) + subprocess.run(['systemctl', 'restart', 'NetworkManager'], check=True) except Exception as e: - logging.error(f"[BT-Tether] Failed to save Bluetooth connection file: {e}") + logging.error(f"[BT-Tether] Failed to connect to device: {e}") + self.ready = True + + def on_ready(self, agent): + try: + mac = self.options['mac'] + subprocess.run(['nmcli', 'device', 'connect', f'{mac}'], check=True) + except Exception as e: + logging.error(f"[BT-Tether] Failed to connect to device: {e}") self.ready = True def on_ui_setup(self, ui):