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-26 13:02:45 +0100 |
commit | a36c4daa23d32aeee9539374aa591152ef2c914b (patch) | |
tree | b31459ed9704dfc0ba7e6e98a0514e0c6c068249 /src/linux/ogOperations.py | |
parent | a1bd0c36f3be137e908540e5ea50354fd9293ca3 (diff) |
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.
Diffstat (limited to 'src/linux/ogOperations.py')
-rw-r--r-- | src/linux/ogOperations.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py index 4728201..bbce41a 100644 --- a/src/linux/ogOperations.py +++ b/src/linux/ogOperations.py @@ -7,6 +7,7 @@ # (at your option) any later version. import os +import psutil import subprocess from subprocess import CalledProcessError from src.log import OgError @@ -15,6 +16,9 @@ from src.ogRest import ThreadState class OgLinuxOperations: + def __init__(self): + self.session = False + def _restartBrowser(self, url): raise OgError('Function not implemented') @@ -66,4 +70,21 @@ class OgLinuxOperations: raise OgError('Function not implemented') def refresh(self, ogRest): - return {"status": "LINUX"} + if self.session: + session_value = 'LINUXS' + else: + session_value = 'LINUX' + return {"status": session_value} + + def check_interactive_session_change(self): + old_status = self.session + has_logged_user = False + for user in psutil.users(): + if user.terminal: + has_logged_user = True + break + self.session = has_logged_user + + if self.session != old_status: + return self.session + return None |