Exemplo n.º 1
0
        /// <summary>
        /// Start benchmark
        /// </summary>
        /// <returns></returns>
        public CommandResult Start()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();

            ITerminalEmulatorService emulatorService =
                BenchmarkPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.terminalemulator", typeof(ITerminalEmulatorService)) as ITerminalEmulatorService;
            ITerminalSessionsService sessionService =
                (ITerminalSessionsService)BenchmarkPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.terminalsessions", typeof(ITerminalSessionsService));

            if (emulatorService == null || sessionService == null)
            {
                return(CommandResult.Ignored);
            }

            ITerminalSettings settings = emulatorService.CreateDefaultTerminalSettings(GetTerminalCaption(), null);

            settings.BeginUpdate();
            settings.Encoding = Poderosa.ConnectionParam.EncodingType.UTF8;
            settings.EndUpdate();
            ITerminalConnection          connection   = GetTerminalConnection();
            ITerminalSessionStartCommand startCommand = sessionService.TerminalSessionStartCommand;
            ITerminalSession             session      = startCommand.StartTerminalSession(_target, connection, settings);

            StartBenchmarkThread(emulatorService.TerminalEmulatorOptions, session);

            return(CommandResult.Succeeded);
        }
Exemplo n.º 2
0
            public override void OnChange(ICommandTarget target, bool is_checked)
            {
                ITerminalControlHost session = TerminalCommandTarget.AsOpenTerminal(target);
                ITerminalSettings    ts      = session.TerminalSettings;

                ts.BeginUpdate();
                ts.EnabledCharTriggerIntelliSense = is_checked;
                ts.EndUpdate();
            }
Exemplo n.º 3
0
        public ITerminalSettings CreateDefaultCygwinTerminalSettings()
        {
            ITerminalSettings settings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings("", Poderosa.TerminalSession.Properties.Resources.Cygwin16x16);

            settings.BeginUpdate();
            settings.Encoding = EncodingType.UTF8;
            settings.EndUpdate();
            return(settings);
        }
Exemplo n.º 4
0
            public override void OnChange(ICommandTarget target, bool is_checked)
            {
                ITerminalControlHost session = TerminalCommandTarget.AsTerminal(target);
                ITerminalSettings    ts      = session.TerminalSettings;

                ts.BeginUpdate();
                ts.LocalEcho = is_checked;
                ts.EndUpdate();
            }
            public override void OnChange(ICommandTarget target, int selectedIndex)
            {
                ITerminalControlHost session = TerminalCommandTarget.AsTerminal(target);
                ITerminalSettings    ts      = session.TerminalSettings;

                ts.BeginUpdate();
                ts.TransmitNL = (NewLine)selectedIndex;
                ts.EndUpdate();
            }
            public override void OnChange(ICommandTarget target, int selectedIndex)
            {
                ITerminalControlHost session = TerminalCommandTarget.AsOpenTerminal(target);
                ITerminalSettings    ts      = session.TerminalSettings;

                ts.BeginUpdate();
                ts.ShellScheme = TerminalEmulatorPlugin.Instance.ShellSchemeCollection.GetAt(selectedIndex);
                ts.EndUpdate();
            }
Exemplo n.º 7
0
        /// <summary>
        /// Initiates the SSH connection process by getting the <see cref="IProtocolService"/> instance and calling
        /// <see cref="IProtocolService.AsyncSSHConnect"/>.  This is an asynchronous process:  the <see cref="SuccessfullyExit"/> method is called when the
        /// connection is established successfully and <see cref="ConnectionFailed"/> method is called when we are unable to establish the connection.
        /// </summary>
        public void AsyncConnect()
        {
            ITerminalEmulatorService terminalEmulatorService =
                (ITerminalEmulatorService)_poderosaWorld.PluginManager.FindPlugin("org.poderosa.terminalemulator", typeof(ITerminalEmulatorService));
            IProtocolService protocolService = (IProtocolService)_poderosaWorld.PluginManager.FindPlugin("org.poderosa.protocols", typeof(IProtocolService));

            // Create and initialize the SSH login parameters
            ISSHLoginParameter sshLoginParameter = protocolService.CreateDefaultSSHParameter();

            sshLoginParameter.Account = Username;

            if (!String.IsNullOrEmpty(IdentityFile))
            {
                sshLoginParameter.AuthenticationType = AuthenticationType.PublicKey;
                sshLoginParameter.IdentityFileName   = IdentityFile;
            }

            else
            {
                sshLoginParameter.AuthenticationType = AuthenticationType.Password;

                if (Password != null && Password.Length > 0)
                {
                    IntPtr passwordBytes = Marshal.SecureStringToGlobalAllocAnsi(Password);
                    sshLoginParameter.PasswordOrPassphrase = Marshal.PtrToStringAnsi(passwordBytes);
                }
            }

            sshLoginParameter.Method = (SSHProtocol)Enum.Parse(typeof(SSHProtocol), SshProtocol.ToString("G"));

            // Create and initialize the various socket connection properties
            ITCPParameter tcpParameter = (ITCPParameter)sshLoginParameter.GetAdapter(typeof(ITCPParameter));

            tcpParameter.Destination = HostName;
            tcpParameter.Port        = Port;

            // Set the UI settings to use for the terminal itself
            terminalEmulatorService.TerminalEmulatorOptions.RightButtonAction = MouseButtonAction.Paste;
            _settings = terminalEmulatorService.CreateDefaultTerminalSettings(tcpParameter.Destination, null);

            _settings.BeginUpdate();
            _settings.TerminalType            = (ConnectionParam.TerminalType)Enum.Parse(typeof(ConnectionParam.TerminalType), TerminalType.ToString("G"));
            _settings.RenderProfile           = terminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile();
            _settings.RenderProfile.BackColor = BackColor;
            _settings.RenderProfile.ForeColor = ForeColor;
            _settings.RenderProfile.FontName  = Font.Name;
            _settings.RenderProfile.FontSize  = Font.Size;
            _settings.EndUpdate();

            ITerminalParameter param = (ITerminalParameter)tcpParameter.GetAdapter(typeof(ITerminalParameter));

            param.SetTerminalName(_settings.TerminalType.ToString("G").ToLower());

            // Initiate the connection process
            protocolService.AsyncSSHConnect(this, sshLoginParameter);
        }
        protected override ITerminalParameter PrepareTerminalParameter()
        {
            _param.Home      = _homeDirectoryBox.Text;
            _param.ShellName = _shellBox.Text;

            //ログ設定
            LogType            logtype     = (LogType)EnumDescAttribute.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
            ISimpleLogSettings logsettings = null;

            if (logtype != LogType.None)
            {
                logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text);
                if (logsettings == null)
                {
                    return(null);                                  //動作キャンセル
                }
            }
            ITerminalSettings settings = this.TerminalSettings;

            settings.BeginUpdate();
            if (logsettings != null)
            {
                settings.LogSettings.Reset(logsettings);
            }
            settings.Caption      = _param.ShellBody;
            settings.Icon         = Poderosa.TerminalSession.Properties.Resources.Cygwin16x16;
            settings.Encoding     = (EncodingType)_encodingBox.SelectedIndex;
            settings.TerminalType = (TerminalType)_terminalTypeBox.SelectedIndex;
            settings.EndUpdate();

            ITerminalParameter termParam = (ITerminalParameter)_param.GetAdapter(typeof(ITerminalParameter));

            termParam.SetTerminalName(_terminalTypeBox.Text);                   // Used for TERM environment variable (LocalShellUtil)

            _param.CygwinDir = _cygwinDirBox.Text;
            if (_param.CygwinDir.Length > 0 && _param.CygwinDir[_param.CygwinDir.Length - 1] == Path.PathSeparator)
            {
                _param.CygwinDir = _param.CygwinDir.Substring(0, _param.CygwinDir.Length - 1);
            }

            string autoExecMacroPath = null;

            if (_autoExecMacroPathBox.Text.Length != 0)
            {
                autoExecMacroPath = _autoExecMacroPathBox.Text;
            }

            IAutoExecMacroParameter autoExecParams = _param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;

            if (autoExecParams != null)
            {
                autoExecParams.AutoExecMacroPath = autoExecMacroPath;
            }

            return((ITerminalParameter)_param.GetAdapter(typeof(ITerminalParameter)));
        }
