def on_ui_update(self, ui):
        if self.options['scale'] == "fahrenheit":
            temp = (pwnagotchi.temperature() * 9 / 5) + 32
            symbol = "f"
        elif self.options['scale'] == "kelvin":
            temp = pwnagotchi.temperature() + 273.15
            symbol = "k"
        else:
            # default to celsius
            temp = pwnagotchi.temperature()
            symbol = "c"

        if self.options['orientation'] == "vertical":
            # ui.set('memtemp',
            #        " mem:%s%%\n cpu:%s%%\ntemp:%s%s" % (self.mem_usage(), self.cpu_load(), temp, symbol))

            # Updated modular element positioning

            ui.set("mem", f"  {self.mem_usage()}% ")
            ui.set("cpu", f" {self.cpu_load()}% ")
            ui.set("temp", f" {self.cpu_load()}C ")

        else:
            # default to horizontal
            ui.set(
                'memtemp', " mem cpu temp\n %s%% %s%%  %s%s" %
                (self.mem_usage(), self.cpu_load(), temp, symbol))
예제 #2
0
    def on_ui_update(self, ui):
        if self.options['orientation'] == "horizontal":
            ui.set(
                'memtemp', " mem cpu temp\n %s%% %s%%  %sc" %
                (self.mem_usage(), self.cpu_load(), pwnagotchi.temperature()))

        elif self.options['orientation'] == "vertical":
            ui.set(
                'memtemp', " mem:%s%%\n cpu:%s%%\ntemp:%sc" %
                (self.mem_usage(), self.cpu_load(), pwnagotchi.temperature()))
예제 #3
0
def on_ui_update(ui):
    if OPTIONS['orientation'] == "horizontal":
        ui.set(
            'memtemp', " mem cpu temp\n %s%% %s%%  %sc" %
            (mem_usage(), cpu_load(), pwnagotchi.temperature()))

    elif OPTIONS['orientation'] == "vertical":
        ui.set(
            'memtemp', " mem:%s%%\n cpu:%s%%\ntemp:%sc" %
            (mem_usage(), cpu_load(), pwnagotchi.temperature()))
예제 #4
0
 def cpu_temp(self):
     if self.options['scale'] == "fahrenheit":
         temp = (pwnagotchi.temperature() * 9 / 5) + 32
         symbol = "f"
     elif self.options['scale'] == "kelvin":
         temp = pwnagotchi.temperature() + 273.15
         symbol = "k"
     else:
         # default to celsius
         temp = pwnagotchi.temperature()
         symbol = "c"
     return f"{temp}{symbol}"
예제 #5
0
 def cpu_temp(self):
     if self.options['scale'].lower() == 'fahrenheit':
         temp = (pwnagotchi.temperature() * 9 / 5) + 32
         symbol = 'F'
     elif self.options['scale'].lower() == 'kelvin':
         temp = pwnagotchi.temperature() + 273.15
         symbol = 'K'
     else:
         # default to celsius
         temp = pwnagotchi.temperature()
         symbol = 'C'
     return f'{temp}{symbol}'
예제 #6
0
    def on_ui_update(self, ui):
        if self.options['scale'] == "fahrenheit":
            temp = (pwnagotchi.temperature() * 9 / 5) + 32
        elif self.options['scale'] == "celsius":
            temp = pwnagotchi.temperature()
        elif self.options['scale'] == "kelvin":
            temp = pwnagotchi.temperature() + 273.15
        if self.options['orientation'] == "horizontal":
            ui.set(
                'memtemp', " mem cpu temp\n %s%% %s%%  %sc" %
                (self.mem_usage(), self.cpu_load(), temp))

        elif self.options['orientation'] == "vertical":
            ui.set(
                'memtemp', " mem:%s%%\n cpu:%s%%\ntemp:%sc" %
                (self.mem_usage(), self.cpu_load(), temp))
예제 #7
0
    def next(self):
        if self.any_activity is False and self.did_handshakes is False:
            self.inactive_for += 1
            self.active_for = 0
        else:
            self.active_for += 1
            self.inactive_for = 0

        now = time.time()
        cpu = pwnagotchi.cpu_load()
        mem = pwnagotchi.mem_usage()
        temp = pwnagotchi.temperature()

        self.epoch_duration = now - self.epoch_started

        # cache the state of this epoch for other threads to read
        self._epoch_data = {
            'duration_secs': self.epoch_duration,
            'slept_for_secs': self.num_slept,
            'blind_for_epochs': self.blind_for,
            'inactive_for_epochs': self.inactive_for,
            'active_for_epochs': self.active_for,
            'missed_interactions': self.num_missed,
            'num_hops': self.num_hops,
            'num_deauths': self.num_deauths,
            'num_associations': self.num_assocs,
            'num_handshakes': self.num_shakes,
            'cpu_load': cpu,
            'mem_usage': mem,
            'temperature': temp
        }

        self._epoch_data['reward'] = self._reward(self.epoch + 1,
                                                  self._epoch_data)
        self._epoch_data_ready.set()

        logging.info(
            "[epoch %d] duration=%s slept_for=%s blind=%d inactive=%d active=%d hops=%d missed=%d "
            "deauths=%d assocs=%d handshakes=%d cpu=%d%% mem=%d%% temperature=%dC reward=%s"
            % (self.epoch, core.secs_to_hhmmss(
                self.epoch_duration), core.secs_to_hhmmss(
                    self.num_slept), self.blind_for, self.inactive_for,
               self.active_for, self.num_hops, self.num_missed,
               self.num_deauths, self.num_assocs, self.num_shakes, cpu * 100,
               mem * 100, temp, self._epoch_data['reward']))

        self.epoch += 1
        self.epoch_started = now
        self.did_deauth = False
        self.num_deauths = 0
        self.did_associate = False
        self.num_assocs = 0
        self.num_missed = 0
        self.did_handshakes = False
        self.num_shakes = 0
        self.num_hops = 0
        self.num_slept = 0
        self.any_activity = False
