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 @@
Pair devices

Settings

+
+ +
+
+
Change 'pi' user password
diff --git a/web/js/main.js b/web/js/main.js index 17645ef..bed97dc 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -65,6 +65,8 @@ class Main{ $('#stopScanningButton').on('click', e => {that.changeScanningMode(false);}); $('#startDiscoverableButton').on('click', e => {that.changeDiscoverableMode(true);}); $('#stopDiscoverableButton').on('click', e => {that.changeDiscoverableMode(false);}); + $('#restartServiceButton').on('click', e => {that.restartService();}); + $('#rebootButton').on('click', e => {that.rebootRaspberry();}); this.scanning = false; this.setScanningState(); @@ -349,6 +351,26 @@ class Main{ }); } + restartService(){ + $.ajax({ + url: "http://" + location.hostname + ":8080/restartservice", + type: 'POST', cache:false, contentType: false, processData: false, + error: function (jqXHR, textStatus, errorThrown){ + M.toast({html: "Restarting service, reload this page..."}); + } + }); + } + + rebootRaspberry(){ + $.ajax({ + url: "http://" + location.hostname + ":8080/reboot", + type: 'POST', cache:false, contentType: false, processData: false, + error: function (jqXHR, textStatus, errorThrown){ + M.toast({html: "Rebooting Raspberry, reload this page..."}); + } + }); + } + setActiveView(view){ switch (view){ case views.SETTINGS: