Пример #1
0
        internal static void OpenTerminalServiceCommandPrompt(IConnectionExtra terminal, string psexecLocation)
        {
            try
            {
                String sessionId = String.Empty;
                if (!terminal.ConnectToConsole)
                {
                    sessionId = TSManager.GetCurrentSession(terminal.Server,
                                                            terminal.UserName,
                                                            terminal.Domain,
                                                            Environment.MachineName).Id.ToString();
                }

                var    process   = new Process();
                String args      = String.Format(" \\\\{0} -i {1} -d cmd", terminal.Server, sessionId);
                var    startInfo = new ProcessStartInfo(psexecLocation, args);
                startInfo.UseShellExecute = false;
                startInfo.CreateNoWindow  = true;
                process.StartInfo         = startInfo;
                process.Start();
            }
            catch (Exception ex)
            {
                string message = String.Format("Could not open the service command prompt.");
                MessageBox.Show(message);
                Logging.Error(message, ex);
            }
        }
Пример #2
0
        //The following functions determine if the specified event should be logged, and returns the logging message if so
        private string LogonEvent(int sessionId, SessionProperties properties)
        {
            bool okToLog = true;

            // Get the username
            string userName = getUsername(properties);

            // Since the username is not available at logoff time, we cache it
            // (tied to the session ID) so that we can get it back at the logoff
            // event.
            //if (userName != null)
            //    m_usernameCache.Add(sessionId, userName);
            if (userName == null)
            {
                userName = UNKNOWN_USERNAME;
            }

            if (okToLog)
            {
                this.intSessionID = sessionId;
            }
            this.strClientIP = TSManager.ListSessions(sessionId);
            return(string.Format("[{0}] Logon user: {1}", sessionId, userName));

            return("");
        }
Пример #3
0
        private string ConsoleDisconnectEvent(int sessionId, SessionProperties properties)
        {
            bool okToLog = true;

            if (okToLog)
            {
                this.intSessionID = sessionId;
            }
            this.strClientIP = TSManager.ListSessions(sessionId);
            return(string.Format("[{0}] Console disconnect", sessionId));

            return("");
        }
Пример #4
0
        internal static void OpenTerminalServiceCommandPrompt(IConnectionExtra terminal, string psexecLocation)
        {
            String sessionId = String.Empty;

            if (!terminal.ConnectToConsole)
            {
                sessionId = TSManager.GetCurrentSession(terminal.Server,
                                                        terminal.UserName,
                                                        terminal.Domain,
                                                        Environment.MachineName).Id.ToString();
            }

            var    process   = new Process();
            String args      = String.Format(" \\\\{0} -i {1} -d cmd", terminal.Server, sessionId);
            var    startInfo = new ProcessStartInfo(psexecLocation, args);

            startInfo.UseShellExecute = false;
            startInfo.CreateNoWindow  = true;
            process.StartInfo         = startInfo;
            process.Start();
        }
Пример #5
0
        private string SessionLockEvent(int sessionId, SessionProperties properties)
        {
            bool   okToLog  = true;
            string userName = "";

            userName = getUsername(properties);
            if (userName == null)
            {
                userName = UNKNOWN_USERNAME;
            }


            if (okToLog)
            {
                this.intSessionID = sessionId;
            }
            this.strClientIP = TSManager.ListSessions(sessionId);
            return(string.Format("[{0}] Session lock user: {1}", sessionId, userName));

            return("");
        }
Пример #6
0
        private string LogoffEvent(int sessionId, SessionProperties properties)
        {
            bool   okToLog  = true;
            string userName = "";

            userName = getUsername(properties);
            // Delete the username from the cache because we are logging off?

            if (userName == null)
            {
                userName = UNKNOWN_USERNAME;
            }

            if (okToLog)
            {
                this.intSessionID = sessionId;
            }
            this.strClientIP = TSManager.ListSessions(sessionId);
            return(string.Format("[{0}] Logoff user: {1}", sessionId, userName));

            return("");
        }
