summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-04-26 15:45:54 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-04-26 15:45:54 +0000
commitde7acdb4096997634ed3e459bc1e909f59b9c0ce (patch)
tree1ef5233e0626618ab6d48fc7e8af1bd63e0fe4e6
parentaa5b090a1c105963889a73afe8fc303b5b544f01 (diff)
downloadurpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar.gz
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar.bz2
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar.xz
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.zip
Allow to ask user for proxy credentials
-rw-r--r--urpm/args.pm10
-rw-r--r--urpm/download.pm29
-rw-r--r--urpm/prompt.pm57
-rw-r--r--urpmi.spec3
4 files changed, 91 insertions, 8 deletions
diff --git a/urpm/args.pm b/urpm/args.pm
index 4e8440e2..9fe53476 100644
--- a/urpm/args.pm
+++ b/urpm/args.pm
@@ -97,9 +97,13 @@ my %options_spec = (
},
'proxy-user=s' => sub {
my (undef, $value) = @_;
- $value =~ /(.+):(.+)/ or die N("bad proxy declaration on command line\n");
- @{$urpm->{proxy}}{qw(user pwd)} = ($1, $2); #- obsolete, for compat
- urpm::download::set_cmdline_proxy(user => $1, pwd => $2);
+ if ($value eq 'ask') { #- should prompt for user/password
+ urpm::download::set_cmdline_proxy(ask => 1);
+ } else {
+ $value =~ /(.+):(.+)/ or die N("bad proxy declaration on command line\n");
+ @{$urpm->{proxy}}{qw(user pwd)} = ($1, $2); #- obsolete, for compat
+ urpm::download::set_cmdline_proxy(user => $1, pwd => $2);
+ }
},
'bug=s' => \$options{bug},
'env=s' => \$::env,
diff --git a/urpm/download.pm b/urpm/download.pm
index 61d533e5..aa037caf 100644
--- a/urpm/download.pm
+++ b/urpm/download.pm
@@ -42,6 +42,10 @@ sub load_proxy_config () {
$proxy_config->{$1 || ''}{pwd} = $3 if defined $3;
next;
}
+ if (/^(?:(.*):\s*)?proxy_user_ask/) {
+ $proxy_config->{$1 || ''}{ask} = 1;
+ next;
+ }
}
close $f;
}
@@ -50,7 +54,6 @@ sub load_proxy_config () {
sub dump_proxy_config () {
return 0 unless defined $proxy_config; #- hasn't been read yet
open my $f, '>', $PROXY_CFG or return 0;
- print $f "# generated " . (scalar localtime) . "\n";
foreach ('', sort grep { !/^(|cmd_line)$/ } keys %$proxy_config) {
my $m = $_ eq '' ? '' : "$_:";
my $p = $proxy_config->{$_};
@@ -58,6 +61,10 @@ sub dump_proxy_config () {
defined $p->{$_} && $p->{$_} ne ''
and print $f "$m$_=$p->{$_}\n";
}
+ if ($p->{ask}) {
+ print $f "${m}proxy_user_ask\n";
+ next;
+ }
defined $p->{user} && $p->{user} ne ''
and print $f "${m}proxy_user=$p->{user}:$p->{pwd}\n";
}
@@ -77,7 +84,7 @@ sub remove_proxy_media {
sub get_proxy (;$) {
my ($o_media) = @_; $o_media ||= '';
load_proxy_config();
- return $proxy_config->{cmd_line}
+ my $p = $proxy_config->{cmd_line}
|| $proxy_config->{$o_media}
|| $proxy_config->{''}
|| {
@@ -86,10 +93,24 @@ sub get_proxy (;$) {
user => undef,
pwd => undef,
};
+ if ($p->{ask} && ($p->{http_proxy} || $p->{ftp_proxy}) && !$p->{user}) {
+ our $PROMPT_PROXY;
+ unless (defined $PROMPT_PROXY) {
+ require urpm::prompt;
+ $PROMPT_PROXY = new urpm::prompt(
+ N("Please enter your credentials for acceding proxy\n"),
+ [ N("User name:"), N("Password:") ],
+ undef,
+ [ 0, 1 ],
+ );
+ }
+ ($p->{user}, $p->{pwd}) = $PROMPT_PROXY->prompt;
+ }
+ $p;
}
#- copies the settings for proxies from the command line to media named $media
-#- and writes the proxy.cfg file (used for new media)
+#- and writes the proxy.cfg file (used when adding new media)
sub copy_cmd_line_proxy {
my ($media) = @_;
return unless $media;
@@ -118,7 +139,7 @@ sub set_proxy_config {
}
#- set up the environment for proxy usage for the appropriate tool.
-#- returns an array of command-line arguments.
+#- returns an array of command-line arguments for wget or curl.
sub set_proxy {
my ($proxy) = @_;
my @res;
diff --git a/urpm/prompt.pm b/urpm/prompt.pm
new file mode 100644
index 00000000..b2896bde
--- /dev/null
+++ b/urpm/prompt.pm
@@ -0,0 +1,57 @@
+package urpm::prompt;
+
+use strict;
+
+sub new {
+ my ($class, $title, $prompts, $defaults, $hidden) = @_;
+ bless {
+ title => $title,
+ prompts => $prompts,
+ defaults => $defaults,
+ hidden => $hidden,
+ }, $class;
+}
+
+sub write {
+ my (undef, $msg) = @_;
+ if ($urpm::args::options{bug} || !defined fileno ::SAVEOUT) {
+ print STDOUT $msg;
+ } else {
+ print ::SAVEOUT $msg;
+ }
+}
+
+sub prompt {
+ my ($self) = @_;
+ my @answers;
+ $self->write($self->{title});
+ foreach my $i (0 .. $#{$self->{prompts}}) {
+ $self->write($self->{prompts}[$i]);
+ $self->{hidden}[$i] and system("/bin/stty", "-echo");
+ my $input = <STDIN>;
+ $self->{hidden}[$i] and do { system("/bin/stty", "echo"); $self->write("\n") };
+ defined $input or return @answers;
+ chomp $input;
+ $input eq '' and $input = defined $self->{defaults}[$i] ? $self->{defaults}[$i] : '';
+ push @answers, $input;
+ }
+ @answers;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+urpm::prompt - base class to prompt the user for data
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 COPYRIGHT
+
+Copyright (C) 2005 Mandriva
+
+=cut
diff --git a/urpmi.spec b/urpmi.spec
index b5191c09..3a6748cb 100644
--- a/urpmi.spec
+++ b/urpmi.spec
@@ -104,7 +104,7 @@ install -m 644 gurpmi.pm %{buildroot}%{compat_perl_vendorlib}/gurpmi.pm
rm -rf %{buildroot}%{_sbindir}/gurpmi
%endif
mkdir -p %{buildroot}%{compat_perl_vendorlib}/urpm
-for p in args cfg download msg util sys parallel_ka_run parallel_ssh
+for p in args cfg download msg util sys parallel_ka_run parallel_ssh prompt
do
install -m 644 urpm/$p.pm %{buildroot}%{compat_perl_vendorlib}/urpm/$p.pm
done
@@ -208,6 +208,7 @@ if (-e "/etc/urpmi/urpmi.cfg") {
%{compat_perl_vendorlib}/urpm/download.pm
%{compat_perl_vendorlib}/urpm/msg.pm
%{compat_perl_vendorlib}/urpm/util.pm
+%{compat_perl_vendorlib}/urpm/prompt.pm
%{compat_perl_vendorlib}/urpm/sys.pm
%doc ChangeLog