示例#1
0
 public void close()
 {
     if (_session != null)
     {
         _session.InternalTerminate();
     }
     if (_connector != null)
     {
         if (typeof(SSHConnector) == _connector.GetType())
         {
             ((SSHConnector)_connector).Result.Close();
         }
         else
         {
             ((TelnetConnector)_connector).Result.Close();
         }
     }
     if (tcp != null)
     {
         tcp = null;
     }
     if (ssh != null)
     {
         ssh = null;
     }
     if (_param != null)
     {
         _param = null;
     }
     _connector   = null;
     _session     = null;
     _isConnected = false;
     _timedOut    = false;
 }
示例#2
0
        private void _loginButton_Click(object sender, EventArgs e)
        {
            int tabPageIndex = _sessionTypeTab.SelectedIndex;
            var tabPage      = _tabPages[tabPageIndex];

            _loginButton.Enabled    = false;
            _cancelButton.Enabled   = false;
            _sessionTypeTab.Enabled = false;

            this.Cursor = Cursors.WaitCursor;

            ITerminalSettings terminalSettings;
            IInterruptable    interruptable;
            bool started = tabPage.OpenSession(this, out terminalSettings, out interruptable);

            if (!started)
            {
                _loginButton.Enabled    = true;
                _cancelButton.Enabled   = true;
                _sessionTypeTab.Enabled = true;
                return;
            }

            this.Text             = TEnv.Strings.GetString("Caption.LoginDialog.Connecting");
            _terminalSettings     = terminalSettings;
            _interruptable        = interruptable;
            _cancelButton.Enabled = true;
        }
示例#3
0
        public void T07_FormBaseFail()
        {
            ProtocolServiceTestPlugin.Instance.Reset();

            ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter();

            ssh.Method  = SSHProtocol.SSH2;
            ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account");
            ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_wrongpassword");
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = GetSSHConnectableHost();
            Assert.AreEqual(22, tcp.Port);

            ISynchronizedConnector sc  = _protocolService.CreateFormBasedSynchronozedConnector(null);
            IInterruptable         t   = _protocolService.AsyncSSHConnect(sc.InterruptableConnectorClient, ssh);
            ITerminalConnection    con = sc.WaitConnection(t, 5000);

            ProtocolServiceTestPlugin.Instance.AssertFail();

            Socket s = ((InterruptableConnector)t).RawSocket;

            Assert.IsFalse(s.Connected);
            Assert.IsNull(con);
        }
示例#4
0
        public ITerminalConnection WaitConnection(IInterruptable intr, int timeout)
        {
            //ちょっと苦しい判定
            if (!(intr is InterruptableConnector) && !(intr is LocalShellUtil.Connector))
            {
                throw new ArgumentException("IInterruptable object is not correct");
            }

            if (!_event.WaitOne(timeout, true))
            {
                _timeout      = true; //TODO 接続を中止すべきか
                _errorMessage = PEnv.Strings.GetString("Message.ConnectionTimedOut");
            }
            _event.Close();

            if (_result == null)
            {
                if (_form != null)
                {
                    _form.Warning(_errorMessage);
                }
                return(null);
            }
            else
            {
                return(_result);
            }
        }
示例#5
0
        public ITerminalConnection WaitConnection(IInterruptable intr, int timeout)
        {
            //‚¿‚å‚Á‚Ƌꂵ‚¢”»’è
            //if(!(intr is InterruptableConnector) && !(intr is LocalShellUtil.Connector)) throw new ArgumentException("IInterruptable object is not correct");
            if (!(intr is InterruptableConnector))
            {
                throw new ArgumentException("IInterruptable object is not correct");
            }

            if (!_event.WaitOne(timeout, true))
            {
                _timeout      = true; //TODO Ú‘±‚𒆎~‚·‚ׂ«‚©
                _errorMessage = "Message.ConnectionTimedOut";
            }
            _event.Close();

            if (_result == null)
            {
                //if(_form!=null) _form.Warning(_errorMessage)
                Console.WriteLine(_errorMessage);
                return(null);
            }
            else
            {
                return(_result);
            }
        }
            public ITerminalConnection EstablishConnection(IPoderosaMainWindow window, ITerminalParameter destination, ITerminalSettings settings)
            {
                ISSHLoginParameter ssh = (ISSHLoginParameter)destination.GetAdapter(typeof(ISSHLoginParameter));

                if (ssh.LetUserInputPassword && ssh.AuthenticationType != Granados.AuthenticationType.KeyboardInteractive) //ダイアログで入力を促して接続
                {
                    SSHShortcutLoginDialog dlg = new SSHShortcutLoginDialog(window, ssh, settings);
                    if (dlg.ShowDialog(window.AsForm()) == DialogResult.OK)
                    {
                        ITerminalConnection con = dlg.Result;
                        AdjustCaptionAndText(settings, ((ITCPParameter)con.Destination.GetAdapter(typeof(ITCPParameter))).Destination, StartCommandIcon.NewConnection);
                        return(con);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else   //主にReproduceやマクロ。設定済みのパスワードで接続
                {
                    IProtocolService       protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;
                    ISynchronizedConnector conn            = protocolservice.CreateFormBasedSynchronozedConnector(window);
                    IInterruptable         r = protocolservice.AsyncSSHConnect(conn.InterruptableConnectorClient, ssh);
                    AdjustCaptionAndText(settings, ((ITCPParameter)destination.GetAdapter(typeof(ITCPParameter))).Destination, StartCommandIcon.NewConnection);
                    return(conn.WaitConnection(r, TerminalSessionsPlugin.Instance.TerminalSessionOptions.TerminalEstablishTimeout)); //時間?
                }
            }
示例#7
0
 private void ResumeFromOpeningSession()
 {
     _interruptable          = null;
     _loginButton.Enabled    = true;
     _cancelButton.Enabled   = true;
     _sessionTypeTab.Enabled = true;
     this.Cursor             = Cursors.Default;
     this.Text = TEnv.Strings.GetString("Form.LoginDialog.Text");
 }
            public ITerminalConnection EstablishConnection(IPoderosaMainWindow window, ITerminalParameter destination, ITerminalSettings settings)
            {
                ITCPParameter          tcp = (ITCPParameter)destination.GetAdapter(typeof(ITCPParameter));
                IProtocolService       ps  = TerminalSessionsPlugin.Instance.ProtocolService;
                ISynchronizedConnector sc  = ps.CreateFormBasedSynchronozedConnector(window);
                IInterruptable         t   = ps.AsyncTelnetConnect(sc.InterruptableConnectorClient, tcp);
                ITerminalConnection    con = sc.WaitConnection(t, TerminalSessionsPlugin.Instance.TerminalSessionOptions.TerminalEstablishTimeout);

                AdjustCaptionAndText(settings, tcp.Destination, StartCommandIcon.NewConnection);
                return(con);
            }
        public void Connect()
        {
            try
            {
                switch (_protocol)
                {
                case ProtocolType.Cywin:
                    _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                    _asyncConnection       = _basePoderosaInstance.ProtocolService.AsyncCygwinConnect(_synchronizedConnector.InterruptableConnectorClient, (ICygwinParameter)_terminalParameter);
                    _terminalConnection    = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                    break;

                case ProtocolType.Raw:
                    break;

                case ProtocolType.RLogin:
                    break;

                case ProtocolType.Serial:
                    _terminalConnection = (ITerminalConnection)SerialPortUtil.CreateNewSerialConnection(_window, (SerialTerminalParam)_terminalParameter, (SerialTerminalSettings)_terminalSettings);
                    break;

                case ProtocolType.SSH1:
                case ProtocolType.SSH2:
                    _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                    _asyncConnection       = _basePoderosaInstance.ProtocolService.AsyncSSHConnect(_synchronizedConnector.InterruptableConnectorClient, (ISSHLoginParameter)_terminalParameter);
                    _terminalConnection    = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                    break;

                case ProtocolType.Telnet:
                    _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                    _asyncConnection       = _basePoderosaInstance.ProtocolService.AsyncTelnetConnect(_synchronizedConnector.InterruptableConnectorClient, (ITCPParameter)_terminalParameter);
                    _terminalConnection    = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                    break;

                default:
                    _terminalConnection = null;
                    break;
                }
                _terminalSession = new TerminalSession(_terminalConnection, _terminalSettings);
                _basePoderosaInstance.SessionManagerPlugin.StartNewSession(_terminalSession, _terminalView);
                _basePoderosaInstance.SessionManagerPlugin.ActivateDocument(_terminalSession.Terminal.IDocument, ActivateReason.InternalAction);
            }
            catch (Exception ex)
            {
                RuntimeUtil.ReportException(ex);
                //return CommandResult.Failed;
            }
        }
示例#10
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);
        }
示例#11
0
        public void SuccessfullyExit(ITerminalConnection result)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((Action)(() => {
                    SuccessfullyExit(result);
                }));
                return;
            }

            _interruptable      = null; // allow dialog to close
            _terminalConnection = result;
            this.DialogResult   = DialogResult.OK;
            this.Cursor         = Cursors.Default;
            Close();
        }
示例#12
0
        public void T00_TelnetSuccess()
        {
            ProtocolServiceTestPlugin.Instance.Reset();

            ITCPParameter tcp = _protocolService.CreateDefaultTelnetParameter();

            tcp.Destination = GetTelnetConnectableHost();
            Assert.AreEqual(23, tcp.Port);

            ResultCallback client = new ResultCallback();
            IInterruptable t      = _protocolService.AsyncTelnetConnect(client, tcp);

            client.AssertSuccess();

            ProtocolServiceTestPlugin.Instance.AssertSuccess();
        }
 internal void Interrupt()
 {
     if (interruptStack.Count > 0)
     {
         IInterruptable toInterrupt = interruptStack.Peek();
         toInterrupt.Interrupt();
     }
     else
     {
         if (application is ShellApplication)
         {
             ((ShellApplication)application).OnInterrupt();
         }
         System.Console.Error.WriteLine("[Ctrl-C ; interrupted]");
         Environment.Exit(1);
     }
 }
示例#14
0
        //TODO シリアル用テストケースは追加必要。CygwinはTelnetと同じなのでまあいいだろう

        //TODO ITerminalOutputのテスト。正しく送信されたかを確認するのは難しい感じもするが

        //TODO Reproduceサポートの後、SSH2で1Connection-複数Channelを開き、個別に開閉してみる

        private ITerminalConnection CreateTelnetConnection()
        {
            ITCPParameter tcp = _protocolService.CreateDefaultTelnetParameter();

            tcp.Destination = UnitTestUtil.GetUnitTestConfig("protocols.telnet_connectable");
            Debug.Assert(tcp.Port == 23);

            ISynchronizedConnector sc  = _protocolService.CreateFormBasedSynchronozedConnector(null);
            IInterruptable         t   = _protocolService.AsyncTelnetConnect(sc.InterruptableConnectorClient, tcp);
            ITerminalConnection    con = sc.WaitConnection(t, 5000);

            //Assert.ReferenceEquals(con.Destination, tcp); //なぜか成立しない
            Debug.Assert(con.Destination == tcp);
            _rawsocket    = ((InterruptableConnector)t).RawSocket;
            _testReceiver = new TestReceiver();
            con.Socket.RepeatAsyncRead(_testReceiver);
            return(con);
        }
示例#15
0
        public void T06_FormBaseSuccess()
        {
            ProtocolServiceTestPlugin.Instance.Reset();

            ITCPParameter tcp = _protocolService.CreateDefaultTelnetParameter();

            tcp.Destination = GetTelnetConnectableHost();
            Assert.AreEqual(23, tcp.Port);

            ISynchronizedConnector sc  = _protocolService.CreateFormBasedSynchronozedConnector(null);
            IInterruptable         t   = _protocolService.AsyncTelnetConnect(sc.InterruptableConnectorClient, tcp);
            ITerminalConnection    con = sc.WaitConnection(t, 5000);

            Assert.IsNotNull(con);
            Assert.IsFalse(con.IsClosed);

            ProtocolServiceTestPlugin.Instance.AssertSuccess();
        }
示例#16
0
        public ITerminalConnection WaitConnection(IInterruptable intr, int timeout)
        {
            //ちょっと苦しい判定
            if (!(intr is InterruptableConnector) && !(intr is LocalShellUtil.Connector))
                throw new ArgumentException("IInterruptable object is not correct");

            if (!_event.WaitOne(timeout, true)) {
                _timeout = true; //TODO 接続を中止すべきか
                _errorMessage = PEnv.Strings.GetString("Message.ConnectionTimedOut");
            }
            _event.Close();

            if (_result == null) {
                if (_form != null)
                    _form.Warning(_errorMessage);
                return null;
            }
            else
                return _result;
        }
示例#17
0
        private void SSHSuccess(SSHProtocol sshprotocol)
        {
            ProtocolServiceTestPlugin.Instance.Reset();

            ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter();

            ssh.Method  = sshprotocol;
            ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account");
            ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_password");
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = GetSSHConnectableHost();
            Assert.AreEqual(22, tcp.Port);

            ResultCallback client = new ResultCallback();
            IInterruptable t      = _protocolService.AsyncSSHConnect(client, ssh);

            client.AssertSuccess();

            ProtocolServiceTestPlugin.Instance.AssertSuccess();
        }
示例#18
0
        protected override void OnSignal()
        {
            if (once)
            {
                // got the interrupt more than once. May happen if you press
                // Ctrl-C multiple times .. or with broken thread lib on Linux.
                return;
            }

            once = true;
            if (interruptStack.Count > 0)
            {
                IInterruptable toInterrupt = (IInterruptable)interruptStack.Peek();
                toInterrupt.Interrupt();
            }
            else
            {
                System.Console.Error.WriteLine("[Ctrl-C ; interrupted]");
                Environment.Exit(1);
            }
        }
示例#19
0
        private ITerminalConnection CreateSSHConnection(SSHProtocol sshprotocol)
        {
            ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter();

            ssh.Method  = sshprotocol;
            ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account");
            ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_password");
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = UnitTestUtil.GetUnitTestConfig("protocols.ssh_connectable");
            Debug.Assert(tcp.Port == 22);

            ISynchronizedConnector sc  = _protocolService.CreateFormBasedSynchronozedConnector(null);
            IInterruptable         t   = _protocolService.AsyncSSHConnect(sc.InterruptableConnectorClient, ssh);
            ITerminalConnection    con = sc.WaitConnection(t, 5000);

            Debug.Assert(con.Destination == ssh);
            _rawsocket    = ((InterruptableConnector)t).RawSocket;
            _testReceiver = new TestReceiver();
            con.Socket.RepeatAsyncRead(_testReceiver);
            return(con);
        }
示例#20
0
        public void T05_DenyHostKey()
        {
            ProtocolServiceTestPlugin.Instance.Reset();
            ProtocolServiceTestPlugin.Instance.AcceptsHostKey = false;

            ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter();

            ssh.Method  = SSHProtocol.SSH2;
            ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account");
            ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_password");
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = GetSSHConnectableHost();
            Assert.AreEqual(22, tcp.Port);

            ResultCallback client = new ResultCallback();
            IInterruptable t      = _protocolService.AsyncSSHConnect(client, ssh);

            client.AssertFail();

            ProtocolServiceTestPlugin.Instance.AssertFail();
            ProtocolServiceTestPlugin.Instance.AcceptsHostKey = true;
        }
 public void Connect()
 {
     try
     {
         switch (_protocol)
         {
             case ProtocolType.Cywin:
                 _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                 _asyncConnection = _basePoderosaInstance.ProtocolService.AsyncCygwinConnect(_synchronizedConnector.InterruptableConnectorClient, (ICygwinParameter)_terminalParameter);
                 _terminalConnection = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                 break;
             case ProtocolType.Raw:
                 break;
             case ProtocolType.RLogin:
                 break;
             case ProtocolType.Serial:
                 _terminalConnection =(ITerminalConnection) SerialPortUtil.CreateNewSerialConnection(_window,(SerialTerminalParam)_terminalParameter,(SerialTerminalSettings)_terminalSettings);
                 break;
             case ProtocolType.SSH1:
             case ProtocolType.SSH2:
                 _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                 _asyncConnection = _basePoderosaInstance.ProtocolService.AsyncSSHConnect(_synchronizedConnector.InterruptableConnectorClient, (ISSHLoginParameter)_terminalParameter);
                 _terminalConnection = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                 break;
             case ProtocolType.Telnet:
                 _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                 _asyncConnection = _basePoderosaInstance.ProtocolService.AsyncTelnetConnect(_synchronizedConnector.InterruptableConnectorClient, (ITCPParameter)_terminalParameter);
                 _terminalConnection = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                 break;
             default:
                 _terminalConnection = null;
                 break;
         }
         _terminalSession = new TerminalSession(_terminalConnection, _terminalSettings);
         _basePoderosaInstance.SessionManagerPlugin.StartNewSession(_terminalSession, _terminalView);
         _basePoderosaInstance.SessionManagerPlugin.ActivateDocument(_terminalSession.Terminal.IDocument, ActivateReason.InternalAction);
     }
     catch (Exception ex)
     {
         RuntimeUtil.ReportException(ex);
         //return CommandResult.Failed;
     }
 }
 private void ResumeFromOpeningSession()
 {
     _interruptable = null;
     _loginButton.Enabled = true;
     _cancelButton.Enabled = true;
     _sessionTypeTab.Enabled = true;
     this.Cursor = Cursors.Default;
     this.Text = TEnv.Strings.GetString("Form.LoginDialog.Text");
 }
        private void _loginButton_Click(object sender, EventArgs e)
        {
            int tabPageIndex = _sessionTypeTab.SelectedIndex;
            var tabPage = _tabPages[tabPageIndex];

            _loginButton.Enabled = false;
            _cancelButton.Enabled = false;
            _sessionTypeTab.Enabled = false;

            this.Cursor = Cursors.WaitCursor;

            ITerminalSettings terminalSettings;
            IInterruptable interruptable;
            bool started = tabPage.OpenSession(this, out terminalSettings, out interruptable);

            if (!started) {
                _loginButton.Enabled = true;
                _cancelButton.Enabled = true;
                _sessionTypeTab.Enabled = true;
                return;
            }

            this.Text = TEnv.Strings.GetString("Caption.LoginDialog.Connecting");
            _terminalSettings = terminalSettings;
            _interruptable = interruptable;
            _cancelButton.Enabled = true;
        }
示例#24
0
        public bool StartConnection()
        {
            bool bConResult = false;

            _isConnected = false;

            /*if (_session != null)
             *  if (_session.TerminalConnection != null)
             *      _isConnected = _session.TerminalConnection.IsClosed;
             */
            if (_Console == null)
            {
                _Console = new ConsoleMain();
            }
            //ISynchronizedConnector synchCon = _Console.CreateSynchronizedConnector(null);

            if (ssh != null)
            {
                _connector = _Console.AsyncSSHConnect(this /* synchCon.InterruptableConnectorClient */, ssh);
            }
            else
            {
                _connector = _Console.AsyncTelnetConnect(this /* synchCon.InterruptableConnectorClient */, tcp);
            }

            if (_connector == null)
            {
                _isRunning = false;
                return(bConResult);
            }

            //_result = synchCon.WaitConnection(_connector, _timeout * 1000);
            while ((!_timedOut) && (!_isConnected))
            {
                Thread.Sleep(100);
            }

            _result = ((InterruptableConnector)_connector).Result;
            if (_result == null)
            {
                _connector = null;
                _isRunning = false;
                return(bConResult);
            }

            try
            {
                _session         = new TerminalSession(((InterruptableConnector)_connector).Result, _terminalSettings, _terminalOptions);
                _session._parent = this;
                //SessionHost host = new SessionHost(this, session);
                _session.InternalStart();  // => _output.Connection.Socket.RepeatAsyncRead(_terminal);
                bConResult = true;
            }
            catch (Exception ex)
            {
                bConResult = false;
                if (_debug > 0)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(bConResult);
        }
        public void SuccessfullyExit(ITerminalConnection result)
        {
            if (this.InvokeRequired) {
                this.Invoke((Action)(() => {
                    SuccessfullyExit(result);
                }));
                return;
            }

            _interruptable = null;  // allow dialog to close
            _terminalConnection = result;
            this.DialogResult = DialogResult.OK;
            this.Cursor = Cursors.Default;
            Close();
        }
示例#26
0
 public static IInterruptable SetInterval(int ms, Action function)
 {
     return(timer = ms > -1 ? StartTimer(ms, function, true) : null);
 }
示例#27
0
 public void Push(IInterruptable interruptable)
 {
     interruptStack.Push(interruptable);
 }
示例#28
0
        /// <summary>
        /// Start opening session
        /// </summary>
        /// <remarks>
        /// The implementation of this method also do validation of the input values.
        /// </remarks>
        /// <param name="client">an instance who receive the result of opening session.</param>
        /// <param name="terminalSettings">terminal settings is set if this method returns true.</param>
        /// <param name="interruptable">an object for cancellation is set if this method returns true.</param>
        /// <returns>true if the opening session has been started, or false if failed.</returns>
        public bool OpenSession(IInterruptableConnectorClient client, out ITerminalSettings terminalSettings, out IInterruptable interruptable)
        {
            ISSHLoginParameter loginParam;
            ITerminalSettings  termSettings;
            string             errorMessage;

            if (!Validate(out loginParam, out termSettings, out errorMessage))
            {
                client.ConnectionFailed(errorMessage);
                terminalSettings = null;
                interruptable    = null;
                return(false);
            }

            IProtocolService protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;

            interruptable    = protocolservice.AsyncSSHConnect(client, loginParam);
            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);
            }
        }
 internal void Push(IInterruptable interruptable)
 {
     interruptStack.Push(interruptable);
 }
 internal void Push(IInterruptable interruptable)
 {
     interruptStack.Push(interruptable);
 }
示例#32
0
 public static IInterruptable SetTimeout(int ms, Action function)
 {
     return(timer = ms > -1 ? StartTimer(ms, function, false) : null);
 }
示例#33
0
 public void Push(IInterruptable interruptable)
 {
     interruptStack.Push(interruptable);
 }