public void OnOK(object sender, System.EventArgs e) { this.DialogResult = DialogResult.None; TCPTerminalParam param = ValidateContent(); if (param == null) { return; //パラメータに誤りがあれば即脱出 } _loginButton.Enabled = false; _cancelButton.Enabled = false; this.Cursor = Cursors.WaitCursor; this.Text = GApp.Strings.GetString("Caption.LoginDialog.Connecting"); _savedHWND = this.Handle; HostKeyCheckCallback checker = null; if (param.IsSSH) { checker = new HostKeyCheckCallback(new HostKeyChecker(this, (SSHTerminalParam)param).CheckHostKeyCallback); } _connector = CommunicationUtil.StartNewConnection(this, param, _passphraseBox.Text, checker); if (_connector == null) { ClearConnectingState(); } }
public CommandResult NewConnectionWithDialog(TCPTerminalParam param) { if (!CheckPaneCount()) { return(CommandResult.Denied); } ConnectionHistory hst = GApp.ConnectionHistory; LoginDialog dlg = new LoginDialog(); if (param != null) { dlg.ApplyParam(param); } else { dlg.ApplyParam(hst.TopTCPParam); } if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK) //ダイアログを出さないなら無条件で接続を開く { AddNewTerminal(dlg.Result); return(CommandResult.Success); } else { return(CommandResult.Cancelled); } }
public void ApplyParam(TCPTerminalParam param) { _initializing = true; _methodBox.SelectedIndex = (int)param.Method; _portBox.SelectedIndex = _portBox.FindStringExact(PortDescription(param.Port)); _methodBox.SelectedIndex = _methodBox.FindStringExact(param.Method.ToString()); if (param.IsSSH) { SSHTerminalParam sp = (SSHTerminalParam)param; _userNameBox.SelectedIndex = _userNameBox.FindStringExact(sp.Account); _passphraseBox.Text = sp.Passphrase; if (sp.AuthType == AuthType.PublicKey) { _privateKeyFile.Text = sp.IdentityFile; } else { _privateKeyFile.Text = ""; } _authOptions.SelectedIndex = (int)sp.AuthType; } _encodingBox.SelectedIndex = (int)param.EncodingProfile.Type; _newLineBox.SelectedIndex = (int)param.TransmitNL; _localEchoBox.SelectedIndex = param.LocalEcho? 1 : 0; _terminalTypeBox.SelectedIndex = (int)param.TerminalType; _initializing = false; EnableValidControls(); }
private void connectSSHToolStripMenuItem_Click(object sender, EventArgs e) { //Poderosa.Forms.MultiPaneControl mc = new Poderosa.Forms.MultiPaneControl(); //mc.Dock = DockStyle.Fill; //mc.BackColor = System.Drawing.Color.AliceBlue; //tabPage1.Controls.Add(mc); InitialAction a = new InitialAction(); //Poderosa.Forms.GFrame frame = new Poderosa.Forms.GFrame(a); ConnectionHistory hst = GApp.ConnectionHistory; Poderosa.Forms.LoginDialog dlg = new Poderosa.Forms.LoginDialog(); TCPTerminalParam param = hst.TopTCPParam; dlg.ApplyParam(param); dlg.StartPosition = FormStartPosition.CenterParent; //if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK) //frame.Show(); //GCUtil.ShowModalDialog(frame, dlg); //dlg.ShowDialog(); dlg._hostBox.Text = "palm"; dlg._methodBox.SelectedIndex = 2; dlg._portBox.Text = "22"; dlg._userNameBox.Text = "bwilliam"; dlg._passphraseBox.Text = "lkmj9u"; dlg.OnOK(null, null); Connection.ConnectionTag ct = dlg.Result; }
private void InitializeLoginParams() { StringCollection c = _history.Hosts; foreach (string h in c) { _hostBox.Items.Add(h); } if (_hostBox.Items.Count > 0) { _hostBox.SelectedIndex = 0; } c = _history.Accounts; foreach (string a in c) { _userNameBox.Items.Add(a); } if (_userNameBox.Items.Count > 0) { _userNameBox.SelectedIndex = 0; } int[] ic = _history.Ports; foreach (int p in ic) { _portBox.Items.Add(PortDescription(p)); } if (_hostBox.Items.Count > 0) { TCPTerminalParam last = _history.SearchByHost((string)_hostBox.Items[0]); if (last != null) { ApplyParam(last); } } c = _history.LogPaths; foreach (string p in c) { _logFileBox.Items.Add(p); } if (GApp.Options.DefaultLogType != LogType.None) { _logTypeBox.SelectedIndex = (int)GApp.Options.DefaultLogType; string t = GUtil.CreateLogFileName(null); _logFileBox.Items.Add(t); _logFileBox.Text = t; } else { _logTypeBox.SelectedIndex = 0; } }
private void OnHostIsSelected(object sender, System.EventArgs e) { if (_initializing) { return; } string host = _hostBox.Text; TCPTerminalParam param = _history.SearchByHost(host); Debug.Assert(param != null); ApplyParam(param); }
public TCPTerminalParam SearchByHost(string host) { foreach (TerminalParam p in _history) { TCPTerminalParam tp = p as TCPTerminalParam; if (tp != null && tp.Host == host) { return(tp); } } return(null); }
public CommandResult NewConnection(TerminalParam p) { if (!CheckPaneCount()) { return(CommandResult.Denied); } ConnectionTag con = null; if (p is TCPTerminalParam) { TCPTerminalParam param = (TCPTerminalParam)p; if (param.IsSSH) { SSHShortcutLoginDialog dlg = new SSHShortcutLoginDialog((SSHTerminalParam)param); if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK) { con = dlg.Result; } } else { con = CommunicationUtil.CreateNewConnection(param); } } else if (p is SerialTerminalParam) { SerialTerminalParam param = (SerialTerminalParam)p; con = CommunicationUtil.CreateNewSerialConnection(_frame, param); } else if (p is LocalShellTerminalParam) { LocalShellTerminalParam param = (LocalShellTerminalParam)p; con = CommunicationUtil.CreateNewLocalShellConnection(_frame, param); } if (con != null) { AddNewTerminal(con); return(CommandResult.Success); } else { return(CommandResult.Cancelled); } }
public static SocketWithTimeout StartNewConnection(ISocketWithTimeoutClient client, TCPTerminalParam param, string password, HostKeyCheckCallback keycheck) { Size sz = GEnv.Frame.TerminalSizeForNextConnection; //Size sz = new System.Drawing.Size(528, 316); SocketWithTimeout swt; if (param.Method == ConnectionMethod.Telnet) //Telnet { swt = new TelnetConnector((TelnetTerminalParam)param, sz); } else //SSH { swt = new SSHConnector((SSHTerminalParam)param, sz, password, keycheck); } if (GEnv.Options.UseSocks) { swt.AsyncConnect(client, CreateSocksParam(param.Host, param.Port)); } else { swt.AsyncConnect(client, param.Host, param.Port); } return(swt); }
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; } }
//入力内容に誤りがあればそれを警告して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); } }
private int ReturnPort(TerminalParam p) { TCPTerminalParam pp = p as TCPTerminalParam; return(pp == null? -1 : pp.Port); }
private string ReturnHost(TerminalParam p) { TCPTerminalParam pp = p as TCPTerminalParam; return(pp == null? null : pp.Host); }