Exemple #1
0
        public EnterpriseConnectionDetails GetSessionConnectionDetails(string sessionID, long hostID, string sessionKey)
        {
            using (var db = new MyrtilleEnterpriseDBContext())
            {
                var sessionInfo = db.Session
                                  .Where(m => m.SessionID == sessionID && m.Expire > DateTime.Now)
                                  .Select(m => new
                {
                    SessionID = m.SessionID,
                    OneTime   = m.OneTime,
                    IsAdmin   = m.IsAdmin
                })
                                  .FirstOrDefault();

                EnterpriseConnectionDetails result = null;
                if (sessionInfo != null)
                {
                    if (sessionInfo.OneTime)
                    {
                        result = (from s in db.Session
                                  from h in db.Host
                                  where s.SessionID == sessionID &&
                                  h.ID == hostID &&
                                  s.Expire > DateTime.Now
                                  select new EnterpriseConnectionDetails
                        {
                            HostID = h.ID
                            ,
                            HostName = h.HostName
                            ,
                            HostAddress = h.HostAddress
                            ,
                            VMGuid = h.VMGuid
                            ,
                            VMEnhancedMode = h.VMEnhancedMode
                            ,
                            HostType = h.HostType
                            ,
                            Domain = s.Domain
                            ,
                            Username = s.Username
                            ,
                            Password = s.Password
                            ,
                            Protocol = h.Protocol
                            ,
                            StartRemoteProgram = h.StartRemoteProgram
                        })
                                 .FirstOrDefault();
                    }
                    else
                    {
                        if (sessionInfo.IsAdmin)
                        {
                            result = (from s in db.Session
                                      from h in db.Host
                                      join sc in db.SessionHostCredentials on new { x1 = s.ID, x2 = h.ID } equals new { x1 = sc.SessionID, x2 = sc.HostID } into scl
                                      from sc in scl.DefaultIfEmpty()
                                      where s.SessionID == sessionID &&
                                      h.ID == hostID &&
                                      s.Expire > DateTime.Now
                                      select new EnterpriseConnectionDetails
                            {
                                HostID = h.ID
                                ,
                                HostName = h.HostName
                                ,
                                HostAddress = h.HostAddress
                                ,
                                VMGuid = h.VMGuid
                                ,
                                VMEnhancedMode = h.VMEnhancedMode
                                ,
                                HostType = h.HostType
                                ,
                                Domain = (h.PromptForCredentials ? sc.Domain : s.Domain)
                                ,
                                Username = (h.PromptForCredentials ? sc.Username : s.Username)
                                ,
                                Password = (h.PromptForCredentials ? sc.Password : s.Password)
                                ,
                                Protocol = h.Protocol
                                ,
                                StartRemoteProgram = h.StartRemoteProgram
                            })
                                     .FirstOrDefault();
                        }
                        else
                        {
                            result = (from s in db.Session
                                      join sg in db.SessionGroup on s.ID equals sg.SessionID
                                      join hag in db.HostAccessGroups on sg.DirectoryGroup equals hag.AccessGroup
                                      join h in db.Host on hag.HostID equals h.ID
                                      join sc in db.SessionHostCredentials on new { x1 = s.ID, x2 = h.ID } equals new { x1 = sc.SessionID, x2 = sc.HostID } into scl
                                      from sc in scl.DefaultIfEmpty()
                                      where s.SessionID == sessionID &&
                                      h.ID == hostID &&
                                      s.Expire > DateTime.Now
                                      select new EnterpriseConnectionDetails
                            {
                                HostID = h.ID
                                ,
                                HostName = h.HostName
                                ,
                                HostAddress = h.HostAddress
                                ,
                                VMGuid = h.VMGuid
                                ,
                                VMEnhancedMode = h.VMEnhancedMode
                                ,
                                HostType = h.HostType
                                ,
                                Domain = (h.PromptForCredentials ? sc.Domain : s.Domain)
                                ,
                                Username = (h.PromptForCredentials ? sc.Username : s.Username)
                                ,
                                Password = (h.PromptForCredentials ? sc.Password : s.Password)
                                ,
                                Protocol = h.Protocol
                                ,
                                StartRemoteProgram = h.StartRemoteProgram
                            })
                                     .FirstOrDefault();
                        }
                    }

                    if (result != null)
                    {
                        result.Password = CryptoHelper.AES_Decrypt(result.Password, sessionKey);
                    }

                    // when connected from the login page, the session logout is based on expiration or user action
                    // when connected from a one time url, the logout is done immediately
                    if (sessionInfo.OneTime)
                    {
                        Logout(sessionID);
                    }
                }

                return(result);
            }
        }
Exemple #2
0
        /// <summary>
        /// Get the connection details for the session and host
        /// </summary>
        /// <param name="sessionID"></param>
        /// <param name="hostID"></param>
        /// <param name="sessionKey"></param>
        /// <returns></returns>
        public EnterpriseConnectionDetails GetSessionConnectionDetails(string sessionID, long hostID, string sessionKey)
        {
            using (var db = new MyrtilleEnterpriseDBContext())
            {
                var session = db.Session
                              .Where(m => m.SessionID == sessionID && m.Expire > DateTime.Now)
                              .Select(m => new
                {
                    SessionID = m.SessionID
                    ,
                    OneTime = m.OneTime
                })
                              .FirstOrDefault();

                EnterpriseConnectionDetails result = null;
                if (session != null)
                {
                    if (session.OneTime)
                    {
                        result = (from s in db.Session
                                  from h in db.Host
                                  where s.SessionID == sessionID &&
                                  h.ID == hostID &&
                                  s.Expire > DateTime.Now
                                  select new EnterpriseConnectionDetails
                        {
                            HostID = h.ID
                            ,
                            HostName = h.HostName
                            ,
                            HostAddress = h.HostAddress
                            ,
                            Username = s.Username
                            ,
                            Password = s.Password
                            ,
                            Protocol = h.Protocol
                        })
                                 .FirstOrDefault();
                    }
                    else
                    {
                        result = (from s in db.Session
                                  join sg in db.SessionGroup on s.ID equals sg.SessionID
                                  join hag in db.HostAccessGroups on sg.DirectoryGroup equals hag.AccessGroup
                                  join h in db.Host on hag.HostID equals h.ID
                                  where s.SessionID == sessionID &&
                                  h.ID == hostID &&
                                  s.Expire > DateTime.Now
                                  select new EnterpriseConnectionDetails
                        {
                            HostID = h.ID
                            ,
                            HostName = h.HostName
                            ,
                            HostAddress = h.HostAddress
                            ,
                            Username = s.Username
                            ,
                            Password = s.Password
                            ,
                            Protocol = h.Protocol
                        })
                                 .FirstOrDefault();
                    }

                    if (result != null)
                    {
                        result.Password = AES_Decrypt(result.Password, sessionKey);
                    }

                    // when connected from the login page, the session logout is based on expiration or user action
                    // when connected from a one time url, the logout is done immediately
                    if (session.OneTime)
                    {
                        Logout(sessionID);
                    }
                }

                return(result);
            }
        }