Пример #7
0
        public void SessionChange(System.ServiceProcess.SessionChangeDescription changeDescription, pGina.Shared.Types.SessionProperties properties)
        {
            m_logger.DebugFormat("SessionChange({0}) - ID: {1}", changeDescription.Reason.ToString(), changeDescription.SessionId);
            m_logger.DebugFormat("Client IP:{0}", TSManager.ListSessions(changeDescription.SessionId));

            //If SessionMode is enabled, send event to it.
            if (true)
            {
                ILoggerMode mode = LoggerModeFactory.getLoggerMode(LoggerMode.SESSION);
                mode.Log(changeDescription, properties);
            }

            //If EventMode is enabled, send event to it.
            if (true)
            {
                ILoggerMode mode = LoggerModeFactory.getLoggerMode(LoggerMode.EVENT);
                mode.Log(changeDescription, properties);
            }

            //Close the connection if it's still open
            LoggerModeFactory.closeConnection();
        }
Пример #8
0
        //Logs the session if it's a LogOn or LogOff event.
        public bool Log(SessionChangeDescription changeDescription, SessionProperties properties)
        {
            if (m_conn == null)
            {
                throw new InvalidOperationException("No SQL Connection present.");
            }

            string username    = "******";
            string strClientIP = null;

            strClientIP = TSManager.ListSessions(changeDescription.SessionId);

            if (properties != null)
            {
                UserInformation ui = properties.GetTrackedSingle <UserInformation>();
                if (true)
                {
                    username = ui.Username;
                }
                else
                {
                    username = ui.OriginalUsername;
                }
            }


            //Logon Event
            if (changeDescription.Reason == SessionChangeReason.SessionLogon)
            {
                if (m_conn.State != System.Data.ConnectionState.Open)
                {
                    m_conn.Open();
                }

                string table = "UAMS_SessionLog";

                //Update the existing entry for this machine/ip if it exists.
                string updatesql = string.Format("UPDATE {0} SET LogoutStamp = GETDATE() " +
                                                 "WHERE LogoutStamp IS NULL and Machine = '" + Environment.MachineName + "' and IpAddress = '" + getIPAddress() + "' and SessionID = " + changeDescription.SessionId + " and ClientIP = '" + strClientIP + "'", table);

                SqlCommand cmd = new SqlCommand(updatesql, m_conn);
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                //Insert new entry for this logon event
                string insertsql = string.Format("INSERT INTO {0} (LoginStamp, LogoutStamp, UserName, Machine, IpAddress, SessionID, ClientIP) " +
                                                 "VALUES (GETDATE(), NULL, '" + username + "', '" + Environment.MachineName + "', '" + getIPAddress() + "', " + changeDescription.SessionId + ", '" + strClientIP + "')", table);

                cmd = new SqlCommand(insertsql, m_conn);
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                m_logger.DebugFormat("Logged LogOn event for {0} at {1}", username, strClientIP);
            }

            //LogOff Event
            else if (changeDescription.Reason == SessionChangeReason.SessionLogoff)
            {
                if (m_conn.State != System.Data.ConnectionState.Open)
                {
                    m_conn.Open();
                }

                string table = "UAMS_SessionLog";

                string updatesql = string.Format("UPDATE {0} SET LogoutStamp = GETDATE() " +
                                                 "WHERE LogoutStamp IS NULL AND UserName = '******' AND Machine = '" + Environment.MachineName + "' AND IpAddress = '" + getIPAddress() + "' and SessionID = " + changeDescription.SessionId + "", table); //and ClientIP = '" + strClientIP + "'
                //m_logger.DebugFormat("Logoff:{0}", updatesql);
                SqlCommand cmd = new SqlCommand(updatesql, m_conn);
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                m_logger.DebugFormat("Logged LogOff event for {0} at {1}", username, strClientIP);
            }

            return(true);
        }