Exemplo n.º 9
0
            public override void OnChange(ICommandTarget target, int selectedIndex, object selectedItem)
            {
                EnumListItem <EncodingType> item = selectedItem as EnumListItem <EncodingType>;

                if (item != null)
                {
                    ITerminalControlHost session = TerminalCommandTarget.AsTerminal(target);
                    ITerminalSettings    ts      = session.TerminalSettings;
                    ts.BeginUpdate();
                    ts.Encoding = item.Value;
                    ts.EndUpdate();
                }
            }
Exemplo n.º 10
0
        private static CommandResult CmdEncoding(ICommandTarget target, EncodingType encoding)
        {
            ITerminalControlHost ts = TerminalCommandTarget.AsOpenTerminal(target);

            if (ts == null)
            {
                return(CommandResult.Failed);
            }
            ITerminalSettings settings = ts.TerminalSettings;

            settings.BeginUpdate();
            settings.Encoding = encoding;
            settings.EndUpdate();
            return(CommandResult.Succeeded);
        }
Exemplo n.º 11
0
        private static CommandResult CmdToggleLocalEcho(ICommandTarget target)
        {
            ITerminalControlHost ts = TerminalCommandTarget.AsOpenTerminal(target);

            if (ts == null)
            {
                return(CommandResult.Failed);
            }
            ITerminalSettings settings = ts.TerminalSettings;

            settings.BeginUpdate();
            settings.LocalEcho = !settings.LocalEcho;
            settings.EndUpdate();
            return(CommandResult.Succeeded);
        }
Exemplo n.º 12
0
            public override void OnChange(ICommandTarget target, int selectedIndex, object selectedItem)
            {
                ListItem <IShellScheme> item = selectedItem as ListItem <IShellScheme>;

                if (item != null)
                {
                    IShellScheme scheme = item.Value;

                    ITerminalControlHost session = TerminalCommandTarget.AsOpenTerminal(target);
                    ITerminalSettings    ts      = session.TerminalSettings;
                    ts.BeginUpdate();
                    ts.ShellScheme = scheme;
                    ts.EndUpdate();
                }
            }
Exemplo n.º 13
0
        private static CommandResult CmdNewLine(ICommandTarget target, NewLine nl)
        {
            ITerminalControlHost ts = TerminalCommandTarget.AsOpenTerminal(target);

            if (ts == null)
            {
                return(CommandResult.Failed);
            }
            ITerminalSettings settings = ts.TerminalSettings;

            settings.BeginUpdate();
            settings.TransmitNL = nl;
            settings.EndUpdate();
            return(CommandResult.Succeeded);
        }
Exemplo n.º 14
0
        private static CommandResult LoopbackTerminalCommand(ICommandTarget target)
        {
            IPluginManager               pm = SessionTestPlugin.Instance.PoderosaWorld.PluginManager;
            IProtocolTestService         ps = (IProtocolTestService)pm.FindPlugin("org.poderosa.protocols", typeof(IProtocolTestService));
            ITerminalSessionStartCommand s  = ((ITerminalSessionsService)pm.FindPlugin("org.poderosa.terminalsessions", typeof(ITerminalSessionsService))).TerminalSessionStartCommand;
            ITerminalEmulatorService     es = (ITerminalEmulatorService)pm.FindPlugin("org.poderosa.terminalemulator", typeof(ITerminalEmulatorService));
            ITerminalSettings            ts = es.CreateDefaultTerminalSettings("LOOPBACK", null);

            //改行はCRLFがいいっすね
            ts.BeginUpdate();
            ts.TransmitNL = Poderosa.ConnectionParam.NewLine.CRLF;
            ts.EndUpdate();
            s.StartTerminalSession(target, ps.CreateLoopbackConnection(), ts);
            return(CommandResult.Succeeded);
        }
