Ejemplo n.º 1
0
        private void OnOK(object sender, EventArgs args)
        {
            this.DialogResult = DialogResult.None;
            ISimpleLogSettings ls   = TerminalUIPlugin.Instance.TerminalEmulatorPlugin.CreateDefaultSimpleLogSettings();
            LogType            t    = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value;
            string             path = null;

            bool append = false;

            if (t != LogType.None)
            {
                path = _fileNameBox.Text;
                LogFileCheckResult r = LogUtil.CheckLogFileName(path, this);
                if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                {
                    return;
                }
                append = (r == LogFileCheckResult.Append);
            }

            ls.LogType   = t;
            ls.LogPath   = path;
            ls.LogAppend = append;
            _session.Terminal.ILogService.ApplyLogSettings(ls, true);

            this.DialogResult = DialogResult.OK;
        }
        //ログ設定を作る。単一ファイル版。
        protected ISimpleLogSettings CreateSimpleLogSettings(LogType logtype, string path)
        {
            ISimpleLogSettings logsettings = SerialPortPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings();

            logsettings.LogPath = path;
            logsettings.LogType = logtype;
            LogFileCheckResult r = LogUtil.CheckLogFileName(path, this);

            if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
            {
                return(null);
            }
            logsettings.LogAppend = (r == LogFileCheckResult.Append);
            return(logsettings);
        }
Ejemplo n.º 3
0
        private void OnOK(object sender, EventArgs args)
        {
            this.DialogResult = DialogResult.None;
            if (_homeDirectoryBox.Text.Length == 0)
            {
                GUtil.Warning(this, GApp.Strings.GetString("Message.CygwinLoginDialog.EmptyHomeDirectory"));
            }
            else if (_shellBox.Text.Length == 0)
            {
                GUtil.Warning(this, GApp.Strings.GetString("Message.CygwinLoginDialog.EmptyShell"));
            }

            _param.LogType = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
            if (_param.LogType != LogType.None)
            {
                _param.LogPath = _logFileBox.Text;
                LogFileCheckResult r = GCUtil.CheckLogFileName(_param.LogPath, this);
                if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                {
                    return;
                }
                _param.LogAppend = (r == LogFileCheckResult.Append);
            }

            _param.Home  = _homeDirectoryBox.Text;
            _param.Shell = _shellBox.Text;

            _okButton.Enabled     = false;
            _cancelButton.Enabled = false;
            this.Cursor           = Cursors.WaitCursor;
            _savedHWND            = this.Handle;
            if (_param is CygwinTerminalParam)
            {
                this.Text = GApp.Strings.GetString("Caption.CygwinLoginDialog.ConnectingCygwin");
            }
            else
            {
                this.Text = GApp.Strings.GetString("Caption.CygwinLoginDialog.ConnectingSFU");
            }

            _connector = CygwinUtil.AsyncPrepareSocket(this, _param);
            if (_connector == null)
            {
                ClearConnectingState();
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        private SerialTerminalParam ValidateParam()
        {
            SerialTerminalParam p = new SerialTerminalParam();

            try {
                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(String.Format("com{0}", _portBox.SelectedIndex + 1));
                    }
                    LogFileCheckResult r = GCUtil.CheckLogFileName(p.LogPath, this);
                    if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                    {
                        return(null);
                    }
                    p.LogAppend = (r == LogFileCheckResult.Append);
                }

                p.Port        = _portBox.SelectedIndex + 1;
                p.BaudRate    = Int32.Parse(_baudRateBox.Text);
                p.ByteSize    = (byte)(_dataBitsBox.SelectedIndex == 0? 7 : 8);
                p.StopBits    = (StopBits)_stopBitsBox.SelectedIndex;
                p.Parity      = (Parity)_parityBox.SelectedIndex;
                p.FlowControl = (FlowControl)_flowControlBox.SelectedIndex;

                p.EncodingProfile = EncodingProfile.Get((EncodingType)_encodingBox.SelectedIndex);

                p.LocalEcho  = _localEchoBox.SelectedIndex == 1;
                p.TransmitNL = (NewLine)EnumDescAttributeT.For(typeof(NewLine)).FromDescription(_newLineBox.Text, LogType.None);

                p.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text);
                p.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text);
                return(p);
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(null);
            }
        }
