Skip to content

Commit

Permalink
In TSecureShellCmd.Connect, include parallel happened errors in any s…
Browse files Browse the repository at this point in the history
…uccess dialog. Also, log errors to the log panel when both pipes have content. Closes #1940
  • Loading branch information
ansgarbecker committed Apr 17, 2024
1 parent ee3aaf8 commit 3c45d41
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions source/dbconnection.pas
Expand Up @@ -1087,7 +1087,7 @@ destructor TSecureShellCmd.Destroy;
procedure TSecureShellCmd.Connect;
var
SshCmd, SshCmdDisplay, DialogTitle: String;
OutText, ErrorText, UserInput: String;
OutText, ErrorText, AllPipesText, UserInput: String;
rx: TRegExpr;
StartupInfo: TStartupInfo;
ExitCode: LongWord;
Expand Down Expand Up @@ -1191,21 +1191,27 @@ procedure TSecureShellCmd.Connect;
end;

if OutText <> '' then begin
// Prepend error text in the dialog, e.g. "Unable to use keyfile"
AllPipesText := OutText;
if not ErrorText.IsEmpty then begin
FConnection.Log(lcError, 'SSH: '+ErrorText);
AllPipesText := Trim('Error: ' + ErrorText + sLineBreak + AllPipesText);
end;
if ExecRegExpr('login as\s*\:', OutText) then begin
// Prompt for username
UserInput := InputBox(DialogTitle, OutText, '');
UserInput := InputBox(DialogTitle, AllPipesText, '');
SendText(UserInput + CRLF);
end else if ExecRegExpr('(password|Passphrase for key "[^"]+")\s*\:', OutText) then begin
// Prompt for sensitive input. Send * as first char of prompt param so InputBox hides input characters
UserInput := InputBox(DialogTitle, #31+OutText, '');
UserInput := InputBox(DialogTitle, #31+AllPipesText, '');
SendText(UserInput + CRLF);
end else begin
// Informational message box
rx.Expression := '^[^\.]+\.';
if rx.Exec(OutText) then begin // First words end with a dot - use it as caption
MessageDialog(DialogTitle + ': ' + rx.Match[0], OutText, mtInformation, [mbOK])
MessageDialog(DialogTitle + ': ' + rx.Match[0], AllPipesText, mtInformation, [mbOK])
end else begin
MessageDialog(DialogTitle, OutText, mtInformation, [mbOK]);
MessageDialog(DialogTitle, AllPipesText, mtInformation, [mbOK]);
end;
end;
end
Expand Down

0 comments on commit 3c45d41

Please sign in to comment.