Skip to content

Commit

Permalink
Updated agent.py logic
Browse files Browse the repository at this point in the history
Updated agent.py to not kill _fetch_stats thread when bettercap fails
Updated agent.py to attempt to reconnect / reconfigure bettercap after it gets restarted from failure
  • Loading branch information
matrix224 authored May 3, 2024
1 parent d6af2b7 commit 8000a38
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pwnagotchi/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _reset_wifi_settings(self):
self.run('set wifi.handshakes.file %s' % self._config['bettercap']['handshakes'])
self.run('set wifi.handshakes.aggregate false')

def start_monitor_mode(self):
def start_monitor_mode(self, start_advertisement=True):
mon_iface = self._config['main']['iface']
mon_start_cmd = self._config['main']['mon_start_cmd']
restart = not self._config['main']['no_restart']
Expand Down Expand Up @@ -117,6 +117,8 @@ def start_monitor_mode(self):
logging.debug("starting wifi module ...")
self.start_module('wifi.recon')


if start_advertisement:
self.start_advertising()

def _wait_bettercap(self):
Expand Down Expand Up @@ -237,6 +239,7 @@ def _find_ap_sta_in(self, station_mac, ap_mac, session):
def _update_uptime(self, s):
secs = pwnagotchi.uptime()
self._view.set('uptime', utils.secs_to_hhmmss(secs))
#logging.info("AGENT-UPTIME = %d",secs)
# self._view.set('epoch', '%04d' % self._epoch.epoch)

def _update_counters(self):
Expand Down Expand Up @@ -311,8 +314,20 @@ def start_session_fetcher(self):


def _fetch_stats(self):
bettercap_failed = False
while True:
try:
s = self.session()
except Exception as e:
logging.error("Agent fetch_stats session error -> %s" % e)
bettercap_failed = True
else:
if bettercap_failed:
logging.info("Agent fetch_stats: Re-established bettercap session, restarting events and monitor...")
self.setup_events()
self.start_monitor_mode(False)
bettercap_failed = False
# TODO: update_uptime and update_advertisements take s, but don't use it?
self._update_uptime(s)
self._update_advertisement(s)
self._update_peers()
Expand Down

0 comments on commit 8000a38

Please sign in to comment.