Ejemplo n.º 6
0
        private void OnOK(object sender, EventArgs args)
        {
            this.DialogResult = DialogResult.None;
            LogType t    = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
            string  path = null;

            bool append = false;

            if (t != LogType.None)
            {
                path = _fileNameBox.Text;
                LogFileCheckResult r = GCUtil.CheckLogFileName(path, this);
                if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                {
                    return;
                }
                append = (r == LogFileCheckResult.Append);
            }

            _connection.ResetLog(t, path, append);
            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        /// <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);
        }
Ejemplo n.º 10
0
        private bool ValidateParams(out PipeTerminalParameter param, out PipeTerminalSettings settings)
        {
            PipeTerminalParameter paramTmp    = new PipeTerminalParameter();
            PipeTerminalSettings  settingsTmp = new PipeTerminalSettings();

            StringResource res = PipePlugin.Instance.Strings;

            try {
                string caption;

                if (_radioButtonProcess.Checked)
                {
                    string exePath = _textBoxExePath.Text;
                    if (exePath.Length == 0)
                    {
                        throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoExePath"));
                    }
                    paramTmp.ExeFilePath          = exePath;
                    paramTmp.CommandLineOptions   = _textBoxCommandLineOptions.Text;
                    paramTmp.EnvironmentVariables = _environmentVariables;
                    caption = Path.GetFileName(exePath);
                }
                else if (_radioButtonPipe.Checked)
                {
                    string path = _textBoxInputPath.Text;
                    if (path.Length == 0)
                    {
                        throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoInputPath"));
                    }
                    paramTmp.InputPipePath = path;
                    caption = Path.GetFileName(path);

                    if (!_checkBoxBidirectinal.Checked)
                    {
                        path = _textBoxOutputPath.Text;
                        if (path.Length == 0)
                        {
                            throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoOutputPath"));
                        }
                        paramTmp.OutputPipePath = path;
                        caption += "/" + Path.GetFileName(path);
                    }
                }
                else
                {
                    throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoOpenMode"));
                }

                TerminalType terminalType = ((EnumListItem <TerminalType>)_comboBoxTerminalType.SelectedItem).Value;
                paramTmp.SetTerminalName(terminalType.ToString().ToLowerInvariant());

                LogType            logType     = ((EnumListItem <LogType>)_comboBoxLogType.SelectedItem).Value;
                ISimpleLogSettings logSettings = null;
                if (logType != LogType.None)
                {
                    string             logFile = _textBoxLogFile.Text;
                    LogFileCheckResult r       = LogUtil.CheckLogFileName(logFile, this);
                    if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                    {
                        throw new Exception("");
                    }

                    logSettings           = PipePlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings();
                    logSettings.LogPath   = logFile;
                    logSettings.LogType   = logType;
                    logSettings.LogAppend = (r == LogFileCheckResult.Append);
                }

                string autoExecMacroPath = null;
                if (_textBoxAutoExecMacroPath.Text.Length != 0)
                {
                    autoExecMacroPath = _textBoxAutoExecMacroPath.Text;
                }

                IAutoExecMacroParameter autoExecParams = paramTmp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                if (autoExecParams != null)
                {
                    autoExecParams.AutoExecMacroPath = autoExecMacroPath;
                }

                settingsTmp.BeginUpdate();
                settingsTmp.Caption      = caption;
                settingsTmp.Icon         = Poderosa.Pipe.Properties.Resources.Icon16x16;
                settingsTmp.Encoding     = ((EnumListItem <EncodingType>)_comboBoxEncoding.SelectedItem).Value;
                settingsTmp.LocalEcho    = _comboBoxLocalEcho.SelectedIndex == 1;
                settingsTmp.TransmitNL   = ((EnumListItem <NewLine>)_comboBoxNewLine.SelectedItem).Value;
                settingsTmp.TerminalType = terminalType;
                if (logSettings != null)
                {
                    settingsTmp.LogSettings.Reset(logSettings);
                }
                settingsTmp.EndUpdate();

                param    = paramTmp;
                settings = settingsTmp;
                return(true);
            }
            catch (Exception e) {
                if (e.Message.Length > 0)
                {
                    GUtil.Warning(this, e.Message);
                }
                param    = null;
                settings = null;
                return(false);
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }