This rough patch adds a '--ask-password' option to wget. About all that
can be said for it is that it works; hopefully it will serve as a useful
proof of concept and possible a starting point for a fully-developed
feature.
--
Matthew
"Resistance is futile" -- Borg
"No, resistance is the reciprocal of conductance" -- Dave Korn
Index: src/options.h
===================================================================
--- src/options.h (revision 2295)
+++ src/options.h (working copy)
@@ -81,6 +81,7 @@
char *user; /* Generic username */
char *passwd; /* Generic password */
+ bool ask_passwd; /* Ask for password? */
bool always_rest; /* Always use REST. */
char *ftp_user; /* FTP username */
Index: src/init.c
===================================================================
--- src/init.c (revision 2295)
+++ src/init.c (working copy)
@@ -112,6 +112,7 @@
{ "accept", &opt.accepts, cmd_vector },
{ "addhostdir", &opt.add_hostdir, cmd_boolean },
{ "alwaysrest", &opt.always_rest, cmd_boolean }, /* deprecated */
+ { "askpassword", &opt.ask_passwd, cmd_boolean },
{ "background", &opt.background, cmd_boolean },
{ "backupconverted", &opt.backup_converted, cmd_boolean },
{ "backups", &opt.backups, cmd_number },
Index: src/http.c
===================================================================
--- src/http.c (revision 2295)
+++ src/http.c (working copy)
@@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h> /* FIXME probably not portable? */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@@ -1302,6 +1303,7 @@
char *type;
char *user, *passwd;
+ char buffer[1024]; /* for ask_passwd */
char *proxyauth;
int statcode;
int write_error;
@@ -1419,7 +1421,29 @@
passwd = u->passwd;
search_netrc (u->host, (const char **)&user, (const char **)&passwd, 0);
user = user ? user : (opt.http_user ? opt.http_user : opt.user);
+ if (opt.ask_passwd)
+ {
+ int in_fd = fileno(stdin);
+ struct termios attr;
+ tcflag_t old_flags;
+ int n;
+ printf("URL \"%s\"\nPassword for user \"%s\": ", u->url, user);
+ /* TODO check error */
+ tcgetattr(in_fd, &attr);
+ old_flags = attr.c_lflag;
+ attr.c_lflag &= ~ECHO;
+ tcsetattr(in_fd, TCSANOW, &attr);
+ fgets(buffer, sizeof(buffer), stdin);
+ attr.c_lflag = old_flags;
+ tcsetattr(in_fd, TCSANOW, &attr);
+ n = strlen(buffer) - 1;
+ if (n >= 0 && buffer[n] == '\n') buffer[n] = 0;
+ passwd = buffer;
+ }
+ else
+ {
passwd = passwd ? passwd : (opt.http_passwd ? opt.http_passwd : opt.passwd);
+ }
if (user && passwd)
{
Index: src/main.c
===================================================================
--- src/main.c (revision 2295)
+++ src/main.c (working copy)
@@ -129,6 +129,7 @@
{
{ "accept", 'A', OPT_VALUE, "accept", -1 },
{ "append-output", 'a', OPT__APPEND_OUTPUT, NULL, required_argument },
+ { "ask-password", 0, OPT_BOOLEAN, "askpassword", -1 },
{ "background", 'b', OPT_BOOLEAN, "background", -1 },
{ "backup-converted", 'K', OPT_BOOLEAN, "backupconverted", -1 },
{ "backups", 0, OPT_BOOLEAN, "backups", -1 },
@@ -464,6 +465,8 @@
--user=USER set both ftp and http user to USER.\n"),
N_("\
--password=PASS set both ftp and http password to PASS.\n"),
+ N_("\
+ --ask-password prompt for passwords.\n"),
"\n",
N_("\