def on_internet_available(agent): global REPORT, UNREAD_MESSAGES, TOTAL_MESSAGES logging.debug("internet available") try: grid.update_data(agent.last_session) except Exception as e: logging.error("error connecting to the pwngrid-peer service: %s" % e) 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]) if TOTAL_MESSAGES: on_ui_update(agent.view()) 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")) num_networks = len(pcap_files) reported = REPORT.data_field_or('reported', default=[]) num_reported = len(reported) num_new = num_networks - num_reported if num_new > 0: if OPTIONS['report']: logging.info("grid: %d new networks to report" % num_new) logging.debug("OPTIONS: %s" % OPTIONS) logging.debug(" exclude: %s" % OPTIONS['exclude']) for pcap_file in pcap_files: net_id = os.path.basename(pcap_file).replace('.pcap', '') if net_id not in reported: if is_excluded(net_id): logging.debug("skipping %s due to exclusion filter" % pcap_file) set_reported(reported, net_id) continue essid, bssid = parse_pcap(pcap_file) if bssid: if is_excluded(essid) or is_excluded(bssid): logging.debug("not reporting %s due to exclusion filter" % pcap_file) set_reported(reported, net_id) else: if grid.report_ap(essid, bssid): set_reported(reported, net_id) time.sleep(1.5) else: logging.warning("no bssid found?!") else: logging.debug("grid: reporting disabled") except Exception as e: logging.error("grid api: %s" % e)
def check_inbox(self, agent): logging.debug("checking mailbox ...") messages = grid.inbox() self.total_messages = len(messages) self.unread_messages = len([m for m in messages if m['seen_at'] is None]) if self.unread_messages: logging.debug("[grid] unread:%d total:%d" % (self.unread_messages, self.total_messages)) agent.view().on_unread_messages(self.unread_messages, self.total_messages)
def check_inbox(self, agent): logging.debug("[grid] Checking mailbox...") messages = grid.inbox() self.total_messages = len(messages) self.unread_messages = len([m for m in messages if m['seen_at'] is None]) if self.unread_messages: plugins.on('unread_inbox', self.unread_messages) logging.debug(f"[grid] unread:{self.unread_messages} total:{self.total_messages}") agent.view().on_unread_messages(self.unread_messages, self.total_messages)
def check_inbox(agent): global REPORT, UNREAD_MESSAGES, TOTAL_MESSAGES 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]) if UNREAD_MESSAGES: logging.debug("[grid] unread:%d total:%d" % (UNREAD_MESSAGES, TOTAL_MESSAGES)) agent.view().on_unread_messages(UNREAD_MESSAGES, TOTAL_MESSAGES)
def _return_json(self): display = self._agent.view() mesh_data = grid.call("/mesh/data") mesh_peers = grid.peers() messages = grid.inbox() total_messages = len(messages) unread_messages = len([m for m in messages if m['seen_at'] is None]) peers = [] for peer in mesh_peers: peers.append({ "identity": peer["advertisement"]["identity"], "name": peer["advertisement"]["name"], "face": peer["advertisement"]["face"], "pwnd_run": peer["advertisement"]["pwnd_run"], "pwnd_tot": peer["advertisement"]["pwnd_tot"], }) result = { "identity": mesh_data["identity"], "epoch": mesh_data["epoch"], "status": display.get('status'), "channel_text": display.get('channel'), "aps_text": 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": display.get('uptime'), "mode": display.get('mode'), "name": mesh_data["name"], "face": mesh_data["face"], "num_peers": len(mesh_peers), "peers": peers, "total_messages": total_messages, "unread_messages": unread_messages, "friend_face_text": display.get('friend_face'), "friend_name_text": display.get('friend_name'), "pwnd_run": mesh_data["pwnd_run"], "pwnd_tot": mesh_data["pwnd_tot"], "version": pwnagotchi.version, "memory": pwnagotchi.mem_usage(), # Scale 0-1 "cpu": pwnagotchi.cpu_load(), # Scale 0-1 "temperature": pwnagotchi.temperature() # Degrees C } return jsonify(result)
def inbox(self): page = request.args.get("p", default=1, type=int) inbox = {"pages": 1, "records": 0, "messages": []} error = None try: inbox = grid.inbox(page, with_pager=True) except Exception as e: logging.exception('error while reading pwnmail inbox') error = str(e) return render_template('inbox.html', name=pwnagotchi.name(), page=page, error=error, inbox=inbox)
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)