From a36c4daa23d32aeee9539374aa591152ef2c914b Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 13 Nov 2024 19:41:20 +0100 Subject: src: add user session detection implementation Detect user login and logout for Linux and Windows. Report an active interactive session through the /refresh response so a new ogserver instance can update the session status. 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. Use the method check_interactive_session_change in each ogOperations.py to report the session status. Return values: None: no session changes are found True: login False: logout Windows Verify if psutil.users() has any value. Linux Verify all the psutil.users() asociated to a terminal. --- src/windows/ogOperations.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/windows') diff --git a/src/windows/ogOperations.py b/src/windows/ogOperations.py index bdb2a39..23e962c 100644 --- a/src/windows/ogOperations.py +++ b/src/windows/ogOperations.py @@ -8,6 +8,7 @@ import os import ctypes +import psutil import subprocess from subprocess import CalledProcessError import multiprocessing as mp @@ -64,6 +65,7 @@ def create_systray(): class OgWindowsOperations: def __init__(self): + self.session = False freeze_support() mp.set_start_method('spawn') self.systray_p = Process(target=create_systray, daemon=True) @@ -122,4 +124,20 @@ class OgWindowsOperations: raise OgError('Function not implemented') def refresh(self, ogRest): - return {"status": "WIN"} + if self.session: + session_value = 'WINS' + else: + session_value = 'WIN' + return {"status": session_value} + + def check_interactive_session_change(self): + old_status = self.session + has_logged_user = False + for user in psutil.users(): + has_logged_user = True + break + self.session = has_logged_user + + if self.session != old_status: + return self.session + return None -- cgit v1.2.3-18-g5258