Exemplo n.º 15
0
        private static CommandResult ToggleIntelliSense(ICommandTarget target)
        {
            ITerminalControlHost ts = TerminalCommandTarget.AsOpenTerminal(target);

            if (ts == null)
            {
                return(CommandResult.Failed);
            }
            ITerminalSettings settings = ts.TerminalSettings;

            settings.BeginUpdate();
            settings.EnabledCharTriggerIntelliSense = !settings.EnabledCharTriggerIntelliSense;
            settings.EndUpdate();
            return(CommandResult.Succeeded);
        }
Exemplo n.º 16
0
        public bool Connect(ConnectCallback callback)
        {
            _connectCallback = callback;
            var ssh = new SSHLoginParameter();

            ssh.Method               = SSHProtocol.SSH2;
            ssh.AuthenticationType   = AuthenticationType.Password;
            ssh.Account              = "cxn2356";
            ssh.PasswordOrPassphrase = "Jumanji123.";
            //--- X11 forwarding settings
            ssh.EnableX11Forwarding = false;
            ssh.X11Forwarding       = null;
            //--- Agent forwarding settings
            ssh.EnableAgentForwarding          = false;
            ssh.AgentForwardingAuthKeyProvider = null;
            // -- tcp
            var tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = "10.93.1.255";
            tcp.Port        = 22;
            //--- Log settings
            ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings();

            logSettings.LogType = Poderosa.ConnectionParam.LogType.None;
            if (logSettings.LogType != Poderosa.ConnectionParam.LogType.None)
            {
                logSettings.LogPath   = Path.GetTempFileName();
                logSettings.LogAppend = true;
            }
            // -- terminal settings
            _terminalSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings("Terminal", null);
            _terminalSettings.BeginUpdate();
            _terminalSettings.EnabledCharTriggerIntelliSense = false;
            _terminalSettings.Encoding     = Poderosa.ConnectionParam.EncodingType.UTF8;
            _terminalSettings.LocalEcho    = false;
            _terminalSettings.TransmitNL   = Poderosa.ConnectionParam.NewLine.CR;
            _terminalSettings.TerminalType = Poderosa.ConnectionParam.TerminalType.XTerm;
            _terminalSettings.LogSettings.Reset(logSettings);
            _terminalSettings.EndUpdate();
            IProtocolService protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;

            mreConnect.Reset();
            IInterruptable interruptable = protocolservice.AsyncSSHConnect(this, ssh);

            Task.Factory.StartNew(() => AwaitConnectResult());

            return(true);
        }
Exemplo n.º 17
0
        private static ITerminalSettings CreateTerminalSettings(TerminalParam param)
        {
            ITerminalSettings ts = MacroPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(param.Caption, null);

            ts.BeginUpdate();
            ts.RenderProfile = param.RenderProfile;
            ts.TransmitNL    = param.TransmitNL;
            ts.LocalEcho     = param.LocalEcho;
            ts.Encoding      = param.Encoding;
            if (param.LogType != LogType.None)
            {
                ts.LogSettings.Reset(CreateSimpleLogSettings(param));
            }
            ts.EndUpdate();
            return(ts);
        }
Exemplo n.º 18
0
        public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            IShellScheme ss = (IShellScheme)args[0].GetAdapter(typeof(IShellScheme));

            Debug.Assert(ss != null);

            ITerminalControlHost ts = TerminalCommandTarget.AsOpenTerminal(target);

            if (ts == null)
            {
                return(CommandResult.Failed);
            }
            ITerminalSettings settings = ts.TerminalSettings;

            settings.BeginUpdate();
            settings.ShellScheme = ss;
            settings.EndUpdate();
            return(CommandResult.Succeeded);
        }
