Se ocupa de detectar sesiones inactivas de Citrix cuya inactividad supera el periodo de tiempo predefinido en un equipo que ejecuta Citrix Presentation Server
//Logs an error event to the event log
function logError(message, error)
{
var str = SCRIPT_NAME + ":\n" + message;
if (error)
{
var num = (error.number < 0) ? (error.number + 0x100000000) : error.number;
var estr = error.description;
if (num == 0x80010105)
estr += " [RPC_E_SERVERFAULT: The server threw an exception.]";
else if (num == 0x80041001)
estr += " [WBEM_E_FAILED]";
else if (num == 0x80010108)
estr += " [RPC_E_DISCONNECTED]";
else if (num == 0x8007007e)
estr += " [ERROR_MOD_NOT_FOUND: The specified module could not be found.]";
else if (num == 0x80041010)
estr += " [WBEM_E_INVALID_CLASS]";
else if (num == 0x8004100e)
estr += " [WBEM_E_INVALID_NAMESPACE]";
if (estr == "")
estr = "<error description not given>";
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.LogEvent(EVENT_TYPE_ERROR, str);
}
function ConvertWMITime(wmitime)
{
var year = wmitime.substring(0, 4);
var month = wmitime.substring(4, 6) - 1;
var day = wmitime.substring(6, 8);
var hour = wmitime.substring(8, 10);
var minute = wmitime.substring(10, 12);
var second = wmitime.substring(12, 14);
var UTCoffset = parseInt(wmitime.substring(21, 25), 10);
// Avoid the local time zone from confusing the issue by using the UTC
// functions to set it up.
var date = new Date(NaN);
// next check the idle time of active sessions and raise an event
// if it exceeds the limit given in the parameter
try
{
var idleSessions = false;
var e = new Enumerator( oSessions );
for (; !e.atEnd(); e.moveNext())
{
var session = e.item();
if (session.SessionState != SESSION_ACTIVE)
continue;
var last = ConvertWMITime(session.LastInputTime);
var now = ConvertWMITime(session.CurrentTime);
var diff = (now.getTime() - last.getTime()) / (1000 * 60);
if (diff > MinutesIdle)
{
idleSessions = true;
var user = "(unknown user)";
try
{
var userobj = oWMIService.Get(session.SessionUser);
user = userobj.UserName;
}
catch (ex)
{
// Citrix WMI provider only enumerates users for local authority
// If no user found, see if can extract user info from the ref string
if ( session.SessionUser != "")
{
var wmiAuth = "AuthorityName=\\\"", wmiUser = "UserName=\"";
var sessionUser = session.SessionUser;
var userName = sessionUser.substring(sessionUser.indexOf(wmiUser) + wmiUser.length, sessionUser.indexOf("\","));
var authName = sessionUser.substring(sessionUser.indexOf(wmiAuth) + wmiAuth.length, sessionUser.indexOf("\\\","));
user = authName + "\\" + userName;
}
}
try
{
var msg = "Session " + session.SessionID + " for user " +
user + " has been idle for too long."