From ba22b7d5d7ea9be1663cf8c43b4e432015106acd Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Mon, 4 Nov 2019 11:13:51 +0100 Subject: [PATCH] misc: basic refactoring of #502 --- pwnagotchi/__init__.py | 18 ++++++++++-------- pwnagotchi/ui/web.py | 23 ++++++----------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/pwnagotchi/__init__.py b/pwnagotchi/__init__.py index 827f801..cba31ea 100644 --- a/pwnagotchi/__init__.py +++ b/pwnagotchi/__init__.py @@ -108,18 +108,20 @@ def shutdown(): os.system("halt") -def reboot(): - logging.warning("rebooting ...") - os.system("sync") - os.system("shutdown -r now") +def reboot(mode=None): + if mode is not None: + mode = mode.upper() + logging.warning("rebooting in %s mode ..." % mode) + else: + logging.warning("rebooting ...") - -def reboot_into_auto(): - logging.warning("rebooting into AUTO mode ...") if view.ROOT: view.ROOT.on_reboot() # give it some time to refresh the ui time.sleep(10) - os.system("touch /root/.pwnagotchi-auto") + + if mode == 'AUTO': + os.system("touch /root/.pwnagotchi-auto") + os.system("sync") os.system("shutdown -r now") diff --git a/pwnagotchi/ui/web.py b/pwnagotchi/ui/web.py index 94ce450..e4afdd6 100644 --- a/pwnagotchi/ui/web.py +++ b/pwnagotchi/ui/web.py @@ -64,29 +64,18 @@ INDEX = """ """ -SHUTDOWN = """ +STATUS_PAGE = """ %s
- Shutting down ... + %s
""" -REBOOT_INTO_AUTO = """ - - %s - - - -
- Rebooting into AUTO mode ... -
- -""" class Handler(BaseHTTPRequestHandler): AllowedOrigin = None # CORS headers are not sent @@ -107,7 +96,7 @@ class Handler(BaseHTTPRequestHandler): self.send_header('Access-Control-Allow-Credentials', 'true') self.send_header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") self.send_header("Access-Control-Allow-Headers", - "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") + "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") self.send_header("Vary", "Origin") # just render some html in a 200 response @@ -127,13 +116,13 @@ class Handler(BaseHTTPRequestHandler): # serve a message and shuts down the unit def _shutdown(self): - self._html(SHUTDOWN % pwnagotchi.name()) + self._html(STATUS_PAGE % (pwnagotchi.name(), 'Shutting down ...')) pwnagotchi.shutdown() # serve a message and reboot the unit into auto mode def _reboot(self): - self._html(REBOOT % pwnagotchi.name()) - pwnagotchi.reboot_into_auto() + self._html(STATUS_PAGE % (pwnagotchi.name(), 'Rebooting into AUTO mode ...')) + pwnagotchi.reboot(mode='AUTO') # serve the PNG file with the display image def _image(self):