From 636aca6cbd960de5c5f5a7889ffcac53a951dd8a Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 20 Aug 2022 17:18:27 -0400 Subject: [PATCH] app: add sudo request form to welcome page Signed-off-by: Eric Callahan --- moonraker/app.py | 21 ++- moonraker/assets/welcome.html | 271 +++++++++++++++++++++++++++++++++- 2 files changed, 285 insertions(+), 7 deletions(-) diff --git a/moonraker/app.py b/moonraker/app.py index c9a70db..1df2aff 100644 --- a/moonraker/app.py +++ b/moonraker/app.py @@ -48,6 +48,7 @@ if TYPE_CHECKING: from klippy_connection import KlippyConnection as Klippy from components.file_manager.file_manager import FileManager from components.announcements import Announcements + from components.machine import Machine from io import BufferedReader import components.authorization MessageDelgate = Optional[tornado.httputil.HTTPMessageDelegate] @@ -623,7 +624,10 @@ class DynamicRequestHandler(AuthorizedRequestHandler): if self.server.is_debug_enabled(): resp = args if isinstance(args, dict): - if self.request.path.startswith('/access'): + if ( + self.request.path.startswith("/access") or + self.request.path.startswith("/machine/sudo/password") + ): resp = {key: "" for key in args} elif isinstance(args, str): if args.startswith(""): @@ -671,7 +675,7 @@ class DynamicRequestHandler(AuthorizedRequestHandler): result = await self._do_request(args, conn) except ServerError as e: raise tornado.web.HTTPError( - e.status_code, str(e)) from e + e.status_code, reason=str(e)) from e if self.wrap_result: result = {'result': result} if result is None: @@ -1033,8 +1037,11 @@ class WelcomeHandler(tornado.web.RequestHandler): ancomp: Announcements ancomp = self.server.lookup_component("announcements") wsm: WebsocketManager = self.server.lookup_component("websockets") + machine: Machine = self.server.lookup_component("machine") + svc_info = machine.get_moonraker_service_info() + sudo_req_msg = "
".join(machine.sudo_request_messages) context: Dict[str, Any] = { - "ip_address": self.request.remote_ip, + "remote_ip": self.request.remote_ip, "authorized": authorized, "cors_enabled": cors_enabled, "version": self.server.get_app_args()["software_version"], @@ -1042,7 +1049,13 @@ class WelcomeHandler(tornado.web.RequestHandler): "klippy_state": kstate, "warnings": self.server.get_warnings(), "summary": summary, - "announcements": await ancomp.get_announcements() + "announcements": await ancomp.get_announcements(), + "sudo_requested": machine.sudo_requested, + "sudo_request_message": sudo_req_msg, + "linux_user": machine.linux_user, + "local_ip": machine.public_ip or "unknown", + "service_name": svc_info.get("unit_name", "unknown"), + "hostname": self.server.get_host_info()["hostname"], } self.render("welcome.html", **context) diff --git a/moonraker/assets/welcome.html b/moonraker/assets/welcome.html index 102afc9..f3caa39 100644 --- a/moonraker/assets/welcome.html +++ b/moonraker/assets/welcome.html @@ -123,6 +123,137 @@ background-color: rgb(160, 64, 8); } } + + .modal { + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgb(0,0,0); + background-color: rgba(0,0,0,0.4); + } + + .modal-card { + background: none; + position: relative; + border: 0px; + border-radius: 1rem; + background-color: #1a1a1a; + margin: 20% auto 2rem auto; + padding: 0rem; + border: 0px; + width: 50%; + animation-name: fadein; + animation-duration: .5s; + } + + .modal-card h1 { + background-color: #006f7e; + text-align: center; + line-height: 3rem; + font-size: 1.1rem; + height: 3rem; + margin: 0; + border-top-left-radius: 1rem; + border-top-right-radius: 1rem; + } + + .modal-content { + background-color: #3e3e3e; + padding: 1rem; + margin: 0; + height: auto + } + + .modal-content .entry { + display: inline-block; + width: 100%; + } + .modal-content .entry:not(:last-child) { + margin-bottom: .5rem; + } + .modal-content .value { + float: right; + display: inline; + } + .modal-content input { + width: 100%; + padding: 8px; + border-radius: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + font-size: 1rem; color: #222; + background: #F7F7F7; + + } + + .modal-footer { + display: inline-block; + background-color: #3e3e3e; + margin: 0; + height: auto; + width: 100%; + border-bottom-left-radius: 1rem; + border-bottom-right-radius: 1rem; + } + + .modal-button { + float: right; + background: #cecece; + border: none; + width: auto; + overflow: visible; + font-size: 1rem; + font-weight: bold; + color: rgb(0, 0, 0); + padding: .4rem .5rem; + margin: 0rem .5rem .5rem 0rem; + border-radius: .5rem; + -webkit-border-radius: .5rem; + -moz-border-radius: .5rem; + } + + .modal-button:hover { + color: rgb(8, 154, 45); + text-decoration: none; + cursor: pointer; + } + + .modal-status { + display: none; + position: relative; + border: 0; + border-radius: 1rem; + background-color: #3e3e3e; + margin: auto; + padding: 0rem; + width: 50%; + animation-name: fadebottom; + animation-duration: .5s; + } + + .modal-status:hover { + cursor: pointer; + } + + .modal-status .content { + display: inline-block; + margin: 1rem; + } + + @keyframes fadebottom { + from {top: 10em; opacity: 0} + to {top: 0em; opacity: 1} + } + + @keyframes fadein { + from {opacity: 0} + to {opacity: 1} + }