You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.6 KiB
45 lines
1.6 KiB
-- Windows desktop session check module for auto-boot-ollama-host
|
|
-- Checks if a specific user is currently logged into a Windows desktop session
|
|
|
|
local utils = require("utils")
|
|
local ssh = require("ssh")
|
|
|
|
local session_check = {}
|
|
|
|
-- Check if user is currently logged into a Windows desktop session using quser
|
|
-- Returns true if user is logged in, false otherwise
|
|
function session_check.is_user_logged_in(config)
|
|
utils.log(("Checking if user '%s' is logged into desktop session using quser..."):format(config.SSH_USER))
|
|
|
|
-- Use quser command to check for active sessions
|
|
-- This works regardless of Windows language (looks for console/rdp sessions)
|
|
local command = "quser 2>nul | findstr /i \"console rdp-tcp#\" >nul && echo 1 || echo 0"
|
|
|
|
local ok, output, err = ssh.execute_with_output(command, config.SSH_USER, config.OLLAMA_HOST, config.SSH_PORT, config.SSH_IDENTITY_FILE)
|
|
|
|
if not ok then
|
|
utils.log(("Failed to execute quser session check command: %s"):format(tostring(err)))
|
|
return false
|
|
end
|
|
|
|
if output and output ~= "" then
|
|
utils.log("Quser session check output received: " .. output)
|
|
|
|
-- Parse the result (remove any whitespace/newlines)
|
|
local clean_output = output:gsub("%s+", "")
|
|
local result = tonumber(clean_output)
|
|
|
|
if result == 1 then
|
|
utils.log(("User '%s' has an active desktop session"):format(config.SSH_USER))
|
|
return true
|
|
else
|
|
utils.log(("User '%s' has no active desktop sessions"):format(config.SSH_USER))
|
|
return false
|
|
end
|
|
else
|
|
utils.log("No output received from quser session check command")
|
|
return false
|
|
end
|
|
end
|
|
|
|
return session_check
|
|
|