protected override ITerminalParameter PrepareTerminalParameter() { _param.Home = _homeDirectoryBox.Text; _param.ShellName = _shellBox.Text; //ログ設定 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); //動作キャンセル } } ITerminalSettings settings = this.TerminalSettings; settings.BeginUpdate(); if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.Caption = _param.ShellBody; settings.Icon = Poderosa.TerminalSession.Properties.Resources.Cygwin16x16; settings.Encoding = (EncodingType)_encodingBox.SelectedIndex; settings.TerminalType = (TerminalType)_terminalTypeBox.SelectedIndex; settings.EndUpdate(); ITerminalParameter termParam = (ITerminalParameter)_param.GetAdapter(typeof(ITerminalParameter)); termParam.SetTerminalName(_terminalTypeBox.Text); // Used for TERM environment variable (LocalShellUtil) _param.CygwinDir = _cygwinDirBox.Text; if (_param.CygwinDir.Length > 0 && _param.CygwinDir[_param.CygwinDir.Length - 1] == Path.PathSeparator) { _param.CygwinDir = _param.CygwinDir.Substring(0, _param.CygwinDir.Length - 1); } string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = _param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } return((ITerminalParameter)_param.GetAdapter(typeof(ITerminalParameter))); }
/// <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); }
//入力内容に誤りがあればそれを警告してnullを返す。なければ必要なところを埋めたTCPTerminalParamを返す private ISSHLoginParameter ValidateContent() { ISSHLoginParameter p = (ISSHLoginParameter)_sshParam.Clone(); string msg = null; try { LogType logtype = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(null); //動作キャンセル } } ITerminalSettings settings = this.TerminalSettings; if (logsettings != null) { settings.BeginUpdate(); settings.LogSettings.Reset(logsettings); settings.EndUpdate(); } ITerminalParameter param = (ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)); param.SetTerminalName(ToTerminalName(settings.TerminalType)); if (p.AuthenticationType == AuthenticationType.PublicKey) { if (!File.Exists(_privateKeyBox.Text)) { msg = TEnv.Strings.GetString("Message.SSHShortcutLoginDialog.KeyFileNotExist"); } else { p.IdentityFileName = _privateKeyBox.Text; } } p.PasswordOrPassphrase = _passphraseBox.Text; string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = p.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } if (msg != null) { GUtil.Warning(this, msg); return(null); } else { return(p); } } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(null); } }
public MockTerminalConnection(string terminalType, MockSocket mockSocket) { _param = new TerminalParameter(); _param.SetTerminalName(terminalType); _mockSocket = mockSocket; }
/// <summary> /// Validates input values and constructs parameter objects. /// </summary> /// <param name="loginParam">SSH parameter object is set when this method returns true.</param> /// <param name="terminalSettings">terminal settings object is set when this method returns true.</param> /// <param name="errorMessage">validation error message is set when this method returns false. this can be null when displaying error message is not needed.</param> /// <returns>true if all validations passed and parameter objects were created.</returns> private bool Validate(out ISSHLoginParameter loginParam, out ITerminalSettings terminalSettings, out string errorMessage) { loginParam = null; terminalSettings = null; errorMessage = null; var ssh = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultSSHParameter(); var tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter)); //--- SSH connection settings if (_ssh1RadioButton.Checked) { ssh.Method = SSHProtocol.SSH1; } else if (_ssh2RadioButton.Checked) { ssh.Method = SSHProtocol.SSH2; } else { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.ProtocolVersionIsNotSpecified"); return(false); } tcp.Destination = _hostBox.Text; if (String.IsNullOrEmpty(tcp.Destination)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty"); return(false); } int port; if (Int32.TryParse(_portBox.Text, out port) && port >= 0 && port <= 65535) { tcp.Port = port; } else { errorMessage = String.Format( TEnv.Strings.GetString("Message.LoginDialog.InvalidPort"), _portBox.Text); return(false); } ssh.Account = _userNameBox.Text; AuthType authType = ((EnumListItem <AuthType>)_authOptions.SelectedItem).Value; ssh.AuthenticationType = authType.ToAuthenticationType(); if (ssh.AuthenticationType == AuthenticationType.PublicKey) { ssh.IdentityFileName = _privateKeyFile.Text; if (String.IsNullOrEmpty(ssh.IdentityFileName)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.PrivateKeyFileIsNotSpecified"); return(false); } if (!File.Exists(ssh.IdentityFileName)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.KeyFileNotExist"); return(false); } } if (ssh.AuthenticationType == AuthenticationType.Password || ssh.AuthenticationType == AuthenticationType.PublicKey) { ssh.PasswordOrPassphrase = _passphraseBox.Text; } //--- Log settings ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings(); logSettings.LogType = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; if (logSettings.LogType != LogType.None) { logSettings.LogPath = _logFileBox.Text; LogFileCheckResult r = LogUtil.CheckLogFileName(logSettings.LogPath, this.ParentForm); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { errorMessage = null; return(false); } logSettings.LogAppend = (r == LogFileCheckResult.Append); } //--- Terminal settings ITerminalParameter termParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)); TerminalType terminalType = ((EnumListItem <TerminalType>)_terminalTypeBox.SelectedItem).Value; termParam.SetTerminalName(terminalType.ToTermValue()); string terminalCaption = tcp.Destination; Image terminalIcon = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16; ITerminalSettings termSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(terminalCaption, terminalIcon); termSettings.BeginUpdate(); termSettings.Encoding = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value; termSettings.LocalEcho = ((ListItem <bool>)_localEchoBox.SelectedItem).Value; termSettings.TransmitNL = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value; termSettings.TerminalType = terminalType; termSettings.LogSettings.Reset(logSettings); termSettings.EndUpdate(); //--- X11 forwarding settings if (_useX11ForwardingCheckBox.Checked) { if (String.IsNullOrEmpty(_x11DisplayText.Text)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11DisplayIsNotEntered"); return(false); } int display; if (!Int32.TryParse(_x11DisplayText.Text, out display) || display < 0 || display > (65535 - 6000)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.InvalidX11Display"); return(false); } X11ForwardingParams x11Param = new X11ForwardingParams(display); if (String.IsNullOrEmpty(_x11ScreenText.Text)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11ScreenIsNotEntered"); return(false); } int screen; if (!Int32.TryParse(_x11ScreenText.Text, out screen) || screen < 0) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.InvalidX11Screen"); return(false); } x11Param.Screen = screen; if (_x11NeedAuthCheckBox.Checked) { x11Param.NeedAuth = true; x11Param.XauthorityFile = _x11XauthorityText.Text; if (String.IsNullOrEmpty(x11Param.XauthorityFile)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.XauthorityFileIsNotSpecified"); return(false); } } else { x11Param.NeedAuth = false; } if (_x11UseCygwinDomainSocketCheckBox.Checked) { x11Param.UseCygwinUnixDomainSocket = true; x11Param.X11UnixFolder = _x11CygwinX11UnixFolderText.Text; if (String.IsNullOrEmpty(x11Param.X11UnixFolder)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11UnixFolderIsNotSpecified"); return(false); } } ssh.EnableX11Forwarding = true; ssh.X11Forwarding = x11Param; } else { ssh.EnableX11Forwarding = false; ssh.X11Forwarding = null; } //--- Agent forwarding settings if (_useAgentForwardingCheckBox.Checked) { ssh.EnableAgentForwarding = true; ssh.AgentForwardingAuthKeyProvider = null; // set later } else { ssh.EnableAgentForwarding = false; ssh.AgentForwardingAuthKeyProvider = null; } //--- Macro IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) // macro plugin is enabled { if (!String.IsNullOrEmpty(_autoExecMacroPathBox.Text)) { autoExecParams.AutoExecMacroPath = _autoExecMacroPathBox.Text; } else { autoExecParams.AutoExecMacroPath = null; } } loginParam = ssh; terminalSettings = termSettings; return(true); }
//入力内容に誤りがあればそれを警告して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); } }
/// <summary> /// Validates input values and constructs parameter objects. /// </summary> /// <param name="telnetParam">Telnet parameter object is set when this method returns true.</param> /// <param name="terminalSettings">terminal settings object is set when this method returns true.</param> /// <param name="errorMessage">validation error message is set when this method returns false. this can be null when displaying error message is not needed.</param> /// <returns>true if all validations passed and parameter objects were created.</returns> private bool Validate(out ITCPParameter telnetParam, out ITerminalSettings terminalSettings, out string errorMessage) { telnetParam = null; terminalSettings = null; errorMessage = null; var telnet = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter(); var tcp = (ITCPParameter)telnet.GetAdapter(typeof(ITCPParameter)); var protocolParam = (ITelnetParameter)telnet.GetAdapter(typeof(ITelnetParameter)); tcp.Destination = _hostBox.Text; if (String.IsNullOrEmpty(tcp.Destination)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty"); return(false); } int port; if (Int32.TryParse(_portBox.Text, out port) && port >= 0 && port <= 65535) { tcp.Port = port; } else { errorMessage = String.Format( TEnv.Strings.GetString("Message.LoginDialog.InvalidPort"), _portBox.Text); return(false); } //--- Log settings ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings(); logSettings.LogType = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; if (logSettings.LogType != LogType.None) { logSettings.LogPath = _logFileBox.Text; LogFileCheckResult r = LogUtil.CheckLogFileName(logSettings.LogPath, this.ParentForm); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { errorMessage = null; return(false); } logSettings.LogAppend = (r == LogFileCheckResult.Append); } //--- Terminal settings ITerminalParameter termParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)); TerminalType terminalType = ((EnumListItem <TerminalType>)_terminalTypeBox.SelectedItem).Value; termParam.SetTerminalName(terminalType.ToTermValue()); string terminalCaption = tcp.Destination; Image terminalIcon = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16; ITerminalSettings termSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(terminalCaption, terminalIcon); termSettings.BeginUpdate(); termSettings.Encoding = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value; termSettings.LocalEcho = ((ListItem <bool>)_localEchoBox.SelectedItem).Value; termSettings.TransmitNL = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value; termSettings.TerminalType = terminalType; termSettings.LogSettings.Reset(logSettings); termSettings.EndUpdate(); //--- TELNET protocol settings protocolParam.TelnetNewLine = (termSettings.TransmitNL == NewLine.CRLF) ? _telnetNewLine.Checked : false; //--- Macro IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) // macro plugin is enabled { if (!String.IsNullOrEmpty(_autoExecMacroPathBox.Text)) { autoExecParams.AutoExecMacroPath = _autoExecMacroPathBox.Text; } else { autoExecParams.AutoExecMacroPath = null; } } telnetParam = tcp; terminalSettings = termSettings; return(true); }
public MockTerminalConnection(string terminalType, MockSocket mockSocket) { _param = new TerminalParameter(); _param.SetTerminalName(terminalType); _mockSocket = mockSocket; }
public ITerminalParameter PrepareTerminalParameter(string UserName, string Pwd, string DestHost, int Port, ConnectionMethod m, string PublicKeyFile, LogType logType, string logPath) { string msg = null; if (_terminalOptions == null) { _terminalOptions = new TerminalOptions(""); } if (_terminalSettings == null) { _terminalSettings = new TerminalSettings(); } try { if (Port == 0) { if (m == ConnectionMethod.Telnet) { Port = 23; } else { Port = 22; } } tcp = _Console.CreateDefaultTelnetParameter(); tcp.Destination = DestHost; tcp.Port = Port; if (m == ConnectionMethod.SSH1 || (m == ConnectionMethod.SSH2)) { SSHLoginParameter sp = _Console.CreateDefaultSSHParameter(); ssh = sp; ssh.Destination = DestHost; ssh.Port = Port; ssh.Method = m == ConnectionMethod.SSH1 ? SSHProtocol.SSH1 : SSHProtocol.SSH2; ssh.Account = UserName; ssh.PasswordOrPassphrase = Pwd; } if (DestHost.Length == 0) { msg = "Message.TelnetSSHLogin.HostIsEmpty"; } //ƒƒOÝ’è ISimpleLogSettings logsettings = null; if (logType != LogType.None) { if (logPath.Length == 0) { logPath = AppDomain.CurrentDomain.BaseDirectory;// +DestHost; } logsettings = new SimpleLogSettings(); logsettings.LogPath = logPath; logsettings.LogType = logType; LogFileCheckResult r = LogUtil.CheckLogFileName(logPath); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { return(null); } logsettings.LogAppend = (r == LogFileCheckResult.Append); if (logsettings == null) { return(null); //“®ìƒLƒƒƒ“ƒZƒ‹ } _terminalOptions.DefaultLogType = logType; _terminalOptions.DefaultLogDirectory = logPath; } _param = (ITerminalParameter)tcp; //(ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)); TerminalType terminal_type = TerminalType.VT100; _param.SetTerminalName(ToTerminalName(terminal_type)); if (ssh != null) { Debug.Assert(ssh != null); if (PublicKeyFile.Length > 0) { ssh.AuthenticationType = AuthenticationType.PublicKey; if (!File.Exists(PublicKeyFile)) { msg = "Message.TelnetSSHLogin.KeyFileNotExist"; } else { ssh.IdentityFileName = PublicKeyFile; } } } ITerminalSettings settings = this.TerminalSettings; settings.BeginUpdate(); settings.Caption = DestHost; //settings.Icon = IconList.LoadIcon(IconList.ICON_NEWCONNECTION); settings.Encoding = EncodingType.ISO8859_1; settings.LocalEcho = false; settings.TransmitNL = NewLine.CRLF; // .LF; //.CR; settings.LineFeedRule = ConnectionParam.LineFeedRule.Normal; settings.TerminalType = terminal_type; settings.DebugFlag = _debug; if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.EndUpdate(); if (msg != null) { if (_debug > 0) //ShowError(msg); { Console.WriteLine(msg); } return(null); } else { return((ITerminalParameter)tcp); //.GetAdapter(typeof(ITerminalParameter)); } } catch (Exception ex) { if (_debug > 0) { Console.WriteLine(ex.Message); } return(null); } }