mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Fix bt-tether to actually use IP set in config.toml
Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
@ -23,6 +23,7 @@ main.plugins.auto-update.install = false
|
|||||||
main.plugins.auto-update.interval = 1
|
main.plugins.auto-update.interval = 1
|
||||||
|
|
||||||
main.plugins.bt-tether.enabled = false
|
main.plugins.bt-tether.enabled = false
|
||||||
|
main.plugins.bt-tether.phone-name = ""
|
||||||
main.plugins.bt-tether.mac = ""
|
main.plugins.bt-tether.mac = ""
|
||||||
main.plugins.bt-tether.phone = "" # android or ios
|
main.plugins.bt-tether.phone = "" # android or ios
|
||||||
main.plugins.bt-tether.ip = "" # 192.168.44.2 android / 172.20.10.2 ios
|
main.plugins.bt-tether.ip = "" # 192.168.44.2 android / 172.20.10.2 ios
|
||||||
|
@ -7,7 +7,7 @@ from pwnagotchi.ui.view import BLACK
|
|||||||
|
|
||||||
class BTTether(plugins.Plugin):
|
class BTTether(plugins.Plugin):
|
||||||
__author__ = 'Jayofelony'
|
__author__ = 'Jayofelony'
|
||||||
__version__ = '1.0'
|
__version__ = '1.1'
|
||||||
__license__ = 'GPL3'
|
__license__ = 'GPL3'
|
||||||
__description__ = 'A new BT-Tether plugin'
|
__description__ = 'A new BT-Tether plugin'
|
||||||
|
|
||||||
@ -19,45 +19,29 @@ class BTTether(plugins.Plugin):
|
|||||||
def on_loaded(self):
|
def on_loaded(self):
|
||||||
logging.info("[BT-Tether] plugin loaded.")
|
logging.info("[BT-Tether] plugin loaded.")
|
||||||
|
|
||||||
def on_ready(self, agent):
|
def on_config_changed(self, config):
|
||||||
ip = self.options['ip']
|
ip = config['main']['plugins']['bt-tether']['ip']
|
||||||
if self.options['phone'].lower() == 'android':
|
phone_name = config['main']['plugins']['bt-tether']['phone-name'] + ' Network'
|
||||||
address = f'{ip}/24,192.168.44.1'
|
if config['main']['plugins']['bt-tether']['phone'].lower() == 'android':
|
||||||
route = '192.168.44.0/24,192.168.44.1'
|
address = f'{ip}'
|
||||||
elif self.options['phone'].lower() == 'ios':
|
gateway = '192.168.44.1'
|
||||||
address = f'{ip}/24,172.20.10.1'
|
elif config['main']['plugins']['bt-tether']['phone'].lower() == 'ios':
|
||||||
route = '172.20.10.0/24,172.20.10.1'
|
address = f'{ip}'
|
||||||
file = f'''
|
gateway = '172.20.10.1'
|
||||||
[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]
|
|
||||||
'''
|
|
||||||
try:
|
try:
|
||||||
file = '\n'.join(line.strip() for line in file.strip().splitlines() if line.strip())
|
subprocess.run(['nmcli', 'connection', 'modify', f'{phone_name}', 'ipv4.addresses', f'{address}', 'ipv4.gateway',f'{gateway}'], check=True)
|
||||||
with open('/etc/NetworkManager/system-connections/bluetooth.nmconnection', 'w+') as bt_file:
|
subprocess.run(['nmcli', 'connection', 'reload'], check=True)
|
||||||
bt_file.write(file)
|
subprocess.run(['systemctl', 'restart', 'NetworkManager'], check=True)
|
||||||
subprocess.run(['chmod', '600', '/etc/NetworkManager/system-connections/bluetooth.nmconnection'], check=True)
|
except Exception as e:
|
||||||
|
logging.error(f"[BT-Tether] Failed to connect to device: {e}")
|
||||||
|
self.ready = True
|
||||||
|
|
||||||
|
def on_ready(self, agent):
|
||||||
try:
|
try:
|
||||||
mac = self.options['mac']
|
mac = self.options['mac']
|
||||||
subprocess.run(['nmcli', 'device', 'connect', f'{mac}'], check=True)
|
subprocess.run(['nmcli', 'device', 'connect', f'{mac}'], check=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"[BT-Tether] Failed to connect to device: {e}")
|
logging.error(f"[BT-Tether] Failed to connect to device: {e}")
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"[BT-Tether] Failed to save Bluetooth connection file: {e}")
|
|
||||||
self.ready = True
|
self.ready = True
|
||||||
|
|
||||||
def on_ui_setup(self, ui):
|
def on_ui_setup(self, ui):
|
||||||
|
Reference in New Issue
Block a user