Esempio n. 1
0
        private static int GetDefaultPort(PuttyConnectionType connectionType)
        {
            switch (connectionType)
            {
            // Return the SSH port
            case PuttyConnectionType.Raw:
            case PuttyConnectionType.Ssh:
                return(22);

            // Return the RLogin port
            case PuttyConnectionType.Rlogin:
                return(513);

            // Return the telnet port in any other case
            default:
                return(23);
            }
        }
Esempio n. 2
0
            public Options(string hostName, PuttyConnectionType connectionType, int port, string proxyHost, int proxyPort, PuttyProxyType proxyType, bool enableX11)
            {
                this.connectionType = connectionType;

                // Create the command line string for the Putty verbose option and leave any other property unchanged.
                this.Verbose = new Property <bool, int>
                {
                    GetCmdLine =
                        () => this.Verbose.Value ? "-v" : string.Empty
                };

                // Create the command line string  for the Putty liogin name option and leave any other property unchanged.
                this.LoginName = new Property <string, int>
                {
                    GetCmdLine =
                        () => string.IsNullOrEmpty(this.LoginName.Value)
                                                       ? string.Empty
                                                       : "-l " + this.LoginName.Value
                };

                // Create the command line string for the Putty password option and leave any other property unchanged.
                this.Password = new Property <string, int>
                {
                    GetCmdLine =
                        () => string.IsNullOrEmpty(this.Password.Value)
                                                      ? string.Empty
                                                      : "-pw " + this.Password.Value
                };

                // Create the command line string for the Putty compression option and leave any other property unchanged.
                this.Compression = new Property <bool, int>
                {
                    GetCmdLine =
                        () => this.Compression.Value
                                                         ? "-C"
                                                         : string.Empty
                };

                // Set the hostname
                this.HostName = new Property <string, int> {
                    ClassName = "EDIT", Identifier = 1044, Value = hostName
                };

                this.EnableX11 = new Property <bool, int> {
                    ClassName = "BUTTON", Identifier = 0x413, Value = enableX11
                };

                this.ProxyHost = new Property <string, int> {
                    ClassName = "EDIT", Identifier = 0x41B, Value = proxyHost
                };

                this.ProxyPort = new Property <int, int> {
                    ClassName = "EDIT", Identifier = 0x41D, Value = proxyPort
                };

                this.ProxyType = new Property <PuttyProxyType, Dictionary <PuttyProxyType, int> > {
                    ClassName = "EDIT", Value = proxyType
                };

                this.ProxyType.Identifier = new Dictionary <PuttyProxyType, int> {
                    {
                        PuttyProxyType.HTTP,
                        0x417
                    },
                    {
                        PuttyProxyType.Local,
                        0x419
                    },
                    {
                        PuttyProxyType.None,
                        0x414
                    },
                    {
                        PuttyProxyType.SOCKS4,
                        0x415
                    },
                    {
                        PuttyProxyType.SOCKS5,
                        0x416
                    },
                    {
                        PuttyProxyType.Telnet,
                        0x418
                    }
                };

                this.ConnectionType = new Property <PuttyConnectionType, int[]>
                {
                    ClassName  = "BUTTON",
                    Identifier = new[] { 1049, 1050, 1051, 1052 },
                    Value      = connectionType,
                    GetCmdLine = delegate
                    {
                        // serial port is not supported by putty command line
                        switch (this.ConnectionType.Value)
                        {
                        case PuttyConnectionType.Telnet:
                            return("-telnet");

                        case PuttyConnectionType.Rlogin:
                            return("-rlogin");

                        case PuttyConnectionType.Raw:
                            return("-raw");

                        default:
                            return("-ssh");
                        }
                    }
                };

                if (port < 1 || port > 65535)
                {
                    port = GetDefaultPort(connectionType);
                }

                this.Port = new Property <int, int>
                {
                    ClassName  = "EDIT",
                    Identifier = 1046,
                    Value      = port,
                    GetCmdLine = () => "-P " + this.Port.Value
                };

                this.CloseWindowOnExit = new Property <PuttyCloseWindowOnExit, Dictionary <PuttyCloseWindowOnExit, int> >();

                this.CloseWindowOnExit.Identifier = new Dictionary <PuttyCloseWindowOnExit, int> {
                    {
                        PuttyCloseWindowOnExit.OnlyOnCleanExit,
                        1065
                    },
                    {
                        PuttyCloseWindowOnExit.Always,
                        1063
                    },
                    {
                        PuttyCloseWindowOnExit.Never,
                        1064
                    }
                };
            }