protected override bool HandleOnExit(ref bool isError)
        {
            if (restart)
            {
                Retry();
                return(true);
            }


            // An error occurred!
            if (isError && Plink)
            {
                //there might be an other error, this condition is too weak

                /*
                 * if (OutputString.ToString().Contains("successfully authenticated"))
                 * {
                 *  isError = false;
                 *  return false;
                 * }
                 */

                // If the authentication failed because of a missing key, ask the user to supply one.
                if (OutputString.ToString().Contains("FATAL ERROR") && OutputString.ToString().Contains("authentication"))
                {
                    string loadedKey;
                    if (FormPuttyError.AskForKey(this, out loadedKey))
                    {
                        // To prevent future authentication errors, save this key for this remote.
                        if (!String.IsNullOrEmpty(loadedKey) && !String.IsNullOrEmpty(this.Remote) &&
                            String.IsNullOrEmpty(Module.GetPathSetting("remote.{0}.puttykeyfile")))
                        {
                            Module.SetPathSetting(string.Format("remote.{0}.puttykeyfile", this.Remote), loadedKey);
                        }

                        // Retry the command.
                        Retry();
                        return(true);
                    }
                }
                if (OutputString.ToString().ToLower().Contains("the server's host key is not cached in the registry"))
                {
                    string remoteUrl;

                    if (string.IsNullOrEmpty(UrlTryingToConnect))
                    {
                        remoteUrl = Module.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, Remote));
                        if (string.IsNullOrEmpty(remoteUrl))
                        {
                            remoteUrl = Remote;
                        }
                    }
                    else
                    {
                        remoteUrl = UrlTryingToConnect;
                    }
                    if (!string.IsNullOrEmpty(remoteUrl))
                    {
                        if (MessageBox.Show(this, _serverHotkeyNotCachedText.Text, "SSH", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        {
                            Module.RunRealCmd(
                                "cmd.exe",
                                string.Format("/k \"\"{0}\" -T \"{1}\"\"", Settings.Plink, remoteUrl));

                            Retry();
                            return(true);
                        }
                    }
                }
            }

            return(base.HandleOnExit(ref isError));
        }
Esempio n. 2
0
        protected override bool HandleOnExit(ref bool isError)
        {
            if (restart)
            {
                Retry();
                return(true);
            }


            // An error occurred!
            if (isError && Plink)
            {
                //there might be an other error, this condition is too weak

                /*
                 * if (GetOutputString().Contains("successfully authenticated"))
                 * {
                 *  isError = false;
                 *  return false;
                 * }
                 */

                // If the authentication failed because of a missing key, ask the user to supply one.
                if (GetOutputString().Contains("FATAL ERROR") && GetOutputString().Contains("authentication"))
                {
                    string loadedKey;
                    if (FormPuttyError.AskForKey(this, out loadedKey))
                    {
                        // To prevent future authentication errors, save this key for this remote.
                        if (!String.IsNullOrEmpty(loadedKey) && !String.IsNullOrEmpty(this.Remote) &&
                            String.IsNullOrEmpty(Module.GetPathSetting("remote.{0}.puttykeyfile")))
                        {
                            Module.SetPathSetting(string.Format("remote.{0}.puttykeyfile", this.Remote), loadedKey);
                        }

                        // Retry the command.
                        Retry();
                        return(true);
                    }
                }
                if (GetOutputString().ToLower().Contains("the server's host key is not cached in the registry"))
                {
                    string remoteUrl;

                    if (string.IsNullOrEmpty(UrlTryingToConnect))
                    {
                        remoteUrl = Module.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, Remote));
                        if (string.IsNullOrEmpty(remoteUrl))
                        {
                            remoteUrl = Remote;
                        }
                    }
                    else
                    {
                        remoteUrl = UrlTryingToConnect;
                    }

                    if (AskForCacheHostkey(this, Module, remoteUrl))
                    {
                        Retry();
                        return(true);
                    }
                }
            }

            return(base.HandleOnExit(ref isError));
        }