misc: basic refactoring of #502
This commit is contained in:
parent
59019efad0
commit
ba22b7d5d7
@ -108,18 +108,20 @@ def shutdown():
|
|||||||
os.system("halt")
|
os.system("halt")
|
||||||
|
|
||||||
|
|
||||||
def reboot():
|
def reboot(mode=None):
|
||||||
logging.warning("rebooting ...")
|
if mode is not None:
|
||||||
os.system("sync")
|
mode = mode.upper()
|
||||||
os.system("shutdown -r now")
|
logging.warning("rebooting in %s mode ..." % mode)
|
||||||
|
else:
|
||||||
|
logging.warning("rebooting ...")
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
os.system("touch /root/.pwnagotchi-auto")
|
|
||||||
|
if mode == 'AUTO':
|
||||||
|
os.system("touch /root/.pwnagotchi-auto")
|
||||||
|
|
||||||
os.system("sync")
|
os.system("sync")
|
||||||
os.system("shutdown -r now")
|
os.system("shutdown -r now")
|
||||||
|
@ -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
|
||||||
@ -107,7 +96,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
self.send_header('Access-Control-Allow-Credentials', 'true')
|
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-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||||
self.send_header("Access-Control-Allow-Headers",
|
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")
|
self.send_header("Vary", "Origin")
|
||||||
|
|
||||||
# just render some html in a 200 response
|
# just render some html in a 200 response
|
||||||
@ -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):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user