diff --git a/docs/events/index.rst b/docs/events/index.rst index 93a55066b..224656b3f 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -100,7 +100,7 @@ Shutdown The server is shutting down. ClientOpened - A client has connected to the web server. + A client has connected to the push socket. Payload: @@ -109,12 +109,22 @@ ClientOpened **Note:** Name changed in version 1.1.0 -ClientClosed - A client has disconnected from the webserver +ClientAuthed + A client has authenticated a user session on the push socket. Payload: - * ``remoteAddress``: the remote address (IP) of the client that disconnected + * ``remoteAddress``: the remote address (IP) of the client that authed. On the push socket only available with a + valid login session. + * ``username``: the name of the user who authed. On the push socket only available with a valid login session. + +ClientClosed + A client has disconnected from the push socket. + + Payload: + + * ``remoteAddress``: the remote address (IP) of the client that disconnected. On the push socket only available + with a valid login session. UserLoggedIn A user logged in. On the push socket only available with a valid login session with admin rights. diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 526e0e3e7..7ac01ea00 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -46,6 +46,8 @@ class Events(object): # connect/disconnect by client CLIENT_OPENED = "ClientOpened" CLIENT_CLOSED = "ClientClosed" + CLIENT_AUTHED = "ClientAuthed" + CLIENT_DEAUTHED = "ClientDeauthed" # user login/logout USER_LOGGED_IN = "UserLoggedIn" diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index bf3b5ab92..96c1f0697 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -78,6 +78,7 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, "*": []} _event_payload_processors = {Events.CLIENT_OPENED: [lambda user, payload: payload if user.has_permission(Permissions.ADMIN) else dict()], + Events.CLIENT_AUTHED: [lambda user, payload: payload if user.has_permission(Permissions.ADMIN) else dict()], "*": []} _emit_permissions = {"connected": [], @@ -436,6 +437,10 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, self._logger.exception("Error processing authed hook handler for plugin {}".format(name), extra=dict(plugin=name)) + octoprint.events.eventManager().fire(octoprint.events.Events.CLIENT_AUTHED, + payload=dict(username=user.get_name(), + remoteAddress=self._remoteAddress)) + def _on_logout(self): self._user = self._userManager.anonymous_user_factory()