Exemplo n.º 19
0
        private static void AdjustCaptionAndText(ITerminalSettings terminal_settings, string caption, StartCommandIcon icon)
        {
            terminal_settings.BeginUpdate();
            if (terminal_settings.Caption == null || terminal_settings.Caption.Length == 0)
            {
                terminal_settings.Caption = caption; //長さ0はいかん
            }
            if (terminal_settings.Icon == null)
            {
                switch (icon)
                {
                case StartCommandIcon.NewConnection:
                    terminal_settings.Icon = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16;
                    break;

                case StartCommandIcon.Cygwin:
                    terminal_settings.Icon = Poderosa.TerminalSession.Properties.Resources.Cygwin16x16;
                    break;
                }
            }
            terminal_settings.EndUpdate();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Validates input values and constructs parameter objects.
        /// </summary>
        /// <param name="loginParam">SSH parameter object is set when this method returns true.</param>
        /// <param name="terminalSettings">terminal settings object is set when this method returns true.</param>
        /// <param name="errorMessage">validation error message is set when this method returns false. this can be null when displaying error message is not needed.</param>
        /// <returns>true if all validations passed and parameter objects were created.</returns>
        private bool Validate(out ISSHLoginParameter loginParam, out ITerminalSettings terminalSettings, out string errorMessage)
        {
            loginParam       = null;
            terminalSettings = null;
            errorMessage     = null;

            var ssh = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
            var tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            //--- SSH connection settings

            if (_ssh1RadioButton.Checked)
            {
                ssh.Method = SSHProtocol.SSH1;
            }
            else if (_ssh2RadioButton.Checked)
            {
                ssh.Method = SSHProtocol.SSH2;
            }
            else
            {
                errorMessage = TEnv.Strings.GetString("Message.LoginDialog.ProtocolVersionIsNotSpecified");
                return(false);
            }

            tcp.Destination = _hostBox.Text;
            if (String.IsNullOrEmpty(tcp.Destination))
            {
                errorMessage = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty");
                return(false);
            }

            int port;

            if (Int32.TryParse(_portBox.Text, out port) && port >= 0 && port <= 65535)
            {
                tcp.Port = port;
            }
            else
            {
                errorMessage = String.Format(
                    TEnv.Strings.GetString("Message.LoginDialog.InvalidPort"),
                    _portBox.Text);
                return(false);
            }

            ssh.Account = _userNameBox.Text;

            AuthType authType = ((EnumListItem <AuthType>)_authOptions.SelectedItem).Value;

            ssh.AuthenticationType = authType.ToAuthenticationType();

            if (ssh.AuthenticationType == AuthenticationType.PublicKey)
            {
                ssh.IdentityFileName = _privateKeyFile.Text;

                if (String.IsNullOrEmpty(ssh.IdentityFileName))
                {
                    errorMessage = TEnv.Strings.GetString("Message.LoginDialog.PrivateKeyFileIsNotSpecified");
                    return(false);
                }

                if (!File.Exists(ssh.IdentityFileName))
                {
                    errorMessage = TEnv.Strings.GetString("Message.LoginDialog.KeyFileNotExist");
                    return(false);
                }
            }

            if (ssh.AuthenticationType == AuthenticationType.Password || ssh.AuthenticationType == AuthenticationType.PublicKey)
            {
                ssh.PasswordOrPassphrase = _passphraseBox.Text;
            }

            //--- Log settings

            ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings();

            logSettings.LogType = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value;
            if (logSettings.LogType != LogType.None)
            {
                logSettings.LogPath = _logFileBox.Text;
                LogFileCheckResult r = LogUtil.CheckLogFileName(logSettings.LogPath, this.ParentForm);
                if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                {
                    errorMessage = null;
                    return(false);
                }
                logSettings.LogAppend = (r == LogFileCheckResult.Append);
            }

            //--- Terminal settings

            ITerminalParameter termParam    = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));
            TerminalType       terminalType = ((EnumListItem <TerminalType>)_terminalTypeBox.SelectedItem).Value;

            termParam.SetTerminalName(terminalType.ToTermValue());

            string            terminalCaption = tcp.Destination;
            Image             terminalIcon    = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16;
            ITerminalSettings termSettings    = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(terminalCaption, terminalIcon);

            termSettings.BeginUpdate();
            termSettings.Encoding     = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value;
            termSettings.LocalEcho    = ((ListItem <bool>)_localEchoBox.SelectedItem).Value;
            termSettings.TransmitNL   = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value;
            termSettings.TerminalType = terminalType;
            termSettings.LogSettings.Reset(logSettings);
            termSettings.EndUpdate();

            //--- X11 forwarding settings

            if (_useX11ForwardingCheckBox.Checked)
            {
                if (String.IsNullOrEmpty(_x11DisplayText.Text))
                {
                    errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11DisplayIsNotEntered");
                    return(false);
                }
                int display;
                if (!Int32.TryParse(_x11DisplayText.Text, out display) || display < 0 || display > (65535 - 6000))
                {
                    errorMessage = TEnv.Strings.GetString("Message.LoginDialog.InvalidX11Display");
                    return(false);
                }

                X11ForwardingParams x11Param = new X11ForwardingParams(display);

                if (String.IsNullOrEmpty(_x11ScreenText.Text))
                {
                    errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11ScreenIsNotEntered");
                    return(false);
                }
                int screen;
                if (!Int32.TryParse(_x11ScreenText.Text, out screen) || screen < 0)
                {
                    errorMessage = TEnv.Strings.GetString("Message.LoginDialog.InvalidX11Screen");
                    return(false);
                }
                x11Param.Screen = screen;

                if (_x11NeedAuthCheckBox.Checked)
                {
                    x11Param.NeedAuth       = true;
                    x11Param.XauthorityFile = _x11XauthorityText.Text;
                    if (String.IsNullOrEmpty(x11Param.XauthorityFile))
                    {
                        errorMessage = TEnv.Strings.GetString("Message.LoginDialog.XauthorityFileIsNotSpecified");
                        return(false);
                    }
                }
                else
                {
                    x11Param.NeedAuth = false;
                }

                if (_x11UseCygwinDomainSocketCheckBox.Checked)
                {
                    x11Param.UseCygwinUnixDomainSocket = true;
                    x11Param.X11UnixFolder             = _x11CygwinX11UnixFolderText.Text;
                    if (String.IsNullOrEmpty(x11Param.X11UnixFolder))
                    {
                        errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11UnixFolderIsNotSpecified");
                        return(false);
                    }
                }

                ssh.EnableX11Forwarding = true;
                ssh.X11Forwarding       = x11Param;
            }
            else
            {
                ssh.EnableX11Forwarding = false;
                ssh.X11Forwarding       = null;
            }

            //--- Agent forwarding settings

            if (_useAgentForwardingCheckBox.Checked)
            {
                ssh.EnableAgentForwarding          = true;
                ssh.AgentForwardingAuthKeyProvider = null;  // set later
            }
            else
            {
                ssh.EnableAgentForwarding          = false;
                ssh.AgentForwardingAuthKeyProvider = null;
            }

            //--- Macro

            IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;

            if (autoExecParams != null)     // macro plugin is enabled
            {
                if (!String.IsNullOrEmpty(_autoExecMacroPathBox.Text))
                {
                    autoExecParams.AutoExecMacroPath = _autoExecMacroPathBox.Text;
                }
                else
                {
                    autoExecParams.AutoExecMacroPath = null;
                }
            }

            loginParam       = ssh;
            terminalSettings = termSettings;
            return(true);
        }
        // --------------------------------------------------------------------
        // 接続開始
        // --------------------------------------------------------------------
        /// <summary>
        /// 非同期接続を開始します。
        /// </summary>
        /// <remarks>
        /// 接続パラメータとターミナル設定を作成して、非同期接続を開始します。
        /// 接続が成功するとSuccessfullyExit()が呼ばれ、失敗するとConnectionFailed()が呼ばれます。
        /// </remarks>
        public void AsyncConnect()
        {
            State = LineState.Connecting;
            _settings = null;
            _session = null;
            _connector = null;

            //
            // ターミナルエミュレータサービスとプロトコルサービスを取得します。
            //
            ITerminalEmulatorService terminalEmulatorService =
                (ITerminalEmulatorService)PoderosaAccessPoint.World.PluginManager.FindPlugin(
                "org.poderosa.terminalemulator", typeof(ITerminalEmulatorService));
            IProtocolService protocolService =
                (IProtocolService)PoderosaAccessPoint.World.PluginManager.FindPlugin(
                "org.poderosa.protocols", typeof(IProtocolService));

            //
            // 接続パラメータを作成します。
            //
            ITCPParameter tcpParameter = null;
            ISSHLoginParameter sshLoginParameter =  null;
            if (LoginProfile.ConnectionMethod == ConnectionParam.ConnectionMethod.Telnet)
            {
                //
                // Telnet接続パラメータの作成
                // ※ tcpParameterの実体はTCPParameterクラスのインスタンスです。
                //
                tcpParameter = protocolService.CreateDefaultTelnetParameter();
                tcpParameter.Destination = LoginProfile.Host;
                tcpParameter.Port = LoginProfile.Port;
            }
            else
            {
                //
                // SSH接続パラメータの作成
                // ※ sshLoginParameterの実体はSSHLoginParameterクラスのインスタンスであり、
                //    SSHLoginParameterクラスはTCPParameterクラスを継承しています。
                //
                sshLoginParameter = protocolService.CreateDefaultSSHParameter();
                sshLoginParameter.Account = LoginProfile.UserName;
                if (LoginProfile.Password != null && LoginProfile.Password.Length > 0)
                {
                    IntPtr pswdBytes = Marshal.SecureStringToGlobalAllocAnsi(LoginProfile.Password);
                    sshLoginParameter.PasswordOrPassphrase = Marshal.PtrToStringAnsi(pswdBytes);
                }
                if (!String.IsNullOrEmpty(LoginProfile.IdentityFile))
                {
                    sshLoginParameter.AuthenticationType = AuthenticationType.PublicKey;
                    sshLoginParameter.IdentityFileName = LoginProfile.IdentityFile;
                }
                else
                {
                    sshLoginParameter.AuthenticationType = AuthenticationType.Password;
                }
                sshLoginParameter.Method = (SSHProtocol)Enum.Parse(
                    typeof(SSHProtocol), LoginProfile.ConnectionMethod.ToString("G"));

                tcpParameter = (ITCPParameter)sshLoginParameter.GetAdapter(typeof(ITCPParameter));
                tcpParameter.Destination = LoginProfile.Host;
                tcpParameter.Port = LoginProfile.Port;
            }

            //
            // ターミナル設定のパラメータをセットします。
            //
            terminalEmulatorService.TerminalEmulatorOptions.RightButtonAction =
                MouseButtonAction.Paste;
            _settings = terminalEmulatorService.CreateDefaultTerminalSettings(
                tcpParameter.Destination, null);
            _settings.BeginUpdate();
            _settings.TerminalType = (ConnectionParam.TerminalType)Enum.Parse(
                typeof(ConnectionParam.TerminalType), LoginProfile.TerminalType.ToString("G"));
            _settings.Encoding = LoginProfile.EncodingType;
            _settings.LocalEcho = LoginProfile.LocalEcho;
            _settings.TransmitNL = LoginProfile.TransmitNL;
            _settings.RenderProfile = LoginProfile.ExportRenderProfile();
            _settings.EndUpdate();
            ITerminalParameter param =
                (ITerminalParameter)tcpParameter.GetAdapter(typeof(ITerminalParameter));
            param.SetTerminalName(_settings.TerminalType.ToString("G").ToLower());

            //
            // 非同期接続開始処理を行います。
            //
            if (LoginProfile.ConnectionMethod == ConnectionParam.ConnectionMethod.Telnet)
            {
            #if DEBUG
                WriteLog("Telnet非同期接続を開始します。");
            #endif
                _connector = protocolService.AsyncTelnetConnect(this, tcpParameter);
            }
            else
            {
            #if DEBUG
                WriteLog("SSH非同期接続を開始します。");
            #endif
                _connector = protocolService.AsyncSSHConnect(this, sshLoginParameter);
            }
        }
Exemplo n.º 22
0
        private static void AdjustCaptionAndText(ITerminalSettings terminal_settings, string caption, StartCommandIcon icon) {
            terminal_settings.BeginUpdate();
            if (terminal_settings.Caption == null || terminal_settings.Caption.Length == 0)
                terminal_settings.Caption = caption; //長さ0はいかん
            if (terminal_settings.Icon == null) {
                switch (icon) {
                    case StartCommandIcon.NewConnection:
                        terminal_settings.Icon = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16;
                        break;
                    case StartCommandIcon.Cygwin:
                        terminal_settings.Icon = Poderosa.TerminalSession.Properties.Resources.Cygwin16x16;
                        break;
                }
            }
            terminal_settings.EndUpdate();

        }
Exemplo n.º 23
0
 public void Do()
 {
     _settings.BeginUpdate();
     _settings.LocalEcho = _value;
     _settings.EndUpdate();
 }
Exemplo n.º 24
0
        //旧バージョンフォーマットの読み込み
        private static ShortcutFileContent ParseOldFormat(XmlElement root)
        {
            if (root.GetAttribute("type") != "tcp")
            {
                throw new FormatException("Unknown File Format");
            }

            //accountの有無でTelnet/SSHを切り替え
            ITerminalParameter param;
            ISSHLoginParameter ssh     = null;
            ITCPParameter      tcp     = null;
            string             account = root.GetAttribute("account");

            if (account.Length > 0)
            {
                ssh         = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
                ssh.Account = account;
                tcp         = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
            }
            else
            {
                tcp = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
            }

            param = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));
            ITerminalSettings settings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings("", null);

            settings.BeginUpdate();
            //アトリビュート舐めて設定
            foreach (XmlAttribute attr in root.Attributes)
            {
                switch (attr.Name)
                {
                case "auth":
                    if (ssh != null)
                    {
                        ssh.AuthenticationType = ParseUtil.ParseEnum <AuthenticationType>(attr.Value, AuthenticationType.Password);
                    }
                    break;

                case "keyfile":
                    if (ssh != null)
                    {
                        ssh.IdentityFileName = attr.Value;
                    }
                    break;

                case "encoding":
                    settings.Encoding = (EncodingType)EnumDescAttribute.For(typeof(EncodingType)).FromDescription(attr.Value, EncodingType.ISO8859_1);
                    break;

                case "terminal-type":
                    settings.TerminalType = ParseUtil.ParseEnum <TerminalType>(attr.Value, TerminalType.XTerm);
                    param.SetTerminalName(attr.Value);
                    break;

                case "localecho":
                    settings.LocalEcho = ParseUtil.ParseBool(attr.Value, false);
                    break;

                case "caption":
                    settings.Caption = attr.Value;
                    break;

                case "transmit-nl":
                    settings.TransmitNL = ParseUtil.ParseEnum <NewLine>(attr.Value, NewLine.CR);
                    break;

                case "host":
                    tcp.Destination = attr.Value;
                    break;

                case "port":
                    tcp.Port = ParseUtil.ParseInt(attr.Value, ssh != null? 22 : 23);
                    break;

                case "method":
                    if (ssh != null)
                    {
                        ssh.Method = attr.Value == "SSH1"? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                    }
                    break;
                }
            }
            //ts.LineFeedRule = ParseUtil.ParseEnum<LineFeedRule>(node.Get("linefeedrule"), LineFeedRule.Normal);
            settings.EndUpdate();

            return(new ShortcutFileContent(settings, param));
        }
Exemplo n.º 25
0
 public void Do()
 {
     _settings.BeginUpdate();
     _settings.Caption = _title;
     _settings.EndUpdate();
 }
Exemplo n.º 26
0
        /// <summary>
        /// Validates input values and constructs parameter objects.
        /// </summary>
        /// <param name="telnetParam">Telnet parameter object is set when this method returns true.</param>
        /// <param name="terminalSettings">terminal settings object is set when this method returns true.</param>
        /// <param name="errorMessage">validation error message is set when this method returns false. this can be null when displaying error message is not needed.</param>
        /// <returns>true if all validations passed and parameter objects were created.</returns>
        private bool Validate(out ITCPParameter telnetParam, out ITerminalSettings terminalSettings, out string errorMessage)
        {
            telnetParam      = null;
            terminalSettings = null;
            errorMessage     = null;

            var telnet        = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
            var tcp           = (ITCPParameter)telnet.GetAdapter(typeof(ITCPParameter));
            var protocolParam = (ITelnetParameter)telnet.GetAdapter(typeof(ITelnetParameter));

            tcp.Destination = _hostBox.Text;
            if (String.IsNullOrEmpty(tcp.Destination))
            {
                errorMessage = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty");
                return(false);
            }

            int port;

            if (Int32.TryParse(_portBox.Text, out port) && port >= 0 && port <= 65535)
            {
                tcp.Port = port;
            }
            else
            {
                errorMessage = String.Format(
                    TEnv.Strings.GetString("Message.LoginDialog.InvalidPort"),
                    _portBox.Text);
                return(false);
            }

            //--- Log settings

            ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings();

            logSettings.LogType = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value;
            if (logSettings.LogType != LogType.None)
            {
                logSettings.LogPath = _logFileBox.Text;
                LogFileCheckResult r = LogUtil.CheckLogFileName(logSettings.LogPath, this.ParentForm);
                if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                {
                    errorMessage = null;
                    return(false);
                }
                logSettings.LogAppend = (r == LogFileCheckResult.Append);
            }

            //--- Terminal settings

            ITerminalParameter termParam    = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));
            TerminalType       terminalType = ((EnumListItem <TerminalType>)_terminalTypeBox.SelectedItem).Value;

            termParam.SetTerminalName(terminalType.ToTermValue());

            string            terminalCaption = tcp.Destination;
            Image             terminalIcon    = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16;
            ITerminalSettings termSettings    = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(terminalCaption, terminalIcon);

            termSettings.BeginUpdate();
            termSettings.Encoding     = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value;
            termSettings.LocalEcho    = ((ListItem <bool>)_localEchoBox.SelectedItem).Value;
            termSettings.TransmitNL   = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value;
            termSettings.TerminalType = terminalType;
            termSettings.LogSettings.Reset(logSettings);
            termSettings.EndUpdate();

            //--- TELNET protocol settings

            protocolParam.TelnetNewLine =
                (termSettings.TransmitNL == NewLine.CRLF) ? _telnetNewLine.Checked : false;

            //--- Macro

            IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;

            if (autoExecParams != null)     // macro plugin is enabled
            {
                if (!String.IsNullOrEmpty(_autoExecMacroPathBox.Text))
                {
                    autoExecParams.AutoExecMacroPath = _autoExecMacroPathBox.Text;
                }
                else
                {
                    autoExecParams.AutoExecMacroPath = null;
                }
            }

            telnetParam      = tcp;
            terminalSettings = termSettings;
            return(true);
        }
Exemplo n.º 27
0
        //入力内容に誤りがあればそれを警告してnullを返す。なければ必要なところを埋めたTCPTerminalParamを返す
        private ISSHLoginParameter ValidateContent()
        {
            ISSHLoginParameter p   = (ISSHLoginParameter)_sshParam.Clone();
            string             msg = null;

            try {
                LogType            logtype     = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value;
                ISimpleLogSettings logsettings = null;
                if (logtype != LogType.None)
                {
                    logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text);
                    if (logsettings == null)
                    {
                        return(null); //動作キャンセル
                    }
                }

                ITerminalSettings settings = this.TerminalSettings;

                if (logsettings != null)
                {
                    settings.BeginUpdate();
                    settings.LogSettings.Reset(logsettings);
                    settings.EndUpdate();
                }

                ITerminalParameter param = (ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter));
                param.SetTerminalName(ToTerminalName(settings.TerminalType));

                if (p.AuthenticationType == AuthenticationType.PublicKey)
                {
                    if (!File.Exists(_privateKeyBox.Text))
                    {
                        msg = TEnv.Strings.GetString("Message.SSHShortcutLoginDialog.KeyFileNotExist");
                    }
                    else
                    {
                        p.IdentityFileName = _privateKeyBox.Text;
                    }
                }

                p.PasswordOrPassphrase = _passphraseBox.Text;

                string autoExecMacroPath = null;
                if (_autoExecMacroPathBox.Text.Length != 0)
                {
                    autoExecMacroPath = _autoExecMacroPathBox.Text;
                }

                IAutoExecMacroParameter autoExecParams = p.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                if (autoExecParams != null)
                {
                    autoExecParams.AutoExecMacroPath = autoExecMacroPath;
                }

                if (msg != null)
                {
                    GUtil.Warning(this, msg);
                    return(null);
                }
                else
                {
                    return(p);
                }
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(null);
            }
        }
Exemplo n.º 28
0
        public ITerminalParameter PrepareTerminalParameter(string UserName, string Pwd, string DestHost, int Port, ConnectionMethod m, string PublicKeyFile, LogType logType, string logPath)
        {
            string msg = null;

            if (_terminalOptions == null)
            {
                _terminalOptions = new TerminalOptions("");
            }
            if (_terminalSettings == null)
            {
                _terminalSettings = new TerminalSettings();
            }

            try
            {
                if (Port == 0)
                {
                    if (m == ConnectionMethod.Telnet)
                    {
                        Port = 23;
                    }
                    else
                    {
                        Port = 22;
                    }
                }

                tcp             = _Console.CreateDefaultTelnetParameter();
                tcp.Destination = DestHost;
                tcp.Port        = Port;
                if (m == ConnectionMethod.SSH1 || (m == ConnectionMethod.SSH2))
                {
                    SSHLoginParameter sp = _Console.CreateDefaultSSHParameter();
                    ssh                      = sp;
                    ssh.Destination          = DestHost;
                    ssh.Port                 = Port;
                    ssh.Method               = m == ConnectionMethod.SSH1 ? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                    ssh.Account              = UserName;
                    ssh.PasswordOrPassphrase = Pwd;
                }

                if (DestHost.Length == 0)
                {
                    msg = "Message.TelnetSSHLogin.HostIsEmpty";
                }

                //ƒƒOÝ’è
                ISimpleLogSettings logsettings = null;
                if (logType != LogType.None)
                {
                    if (logPath.Length == 0)
                    {
                        logPath = AppDomain.CurrentDomain.BaseDirectory;// +DestHost;
                    }
                    logsettings         = new SimpleLogSettings();
                    logsettings.LogPath = logPath;
                    logsettings.LogType = logType;
                    LogFileCheckResult r = LogUtil.CheckLogFileName(logPath);
                    if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                    {
                        return(null);
                    }
                    logsettings.LogAppend = (r == LogFileCheckResult.Append);
                    if (logsettings == null)
                    {
                        return(null); //“®ìƒLƒƒƒ“ƒZƒ‹
                    }
                    _terminalOptions.DefaultLogType      = logType;
                    _terminalOptions.DefaultLogDirectory = logPath;
                }

                _param = (ITerminalParameter)tcp; //(ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));
                TerminalType terminal_type = TerminalType.VT100;
                _param.SetTerminalName(ToTerminalName(terminal_type));

                if (ssh != null)
                {
                    Debug.Assert(ssh != null);
                    if (PublicKeyFile.Length > 0)
                    {
                        ssh.AuthenticationType = AuthenticationType.PublicKey;
                        if (!File.Exists(PublicKeyFile))
                        {
                            msg = "Message.TelnetSSHLogin.KeyFileNotExist";
                        }
                        else
                        {
                            ssh.IdentityFileName = PublicKeyFile;
                        }
                    }
                }

                ITerminalSettings settings = this.TerminalSettings;
                settings.BeginUpdate();
                settings.Caption = DestHost;
                //settings.Icon = IconList.LoadIcon(IconList.ICON_NEWCONNECTION);
                settings.Encoding     = EncodingType.ISO8859_1;
                settings.LocalEcho    = false;
                settings.TransmitNL   = NewLine.CRLF; // .LF; //.CR;
                settings.LineFeedRule = ConnectionParam.LineFeedRule.Normal;
                settings.TerminalType = terminal_type;
                settings.DebugFlag    = _debug;
                if (logsettings != null)
                {
                    settings.LogSettings.Reset(logsettings);
                }
                settings.EndUpdate();

                if (msg != null)
                {
                    if (_debug > 0) //ShowError(msg);
                    {
                        Console.WriteLine(msg);
                    }
                    return(null);
                }
                else
                {
                    return((ITerminalParameter)tcp); //.GetAdapter(typeof(ITerminalParameter));
                }
            }
            catch (Exception ex)
            {
                if (_debug > 0)
                {
                    Console.WriteLine(ex.Message);
                }
                return(null);
            }
        }
        /// <summary>
        /// 接続
        /// </summary>
        public void Connect()
        {
            ITCPParameter tcp = null;

            // プロトコル
            if (_prof.Protocol == ConnectionMethod.Telnet)
            {
                // Telnet
                tcp             = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
                tcp.Destination = _prof.HostName;
                tcp.Port        = _prof.Port;
                ITelnetParameter telnetParameter = null;
                telnetParameter = (ITelnetParameter)tcp.GetAdapter(typeof(ITelnetParameter));
                if (telnetParameter != null)
                {
                    telnetParameter.TelnetNewLine = _prof.TelnetNewLine;
                }
            }
            else if ((_prof.Protocol == ConnectionMethod.SSH1) || (_prof.Protocol == ConnectionMethod.SSH2))
            {
                // SSH
                ISSHLoginParameter ssh = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
                tcp                      = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
                tcp.Destination          = _prof.HostName;
                tcp.Port                 = _prof.Port;
                ssh.Method               = (_prof.Protocol == ConnectionMethod.SSH1) ? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                ssh.Account              = _prof.UserName;
                ssh.AuthenticationType   = ConvertAuth(_prof.AuthType);
                ssh.PasswordOrPassphrase = _prof.Password;
                ssh.IdentityFileName     = _prof.KeyFile;
                ssh.LetUserInputPassword = (_prof.AutoLogin == true) ? false : true;
            }

            // TerminalSettings(表示プロファイル/改行コード/文字コード)
            ITerminalSettings terminalSettings = ConnectProfilePlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(_prof.HostName, null);

            terminalSettings.BeginUpdate();
            terminalSettings.RenderProfile = _prof.RenderProfile;
            terminalSettings.TransmitNL    = _prof.NewLine;
            terminalSettings.Encoding      = _prof.CharCode;
            terminalSettings.LocalEcho     = false;
            terminalSettings.EndUpdate();

            // TerminalParameter
            ITerminalParameter terminalParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));

            // ターミナルサイズ(これを行わないとPoderosa起動直後のOnReceptionが何故か機能しない, 行わない場合は2回目以降の接続時は正常)
            IViewManager            viewManager            = CommandTargetUtil.AsWindow(ConnectProfilePlugin.Instance.WindowManager.ActiveWindow).ViewManager;
            IContentReplaceableView contentReplaceableView = (IContentReplaceableView)viewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
            TerminalControl         terminalControl        = (TerminalControl)contentReplaceableView.GetCurrentContent().GetAdapter(typeof(TerminalControl));

            if (terminalControl != null)
            {
                Size size = terminalControl.CalcTerminalSize(terminalSettings.RenderProfile);
                terminalParam.SetTerminalSize(size.Width, size.Height);
            }

            // 接続(セッションオープン)
            _terminalSession = (ITerminalSession)ConnectProfilePlugin.Instance.WindowManager.ActiveWindow.AsForm().Invoke(new OpenSessionDelegate(InvokeOpenSessionOrNull), terminalParam, terminalSettings);

            // 自動ログイン/SU/実行コマンド
            if (_terminalSession != null)
            {
                // 受信データオブジェクト作成(ユーザからのキーボード入力が不可)
                ReceptionData pool = new ReceptionData();
                _terminalSession.Terminal.StartModalTerminalTask(pool);

                // Telnet自動ログイン
                if ((_prof.AutoLogin == true) && (_prof.Protocol == ConnectionMethod.Telnet))
                {
                    if (TelnetAutoLogin() != true)
                    {
                        return;
                    }
                }

                // SU
                if ((_prof.AutoLogin == true) && (_prof.SUUserName != ""))
                {
                    if (SUSwitch() != true)
                    {
                        return;
                    }
                }

                // 実行コマンド
                if ((_prof.AutoLogin == true) && (_prof.ExecCommand != ""))
                {
                    if (ExecCommand() != true)
                    {
                        return;
                    }
                }

                // 受信データオブジェクト定義解除(ユーザからのキーボード入力を許可)
                _terminalSession.Terminal.EndModalTerminalTask();
            }
        }
