summaryrefslogtreecommitdiffstats
path: root/src/linux/ogOperations.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-11-13 19:41:20 +0100
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-11-15 13:23:28 +0100
commit693c4f4c5c096e067b7d5621f595e26f2b794824 (patch)
tree3bf778629ccf42159f7f98bb12168b4c2b8ecce1 /src/linux/ogOperations.py
parent7e8d5e71ce2a441faa85a178481f4ef30a7901d5 (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/linux/ogOperations.py')
-rw-r--r--src/linux/ogOperations.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py
index 4728201..10efaa4 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,28 @@ 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:
+ try:
+ process = psutil.Process(user.pid)
+ env = process.environ()
+ if "DISPLAY" in env or "WAYLAND_DISPLAY" in env:
+ has_logged_user = True
+ break
+
+ except (psutil.NoSuchProcess, psutil.AccessDenied):
+ continue
+ self.session = has_logged_user
+
+ if self.session != old_status:
+ return self.session
+ return None