예제 #1
0
        public void UpdateSessionWatchers(object state)
        {
            int[]     winSessions  = WTSEngine.GetActiveSessions();
            Process[] rcdProcesses = GetRcordingProcesses();

            _watchers.Clear();
            foreach (int wsid in winSessions)
            {
                var watcher = new SessionWatcher()
                {
                    WinSessionId = wsid
                };
                _watchers.Add(watcher);

                var proc = Array.Find(rcdProcesses, p => p.SessionId == wsid);
                if (proc != null)
                {
                    watcher.RecordProcess = proc;
                    watcher.State         = SessionState.Recording;
                }
                else
                {
                    string user = WTSEngine.GetDomainUserBySessionId(wsid);
                    if (UserPolicy.IsUserRecording(user))
                    {
                        // logon
                    }
                    else
                    {
                        watcher.State = SessionState.Exclude;
                    }
                }
            }
        }
예제 #2
0
        public void SessionLogon(int winSessionId)
        {
            if (!Global.Config.RecordEnabled)
            {
                return;
            }
            try
            {
                while (!WTSEngine.IsSessionActive(winSessionId))
                {
                    System.Threading.Thread.Sleep(1000);
                }

                //if (checkUserPolicy && (!IsUserRecording(winSessionId)))
                //    return;

                string rcdSessionId = Guid.NewGuid().ToString("n");
                string rcdProgram   = System.IO.Path.Combine(Application.StartupPath, "rcda.exe");
                int    pid;
                if (bfbd.Common.OSVersion.IsVista)
                {
                    pid = ProcessEngine.CreateProcessAsAdmin(winSessionId, rcdProgram, rcdSessionId);
                }
                else
                {
                    pid = ProcessEngine.CreateProcessAsUser(winSessionId, rcdProgram, rcdSessionId);
                }

                if (pid != 0)
                {
                    TraceLogger.Instance.WriteLineInfo("Record process has started.");
                    TraceLogger.Instance.WriteLineInfo(string.Format("winSessionId={0}, ProcessId={1}, rcdSessionId={2}", winSessionId, pid, rcdSessionId));

                    SessionWatcher watcher = new SessionWatcher()
                    {
                        WinSessionId = winSessionId,
                        RcdSessionId = rcdSessionId,
                        ProcessId    = pid,
                    };
                    _watchers[winSessionId] = watcher;
                }
                else
                {
                    TraceLogger.Instance.WriteLineError("CreateProcessAsUser Fail. SessionId=" + winSessionId);
                }
            }
            catch (Exception ex) { TraceLogger.Instance.WriteException(ex); }
        }
예제 #3
0
        public void Start()
        {
            TraceLogger.Instance.WriteLineInfo("Privileges ajusting...");
            bool succeed = WTSEngine.SetProcessPrivileges(Process.GetCurrentProcess().Id,
                                                          bfbd.WindowsAPI.WTS.NtPrivileges.SE_ASSIGNPRIMARYTOKEN_NAME,
                                                          bfbd.WindowsAPI.WTS.NtPrivileges.SE_INCREASE_QUOTA_NAME,
                                                          bfbd.WindowsAPI.WTS.NtPrivileges.SE_TCB_NAME);

            TraceLogger.Instance.WriteLineInfo("Privileges ajusted: " + succeed);

            TraceLogger.Instance.WriteLineInfo("Record Service is starting...");
            _tasks = new PeriodTask(1000);
            _tasks.AddTask("License", this.UpdateLicenseInfo, 60 * 60, 0);
            _tasks.AddTask("Configuration", this.UpdateConfigurationFile, 60, 0);
            _tasks.AddTask("Session", this.ScanWinSessionsToRecordOrEnd, 2, 10);
            _tasks.AddTask("Storage", StorageEngine.ScanAndStoreCacheFiles, 5, 15);
            _tasks.AddTask("Restrict", StorageEngine.ScanAndRestrictLocalStore, 60 * 60, 60 * 60);
            _tasks.AddTask("AccessPolicy", this.UpdateWebAccessPolicy, 60, 0);
            _tasks.Start();
            TraceLogger.Instance.WriteLineInfo("Record Service is started.");

            if (Global.Config.AdminWebPort > 80)
            {
                try
                {
                    TraceLogger.Instance.WriteLineInfo("Admin Service is starting...");
                    _adminWeb = new Server.AdminServiceCore();
                    _adminWeb.Start();
                    TraceLogger.Instance.WriteLineInfo("Admin Service is started.");
                }
                catch (Exception ex)
                {
                    TraceLogger.Instance.WriteException(ex);
                    _adminWeb = null;
                }
            }
        }
예제 #4
0
        private void ScanWinSessionsToRecordOrEnd(object state)
        {
            int[] winSessions  = WTSEngine.GetActiveSessions();
            var   rcdProcesses = GetRcordingProcesses();

            // if not recording, record it.
            foreach (int sid in winSessions)
            {
                if (Array.Find(rcdProcesses, p => p.SessionId == sid) == null)
                {
                    string user = WTSEngine.GetDomainUserBySessionId(sid);
                    if (UserPolicy.IsUserRecording(user))
                    {
                        TraceLogger.Instance.WriteLineInfo("Start recording by configuration. user: "******"Stop recording by configuration. user: "******"Kill recording agent because double process. sessionId: " + proc.SessionId);
                    try { proc.Kill(); }
                    catch (Exception) { }
                }
                else
                {
                    sessions.Add(proc.SessionId);
                }
            }

            // dispose
            Array.ForEach(rcdProcesses, p => p.Dispose());
        }