From fae58c8f24864d3dc651e45c83a37f21287644b1 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 8 Sep 2023 18:16:03 +0200 Subject: [PATCH] Version 2.3.4 Signed-off-by: Jeroen Oudshoorn Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/bettercap.py | 4 +++- pwnagotchi/mesh/peer.py | 3 --- pwnagotchi/mesh/utils.py | 7 +++++-- pwnagotchi/plugins/cmd.py | 2 +- pwnagotchi/ui/web/templates/profile.html | 4 ++-- pwnagotchi/utils.py | 21 +++++++++++++-------- requirements.txt | 1 + 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/pwnagotchi/bettercap.py b/pwnagotchi/bettercap.py index e2eef3dd..f7aedd52 100644 --- a/pwnagotchi/bettercap.py +++ b/pwnagotchi/bettercap.py @@ -1,7 +1,7 @@ -import json import logging import requests import websockets +import backoff from requests.auth import HTTPBasicAuth import asyncio # Add asyncio for async functionality @@ -39,6 +39,7 @@ class Client(object): r = requests.get("%s/%s" % (self.url, sess), auth=self.auth) return decode(r) + @backoff.on_exception(backoff.expo, requests.exceptions.ConnectionError, max_tries=10) async def start_websocket(self, consumer): s = "%s/events" % self.websocket while True: @@ -59,6 +60,7 @@ class Client(object): logging.exception("Other error while opening websocket (%s) with parameter %s", e, s) await asyncio.sleep(1) # Sleep for x seconds before reconnecting + @backoff.on_exception(backoff.expo, requests.exceptions.ConnectionError, max_tries=10) def run(self, command, verbose_errors=True): for _ in range(0, 2): try: diff --git a/pwnagotchi/mesh/peer.py b/pwnagotchi/mesh/peer.py index 6c1afee2..38f55641 100644 --- a/pwnagotchi/mesh/peer.py +++ b/pwnagotchi/mesh/peer.py @@ -85,8 +85,5 @@ class Peer(object): def epoch(self): return self.adv.get('epoch', 0) - def full_name(self): - return '%s@%s' % (self.name(), self.identity()) - def is_closer(self, other): return self.rssi > other.rssi diff --git a/pwnagotchi/mesh/utils.py b/pwnagotchi/mesh/utils.py index c46bae5d..e97fa969 100644 --- a/pwnagotchi/mesh/utils.py +++ b/pwnagotchi/mesh/utils.py @@ -1,4 +1,5 @@ -import _thread +# import _thread +from concurrent.futures import ThreadPoolExecutor import logging import time @@ -41,7 +42,9 @@ class AsyncAdvertiser(object): def start_advertising(self): if self._config['personality']['advertise']: - _thread.start_new_thread(self._adv_poller, ()) + # _thread.start_new_thread(self._adv_poller, ()) + with ThreadPoolExecutor(max_workers=4) as executor: + executor.submit(self._adv_poller) grid.set_advertisement_data(self._advertisement) grid.advertise(True) diff --git a/pwnagotchi/plugins/cmd.py b/pwnagotchi/plugins/cmd.py index cf76c0c7..c371b030 100644 --- a/pwnagotchi/plugins/cmd.py +++ b/pwnagotchi/plugins/cmd.py @@ -100,7 +100,7 @@ def edit(args, config): Edit the config of the plugin """ plugin = args.name - editor = os.environ.get('EDITOR', 'vim') # because vim is the best + editor = os.environ.get('EDITOR', 'vim') # because vim is the best if plugin not in config['main']['plugins']: return 1 diff --git a/pwnagotchi/ui/web/templates/profile.html b/pwnagotchi/ui/web/templates/profile.html index b02eb33e..60cfb7ad 100644 --- a/pwnagotchi/ui/web/templates/profile.html +++ b/pwnagotchi/ui/web/templates/profile.html @@ -8,7 +8,7 @@ Profile {% block script %} $(function(){ $('#qrcode').qrcode({ - text: 'https://pwnagotchi.ai/pwnfile/#{{ fingerprint }}', + text: 'https://opwngrid.xyz/search/{{ fingerprint }}', render: 'div', mode: 0, size: 400, @@ -25,7 +25,7 @@ $(function(){