Exemplo n.º 30
0
        //入力内容に誤りがあればそれを警告してnullを返す。なければ必要なところを埋めたTCPTerminalParamを返す
        private ITerminalParameter ValidateContent()
        {
            string             msg = null;
            ITCPParameter      tcp = null;
            ISSHLoginParameter ssh = null;

            try {
                ConnectionMethod m = ParseMethod(_methodBox.Text);
                if (m == ConnectionMethod.Telnet)
                {
                    tcp = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
                }
                else
                {
                    ISSHLoginParameter sp = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
                    tcp         = (ITCPParameter)sp.GetAdapter(typeof(ITCPParameter));
                    ssh         = sp;
                    ssh.Method  = m == ConnectionMethod.SSH1? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                    ssh.Account = _userNameBox.Text;
                    ssh.PasswordOrPassphrase = _passphraseBox.Text;
                }

                tcp.Destination = _hostBox.Text;
                try {
                    tcp.Port = ParsePort(_portBox.Text);
                }
                catch (FormatException ex) {
                    msg = ex.Message;
                }

                if (_hostBox.Text.Length == 0)
                {
                    msg = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty");
                }

                //ログ設定
                LogType            logtype     = (LogType)EnumDescAttribute.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
                ISimpleLogSettings logsettings = null;
                if (logtype != LogType.None)
                {
                    logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text);
                    if (logsettings == null)
                    {
                        return(null);                  //動作キャンセル
                    }
                }

                ITerminalParameter param         = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));
                TerminalType       terminal_type = (TerminalType)_terminalTypeBox.SelectedIndex;
                param.SetTerminalName(ToTerminalName(terminal_type));

                if (ssh != null)
                {
                    Debug.Assert(ssh != null);
                    ssh.AuthenticationType = ToAuthenticationType(_authOptions.SelectedIndex);
                    if (ssh.AuthenticationType == AuthenticationType.PublicKey)
                    {
                        if (!File.Exists(_privateKeyFile.Text))
                        {
                            msg = TEnv.Strings.GetString("Message.LoginDialog.KeyFileNotExist");
                        }
                        else
                        {
                            ssh.IdentityFileName = _privateKeyFile.Text;
                        }
                    }
                }

                string autoExecMacroPath = null;
                if (_autoExecMacroPathBox.Text.Length != 0)
                {
                    autoExecMacroPath = _autoExecMacroPathBox.Text;
                }

                IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                if (autoExecParams != null)
                {
                    autoExecParams.AutoExecMacroPath = autoExecMacroPath;
                }

                ITerminalSettings settings = this.TerminalSettings;
                settings.BeginUpdate();
                settings.Caption      = _hostBox.Text;
                settings.Icon         = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16;
                settings.Encoding     = (EncodingType)_encodingBox.SelectedIndex;
                settings.LocalEcho    = _localEchoBox.SelectedIndex == 1;
                settings.TransmitNL   = (NewLine)EnumDescAttribute.For(typeof(NewLine)).FromDescription(_newLineBox.Text, NewLine.CR);
                settings.TerminalType = terminal_type;
                if (logsettings != null)
                {
                    settings.LogSettings.Reset(logsettings);
                }
                settings.EndUpdate();

                if (msg != null)
                {
                    ShowError(msg);
                    return(null);
                }
                else
                {
                    return((ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)));
                }
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(null);
            }
        }