Exemple #1
0
        public bool AddSessionHostCredentials(EnterpriseHostSessionCredentials credentials)
        {
            var success = false;

            using (var db = new MyrtilleEnterpriseDBContext())
            {
                var session = db.Session.FirstOrDefault(m => m.SessionID == credentials.SessionID);
                if (session != null && db.Host.Any(m => m.ID == credentials.HostID))
                {
                    var sessionHost = db.SessionHostCredentials.FirstOrDefault(m =>
                                                                               m.SessionID == session.ID &&
                                                                               m.HostID == credentials.HostID);

                    if (sessionHost != null)
                    {
                        db.SessionHostCredentials.Remove(sessionHost);
                    }

                    sessionHost = new SessionHostCredential
                    {
                        SessionID = session.ID,
                        HostID    = credentials.HostID,
                        Domain    = credentials.Domain,
                        Username  = credentials.Username,
                        Password  = CryptoHelper.AES_Encrypt(CryptoHelper.RDP_Encrypt(credentials.Password), credentials.SessionKey)
                    };

                    db.SessionHostCredentials.Add(sessionHost);
                    db.SaveChanges();
                    success = true;
                }
            }

            return(success);
        }
Exemple #2
0
        /// <summary>
        /// Add override credentials for specific session host
        /// </summary>
        /// <param name="credentials"></param>
        /// <returns></returns>
        public bool AddSessionHostCredentials(EnterpriseHostSessionCredentials credentials)
        {
            using (var db = new MyrtilleEnterpriseDBContext())
            {
                var session = db.Session.FirstOrDefault(m => m.SessionID == credentials.SessionID);

                if (session == null)
                {
                    return(false);
                }

                if (!db.Host.Any(m => m.ID == credentials.HostID))
                {
                    return(false);
                }

                var sessionHost = db.SessionHostCredentials.FirstOrDefault(m => m.SessionID == session.ID &&
                                                                           m.HostID == m.HostID);

                if (sessionHost != null)
                {
                    db.SessionHostCredentials.Remove(sessionHost);
                }

                sessionHost = new SessionHostCredential
                {
                    SessionID = session.ID,
                    HostID    = credentials.HostID,
                    Username  = credentials.Username,
                    Password  = AES_Encrypt(RDPCryptoHelper.EncryptPassword(credentials.Password), credentials.SessionKey),
                };


                db.SessionHostCredentials.Add(sessionHost);
                db.SaveChanges();

                return(true);
            }
        }