Example #1
0
 public ParameterItem(ITelnetParameter telnetParam, ITCPParameter tcpParam, ITerminalParameter terminalParam, ITerminalSettings terminalSettings)
 {
     TelnetParameter   = telnetParam;
     TCPParameter      = tcpParam;
     TerminalParameter = terminalParam;
     TerminalSettings  = terminalSettings;
 }
Example #2
0
        public TelnetTerminalConnection(ITCPParameter p, TelnetNegotiator neg, PlainPoderosaSocket s)
            : base(p)
        {
            s.SetOwnerConnection(this);
            _telnetReceiver = new TelnetReceiver(this, neg);
            ITelnetParameter telnetParams  = (ITelnetParameter)p.GetAdapter(typeof(ITelnetParameter));
            bool             telnetNewLine = (telnetParams != null) ? telnetParams.TelnetNewLine : true /*default*/;

            _telnetSocket   = new TelnetSocket(this, s, _telnetReceiver, telnetNewLine);
            _rawSocket      = s;
            _socket         = _telnetSocket;
            _terminalOutput = _telnetSocket;
        }
Example #3
0
        /// <summary>
        /// Load connection parameter history
        /// </summary>
        private void LoadHistory()
        {
            _hostBox.Items.Clear();
            _historyItems.Clear();

            IExtensionPoint extp = TerminalSessionsPlugin.Instance.PoderosaWorld.PluginManager.FindExtensionPoint("org.poderosa.terminalsessions.terminalParameterStore");

            if (extp != null)
            {
                var stores = extp.GetExtensions() as ITerminalSessionParameterStore[];
                if (stores != null)
                {
                    foreach (var store in stores)
                    {
                        _historyItems.AddRange(
                            // create combobox items from TELNET parameters
                            store.FindTerminalParameter <ITCPParameter>()
                            .Select((sessionParams) => {
                            ITCPParameter tcpParam       = sessionParams.ConnectionParameter;
                            ITelnetParameter telnetParam = tcpParam.GetAdapter(typeof(ITelnetParameter)) as ITelnetParameter;
                            if (telnetParam != null)
                            {
                                return(new ParameterItem(telnetParam, tcpParam, sessionParams.TerminalParameter, sessionParams.TerminalSettings));
                            }
                            else
                            {
                                return(null);
                            }
                        })
                            .Where((item) => {
                            return(item != null);
                        })
                            );
                    }
                }
            }

            if (_historyItems.Count > 0)
            {
                _hostBox.Items.AddRange(_historyItems.ToArray());
                _hostBox.SelectedIndex = 0;
            }
        }
        /// <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();
            }
        }
        /// <summary>
        /// カレントセッションプロファイルを新規作成
        /// </summary>
        /// <param name="ts">ターミナルセッション</param>
        public void NewProfileCurrentSessionCommand(ITerminalSession ts)
        {
            ISSHLoginParameter   ssh    = (ISSHLoginParameter)ts.TerminalConnection.Destination.GetAdapter(typeof(ISSHLoginParameter));
            ITelnetParameter     telnet = (ITelnetParameter)ts.TerminalConnection.Destination.GetAdapter(typeof(ITelnetParameter));
            ITCPParameter        tcp    = null;
            ConnectProfileStruct prof   = new ConnectProfileStruct();

            // プロトコルチェック
            if (telnet != null)
            {
                // Telnet
                tcp                = (ITCPParameter)ts.TerminalConnection.Destination.GetAdapter(typeof(ITCPParameter));
                prof.Protocol      = ConnectionMethod.Telnet;
                prof.HostName      = tcp.Destination;
                prof.Port          = tcp.Port;
                prof.TelnetNewLine = telnet.TelnetNewLine;
            }
            else
            {
                // SSH
                tcp            = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
                prof.HostName  = tcp.Destination;
                prof.Port      = tcp.Port;
                prof.UserName  = ssh.Account;
                prof.Password  = ssh.PasswordOrPassphrase;
                prof.KeyFile   = ssh.IdentityFileName;
                prof.AutoLogin = true;
                if (ssh.Method.ToString() == "SSH1")
                {
                    prof.Protocol = ConnectionMethod.SSH1;
                }
                else if (ssh.Method.ToString() == "SSH2")
                {
                    prof.Protocol = ConnectionMethod.SSH2;
                }
                if (ssh.AuthenticationType.ToString() == "Password")
                {
                    prof.AuthType = AuthType.Password;
                }
                else if (ssh.AuthenticationType.ToString() == "PublicKey")
                {
                    prof.AuthType = AuthType.PublicKey;
                }
                else if (ssh.AuthenticationType.ToString() == "KeyboardInteractive")
                {
                    prof.AuthType = AuthType.KeyboardInteractive;
                }
            }

            // その他設定
            prof.CharCode     = ts.TerminalSettings.Encoding;
            prof.NewLine      = ts.TerminalSettings.TransmitNL;
            prof.TerminalType = ts.TerminalSettings.TerminalType;
            if (ts.TerminalSettings.RenderProfile == null)
            {
                prof.RenderProfile            = ConnectProfilePlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile();
                prof.RenderProfile.ESColorSet = new EscapesequenceColorSet();
                prof.RenderProfile.ESColorSet.ResetToDefault();
            }
            else
            {
                prof.RenderProfile = ts.TerminalSettings.RenderProfile;
            }
            prof.CommandSendInterval = ConnectProfileStruct.DEFAULT_CMD_SEND_INTERVAL;
            prof.PromptRecvTimeout   = ConnectProfileStruct.DEFAULT_PROMPT_RECV_TIMEOUT;
            prof.ProfileItemColor    = System.Drawing.Color.Black;

            // ウィンドウ表示/プロファイル追加
            ProfileEditForm dlg = new ProfileEditForm(prof);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                AddProfileCommand(ConnectProfilePlugin.Profiles, dlg.ResultProfile);
            }
        }