Example #1
0
        /// <summary>
        /// Handle commands from inputs pipe
        /// </summary>
        /// <param name="command"></param>
        /// <param name="data"></param>
        private static void PipeMessaging_OnMessageReceivedEvent(RemoteSessionCommand command, string data = "")
        {
            switch (command)
            {
            case RemoteSessionCommand.SendStartProgram:
                WriteOutput(command, "Program received");
                StartProgram = data;
                break;

            case RemoteSessionCommand.RequestFullscreenUpdate:
                WriteOutput(command, data);
                ClearOrExitTerminal(data);
                break;

            case RemoteSessionCommand.SendUserDomain:
                WriteOutput(command, data);
                Domain = data;
                break;

            case RemoteSessionCommand.SendUserName:
                WriteOutput(command, data);
                UserName = string.IsNullOrEmpty(Domain) ? data : string.Format("{0}\\{1}", Domain, data);
                break;

            case RemoteSessionCommand.SendServerAddress:
                WriteOutput(command, data);
                ServerAddress = data;
                break;

            case RemoteSessionCommand.SendUserPassword:
                WriteOutput(command, "Credentials received");
                Password = data;
                break;

            case RemoteSessionCommand.ConnectClient:
                WriteOutput(command, "Connecting to remote host");
                ConnectSSHClient();
                break;

            case RemoteSessionCommand.CloseClient:
                WriteOutput(command, "Disconnecting from remote host");
                pipeMessaging.ClosePipes();
                break;

            case RemoteSessionCommand.SendKeyUnicode:
                WriteOutput(command, data);
                HandleKeyboardInput(data);
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Handle commands from inputs pipe
        /// </summary>
        /// <param name="command"></param>
        /// <param name="data"></param>
        private static void PipeMessaging_OnMessageReceivedEvent(RemoteSessionCommand command, string data = "")
        {
            switch (command)
            {
            case RemoteSessionCommand.RequestFullscreenUpdate:
                WriteOutput(command, data);
                ClearOrExitTerminal(data);
                break;

            case RemoteSessionCommand.SendUserName:
                WriteOutput(command, data);
                UserName = data;
                break;

            case RemoteSessionCommand.SendServerAddress:
                WriteOutput(command, data);
                ServerAddress = data;
                break;

            case RemoteSessionCommand.SendUserPassword:
                WriteOutput(command, "Credentials received");
                Password = data;
                break;

            case RemoteSessionCommand.ConnectClient:
                WriteOutput(command, "Connecting to remote host");
                ConnectSSHClient();
                break;

            case RemoteSessionCommand.CloseClient:
                WriteOutput(command, "Disconnecting from remote host");
                pipeMessaging.ClosePipes();
                break;

            case RemoteSessionCommand.SendKeyUnicode:
                WriteOutput(command, string.IsNullOrEmpty(data) ? "," : data);
                HandleKeyboardInput(string.IsNullOrEmpty(data) ? "," : data);
                break;

            case RemoteSessionCommand.SetStatMode:
            case RemoteSessionCommand.SetDebugMode:
            case RemoteSessionCommand.SetCompatibilityMode:
                WriteOutput(command, "Reloading terminal");
                pipeMessaging.SendUpdatesPipeMessage("reload");
                break;
            }
        }
Example #3
0
        /// <summary>
        /// Handle messages from input pipe
        /// </summary>
        /// <param name="command"></param>
        /// <param name="data"></param>
        private static void PipeMessaging_OnMessageReceivedEvent(string command, string data)
        {
            switch ((RemoteSessionCommand)RemoteSessionCommandMapping.FromPrefix[command])
            {
            case RemoteSessionCommand.RequestFullscreenUpdate:
                WriteOutput(command, data);
                CheckSSHClientState();
                break;

            case RemoteSessionCommand.SendUserName:
                WriteOutput(command, data);
                UserName = data;
                break;

            case RemoteSessionCommand.SendServerAddress:
                WriteOutput(command, data);
                ServerAddress = data;
                break;

            case RemoteSessionCommand.SendUserPassword:
                WriteOutput(command, "Credentials received, connecting to remote host");
                ConnectSSHClient(data);
                break;

            case RemoteSessionCommand.CloseRdpClient:
                WriteOutput(command, "Disconnect from remote host");
                pipeMessaging.ClosePipes();
                break;

            case RemoteSessionCommand.SendKeyScancode:
                WriteOutput(command, data);
                HandleKeyboardInput(data, true);
                break;

            case RemoteSessionCommand.SendKeyUnicode:
                WriteOutput(command, data);
                HandleKeyboardInput(data, false);
                break;
            }
        }
Example #4
0
        private static int Main(string[] args)
        {
            // enable the code below for debug; disable otherwise
            //if (Environment.UserInteractive)
            //{
            //    MessageBox.Show("Attach the .NET debugger to the 'SSH Debug' Myrtille.SSH.exe process now for debug. Click OK when ready...", "SSH Debug");
            //}
            //else
            //{
            //    Thread.Sleep(10000);
            //}

            // logger
            XmlConfigurator.Configure();

            string argKeyValueSeparator = ":";

            foreach (string arg in args)
            {
                var argParts = arg.Trim().Split(argKeyValueSeparator.ToCharArray(), 2);
                parseCommandLineArg(argParts[0].ToLower(), (argParts.Length > 1 ? argParts[1] : ""));
            }

            if (!ValidConfig)
            {
                return((int)RemoteSessionExitCode.InvalidConfiguration);
            }

            pipeMessaging = new PipeMessaging(RemoteSessionID);

            if (pipeMessaging.ConnectPipes())
            {
                pipeMessaging.OnMessageReceivedEvent += PipeMessaging_OnMessageReceivedEvent;

                try
                {
                    pipeMessaging.ReadInputsPipe();
                }
                catch (Exception e)
                {
                    if (ConsoleOutput)
                    {
                        Console.WriteLine(e.Message);
                    }

                    Trace.TraceError("SSH error, remote session {0} ({1})", RemoteSessionID, e);

                    if (e is SshAuthenticationException)
                    {
                        if (e.Message == "Missing Username")
                        {
                            return((int)RemoteSessionExitCode.MissingUserName);
                        }
                        else if (e.Message == "Missing Password")
                        {
                            return((int)RemoteSessionExitCode.MissingPassword);
                        }
                        else
                        {
                            return((int)RemoteSessionExitCode.InvalidCredentials);
                        }
                    }

                    return((int)RemoteSessionExitCode.Unknown);
                }
                finally
                {
                    pipeMessaging.ClosePipes();
                    DisconnectSSHClient();
                }
            }

            return((int)RemoteSessionExitCode.Success);
        }