fix: webui /shutdown is now on POST

This commit is contained in:
Simone Margaritelli 2019-10-25 19:34:31 +02:00
parent c0252c9830
commit 31c1d742e0

@ -52,7 +52,7 @@ INDEX = """<html>
<img src="/ui" id="ui" style="width:100%%"/> <img src="/ui" id="ui" style="width:100%%"/>
<br/> <br/>
<hr/> <hr/>
<form action="/shutdown" onsubmit="return confirm('This will halt the unit, continue?');"> <form method="POST" action="/shutdown" onsubmit="return confirm('This will halt the unit, continue?');">
<input type="submit" class="block" value="Shutdown"/> <input type="submit" class="block" value="Shutdown"/>
</form> </form>
</div> </div>
@ -149,24 +149,31 @@ class Handler(BaseHTTPRequestHandler):
return True return True
# main entry point of the http server def do_POST(self):
if not self._is_allowed():
return
if self.path.startswith('/shutdown'):
self._shutdown()
else:
self.send_response(404)
def do_GET(self): def do_GET(self):
if not self._is_allowed(): if not self._is_allowed():
return return
if self.path == '/': if self.path == '/':
self._index() self._index()
elif self.path.startswith('/shutdown'):
self._shutdown()
elif self.path.startswith('/ui'): elif self.path.startswith('/ui'):
self._image() self._image()
elif self.path.startswith('/plugins'): elif self.path.startswith('/plugins'):
plugin_from_path = re.match(r'\/plugins\/([^\/]+)(\/.*)?', self.path) plugin_from_path = re.match(r'\/plugins\/([^\/]+)(\/.*)?', self.path)
if plugin_from_path: if plugin_from_path:
plugin_name = plugin_from_path.groups()[0] plugin_name = plugin_from_path.groups()[0]
right_path = plugin_from_path.groups()[1] if len(plugin_from_path.groups()) == 2 else None right_path = plugin_from_path.groups()[1] if len(plugin_from_path.groups()) == 2 else None
plugins.one(plugin_name, 'webhook', right_path) plugins.one(plugin_name, 'webhook', right_path)
else: else:
self.send_response(404) self.send_response(404)