public ConnectionTag SilentNewConnection(TerminalParam p)
        {
            if (!CheckPaneCount())
            {
                return(null);
            }

            ConnectionTag con = null;

            if (p is SSHTerminalParam)
            {
                SSHTerminalParam tp = (SSHTerminalParam)p;
                con = CommunicationUtil.CreateNewConnection(tp, null);
            }
            else if (p is TelnetTerminalParam)
            {
                TelnetTerminalParam tp = (TelnetTerminalParam)p;
                con = CommunicationUtil.CreateNewConnection(tp);
            }
            else if (p is SerialTerminalParam)
            {
                SerialTerminalParam tp = (SerialTerminalParam)p;
                con = CommunicationUtil.CreateNewSerialConnection(_frame, tp);
            }
            else if (p is LocalShellTerminalParam)
            {
                LocalShellTerminalParam tp = (LocalShellTerminalParam)p;
                con = CommunicationUtil.CreateNewLocalShellConnection(_frame, tp);
            }

            if (con != null)
            {
                AddNewTerminal(con);
            }
            return(con);
        }
 public TelnetConnector(TelnetTerminalParam param, Size size)
 {
     _param = param;
     _size  = size;
 }
        public void Connect()
        {
            #region old stuff

            /*
             * Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
             * string file = null;
             * if (this.TerminalPane.Connection != null)
             * {
             *  logType = this.TerminalPane.Connection.LogType;
             *  file = this.TerminalPane.Connection.LogPath;
             *  //GApp.GetConnectionCommandTarget().Close();
             *  this.TerminalPane.Connection.Close();
             *  this.TerminalPane.Detach();
             * }
             *
             *
             * SSHTerminalParam p = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password);
             *
             * GApp.GlobalCommandTarget.SilentNewConnection(p);
             *
             *
             * if (file != null)
             *  this.SetLog((LogType) logType, file, true);
             */
            #endregion

            // Save old log info in case this is a reconnect
            Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
            string file = null;
            if (this.TerminalPane.Connection != null)
            {
                logType = this.TerminalPane.Connection.LogType;
                file    = this.TerminalPane.Connection.LogPath;
                //GApp.GetConnectionCommandTarget().Close();
                this.TerminalPane.Connection.Close();
                this.TerminalPane.Detach();
            }

            try
            {
                TCPTerminalParam  connParam      = null;
                SocketWithTimeout swt            = null;
                CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient();
                Size sz = this.Size;

                if (Method == ConnectionMethod.Telnet)
                {
                    connParam               = new TelnetTerminalParam(this.Host);
                    connParam.Encoding      = EncodingType.ISO8859_1;
                    connParam.Port          = _port;
                    connParam.RenderProfile = new RenderProfile();
                    connParam.TerminalType  = TerminalType.XTerm;

                    swt = new TelnetConnector((TelnetTerminalParam)connParam, sz);
                }
                else if (Method == ConnectionMethod.SSH1 || Method == ConnectionMethod.SSH2)
                {
                    connParam = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod) this.Method, this.Host, this.UserName, this.Password);
                    ((SSHTerminalParam)connParam).AuthType     = this.AuthType;
                    ((SSHTerminalParam)connParam).IdentityFile = this.IdentifyFile;
                    connParam.Encoding      = EncodingType.ISO8859_1;
                    connParam.Port          = _port;
                    connParam.RenderProfile = new RenderProfile();
                    connParam.TerminalType  = TerminalType.XTerm;

                    swt = new SSHConnector((SSHTerminalParam)connParam, sz, ((SSHTerminalParam)connParam).Passphrase, (HostKeyCheckCallback)null);
                }

                swt.AsyncConnect(s, connParam.Host, connParam.Port);

                ConnectionTag ct = s.Wait(swt);

                this.TerminalPane.FakeVisible = true;

                this.TerminalPane.Attach(ct);
                ct.Receiver.Listen();

                //-------------------------------------------------------------
                if (file != null)
                {
                    this.SetLog((LogType)logType, file, true);
                }
                this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile();
                this.SetPaneColors(Color.LightBlue, Color.Black);
            }
            catch
            {
                //MessageBox.Show(e.Message, "Connection Error");
                return;
            }
        }
Exemple #4
0
        //入力内容に誤りがあればそれを警告してnullを返す。なければ必要なところを埋めたTCPTerminalParamを返す
        private TCPTerminalParam ValidateContent()
        {
            string           msg = null;
            TCPTerminalParam p   = null;
            SSHTerminalParam sp  = null;

            try {
                ConnectionMethod m = ParseMethod(_methodBox.Text);
                if (m == ConnectionMethod.Telnet)
                {
                    p = new TelnetTerminalParam("");
                }
                else
                {
                    p          = sp = new SSHTerminalParam(ConnectionMethod.SSH2, "", "", "");
                    sp.Method  = m;
                    sp.Account = _userNameBox.Text;
                }

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

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

                p.LogType = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);

                if (p.LogType != LogType.None)
                {
                    p.LogPath = _logFileBox.Text;
                    if (p.LogPath == GUtil.CreateLogFileName(null))
                    {
                        p.LogPath = GUtil.CreateLogFileName(_hostBox.Text);
                    }
                    LogFileCheckResult r = GCUtil.CheckLogFileName(p.LogPath, this);
                    if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                    {
                        return(null);
                    }
                    p.LogAppend = (r == LogFileCheckResult.Append);
                }

                if (p.IsSSH)
                {
                    Debug.Assert(sp != null);
                    sp.AuthType = (AuthType)_authOptions.SelectedIndex;
                    if (sp.AuthType == AuthType.PublicKey)
                    {
                        if (!File.Exists(_privateKeyFile.Text))
                        {
                            msg = GApp.Strings.GetString("Message.LoginDialog.KeyFileNotExist");
                        }
                        else
                        {
                            sp.IdentityFile = _privateKeyFile.Text;
                        }
                    }
                }
                p.EncodingProfile = EncodingProfile.Get((EncodingType)_encodingBox.SelectedIndex);

                p.LocalEcho    = _localEchoBox.SelectedIndex == 1;
                p.TransmitNL   = (NewLine)EnumDescAttributeT.For(typeof(NewLine)).FromDescription(_newLineBox.Text, NewLine.CR);
                p.TerminalType = (TerminalType)_terminalTypeBox.SelectedIndex;

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