diff --git a/pwnagotchi/_version.py b/pwnagotchi/_version.py index 24da7c50..c15f8ed3 100644 --- a/pwnagotchi/_version.py +++ b/pwnagotchi/_version.py @@ -1 +1 @@ -__version__ = '2.3.9b' +__version__ = '2.4.x' diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml index 5baead7a..1aed4564 100644 --- a/pwnagotchi/defaults.toml +++ b/pwnagotchi/defaults.toml @@ -1,4 +1,4 @@ -main.name = "" +main.name = "pwnagotchi" main.lang = "en" main.confd = "/etc/pwnagotchi/conf.d/" main.custom_plugin_repos = [ diff --git a/pwnagotchi/plugins/default/bluetoothsniffer.py b/pwnagotchi/plugins/default/bluetoothsniffer.py index dedb3d87..3657f063 100644 --- a/pwnagotchi/plugins/default/bluetoothsniffer.py +++ b/pwnagotchi/plugins/default/bluetoothsniffer.py @@ -60,14 +60,13 @@ class BluetoothSniffer(plugins.Plugin): ui.remove_element('BtS') def on_ui_update(self, ui): - with ui._lock: - current_time = time.time() - # Checking the time elapsed since last scan - if current_time - self.last_scan_time >= self.options['timer']: - self.last_scan_time = current_time - # logging.info("[BtS] Bluetooth sniffed: %s", str(self.bt_sniff_info())) - ui.set('BtS', str(self.bt_sniff_info())) - self.scan(ui) + current_time = time.time() + # Checking the time elapsed since last scan + if current_time - self.last_scan_time >= self.options['timer']: + self.last_scan_time = current_time + # logging.info("[BtS] Bluetooth sniffed: %s", str(self.bt_sniff_info())) + ui.set('BtS', str(self.bt_sniff_info())) + self.scan(ui) # Method for scanning the nearby bluetooth devices def scan(self, display): diff --git a/pwnagotchi/plugins/default/bt-tether.py b/pwnagotchi/plugins/default/bt-tether.py index dd0008a0..a65c603b 100644 --- a/pwnagotchi/plugins/default/bt-tether.py +++ b/pwnagotchi/plugins/default/bt-tether.py @@ -583,5 +583,4 @@ class BTTether(plugins.Plugin): label_font=fonts.Bold, text_font=fonts.Medium)) def on_ui_update(self, ui): - with ui._lock: - ui.set('bluetooth', self.status) + ui.set('bluetooth', self.status) diff --git a/pwnagotchi/plugins/default/fix_services.py b/pwnagotchi/plugins/default/fix_services.py index 0fc99f42..5266aa28 100644 --- a/pwnagotchi/plugins/default/fix_services.py +++ b/pwnagotchi/plugins/default/fix_services.py @@ -17,8 +17,8 @@ import pwnagotchi.ui.fonts as fonts class FixServices(plugins.Plugin): - __author__ = 'xBits' - __version__ = '0.1.1' + __author__ = 'jayofelony' + __version__ = '1.0' __license__ = 'GPL3' __description__ = 'Fix blindness, firmware crashes and brain not being loaded' __name__ = 'Fix_Services' @@ -38,6 +38,7 @@ class FixServices(plugins.Plugin): self.pattern2 = re.compile(r'wifi error while hopping to channel') self.pattern3 = re.compile(r'Firmware has halted or crashed') self.pattern4 = re.compile(r'error 400: could not find interface wlan0mon') + self.pattern5 = re.compile(r'connection to the bettercap endpoint failed') self.isReloadingMon = False self.connection = None self.LASTTRY = 0 @@ -98,7 +99,8 @@ class FixServices(plugins.Plugin): logging.info("[Fix_Services] wifi.recon flip: success!") if hasattr(agent, 'view'): display = agent.view() - if display: display.update(force=True, new_data={"status": "Wifi recon flipped!", + if display: + display.update(force=True, new_data={"status": "Wifi recon flipped!", "face": faces.COOL}) else: print("Wifi recon flipped") @@ -189,6 +191,20 @@ class FixServices(plugins.Plugin): except Exception as err: logging.error("[Fix_Services monstart]: %s" % repr(err)) + # Look for pattern 5 + elif len(self.pattern5.findall(other_other_last_lines)) >= 3: + logging.info("[Fix_Services] bettercap is down!") + if hasattr(agent, 'view'): + display = agent.view() + display.set('status', 'Restarting wlan0 now!') + display.update(force=True) + try: + # Restart bettercap/pwnagotchi + logging.info("[Fix_Services restarting]") + pwnagotchi.restart("AUTO") + except Exception as err: + logging.error("[Fix_Services restarting]: %s" % repr(err)) + else: print("logs look good") @@ -224,7 +240,8 @@ class FixServices(plugins.Plugin): self._status = "BL" if hasattr(connection, 'view'): display = connection.view() - if display: display.update(force=True, new_data={"status": "I'm blind! Try turning it off and on again", + if display: + display.update(force=True, new_data={"status": "I'm blind! Try turning it off and on again", "brcmfmac_status": self._status, "face": faces.BORED}) else: @@ -312,7 +329,7 @@ class FixServices(plugins.Plugin): # try accessing mon0 in bettercap result = connection.run("set wifi.interface wlan0mon") if "success" in result: - logging.info("[Fix_Services set wifi.interface wlan0mon] worked: %s" % repr(result)) + logging.info("[Fix_Services set wifi.interface wlan0mon] worked!") self._status = "" self._count = self._count + 1 time.sleep(1) @@ -325,21 +342,25 @@ class FixServices(plugins.Plugin): logging.info( "[Fix_Services set wifi.interface wlan0mon] except: %s" % repr(err)) except Exception as cerr: # - if not display: print("failed loading wlan0mon attempt #%s: %s" % (tries, repr(cerr))) + if not display: + print("failed loading wlan0mon attempt #%s: %s" % (tries, repr(cerr))) except Exception as err: # from modprobe - if not display: print("Failed reloading brcmfmac") + if not display: + print("Failed reloading brcmfmac") logging.error("[Fix_Services] Failed reloading brcmfmac %s" % repr(err)) except Exception as nope: # from modprobe -r # fails if already unloaded, so probably fine logging.error("[Fix_Services #%s modprobe -r] %s" % (tries, repr(nope))) - if not display: print("[Fix_Services #%s modprobe -r] %s" % (tries, repr(nope))) + if not display: + print("[Fix_Services #%s modprobe -r] %s" % (tries, repr(nope))) pass tries = tries + 1 if tries < 3: logging.info("[Fix_Services] wlan0mon didn't make it. trying again") - if not display: print(" wlan0mon didn't make it. trying again") + if not display: + print(" wlan0mon didn't make it. trying again") # exited the loop, so hopefully it loaded if tries < 3: @@ -363,15 +384,15 @@ class FixServices(plugins.Plugin): if "success" in result: # and result["success"] is True: self._status = "" if display: - display.update(force=True, new_data={"status": "I can see again! (probably): %s" % repr(result), + display.update(force=True, new_data={"status": "I can see again! (probably)", "brcmfmac_status": self._status, "face": faces.HAPPY}) else: print("I can see again") - logging.info("[Fix_Services] wifi.recon on %s" % repr(result)) + logging.info("[Fix_Services] wifi.recon on") self.LASTTRY = time.time() + 120 # 2-minute pause until next time. else: - logging.error("[Fix_Services] wifi.recon did not start up: %s" % repr(result)) + logging.error("[Fix_Services] wifi.recon did not start up") self.LASTTRY = time.time() - 300 # failed, so try again ASAP self.isReloadingMon = False @@ -393,12 +414,11 @@ class FixServices(plugins.Plugin): # called when the ui is updated def on_ui_update(self, ui): - with ui._lock: - # update those elements - if self._status: - ui.set('brcmfmac_status', "wlan0mon %s" % self._status) - else: - ui.set('brcmfmac_status', "rst#%s" % self._count) + # update those elements + if self._status: + ui.set('brcmfmac_status', "wlan0mon %s" % self._status) + else: + ui.set('brcmfmac_status', "rst#%s" % self._count) def on_unload(self, ui): with ui._lock: diff --git a/pwnagotchi/plugins/default/memtemp.py b/pwnagotchi/plugins/default/memtemp.py index e3cf3ac8..aab7210f 100644 --- a/pwnagotchi/plugins/default/memtemp.py +++ b/pwnagotchi/plugins/default/memtemp.py @@ -103,91 +103,90 @@ class MemTemp(plugins.Plugin): return " " * (self.FIELD_WIDTH - len(data)) + data def on_ui_setup(self, ui): - with ui._lock: - try: - # Configure field list - self.fields = self.options['fields'].split(',') - self.fields = [x.strip() for x in self.fields if x.strip() in self.ALLOWED_FIELDS.keys()] - self.fields = self.fields[:3] # limit to the first 3 fields - except Exception: - # Set default value - self.fields = self.DEFAULT_FIELDS + try: + # Configure field list + self.fields = self.options['fields'].split(',') + self.fields = [x.strip() for x in self.fields if x.strip() in self.ALLOWED_FIELDS.keys()] + self.fields = self.fields[:3] # limit to the first 3 fields + except Exception: + # Set default value + self.fields = self.DEFAULT_FIELDS - try: - # Configure line_spacing - line_spacing = int(self.options['linespacing']) - except Exception: - # Set default value - line_spacing = self.LINE_SPACING - - try: - # Configure position - pos = self.options['position'].split(',') - pos = [int(x.strip()) for x in pos] - if self.options['orientation'] == "vertical": - v_pos = (pos[0], pos[1]) - else: - h_pos = (pos[0], pos[1]) - except Exception: - # Set default position based on screen type - if ui.is_waveshare_v2(): - h_pos = (178, 84) - v_pos = (197, 74) - elif ui.is_waveshare_v1(): - h_pos = (170, 80) - v_pos = (165, 61) - elif ui.is_waveshare144lcd(): - h_pos = (53, 77) - v_pos = (73, 67) - elif ui.is_inky(): - h_pos = (140, 68) - v_pos = (160, 54) - elif ui.is_waveshare27inch(): - h_pos = (192, 138) - v_pos = (211, 122) - else: - h_pos = (155, 76) - v_pos = (175, 61) + try: + # Configure line_spacing + line_spacing = int(self.options['linespacing']) + except Exception: + # Set default value + line_spacing = self.LINE_SPACING + try: + # Configure position + pos = self.options['position'].split(',') + pos = [int(x.strip()) for x in pos] if self.options['orientation'] == "vertical": - # Dynamically create the required LabeledValue objects - for idx, field in enumerate(self.fields): - v_pos_x = v_pos[0] - v_pos_y = v_pos[1] + ((len(self.fields) - 3) * -1 * line_spacing) - ui.add_element( - f"memtemp_{field}", - LabeledValue( - color=BLACK, - label=f"{self.pad_text(field)}:", - value="-", - position=(v_pos_x, v_pos_y + (idx * line_spacing)), - label_font=fonts.Small, - text_font=fonts.Small, - label_spacing=self.LABEL_SPACING, - ) - ) + v_pos = (pos[0], pos[1]) else: - # default to horizontal - h_pos_x = h_pos[0] + ((len(self.fields) - 3) * -1 * 25) - h_pos_y = h_pos[1] + h_pos = (pos[0], pos[1]) + except Exception: + # Set default position based on screen type + if ui.is_waveshare_v2(): + h_pos = (178, 84) + v_pos = (197, 74) + elif ui.is_waveshare_v1(): + h_pos = (170, 80) + v_pos = (165, 61) + elif ui.is_waveshare144lcd(): + h_pos = (53, 77) + v_pos = (73, 67) + elif ui.is_inky(): + h_pos = (140, 68) + v_pos = (160, 54) + elif ui.is_waveshare27inch(): + h_pos = (192, 138) + v_pos = (211, 122) + else: + h_pos = (155, 76) + v_pos = (175, 61) + + if self.options['orientation'] == "vertical": + # Dynamically create the required LabeledValue objects + for idx, field in enumerate(self.fields): + v_pos_x = v_pos[0] + v_pos_y = v_pos[1] + ((len(self.fields) - 3) * -1 * line_spacing) ui.add_element( - 'memtemp_header', - Text( + f"memtemp_{field}", + LabeledValue( color=BLACK, - value=" ".join([self.pad_text(x) for x in self.fields]), - position=(h_pos_x, h_pos_y), - font=fonts.Small, + label=f"{self.pad_text(field)}:", + value="-", + position=(v_pos_x, v_pos_y + (idx * line_spacing)), + label_font=fonts.Small, + text_font=fonts.Small, + label_spacing=self.LABEL_SPACING, ) ) - ui.add_element( - 'memtemp_data', - Text( - color=BLACK, - value=" ".join([self.pad_text("-") for x in self.fields]), - position=(h_pos_x, h_pos_y + line_spacing), - font=fonts.Small, - ) + else: + # default to horizontal + h_pos_x = h_pos[0] + ((len(self.fields) - 3) * -1 * 25) + h_pos_y = h_pos[1] + ui.add_element( + 'memtemp_header', + Text( + color=BLACK, + value=" ".join([self.pad_text(x) for x in self.fields]), + position=(h_pos_x, h_pos_y), + font=fonts.Small, ) + ) + ui.add_element( + 'memtemp_data', + Text( + color=BLACK, + value=" ".join([self.pad_text("-") for x in self.fields]), + position=(h_pos_x, h_pos_y + line_spacing), + font=fonts.Small, + ) + ) def on_unload(self, ui): with ui._lock: