コード例 #1
0
        internal override ITerminalParameter ConvertToTerminalParameter()
        {
            ITCPParameter tcp = MacroPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();

            tcp.Port        = _port;
            tcp.Destination = _host;
            return((ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)));
        }
コード例 #2
0
        protected override void Negotiate()
        {
            ITerminalParameter       term = (ITerminalParameter)_destination.GetAdapter(typeof(ITerminalParameter));
            TelnetNegotiator         neg  = new TelnetNegotiator(term.TerminalType, term.InitialWidth, term.InitialHeight);
            TelnetTerminalConnection r    = new TelnetTerminalConnection(_destination, neg, new PlainPoderosaSocket(_socket));

            //BACK-BURNER r.UsingSocks = _socks!=null;
            _result = r;
        }
コード例 #3
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);
        }
コード例 #4
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;
        }
コード例 #5
0
        public void AsyncConnect(IInterruptableConnectorClient client, ITCPParameter param) {
            _client = client;
            _tcpDestination = param;
            _host = param.Destination;
            _port = param.Port;

            //AgentForward等のチェックをする
            foreach (IConnectionResultEventHandler ch in ProtocolsPlugin.Instance.ConnectionResultEventHandler.GetExtensions())
                ch.BeforeAsyncConnect((ITerminalParameter)param.GetAdapter(typeof(ITerminalParameter)));

            Thread th = new Thread(new ThreadStart(this.Run));
            th.Start();
        }
コード例 #6
0
        public void AsyncConnect(IInterruptableConnectorClient client, ITCPParameter param)
        {
            _client         = client;
            _tcpDestination = param;
            _host           = param.Destination;
            _port           = param.Port;

            //AgentForward等のチェックをする
            foreach (IConnectionResultEventHandler ch in ProtocolsPlugin.Instance.ConnectionResultEventHandler.GetExtensions())
            {
                ch.BeforeAsyncConnect((ITerminalParameter)param.GetAdapter(typeof(ITerminalParameter)));
            }

            Thread th = new Thread(new ThreadStart(this.Run));

            th.Start();
        }
コード例 #7
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;
            }
        }
コード例 #8
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();
            }
        }
コード例 #9
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));
        }
コード例 #10
0
 protected TCPTerminalConnection(ITCPParameter p)
     : base((ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)))
 {
     _usingSocks = false;
 }
コード例 #11
0
 protected TCPTerminalConnection(ITCPParameter p)
     : base((ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)))
 {
 }
コード例 #12
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);
            }
        }
コード例 #13
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;
 }
コード例 #14
0
 protected TCPTerminalConnection(ITCPParameter p)
     : base((ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)))
 {
 }
コード例 #15
0
 protected TCPTerminalConnection(ITCPParameter p)
     : base((ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)))
 {
     _usingSocks = false;
 }