diff --git a/web.py b/web.py index 88551de..aff613a 100644 --- a/web.py +++ b/web.py @@ -7,6 +7,8 @@ from bluetooth_devices import * import asyncio import concurrent.futures +import sys +import subprocess from aiohttp_session import SimpleCookieStorage, session_middleware from aiohttp_security import check_authorized, \ @@ -46,6 +48,8 @@ def __init__(self, loop: asyncio.AbstractEventLoop, adapter, bluetooth_devices:B self.app = web.Application(middlewares=[middleware]) self.app.router.add_route('*', '/', self.root_handler) self.app.router.add_route('POST', '/changepassword', self.change_password_handler) + self.app.router.add_route('POST', '/restartservice', self.restart_service_handler) + self.app.router.add_route('POST', '/reboot', self.reboot_handler) self.app.router.add_route('POST', '/login', self.handler_login) self.app.router.add_route('GET', '/authorised', self.handler_is_authorised) self.app.router.add_route('POST', '/setdevicecapture', self.set_device_capture) @@ -112,6 +116,14 @@ async def change_password_handler(self, request): return web.HTTPError return web.Response(text="Password successfully changed") + async def restart_service_handler(self, request): + await check_authorized(request) + sys.exit(1) + + async def reboot_handler(self, request): + await check_authorized(request) + subprocess.Popen(['reboot']) + async def get_hid_devices_handler(self, request): await check_authorized(request) return web.Response(text=json.dumps(self.hid_devices.get_hid_devices_with_config())) diff --git a/web/index.html b/web/index.html index ad62ce1..a544adf 100644 --- a/web/index.html +++ b/web/index.html @@ -131,6 +131,18 @@