diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 73f5f996..d163959e 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -65,6 +65,7 @@ if __name__ == '__main__': elif args.do_manual: logging.info("entering manual mode ...") + agent.mode = 'manual' agent.last_session.parse(agent.view(), args.skip_session) if not args.skip_session: logging.info( @@ -85,6 +86,7 @@ if __name__ == '__main__': else: logging.info("entering auto mode ...") + agent.mode = 'auto' agent.start() while True: diff --git a/pwnagotchi/__init__.py b/pwnagotchi/__init__.py index cba31eae..0bd130d4 100644 --- a/pwnagotchi/__init__.py +++ b/pwnagotchi/__init__.py @@ -108,6 +108,18 @@ def shutdown(): os.system("halt") +def restart(mode): + logging.warning("restarting in %s mode ..." % mode) + + if mode == 'AUTO': + os.system("touch /root/.pwnagotchi-auto") + else: + os.system("touch /root/.pwnagotchi-manual") + + os.system("service bettercap restart") + os.system("service pwnagotchi restart") + + def reboot(mode=None): if mode is not None: mode = mode.upper() @@ -122,6 +134,8 @@ def reboot(mode=None): if mode == 'AUTO': os.system("touch /root/.pwnagotchi-auto") + elif mode == 'MANU': + os.system("touch /root/.pwnagotchi-manual") os.system("sync") os.system("shutdown -r now") diff --git a/pwnagotchi/agent.py b/pwnagotchi/agent.py index e1cfd151..f4673b14 100644 --- a/pwnagotchi/agent.py +++ b/pwnagotchi/agent.py @@ -18,6 +18,8 @@ RECOVERY_DATA_FILE = '/root/.pwnagotchi-recovery' class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer): + INSTANCE = None + def __init__(self, view, config, keypair): Client.__init__(self, config['bettercap']['hostname'], config['bettercap']['scheme'], @@ -39,10 +41,13 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer): self._history = {} self._handshakes = {} self.last_session = LastSession(self._config) + self.mode = 'auto' if not os.path.exists(config['bettercap']['handshakes']): os.makedirs(config['bettercap']['handshakes']) + Agent.INSTANCE = self + def config(self): return self._config diff --git a/pwnagotchi/ui/web.py b/pwnagotchi/ui/web.py index 561c1e32..294ae8ea 100644 --- a/pwnagotchi/ui/web.py +++ b/pwnagotchi/ui/web.py @@ -6,6 +6,7 @@ import shutil import logging import pwnagotchi +from pwnagotchi.agent import Agent from pwnagotchi import plugins frame_path = '/root/pwnagotchi.png' @@ -65,8 +66,8 @@ INDEX = """
- @@ -122,17 +123,22 @@ class Handler(BaseHTTPRequestHandler): # serve the main html page def _index(self): - self._html(INDEX % (pwnagotchi.name(), 1000)) + other_mode = 'AUTO' if Agent.INSTANCE.mode == 'manual' else 'MANU' + self._html(INDEX % ( + pwnagotchi.name(), + 1000, other_mode, + other_mode)) # serve a message and shuts down the unit def _shutdown(self): self._html(STATUS_PAGE % (pwnagotchi.name(), 'Shutting down ...')) pwnagotchi.shutdown() - # serve a message and reboot the unit into auto mode + # serve a message and restart the unit in the other mode def _reboot(self): - self._html(STATUS_PAGE % (pwnagotchi.name(), 'Rebooting into AUTO mode ...')) - pwnagotchi.reboot(mode='AUTO') + other_mode = 'AUTO' if Agent.INSTANCE.mode == 'manual' else 'MANU' + self._html(STATUS_PAGE % (pwnagotchi.name(), 'Restart in %s mode ...' % other_mode)) + pwnagotchi.restart(other_mode) # serve the PNG file with the display image def _image(self): @@ -174,21 +180,20 @@ class Handler(BaseHTTPRequestHandler): def do_POST(self): if not self._is_allowed(): return - if self.path.startswith('/shutdown'): + elif self.path.startswith('/shutdown'): self._shutdown() + elif self.path.startswith('/restart'): + self._restart() else: self.send_response(404) def do_GET(self): if not self._is_allowed(): return - - if self.path == '/': + elif self.path == '/': self._index() - elif self.path.startswith('/ui'): self._image() - elif self.path.startswith('/plugins'): matches = re.match(r'\/plugins\/([^\/]+)(\/.*)?', self.path) if matches: @@ -196,7 +201,6 @@ class Handler(BaseHTTPRequestHandler): plugin_name = groups[0] right_path = groups[1] if len(groups) == 2 else None plugins.one(plugin_name, 'webhook', self, right_path) - else: self.send_response(404)