Permalink
Browse files

Implement input box for user/password prompt from plink process. Pass…

…word prompt hides characters, like advised on https://stackoverflow.com/a/21122864/4110077 . Closes #129.
  • Loading branch information...
ansgarbecker committed Jan 2, 2019
1 parent a4e20cc commit 06df04b45e1ea3eb15ae08a6d1bd454e1ed6dc43
Showing with 21 additions and 7 deletions.
  1. +21 −7 source/dbconnection.pas
@@ -851,7 +851,7 @@ destructor TPlink.Destroy;
procedure TPlink.Connect;
var
PlinkCmd, PlinkCmdDisplay: String;
OutText, ErrorText: String;
OutText, ErrorText, UserInput: String;
rx: TRegExpr;
StartupInfo: TStartupInfo;
ExitCode: LongWord;
@@ -925,17 +925,31 @@ procedure TPlink.Connect;
if ExitCode <> STILL_ACTIVE then
raise EDatabaseError.CreateFmt(_('PLink exited unexpected. Command line was: %s'), [CRLF+PlinkCmdDisplay]);

OutText := ReadPipe(FOutPipe);
OutText := Trim(ReadPipe(FOutPipe));
ErrorText := ReadPipe(FErrorPipe);
if (OutText <> '') or (ErrorText <> '') then
ReturnedSomethingAt := Waited;

FConnection.Log(lcDebug, 'plink OutText:'+OutText+' ErrorText:'+ErrorText);

if OutText <> '' then begin
rx.Expression := '^[^\.]+\.';
if rx.Exec(OutText) then
MessageDialog('PLink: '+rx.Match[0], OutText, mtInformation, [mbOK])
else
MessageDialog('PLink:', OutText, mtInformation, [mbOK]);
if ExecRegExpr('login as\s*\:', OutText) then begin
// Prompt for username
UserInput := InputBox('PLink:', OutText, '');
SendText(UserInput + CRLF);
end else if ExecRegExpr('password\s*\:', OutText) then begin
// Prompt for password. Send * as first char of prompt param so InputBox hides input characters
UserInput := InputBox('PLink:', #31+OutText, '');
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('PLink: '+rx.Match[0], OutText, mtInformation, [mbOK])
end else begin
MessageDialog('PLink:', OutText, mtInformation, [mbOK]);
end;
end;
end;

if ErrorText <> '' then begin

0 comments on commit 06df04b

Please sign in to comment.