public SSHShortcutLoginDialog(SSHTerminalParam param) { // // Windows フォーム デザイナ サポートに必要です。 // InitializeComponent(); this._privateKeyLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._privateKeyLabel"); this._passphraseLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._passphraseLabel"); this._logFileLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._logFileLabel"); this._hostLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._hostLabel"); this._methodLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._methodLabel"); this._accountLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._accountLabel"); this._authTypeLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._authTypeLabel"); this._encodingLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._encodingLabel"); this._logTypeLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._logTypeLabel"); this.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog.Text"); this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel"); this._loginButton.Text = GApp.Strings.GetString("Common.OK"); // // _terminalParam = param; InitUI(); }
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(); }
public SSHConnector(SSHTerminalParam param, Size size, string password, HostKeyCheckCallback keycheck) { _param = param; _size = size; _password = password; _keycheck = keycheck; }
private static string ToKeyString(SSHTerminalParam param) { string h = param.Host; if (param.Port != 22) { h += ":" + param.Port; } return(h); }
public void Update(SSHTerminalParam param, string key) { if (param.Method == ConnectionMethod.SSH1) { _dataForSSH1[ToKeyString(param)] = key; } else { _dataForSSH2[ToKeyString(param)] = key; } }
public KeyCheckResult Check(SSHTerminalParam param, string key) { object k = param.Method == ConnectionMethod.SSH1? _dataForSSH1[ToKeyString(param)] : _dataForSSH2[ToKeyString(param)]; if (k == null) { return(KeyCheckResult.NotExists); } else { return(key.Equals(k)? KeyCheckResult.OK : KeyCheckResult.Different); } }
public static ConnectionTag CreateNewConnection(SSHTerminalParam param, HostKeyCheckCallback keycheck) { SilentClient s = new SilentClient(); SocketWithTimeout swt = StartNewConnection(s, param, param.Passphrase, keycheck); if (swt == null) { return(null); } else { return(s.Wait(swt)); } }
private SSHTerminalParam ValidateContent() { SSHTerminalParam p = _terminalParam; string msg = null; try { p.LogType = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None); if (p.LogType != LogType.None) { p.LogPath = _logFileBox.Text; LogFileCheckResult r = GCUtil.CheckLogFileName(p.LogPath, this); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { return(null); } p.LogAppend = (r == LogFileCheckResult.Append); } if (p.AuthType == AuthType.PublicKey) { if (!File.Exists(_privateKeyBox.Text)) { msg = GApp.Strings.GetString("Message.SSHShortcutLoginDialog.KeyFileNotExist"); } else { p.IdentityFile = _privateKeyBox.Text; } } if (msg != null) { GUtil.Warning(this, msg); return(null); } else { return(p); } } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(null); } }
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 void Connect() { // 先判断连接状态 if (IsConnected || _isConnecting) { return; } _isConnecting = true; if (statusText == null) { statusText = new Label(); statusText.Dock = DockStyle.Fill; statusText.BackColor = Color.White; statusText.ForeColor = Color.Black; statusText.Font = new Font("Microsoft YaHei", 10); statusText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; } statusText.Text = "正在连接"; statusText.Visible = true; this.Invalidate(); this.Controls.Add(statusText); if (GApp._frame == null) { GApp.Run(new string[0]); GApp.Options.BGColor = this.BackColor; GApp.Options.TextColor = this.ForeColor; GApp.Options.RightButtonAction = RightButtonAction.Paste; GApp.Options.AutoCopyByLeftButton = true; //GApp.Options.WarningOption = WarningOption.Ignore; GApp.Options.Font = this.Font; GApp._frame._multiPaneControl.InitUI(null, GApp.Options); GEnv.InterThreadUIService.MainFrameHandle = GApp._frame.Handle; } try { //------------------------------------------------------------------------ SSHTerminalParam sshp = new SSHTerminalParam(Poderosa.ConnectionParam.ConnectionMethod.SSH2, this.Host, this.UserName, this.Password); sshp.AuthType = AuthType.Password; sshp.IdentityFile = string.Empty; sshp.Encoding = EncodingType.UTF8; sshp.Port = this._port; sshp.RenderProfile = new RenderProfile(); sshp.TerminalType = TerminalType.XTerm; CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient(); Size sz = this.Size; SocketWithTimeout swt = new SSHConnector(sshp, sz, sshp.Passphrase, null); swt.AsyncConnect(s, sshp.Host, sshp.Port, (ct, errorMessage) => { if (ct == null) { statusText.Invoke(new Action(() => { statusText.Text = "连接异常:" + errorMessage; })); return; } if (this._terminalPane == null) { this.Invoke(new Action(() => { this._terminalPane = new TerminalPane(); InitTerminalPane(ct); })); } else { this._terminalPane.Invoke(new Action(() => { this._terminalPane.Detach(); InitTerminalPane(ct); })); } }); } catch (Exception ex) { statusText.Text = "连接异常:" + ex.Message; return; } _isConnecting = false; }
public HostKeyChecker(IWin32Window parent, SSHTerminalParam param) { _parentForm = parent; _tryingParam = param; }
public virtual void Update(SSHTerminalParam param, string server_key) { }
public virtual KeyCheckResult Check(SSHTerminalParam param, string server_key) { return(KeyCheckResult.OK); }
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 { //------------------------------------------------------------------------ SSHTerminalParam sshp = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod) this.Method, this.Host, this.UserName, this.Password); sshp.AuthType = this.AuthType; sshp.IdentityFile = this.IdentifyFile; sshp.Encoding = EncodingType.ISO8859_1; sshp.Port = 22; sshp.RenderProfile = new RenderProfile(); sshp.TerminalType = TerminalType.XTerm; CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient(); Size sz = this.Size; SocketWithTimeout swt; swt = new SSHConnector((Poderosa.ConnectionParam.SSHTerminalParam)sshp, sz, sshp.Passphrase, (HostKeyCheckCallback)null); swt.AsyncConnect(s, sshp.Host, sshp.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 string ReturnAccount(TerminalParam p) { SSHTerminalParam pp = p as SSHTerminalParam; return(pp == null? null : pp.Account); }