- {{ fingerprint }} + {{ fingerprint }}

diff --git a/pwnagotchi/utils.py b/pwnagotchi/utils.py index d03e5796..19084572 100644 --- a/pwnagotchi/utils.py +++ b/pwnagotchi/utils.py @@ -60,7 +60,7 @@ class DottedTomlEncoder(TomlEncoder): else: retstr += (pre + qsection + " = " + str(self.dump_value(value)) + '\n') - return (retstr, self._dict()) + return retstr, self._dict() def parse_version(version): @@ -75,6 +75,7 @@ def remove_whitelisted(list_of_handshakes, list_of_whitelisted_strings, valid_on Removes a given list of whitelisted handshakes from a path list """ filtered = list() + def normalize(name): """ Only allow alpha/nums @@ -96,7 +97,6 @@ def remove_whitelisted(list_of_handshakes, list_of_whitelisted_strings, valid_on return filtered - def download_file(url, destination, chunk_size=128): import requests resp = requests.get(url) @@ -106,6 +106,7 @@ def download_file(url, destination, chunk_size=128): for chunk in resp.iter_content(chunk_size): fd.write(chunk) + def unzip(file, destination, strip_dirs=0): os.makedirs(destination, exist_ok=True) with ZipFile(file, 'r') as zip: @@ -129,6 +130,7 @@ def merge_config(user, default): user[k] = merge_config(user[k], v) return user + def keys_to_str(data): if isinstance(data,list): converted_list = list() @@ -148,11 +150,13 @@ def keys_to_str(data): return converted_dict + def save_config(config, target): with open(target, 'wt') as fp: fp.write(toml.dumps(config, encoder=DottedTomlEncoder())) return True + def load_config(args): default_config_path = os.path.dirname(args.config) if not os.path.exists(default_config_path): @@ -232,14 +236,14 @@ def load_config(args): additional_config = toml.load(toml_file) config = merge_config(additional_config, config) - # the very first step is to normalize the display name so we don't need dozens of if/elif around + # the very first step is to normalize the display name, so we don't need dozens of if/elif around if config['ui']['display']['type'] in ('inky', 'inkyphat'): config['ui']['display']['type'] = 'inky' elif config['ui']['display']['type'] in ('papirus', 'papi'): config['ui']['display']['type'] = 'papirus' - elif config['ui']['display']['type'] in ('oledhat',): + elif config['ui']['display']['type'] in 'oledhat': config['ui']['display']['type'] = 'oledhat' elif config['ui']['display']['type'] in ('ws_1', 'ws1', 'waveshare_1', 'waveshare1'): @@ -257,7 +261,7 @@ def load_config(args): elif config['ui']['display']['type'] in ('ws_29inch', 'ws29inch', 'waveshare_29inch', 'waveshare29inch'): config['ui']['display']['type'] = 'waveshare29inch' - elif config['ui']['display']['type'] in ('lcdhat',): + elif config['ui']['display']['type'] in 'lcdhat': config['ui']['display']['type'] = 'lcdhat' elif config['ui']['display']['type'] in ('dfrobot_1', 'df1'): @@ -281,13 +285,13 @@ def load_config(args): elif config['ui']['display']['type'] in ('ws_213bv4', 'ws213bv4', 'waveshare_213bv4', 'waveshare213inb_v4'): config['ui']['display']['type'] = 'waveshare213inb_v4' - elif config['ui']['display']['type'] in ('spotpear24inch'): + elif config['ui']['display']['type'] in 'spotpear24inch': config['ui']['display']['type'] = 'spotpear24inch' - elif config['ui']['display']['type'] in ('displayhatmini'): + elif config['ui']['display']['type'] in 'displayhatmini': config['ui']['display']['type'] = 'displayhatmini' - elif config['ui']['display']['type'] in ('waveshare35lcd'): + elif config['ui']['display']['type'] in 'waveshare35lcd': config['ui']['display']['type'] = 'waveshare35lcd' else: @@ -441,6 +445,7 @@ def extract_from_pcap(path, fields): return results + class StatusFile(object): def __init__(self, path, data_format='raw'): self._path = path diff --git a/requirements.txt b/requirements.txt index decdc195..cce7d0ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,3 +22,4 @@ torch torchvision stable_baselines3 RPi.GPIO +backoff