예제 #8
0
    def on_ui_update(self, ui):
        if self.options['scale'] == "fahrenheit":
            temp = (pwnagotchi.temperature() * 9 / 5) + 32
            symbol = "f"
        elif self.options['scale'] == "kelvin":
            temp = pwnagotchi.temperature() + 273.15
            symbol = "k"
        else:
            # default to celsius
            temp = pwnagotchi.temperature()
            symbol = "c"

        if self.options['orientation'] == "vertical":
            ui.set(
                'memtemp',
                f" mem:{self.mem_usage()}%\n cpu:{self.cpu_load()}%\ntemp:{temp}{symbol}"
            )
        else:
            # default to horizontal
            ui.set(
                'memtemp',
                f" mem cpu  temp\n {self.mem_usage()}% {self.cpu_load()}%  {temp}{symbol}"
            )
예제 #9
0
    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)
예제 #10
0
    def next(self):
        if self.any_activity is False and self.did_handshakes is False:
            self.inactive_for += 1
            self.active_for = 0
        else:
            self.active_for += 1
            self.inactive_for = 0
            self.sad_for = 0
            self.bored_for = 0

        if self.inactive_for >= self.config['personality']['sad_num_epochs']:
            # sad > bored; cant be sad and bored
            self.bored_for = 0
            self.sad_for += 1
        elif self.inactive_for >= self.config['personality'][
                'bored_num_epochs']:
            # sad_treshhold > inactive > bored_treshhold; cant be sad and bored
            self.sad_for = 0
            self.bored_for += 1
        else:
            self.sad_for = 0
            self.bored_for = 0

        now = time.time()
        cpu = pwnagotchi.cpu_load()
        mem = pwnagotchi.mem_usage()
        temp = pwnagotchi.temperature()

        self.epoch_duration = now - self.epoch_started

        # cache the state of this epoch for other threads to read
        self._epoch_data = {
            'duration_secs': self.epoch_duration,
            'slept_for_secs': self.num_slept,
            'blind_for_epochs': self.blind_for,
            'inactive_for_epochs': self.inactive_for,
            'active_for_epochs': self.active_for,
            'sad_for_epochs': self.sad_for,
            'bored_for_epochs': self.bored_for,
            'missed_interactions': self.num_missed,
            'num_hops': self.num_hops,
            'num_peers': self.num_peers,
            'tot_bond': self.tot_bond_factor,
            'avg_bond': self.avg_bond_factor,
            'num_deauths': self.num_deauths,
            'num_associations': self.num_assocs,
            'num_handshakes': self.num_shakes,
            'cpu_load': cpu,
            'mem_usage': mem,
            'temperature': temp
        }

        self._epoch_data['reward'] = self._reward(self.epoch + 1,
                                                  self._epoch_data)
        self._epoch_data_ready.set()

        logging.info(
            "[epoch %d] duration=%s slept_for=%s blind=%d sad=%d bored=%d inactive=%d active=%d peers=%d tot_bond=%.2f "
            "avg_bond=%.2f hops=%d missed=%d deauths=%d assocs=%d handshakes=%d cpu=%d%% mem=%d%% "
            "temperature=%dC reward=%s" %
            (self.epoch, utils.secs_to_hhmmss(
                self.epoch_duration), utils.secs_to_hhmmss(self.num_slept),
             self.blind_for, self.sad_for, self.bored_for, self.inactive_for,
             self.active_for, self.num_peers, self.tot_bond_factor,
             self.avg_bond_factor, self.num_hops, self.num_missed,
             self.num_deauths, self.num_assocs, self.num_shakes, cpu * 100,
             mem * 100, temp, self._epoch_data['reward']))

        self.epoch += 1
        self.epoch_started = now
        self.did_deauth = False
        self.num_deauths = 0
        self.num_peers = 0
        self.tot_bond_factor = 0.0
        self.avg_bond_factor = 0.0
        self.did_associate = False
        self.num_assocs = 0
        self.num_missed = 0
        self.did_handshakes = False
        self.num_shakes = 0
        self.num_hops = 0
        self.num_slept = 0
        self.any_activity = False
예제 #11
0
    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)