Exemple #1
0
 def _update_advertisement(self, s):
     self._advertisement['pwnd_run'] = len(self._handshakes)
     self._advertisement['pwnd_tot'] = utils.total_unique_handshakes(
         self._config['bettercap']['handshakes'])
     self._advertisement['uptime'] = pwnagotchi.uptime()
     self._advertisement['epoch'] = self._epoch.epoch
     grid.set_advertisement_data(self._advertisement)
Exemple #2
0
 def on_manual_mode(self, last_session):
     self.set('mode', 'MANU')
     self.set('face', faces.SAD if (last_session.epochs > 3 and last_session.handshakes == 0) else faces.HAPPY)
     self.set('status', self._voice.on_last_session_data(last_session))
     self.set('epoch', "%04d" % last_session.epochs)
     self.set('uptime', last_session.duration)
     self.set('channel', '-')
     self.set('aps', "%d" % last_session.associated)
     self.set('shakes', '%d (%s)' % (last_session.handshakes, \
                                     utils.total_unique_handshakes(self._config['bettercap']['handshakes'])))
     self.update()
Exemple #3
0
 def on_manual_mode(self, log):
     self.set('mode', 'MANU')
     self.set('face', faces.SAD if log.handshakes == 0 else faces.HAPPY)
     self.set('status', self._voice.on_log(log))
     self.set('epoch', "%04d" % log.epochs)
     self.set('uptime', log.duration)
     self.set('channel', '-')
     self.set('aps', "%d" % log.associated)
     self.set('shakes', '%d (%s)' % (log.handshakes, \
                                     utils.total_unique_handshakes(self._config['bettercap']['handshakes'])))
     self.set_closest_peer(log.last_peer)
Exemple #4
0
 def _update_advertisement(self, s):
     run_handshakes = len(self._handshakes)
     tot_handshakes = utils.total_unique_handshakes(self._config['bettercap']['handshakes'])
     started = s['started_at'].split('.')[0]
     started = datetime.strptime(started, '%Y-%m-%dT%H:%M:%S')
     started = time.mktime(started.timetuple())
     self._advertiser.update({ \
         'pwnd_run': run_handshakes,
         'pwnd_tot': tot_handshakes,
         'uptime': time.time() - started,
         'epoch': self._epoch.epoch})
Exemple #5
0
    def _update_handshakes(self, new_shakes=0):
        if new_shakes > 0:
            self._epoch.track(handshake=True, inc=new_shakes)

        tot = utils.total_unique_handshakes(self._config['bettercap']['handshakes'])
        txt = '%d (%d)' % (len(self._handshakes), tot)

        if self._last_pwnd is not None:
            txt += ' [%s]' % self._last_pwnd[:20]

        self._view.set('shakes', txt)

        if new_shakes > 0:
            self._view.on_handshakes(new_shakes)
    def _return_json(self):
        if self.DISPLAY is None:
            return jsonify({"initialised": "false"})

        # All these fall under the local API
        # https://pwnagotchi.ai/api/local/
        # Typically on http://127.0.0.1:8666
        # BUT the local API can trigger calls to the wider grid
        # so bear in mind that grid calls could fail

        # TODO: Break this up into function calls! Keep it SOLID.

        total_messages = "-"
        unread_messages = "-"

        peers_response = None
        try:
            response = requests.get('http://0.0.0.0:8666/api/v1/mesh/peers')
            peers_response = response.json()
        except HTTPError as http_err:
            logging.error(f'HTTP error occurred: {http_err}')
        except Exception as err:
            logging.error(f'Other error occurred: {err}')

        peers = []
        for peer in peers_response:
            peers.append({
                "fingerprint": peer['advertisement']['identity'],
                "name": peer['advertisement']['name'],
                "face": peer['advertisement']['face'],
                "pwnd_run": peer['advertisement']['pwnd_run'],
                "pwnd_tot": peer['advertisement']['pwnd_tot']
            })

        mesh_data_response = None
        try:
            response = requests.get('http://0.0.0.0:8666/api/v1/mesh/data')
            mesh_data_response = response.json()
        except HTTPError as http_err:
            logging.error(f'HTTP error occurred: {http_err}')
        except Exception as err:
            logging.error(f'Other error occurred: {err}')

        # Get mail data (if connected to internet)
        try:
            if grid.is_connected:
                messages = grid.inbox()
                total_messages = len(messages)
                unread_messages = len([m for m in messages if m['seen_at'] is None])
        except Exception as e:
            logging.exception('error while reading state-api: %s' % str(e))

        # TODO: Need a better way of getting this rather than referencing the display
        handshakes_display = self.DISPLAY.get('shakes').split(" ", 2)
        # In general, any underlying state within the state machine should be used.
        # The display is fluid and unreliable.
        pwnd_run = handshakes_display[0]
        pwnd_tot = utils.total_unique_handshakes(self.AGENT.config()['bettercap']['handshakes'])

        pwnd_last = None
        if len(handshakes_display) > 2:
            pwnd_last = handshakes_display[2][1:-1]

        result = {
            "fingerprint": self.AGENT.fingerprint(),
            "epoch": "-" if mesh_data_response is None else mesh_data_response["epoch"],
            "status": self.DISPLAY.get('status'),
            "channel_text": self.DISPLAY.get('channel'),
            "aps_text": self.DISPLAY.get('aps'),
            "apt_tot": self.AGENT.get_total_aps(),
            "aps_on_channel": self.AGENT.get_aps_on_channel(),
            "channel": self.AGENT.get_current_channel(),
            "uptime": self.DISPLAY.get('uptime'),
            "mode": self.DISPLAY.get('mode'),
            "name": pwnagotchi.name(),
            "face": self.DISPLAY.get('face'),
            "num_peers": len(peers),
            "peers": peers,
            "total_messages": total_messages,
            "unread_messages": unread_messages,
            "friend_face_text": self.DISPLAY.get('friend_face'),
            "friend_name_text": self.DISPLAY.get('friend_name'),
            "pwnd_last": pwnd_last,
            "pwnd_run": pwnd_run,
            "pwnd_tot": pwnd_tot,
            "version": pwnagotchi.__version__,
            "memory": pwnagotchi.mem_usage(),  # Scale 0-1
            "cpu": pwnagotchi.cpu_load(),  # Scale 0-1
            "temperature": pwnagotchi.temperature()  # Degrees C
        }

        # TODO See if there is any way of getting a list of plugins and their associated UI components
        # so we can incorporate it into the feedback.
        return jsonify(result)