diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-13 19:41:20 +0100 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-15 13:23:28 +0100 |
commit | 693c4f4c5c096e067b7d5621f595e26f2b794824 (patch) | |
tree | 3bf778629ccf42159f7f98bb12168b4c2b8ecce1 /src/ogClient.py | |
parent | 7e8d5e71ce2a441faa85a178481f4ef30a7901d5 (diff) |
src: add user session detection implementationwinlinux
Detect user login and logout for Linux and Windows.
Poll the session change in 5 second intervals in a thread. Use the
same event socket previously used by the old session detection
mechanism to notify a session change.
Report an active interactive session through the /refresh response
so a new ogserver instance can update the session status.
Diffstat (limited to 'src/ogClient.py')
-rw-r--r-- | src/ogClient.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ogClient.py b/src/ogClient.py index 51aa33b..2635a3f 100644 --- a/src/ogClient.py +++ b/src/ogClient.py @@ -6,6 +6,7 @@ # Free Software Foundation; either version 3 of the License, or # (at your option) any later version. +import threading import errno import select import socket @@ -26,6 +27,8 @@ class State(Enum): class ogClient: OG_PATH = '/opt/opengnsys/' + SESSION_POLL_INTERVAL = 5 + EVENT_SOCKET_PORT = 55885 def __init__(self, config): self.CONFIG = config @@ -36,7 +39,7 @@ class ogClient: if self.mode in {'linux', 'windows'}: self.event_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.event_sock.setblocking(0) - self.event_sock.bind(('127.0.0.1', 55885)) + self.event_sock.bind(('127.0.0.1', ogClient.EVENT_SOCKET_PORT)) else: self.event_sock = None @@ -49,6 +52,25 @@ class ogClient: self.ogrest = ogRest(self.CONFIG) self.seq = None + self.session_check_thread = threading.Thread(target=self._session_check_loop, daemon=True) + self.session_check_thread.start() + + def _session_check_loop(self): + while True: + session_status = self.ogrest.check_interactive_session_change() + if session_status is True: + message = "session start user" + elif session_status is False: + message = "session stop user" + else: + message = None + + if message: + self.event_sock.sendto(message.encode('utf-8'), + ('127.0.0.1', ogClient.EVENT_SOCKET_PORT)) + + time.sleep(ogClient.SESSION_POLL_INTERVAL) + def get_socket(self): return self.sock |