diff --git a/pwnagotchi/__init__.py b/pwnagotchi/__init__.py index d84d2713e..c871ae9d1 100644 --- a/pwnagotchi/__init__.py +++ b/pwnagotchi/__init__.py @@ -4,7 +4,6 @@ import re - from pwnagotchi._version import __version__ _name = None diff --git a/pwnagotchi/_version.py b/pwnagotchi/_version.py index 85a7344db..c284ab79e 100644 --- a/pwnagotchi/_version.py +++ b/pwnagotchi/_version.py @@ -1 +1 @@ -__version__ = '2.3.5' +__version__ = '2.3.6' diff --git a/pwnagotchi/agent.py b/pwnagotchi/agent.py index 75bb9f056..d37005027 100644 --- a/pwnagotchi/agent.py +++ b/pwnagotchi/agent.py @@ -394,7 +394,6 @@ def start_event_polling(self): # start a thread and pass in the mainloop _thread.start_new_thread(self._event_poller, (asyncio.get_event_loop(),)) - def is_module_running(self, module): s = self.session() for m in s['modules']: diff --git a/pwnagotchi/bettercap.py b/pwnagotchi/bettercap.py index f7aedd527..6d7a802f3 100644 --- a/pwnagotchi/bettercap.py +++ b/pwnagotchi/bettercap.py @@ -23,7 +23,8 @@ def decode(r, verbose_errors=True): class Client(object): - def __init__(self, hostname='localhost', scheme='http', port=8081, username='user', password='pass'): + def __init__(self, hostname='localhost', scheme='http', port=8081, username='user', password='pass', + max_websockets=5): self.hostname = hostname self.scheme = scheme self.port = port @@ -32,6 +33,8 @@ def __init__(self, hostname='localhost', scheme='http', port=8081, username='use self.url = "%s://%s:%d/api" % (scheme, hostname, port) self.websocket = "ws://%s:%s@%s:%d/api" % (username, password, hostname, port) self.auth = HTTPBasicAuth(username, password) + self.max_websockets = max_websockets + self.websocket_semaphore = asyncio.Semaphore(max_websockets) # session takes optional argument to pull a sub-dictionary # ex.: "session/wifi", "session/ble" @@ -41,24 +44,25 @@ def session(self, sess="session"): @backoff.on_exception(backoff.expo, requests.exceptions.ConnectionError, max_tries=10) async def start_websocket(self, consumer): - s = "%s/events" % self.websocket - while True: - try: - async with websockets.connect(s, ping_interval=60, ping_timeout=90) as ws: - async for msg in ws: - try: - await consumer(msg) - except Exception as ex: - logging.debug("Error while parsing event (%s)", ex) - except websockets.exceptions.ConnectionClosedError: - logging.debug("Lost websocket connection. Reconnecting...") - await asyncio.sleep(1) # Sleep for x seconds before reconnecting - except websockets.exceptions.WebSocketException as wex: - logging.debug("Websocket exception (%s)", wex) - await asyncio.sleep(1) # Sleep for x seconds before reconnecting - except Exception as e: - logging.exception("Other error while opening websocket (%s) with parameter %s", e, s) - await asyncio.sleep(1) # Sleep for x seconds before reconnecting + async with self.websocket_semaphore: + s = "%s/events" % self.websocket + while True: + try: + async with websockets.connect(s, ping_interval=60, ping_timeout=90) as ws: + async for msg in ws: + try: + await consumer(msg) + except Exception as ex: + logging.debug("Error while parsing event (%s)", ex) + except websockets.ConnectionClosedError: + logging.debug("Lost websocket connection. Reconnecting...") + await asyncio.sleep(5) # Sleep for x seconds before reconnecting + except websockets.WebSocketException as wex: + logging.debug("Websocket exception (%s)", wex) + await asyncio.sleep(5) # Sleep for x seconds before reconnecting + except Exception as e: + logging.exception("Other error while opening websocket (%s) with parameter %s", e, s) + await asyncio.sleep(5) # Sleep for x seconds before reconnecting @backoff.on_exception(backoff.expo, requests.exceptions.ConnectionError, max_tries=10) def run(self, command, verbose_errors=True): diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml index d6bd8f513..5baead7ac 100644 --- a/pwnagotchi/defaults.toml +++ b/pwnagotchi/defaults.toml @@ -40,8 +40,8 @@ main.plugins.pisugar2.enabled = false main.plugins.pisugar2.shutdown = 5 main.plugins.pisugar2.sync_rtc_on_boot = false -main.plugins.grid.enabled = false -main.plugins.grid.report = false +main.plugins.grid.enabled = true +main.plugins.grid.report = true main.plugins.grid.exclude = [ "YourHomeNetworkHere" ] diff --git a/pwnagotchi/grid.py b/pwnagotchi/grid.py index b4abe77a6..78edb8048 100644 --- a/pwnagotchi/grid.py +++ b/pwnagotchi/grid.py @@ -1,5 +1,4 @@ import subprocess -import socket import requests import json import logging @@ -84,7 +83,8 @@ def update_data(last_session): }, 'uname': subprocess.getoutput("uname -a"), 'brain': brain, - 'version': pwnagotchi.__version__ + 'version': pwnagotchi.__version__, + 'build': "Pwnagotchi-Torch by Jayofelony" } logging.debug("updating grid data: %s" % data)