misc: basic refactoring of #502

This commit is contained in:
Simone Margaritelli 2019-11-04 11:13:51 +01:00
parent 59019efad0
commit ba22b7d5d7
2 changed files with 16 additions and 25 deletions

View File

@ -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")

View File

@ -64,29 +64,18 @@ INDEX = """<html>
</body>
</html>"""
SHUTDOWN = """<html>
STATUS_PAGE = """<html>
<head>
<title>%s</title>
<style>""" + STYLE + """</style>
</head>
<body>
<div style="position: absolute; top:0; left:0; width:100%%;">
Shutting down ...
%s
</div>
</body>
</html>"""
REBOOT_INTO_AUTO = """<html>
<head>
<title>%s</title>
<style>""" + STYLE + """</style>
</head>
<body>
<div style="position: absolute; top:0; left:0; width:100%%;">
Rebooting into AUTO mode ...
</div>
</body>
</html>"""
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):