diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml index 5ea0f09..44c20e2 100644 --- a/builder/pwnagotchi.yml +++ b/builder/pwnagotchi.yml @@ -34,7 +34,7 @@ url: "https://github.com/bettercap/bettercap/releases/download/v2.25/bettercap_linux_armv6l_2.25.zip" ui: "https://github.com/bettercap/ui/releases/download/v1.3.0/ui.zip" pwngrid: - url: "https://github.com/evilsocket/pwngrid/releases/download/v1.5.7/pwngrid_linux_armv6l_v1.5.7.zip" + url: "https://github.com/evilsocket/pwngrid/releases/download/v1.6.0/pwngrid_linux_armv6l_v1.6.0.zip" apt: hold: - firmware-atheros diff --git a/pwnagotchi/plugins/default/grid.py b/pwnagotchi/plugins/default/grid.py index 0dd76cc..1236181 100644 --- a/pwnagotchi/plugins/default/grid.py +++ b/pwnagotchi/plugins/default/grid.py @@ -12,11 +12,17 @@ import json import subprocess import pwnagotchi import pwnagotchi.utils as utils +from pwnagotchi.ui.components import LabeledValue +from pwnagotchi.ui.view import BLACK +import pwnagotchi.ui.fonts as fonts from pwnagotchi.utils import WifiInfo, extract_from_pcap OPTIONS = dict() REPORT = utils.StatusFile('/root/.api-report.json', data_format='json') +UNREAD_MESSAGES = 0 +TOTAL_MESSAGES = 0 + def on_loaded(): logging.info("grid plugin loaded.") @@ -59,12 +65,17 @@ def is_excluded(what): return False -def grid_call(path, obj): +def grid_call(path, obj=None): # pwngrid-peer is running on port 8666 api_address = 'http://127.0.0.1:8666/api/v1%s' % path - r = requests.post(api_address, headers=None, json=obj) + if obj is None: + r = requests.get(api_address, headers=None) + else: + r = requests.post(api_address, headers=None, json=obj) + if r.status_code != 200: raise Exception("(status %d) %s" % (r.status_code, r.text)) + return r.json() def grid_update_data(last_session): @@ -93,7 +104,7 @@ def grid_update_data(last_session): 'version': pwnagotchi.version } - logging.debug("updating grid data:\n%s" % data) + logging.debug("updating grid data: %s" % data) grid_call("/data", data) @@ -111,8 +122,24 @@ def grid_report_ap(essid, bssid): return False +def grid_inbox(): + return grid_call("/inbox")["messages"] + + +def on_ui_update(ui): + new_value = ' %d (%d)' % (UNREAD_MESSAGES, TOTAL_MESSAGES) + if not ui.has_element('mailbox'): + logging.debug("add mailbox") + ui.add_element('mailbox', + LabeledValue(color=BLACK, label='MSG', value=new_value, + position=(100, 0), + label_font=fonts.Bold, + text_font=fonts.Medium)) + ui.set('mailbox', new_value) + + def on_internet_available(agent): - global REPORT + global REPORT, UNREAD_MESSAGES, TOTAL_MESSAGES logging.debug("internet available") @@ -123,6 +150,14 @@ def on_internet_available(agent): return try: + logging.debug("checking mailbox ...") + + messages = grid_inbox() + TOTAL_MESSAGES = len(messages) + UNREAD_MESSAGES = len([m for m in messages if m['seen_at'] is None]) + + logging.debug( " %d unread messages of %d total" % (UNREAD_MESSAGES, TOTAL_MESSAGES)) + logging.debug("checking pcaps") pcap_files = glob.glob(os.path.join(agent.config()['bettercap']['handshakes'], "*.pcap")) diff --git a/pwnagotchi/ui/fonts.py b/pwnagotchi/ui/fonts.py index 0f8ae5b..76181ef 100644 --- a/pwnagotchi/ui/fonts.py +++ b/pwnagotchi/ui/fonts.py @@ -4,6 +4,7 @@ PATH = '/usr/share/fonts/truetype/dejavu/DejaVuSansMono' Bold = ImageFont.truetype("%s-Bold.ttf" % PATH, 10) BoldSmall = ImageFont.truetype("%s-Bold.ttf" % PATH, 8) +BoldBig = ImageFont.truetype("%s-Bold.ttf" % PATH, 25) Medium = ImageFont.truetype("%s.ttf" % PATH, 10) Huge = ImageFont.truetype("%s-Bold.ttf" % PATH, 25) diff --git a/pwnagotchi/ui/state.py b/pwnagotchi/ui/state.py index 0a9e37a..b416b4a 100644 --- a/pwnagotchi/ui/state.py +++ b/pwnagotchi/ui/state.py @@ -12,6 +12,13 @@ class State(object): self._state[key] = elem self._changes[key] = True + def has_element(self, key): + return key in self._state + + def remove_element(self, key): + del self._state[key] + self._changes[key] = True + def add_listener(self, key, cb): with self._lock: self._listeners[key] = cb diff --git a/pwnagotchi/ui/view.py b/pwnagotchi/ui/view.py index 423992f..59a9e51 100644 --- a/pwnagotchi/ui/view.py +++ b/pwnagotchi/ui/view.py @@ -124,9 +124,15 @@ class View(object): ROOT = self + def has_element(self, key): + self._state.has_element(key) + def add_element(self, key, elem): self._state.add_element(key, elem) + def remove_element(self, key): + self._state.remove_element(key) + def width(self): return self._width