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") os.system("halt")
def reboot(): def reboot(mode=None):
if mode is not None:
mode = mode.upper()
logging.warning("rebooting in %s mode ..." % mode)
else:
logging.warning("rebooting ...") logging.warning("rebooting ...")
os.system("sync")
os.system("shutdown -r now")
def reboot_into_auto():
logging.warning("rebooting into AUTO mode ...")
if view.ROOT: if view.ROOT:
view.ROOT.on_reboot() view.ROOT.on_reboot()
# give it some time to refresh the ui # give it some time to refresh the ui
time.sleep(10) time.sleep(10)
if mode == 'AUTO':
os.system("touch /root/.pwnagotchi-auto") os.system("touch /root/.pwnagotchi-auto")
os.system("sync") os.system("sync")
os.system("shutdown -r now") os.system("shutdown -r now")

View File

@ -64,29 +64,18 @@ INDEX = """<html>
</body> </body>
</html>""" </html>"""
SHUTDOWN = """<html> STATUS_PAGE = """<html>
<head> <head>
<title>%s</title> <title>%s</title>
<style>""" + STYLE + """</style> <style>""" + STYLE + """</style>
</head> </head>
<body> <body>
<div style="position: absolute; top:0; left:0; width:100%%;"> <div style="position: absolute; top:0; left:0; width:100%%;">
Shutting down ... %s
</div> </div>
</body> </body>
</html>""" </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): class Handler(BaseHTTPRequestHandler):
AllowedOrigin = None # CORS headers are not sent AllowedOrigin = None # CORS headers are not sent
@ -127,13 +116,13 @@ class Handler(BaseHTTPRequestHandler):
# serve a message and shuts down the unit # serve a message and shuts down the unit
def _shutdown(self): def _shutdown(self):
self._html(SHUTDOWN % pwnagotchi.name()) self._html(STATUS_PAGE % (pwnagotchi.name(), 'Shutting down ...'))
pwnagotchi.shutdown() pwnagotchi.shutdown()
# serve a message and reboot the unit into auto mode # serve a message and reboot the unit into auto mode
def _reboot(self): def _reboot(self):
self._html(REBOOT % pwnagotchi.name()) self._html(STATUS_PAGE % (pwnagotchi.name(), 'Rebooting into AUTO mode ...'))
pwnagotchi.reboot_into_auto() pwnagotchi.reboot(mode='AUTO')
# serve the PNG file with the display image # serve the PNG file with the display image
def _image(self): def _image(self):