From ddf64cb0b3ef46312d8682903fbfc95cc052948b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 21 Sep 2023 12:13:41 +0200 Subject: [PATCH] multiple edits Signed-off-by: Jeroen Oudshoorn --- builder/data/etc/dphys-swapfile | 26 ++++++++++++++++ pwnagotchi/_version.py | 2 +- pwnagotchi/bettercap.py | 5 ++-- pwnagotchi/log.py | 8 ++--- pwnagotchi/plugins/__init__.py | 10 +++---- pwnagotchi/plugins/default/bt-tether.py | 4 +-- .../plugins/default/internet-connection.py | 30 ++++++++++++------- pwnagotchi/utils.py | 3 +- 8 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 builder/data/etc/dphys-swapfile diff --git a/builder/data/etc/dphys-swapfile b/builder/data/etc/dphys-swapfile new file mode 100644 index 00000000..1c908a10 --- /dev/null +++ b/builder/data/etc/dphys-swapfile @@ -0,0 +1,26 @@ +# /etc/dphys-swapfile - user settings for dphys-swapfile package +# author Neil Franklin, last modification 2010.05.05 +# copyright ETH Zuerich Physics Departement +# use under either modified/non-advertising BSD or GPL license + +# this file is sourced with . so full normal sh syntax applies + +# the default settings are added as commented out CONF_*=* lines + + +# where we want the swapfile to be, this is the default +#CONF_SWAPFILE=/var/swap + +# set size to absolute value, leaving empty (default) then uses computed value +# you most likely don't want this, unless you have an special disk situation +CONF_SWAPSIZE=2048 + +# set size to computed value, this times RAM size, dynamically adapts, +# guarantees that there is enough swap without wasting disk space on excess +#CONF_SWAPFACTOR=2 + +# restrict size (computed and absolute!) to maximally this limit +# can be set to empty for no limit, but beware of filled partitions! +# this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it +# but is also sensible on 64bit to prevent filling /var or even / partition +#CONF_MAXSWAP=2048 \ No newline at end of file diff --git a/pwnagotchi/_version.py b/pwnagotchi/_version.py index cb9dc8a9..9a0e3da6 100644 --- a/pwnagotchi/_version.py +++ b/pwnagotchi/_version.py @@ -1 +1 @@ -__version__ = '2.4.2' +__version__ = '2.4.3' diff --git a/pwnagotchi/bettercap.py b/pwnagotchi/bettercap.py index 243e00a6..acb4e673 100644 --- a/pwnagotchi/bettercap.py +++ b/pwnagotchi/bettercap.py @@ -70,7 +70,8 @@ class Client(object): while True: logging.info("[bettercap] creating new websocket...") try: - async with websockets.connect(s, ping_interval=ping_interval, ping_timeout=ping_timeout, max_queue=max_queue) as ws: + async with websockets.connect(s, ping_interval=ping_interval, ping_timeout=ping_timeout, + max_queue=max_queue) as ws: # listener loop while True: try: @@ -78,7 +79,7 @@ class Client(object): try: await consumer(msg) except Exception as ex: - logging.debug("error while parsing event (%s)", ex) + logging.debug("error while parsing event (%s)", ex) except websockets.ConnectionClosedError: try: pong = await ws.ping() diff --git a/pwnagotchi/log.py b/pwnagotchi/log.py index 00cc13b8..5cf120e9 100644 --- a/pwnagotchi/log.py +++ b/pwnagotchi/log.py @@ -17,8 +17,8 @@ LAST_SESSION_FILE = '/root/.pwnagotchi-last-session' class LastSession(object): EPOCH_TOKEN = '[epoch ' - EPOCH_PARSER = re.compile(r'^.+\[epoch (\d+)\] (.+)') - EPOCH_DATA_PARSER = re.compile(r'([a-z_]+)=([^\s]+)') + EPOCH_PARSER = re.compile(r'^.+\[epoch (\d+)] (.+)') + EPOCH_DATA_PARSER = re.compile(r'([a-z_]+)=(\S+)') TRAINING_TOKEN = ' training epoch ' START_TOKEN = 'connecting to http' DEAUTH_TOKEN = 'deauthing ' @@ -46,7 +46,7 @@ class LastSession(object): self.max_reward = -1000 self.avg_reward = 0 self._peer_parser = re.compile( - 'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)\]') + 'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)]') self.parsed = False def _get_last_saved_session_id(self): @@ -197,7 +197,7 @@ class LastSession(object): lines.reverse() if len(lines) == 0: - lines.append("Initial Session"); + lines.append("Initial Session") ui.on_reading_logs() diff --git a/pwnagotchi/plugins/__init__.py b/pwnagotchi/plugins/__init__.py index 57e86976..f161b9dd 100644 --- a/pwnagotchi/plugins/__init__.py +++ b/pwnagotchi/plugins/__init__.py @@ -1,10 +1,10 @@ -import os -import glob import _thread -import threading -import importlib, importlib.util +import glob +import importlib +import importlib.util import logging - +import os +import threading default_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "default") loaded = {} diff --git a/pwnagotchi/plugins/default/bt-tether.py b/pwnagotchi/plugins/default/bt-tether.py index fa7c867f..547c6473 100644 --- a/pwnagotchi/plugins/default/bt-tether.py +++ b/pwnagotchi/plugins/default/bt-tether.py @@ -473,7 +473,7 @@ class BTTether(plugins.Plugin): devices_to_try = list() connected_priorities = list() - any_device_connected = False # if this is true, last status on screen should be C + any_device_connected = False # if this is true, last status on screen should be C for _, device in self.devices.items(): if device.connected(): @@ -579,7 +579,7 @@ class BTTether(plugins.Plugin): def on_ui_setup(self, ui): with ui._lock: ui.add_element('bluetooth', LabeledValue(color=BLACK, label='BT', value='-', - position=(ui.width() / 2 - 10, 0), + position=(ui.width() / 2 - 5, 0), label_font=fonts.Bold, text_font=fonts.Medium)) def on_ui_update(self, ui): diff --git a/pwnagotchi/plugins/default/internet-connection.py b/pwnagotchi/plugins/default/internet-connection.py index 2678d27f..4f23957a 100644 --- a/pwnagotchi/plugins/default/internet-connection.py +++ b/pwnagotchi/plugins/default/internet-connection.py @@ -3,14 +3,13 @@ import pwnagotchi.ui.components as components import pwnagotchi.ui.view as view import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins -import pwnagotchi -import subprocess import socket +import os class InternetConnectionPlugin(plugins.Plugin): __author__ = 'adi1708, edited by jayofelony' - __version__ = '1.1' + __version__ = '1.2' __license__ = 'GPL3' __description__ = 'A plugin that displays the Internet connection status on the pwnagotchi display.' __name__ = 'InternetConnectionPlugin' @@ -21,35 +20,44 @@ class InternetConnectionPlugin(plugins.Plugin): 'pip': ['scapy'] } __defaults__ = { - 'enabled': False, + 'enabled': True, } def on_loaded(self): logging.info("[Internet-Connection] plugin loaded.") def on_ui_setup(self, ui): + if ui.is_waveshare35lcd(): + v_pos = (180, 61) + with ui._lock: + ui.add_element('connection_ip', components.LabeledValue(color=view.BLACK, label='eth0:', value='', + position=v_pos, label_font=fonts.Bold, + text_font=fonts.Small)) with ui._lock: # add a LabeledValue element to the UI with the given label and value # the position and font can also be specified ui.add_element('connection_status', components.LabeledValue(color=view.BLACK, label='WWW', value='-', - position=(ui.width() / 2 - 40, 0), + position=(ui.width() / 2 - 35, 0), label_font=fonts.Bold, text_font=fonts.Medium)) def on_ui_update(self, ui): + if ui.is_wavehare35lcd(): + ip = os.popen('ifconfig eth0 | grep inet | awk \'{print $2}\'').read() + ui.set('connection_ip', ip) # check if there is an active Internet connection try: - # See if we can resolve the host name - tells us if there is - # A DNS listening - host = socket.gethostbyname("1.1.1.1") # Connect to the host - tells us if the host is actually reachable - s = socket.create_connection((host, 80), 2) - s.close() + socket.create_connection(("1.1.1.1", 80), 2).close() ui.set('connection_status', 'C') - except: + except TimeoutError as err: # if the command failed, it means there is no active Internet connection + # we could log the error, but no need really + # logging.error('[Internet-Connection] Socket creation failed: %s' % err) ui.set('connection_status', 'D') def on_unload(self, ui): with ui._lock: logging.info("[Internet-Connection] plugin unloaded") ui.remove_element('connection_status') + if ui.is_waveshare35lcd(): + ui.remove_element('connection_ip') diff --git a/pwnagotchi/utils.py b/pwnagotchi/utils.py index 19084572..f8f38677 100644 --- a/pwnagotchi/utils.py +++ b/pwnagotchi/utils.py @@ -58,8 +58,7 @@ class DottedTomlEncoder(TomlEncoder): if not retstr.endswith('\n\n'): retstr += '\n' else: - retstr += (pre + qsection + " = " + - str(self.dump_value(value)) + '\n') + retstr += (pre + qsection + " = " + str(self.dump_value(value)) + '\n') return retstr, self._dict()