Exemple #1
0
        /// <summary>
        /// connect the rdp server
        /// </summary>
        /// <remarks>
        /// the rdp authentication is delegated to the rdp server or connection broker (if applicable)
        /// </remarks>
        private bool ConnectRemoteServer()
        {
            // connection parameters
            var loginServer   = string.IsNullOrEmpty(server.Value) ? "localhost" : server.Value;
            var loginDomain   = domain.Value;
            var loginUser     = user.Value;
            var loginPassword = string.IsNullOrEmpty(passwordHash.Value) ? password.Value : RDPCryptoHelper.DecryptPassword(passwordHash.Value);
            var loginProtocol = SecurityProtocolEnum.auto;

            // connect an host from the hosts list or from a one time session url
            if (_enterpriseSession != null && Request["SD"] != null)
            {
                long hostId  = 0;
                long lResult = 0;
                if (long.TryParse(Request["SD"], out lResult))
                {
                    hostId = lResult;
                }

                try
                {
                    // retrieve the host connection details
                    var connection = _enterpriseClient.GetSessionConnectionDetails(_enterpriseSession.SessionID, hostId, _enterpriseSession.SessionKey);
                    if (connection == null)
                    {
                        System.Diagnostics.Trace.TraceInformation("Unable to retrieve host {0} connection details (invalid host or one time session url already used?)", hostId);
                        return(false);
                    }

                    loginServer   = !string.IsNullOrEmpty(connection.HostAddress) ? connection.HostAddress : connection.HostName;
                    loginDomain   = string.Empty;   // domain is defined into myrtille services config
                    loginUser     = connection.Username;
                    loginPassword = RDPCryptoHelper.DecryptPassword(connection.Password);
                    loginProtocol = connection.Protocol;
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Trace.TraceError("Failed to retrieve host {0} connection details ({1})", hostId, exc);
                    return(false);
                }
            }

            // remote clipboard access
            var  allowRemoteClipboard = true;
            bool bResult = false;

            if (bool.TryParse(ConfigurationManager.AppSettings["allowRemoteClipboard"], out bResult))
            {
                allowRemoteClipboard = bResult;
            }

            // remove any active remote session (disconnected?)
            if (RemoteSession != null)
            {
                // unset the remote session for the current http session
                HttpContext.Current.Session[HttpSessionStateVariables.RemoteSession.ToString()] = null;
                RemoteSession = null;
            }

            // create a new remote session
            try
            {
                HttpContext.Current.Application.Lock();

                // auto-increment the remote sessions counter
                // note that it doesn't really count the active remote sessions... it's just an auto-increment for the remote session id, ensuring it's unique...
                var remoteSessionsCounter = (int)HttpContext.Current.Application[HttpApplicationStateVariables.RemoteSessionsCounter.ToString()];
                remoteSessionsCounter++;

                // create the remote session
                RemoteSession = new RemoteSession
                {
                    Id                   = remoteSessionsCounter,
                    State                = RemoteSessionState.NotConnected,
                    ServerAddress        = loginServer,
                    UserDomain           = loginDomain,
                    UserName             = loginUser,
                    UserPassword         = loginPassword,
                    ClientWidth          = int.Parse(width.Value),
                    ClientHeight         = int.Parse(height.Value),
                    StartProgram         = program.Value,
                    AllowRemoteClipboard = allowRemoteClipboard,
                    SecurityProtocol     = loginProtocol
                };

                // bind the remote session to the current http session
                HttpContext.Current.Session[HttpSessionStateVariables.RemoteSession.ToString()] = RemoteSession;

                // update the remote sessions auto-increment counter
                HttpContext.Current.Application[HttpApplicationStateVariables.RemoteSessionsCounter.ToString()] = remoteSessionsCounter;
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to create remote session ({0})", exc);
                RemoteSession = null;
            }
            finally
            {
                HttpContext.Current.Application.UnLock();
            }

            // connect it
            if (RemoteSession != null)
            {
                try
                {
                    // update the remote session state
                    RemoteSession.State = RemoteSessionState.Connecting;

                    // create pipes for the web gateway and the rdp client to talk
                    RemoteSession.Manager.Pipes.CreatePipes();

                    // the rdp client does connect the pipes when it starts; when it stops (either because it was closed, crashed or because the rdp session had ended), pipes are released
                    // as the process command line can be displayed into the task manager / process explorer, the connection settings (including user credentials) are now passed to the rdp client through the inputs pipe
                    // use http://technet.microsoft.com/en-us/sysinternals/dd581625 to track the existing pipes
                    RemoteSession.Manager.Client.StartProcess(
                        RemoteSession.Id,
                        RemoteSession.ServerAddress,
                        RemoteSession.UserDomain,
                        RemoteSession.UserName,
                        RemoteSession.StartProgram,
                        RemoteSession.ClientWidth,
                        RemoteSession.ClientHeight,
                        RemoteSession.AllowRemoteClipboard,
                        RemoteSession.SecurityProtocol);
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Trace.TraceError("Failed to connect the remote session {0} ({1})", RemoteSession.Id, exc);
                    connectError.InnerText = "Failed to connect! ensure myrtille services are running";
                    return(false);
                }
            }
            else
            {
                connectError.InnerText = "Failed to create remote session!";
                return(false);
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// connect the remote server
        /// </summary>
        /// <remarks>
        /// authentication is delegated to the remote server or connection broker (if applicable)
        /// </remarks>
        private bool ConnectRemoteServer()
        {
            // connection parameters
            string loginHostName       = null;
            var    loginHostType       = (HostTypeEnum)Convert.ToInt32(hostType.Value);
            var    loginProtocol       = (SecurityProtocolEnum)securityProtocol.SelectedIndex;
            var    loginServer         = string.IsNullOrEmpty(server.Value) ? "localhost" : server.Value;
            var    loginVMGuid         = vmGuid.Value;
            var    loginVMEnhancedMode = vmEnhancedMode.Checked;
            var    loginDomain         = domain.Value;
            var    loginUser           = user.Value;
            var    loginPassword       = string.IsNullOrEmpty(passwordHash.Value) ? password.Value : RDPCryptoHelper.DecryptPassword(passwordHash.Value);
            var    startProgram        = program.Value;

            // connect an host from the hosts list or from a one time session url
            if (_enterpriseSession != null && Request["SD"] != null)
            {
                long hostId;
                if (!long.TryParse(Request["SD"], out hostId))
                {
                    hostId = 0;
                }

                try
                {
                    // retrieve the host connection details
                    var connection = _enterpriseClient.GetSessionConnectionDetails(_enterpriseSession.SessionID, hostId, _enterpriseSession.SessionKey);
                    if (connection == null)
                    {
                        System.Diagnostics.Trace.TraceInformation("Unable to retrieve host {0} connection details (invalid host or one time session url already used?)", hostId);
                        return(false);
                    }
                    loginHostName       = connection.HostName;
                    loginHostType       = connection.HostType;
                    loginProtocol       = connection.Protocol;
                    loginServer         = !string.IsNullOrEmpty(connection.HostAddress) ? connection.HostAddress : connection.HostName;
                    loginVMGuid         = connection.VMGuid;
                    loginVMEnhancedMode = connection.VMEnhancedMode;
                    loginDomain         = connection.Domain;
                    loginUser           = connection.Username;
                    loginPassword       = RDPCryptoHelper.DecryptPassword(connection.Password);
                    startProgram        = connection.StartRemoteProgram;
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Trace.TraceError("Failed to retrieve host {0} connection details ({1})", hostId, exc);
                    return(false);
                }
            }

            // remove any active remote session (disconnected?)
            if (RemoteSession != null)
            {
                // unset the remote session for the current http session
                Session[HttpSessionStateVariables.RemoteSession.ToString()] = null;
                RemoteSession = null;
            }

            // create a new remote session
            try
            {
                // create the remote session
                RemoteSession = new RemoteSession(
                    Guid.NewGuid(),
                    RemoteSessionState.NotConnected,
                    loginHostName,
                    loginHostType,
                    loginProtocol,
                    loginServer,
                    loginVMGuid,
                    loginVMEnhancedMode,
                    loginDomain,
                    loginUser,
                    loginPassword,
                    int.Parse(width.Value),
                    int.Parse(height.Value),
                    startProgram,
                    _allowRemoteClipboard,
                    _allowFileTransfer,
                    _allowPrintDownload,
                    _allowSessionSharing,
                    Session.SessionID
                    );

                // bind the remote session to the current http session
                Session[HttpSessionStateVariables.RemoteSession.ToString()] = RemoteSession;
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to create remote session ({0})", exc);
                RemoteSession = null;
            }

            // connect it
            if (RemoteSession != null)
            {
                try
                {
                    // update the remote session state
                    RemoteSession.State = RemoteSessionState.Connecting;

                    // create pipes for the web gateway and the host client to talk
                    RemoteSession.Manager.Pipes.CreatePipes();

                    // the host client does connect the pipes when it starts; when it stops (either because it was closed, crashed or because the remote session had ended), pipes are released
                    // as the process command line can be displayed into the task manager / process explorer, the connection settings (including user credentials) are now passed to the host client through the inputs pipe
                    // use http://technet.microsoft.com/en-us/sysinternals/dd581625 to track the existing pipes
                    RemoteSession.Manager.HostClient.StartProcess(
                        RemoteSession.Id,
                        RemoteSession.HostType,
                        RemoteSession.SecurityProtocol,
                        RemoteSession.ServerAddress,
                        RemoteSession.VMGuid,
                        RemoteSession.UserDomain,
                        RemoteSession.UserName,
                        RemoteSession.StartProgram,
                        RemoteSession.ClientWidth,
                        RemoteSession.ClientHeight,
                        RemoteSession.AllowRemoteClipboard,
                        RemoteSession.AllowPrintDownload);
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Trace.TraceError("Failed to connect the remote session {0} ({1})", RemoteSession.Id, exc);
                    connectError.InnerText = "Failed to connect! ensure myrtille services are running";
                    return(false);
                }
            }
            else
            {
                connectError.InnerText = "Failed to create remote session!";
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// connect the remote server
        /// </summary>
        /// <remarks>
        /// authentication is delegated to the remote server or connection broker (if applicable)
        /// </remarks>
        private bool ConnectRemoteServer()
        {
            // connection parameters
            string loginHostName       = null;
            var    loginHostType       = (HostTypeEnum)Convert.ToInt32(hostType.Value);
            var    loginProtocol       = (SecurityProtocolEnum)securityProtocol.SelectedIndex;
            var    loginServer         = string.IsNullOrEmpty(server.Value) ? "localhost" : server.Value;
            var    loginVMGuid         = vmGuid.Value;
            var    loginVMEnhancedMode = vmEnhancedMode.Checked;
            var    loginDomain         = domain.Value;
            var    loginUser           = user.Value;
            var    loginPassword       = string.IsNullOrEmpty(passwordHash.Value) ? password.Value : RDPCryptoHelper.DecryptPassword(passwordHash.Value);
            var    startProgram        = program.Value;

            // connect an host from the hosts list or from a one time session url
            if (_enterpriseSession != null && Request["SD"] != null)
            {
                long hostId;
                if (!long.TryParse(Request["SD"], out hostId))
                {
                    hostId = 0;
                }

                try
                {
                    // retrieve the host connection details
                    var connection = _enterpriseClient.GetSessionConnectionDetails(_enterpriseSession.SessionID, hostId, _enterpriseSession.SessionKey);
                    if (connection == null)
                    {
                        System.Diagnostics.Trace.TraceInformation("Unable to retrieve host {0} connection details (invalid host or one time session url already used?)", hostId);
                        return(false);
                    }
                    loginHostName       = connection.HostName;
                    loginHostType       = connection.HostType;
                    loginProtocol       = connection.Protocol;
                    loginServer         = !string.IsNullOrEmpty(connection.HostAddress) ? connection.HostAddress : connection.HostName;
                    loginVMGuid         = connection.VMGuid;
                    loginVMEnhancedMode = connection.VMEnhancedMode;
                    loginDomain         = connection.Domain;
                    loginUser           = connection.Username;
                    loginPassword       = RDPCryptoHelper.DecryptPassword(connection.Password);
                    startProgram        = connection.StartRemoteProgram;
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Trace.TraceError("Failed to retrieve host {0} connection details ({1})", hostId, exc);
                    return(false);
                }
            }

            // remove any active remote session (disconnected?)
            if (RemoteSession != null)
            {
                // unset the remote session for the current http session
                Session[HttpSessionStateVariables.RemoteSession.ToString()] = null;
                RemoteSession = null;
            }

            // create a new remote session
            try
            {
                // create the remote session
                RemoteSession = new RemoteSession(
                    Guid.NewGuid(),
                    RemoteSessionState.NotConnected,
                    loginHostName,
                    loginHostType,
                    loginProtocol,
                    loginServer,
                    loginVMGuid,
                    loginVMEnhancedMode,
                    loginDomain,
                    loginUser,
                    loginPassword,
                    int.Parse(width.Value),
                    int.Parse(height.Value),
                    startProgram,
                    _allowRemoteClipboard,
                    _allowFileTransfer,
                    _allowPrintDownload,
                    _allowSessionSharing,
                    Session.SessionID
                    );

                // bind the remote session to the current http session
                Session[HttpSessionStateVariables.RemoteSession.ToString()] = RemoteSession;
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to create remote session ({0})", exc);
                RemoteSession = null;
            }

            // connect it
            if (RemoteSession != null)
            {
                RemoteSession.State = RemoteSessionState.Connecting;
            }
            else
            {
                connectError.InnerText = "Failed to create remote session!";
                return(false);
            }

            return(true);
        }