diff options
author | João Victor Duarte Martins <jvictor@mandriva.com> | 2010-05-13 17:00:13 +0000 |
---|---|---|
committer | João Victor Duarte Martins <jvictor@mandriva.com> | 2010-05-13 17:00:13 +0000 |
commit | 65a27fd40e069cd1cdae0bc5b6b35670f37e208e (patch) | |
tree | 3eb1c223d436cb6387b6085b5d9fd1ff2b06e422 /mdkapplet-restricted-helper | |
parent | 0e25af58eec245d64fe6cd87af5cdaf7aec6d81d (diff) | |
download | mgaonline-65a27fd40e069cd1cdae0bc5b6b35670f37e208e.tar mgaonline-65a27fd40e069cd1cdae0bc5b6b35670f37e208e.tar.gz mgaonline-65a27fd40e069cd1cdae0bc5b6b35670f37e208e.tar.bz2 mgaonline-65a27fd40e069cd1cdae0bc5b6b35670f37e208e.tar.xz mgaonline-65a27fd40e069cd1cdae0bc5b6b35670f37e208e.zip |
* mdkapplet-add-media-helper: Added to gather common add media code
(substitutes both mdkapplet-enterprise-update-helper and
mdkapplet-restricted-helper).
* mdkapplet_gui.pm (run_ask_credentials_dialog): Added here for
reusability.
Diffstat (limited to 'mdkapplet-restricted-helper')
-rwxr-xr-x | mdkapplet-restricted-helper | 199 |
1 files changed, 0 insertions, 199 deletions
diff --git a/mdkapplet-restricted-helper b/mdkapplet-restricted-helper deleted file mode 100755 index 34ac0a0c..00000000 --- a/mdkapplet-restricted-helper +++ /dev/null @@ -1,199 +0,0 @@ -#!/usr/bin/perl -################################################################################ -# Mandriva Online # -# # -# Copyright (C) 2008-2010 Mandriva # -# # -# Thierry Vignaud <tvignaud at mandriva dot com> # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License Version 2 as # -# published by the Free Software Foundation. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -################################################################################ - -use strict; -use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime); -use standalone; # for explanations -use common; -use run_program; -use feature 'state'; - -BEGIN { unshift @::textdomains, 'mdkonline' } - -use mygtk2 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version -use ugtk2 qw(:all); -use urpm::cfg; -use mdkonline; -use mdkapplet_gui; -use interactive; - -use XML::Simple; -use URI::Escape; -use LWP::UserAgent; -use HTTP::Request::Common; -use HTTP::Request; -use interactive::gtk; - -my $version; -foreach my $opt (@ARGV) { - if ($opt =~ /--(rpm-root|urpmi-root)=(.*)/) { - $::rpmdrake_options{$1}[0] = $2; - } else { - $version = $opt; - } -} -$version or die "usage: mdkapplet-restricted-helper <distrib_version>\n"; - -# make it work on 2008.X: -eval { interactive::gtk::add_padding(Gtk2::Label->new) }; -if ($@) { - *interactive::gtk::add_padding = sub { $_[0] }; -} - -get_restricted_authentication(); - -ugtk2::exit(0); - -my $email; - -sub get_restricted_authentication() { - my $w = ugtk2->new(N("Adding an additional package medium"), - width => $width + 20); - my $password_w = gtknew('Entry'); - my $email_w = gtknew('Entry', text => $email); - my $password; - my $clicked; - - $password_w->set_visibility(0); - - $w->{ok_clicked} = sub { - $password = $password_w->get_text; - $email = $email_w->get_text; - $clicked = 1; - Gtk2->main_quit; - }; - - my @widgets = ( - get_banner(N("Adding an additional package medium")), - gtknew('Label_Left', - text => N("Please fill in your account ID to add an " . - "additional package medium"), - @common), - gtknew('HButtonBox', - layout => 'start', - children_tight => [ - interactive::gtk::add_padding( - new_link_button('https://my.mandriva.com/info', - N("More information on your user " . - "account")) - ) - ]), - gtknew('Table', - col_spacings => 5, - row_spacings => 5, - children => [ [ N("Your email"), $email_w ], - [ N("Your password"), $password_w ] ]), - gtknew('HButtonBox', - layout => 'start', - children_tight => [ - interactive::gtk::add_padding( - new_link_button('https://my.mandriva.com/reset' . - '/password/', - N("Forgotten password")) - ) - ]), - create_okcancel($w, N("Next"), N("Cancel")), - ); - - fill_n_run_portable_dialog($w, \@widgets); - - if ($clicked) { - $clicked = 0; - if ($email && $password) { - add_restricted_medium($email, $password); - } - else { - interactive->vnew->ask_warn( - N("Error"), - N("Password and email cannot be empty.") - ); - goto &get_restricted_authentication; - } - } -} - -my $error; -sub add_restricted_medium { - my ($email, $password) = @_; - - my $res = get_from("https://my.mandriva.com/rest/authenticate", - [ 'username', $email, 'password', $password, - 'return', 'userdata' ]); - my $ref = xml2perl($res); - - if ($ref->{code} != 0) { - my $in = interactive->vnew; - $in->ask_warn(N("Error"), N("An error occurred") . "\n" . $ref->{message}); - goto &get_restricted_authentication; - } elsif ($ref->{data}{'can-access-restricted-repositories'} ne 'YES') { - no_rights_dialog(); - } else { - $error = 0; - my $arch = urpm::cfg::get_arch(); - actually_add_restricted_medium($ref, $password, $arch) - or adding_media_failed(); - # FIXME: is not enough if we (unlikely) ever support sparc64, ppc64 and the like: - if ($arch eq 'x86_64') { - actually_add_restricted_medium($ref, $password, 'i586') - or adding_media_failed(); - } - if (!$error) { - #interactive->vnew->ask_okcancel(N("Error"), N("An error occurred while adding medium")); - my $w = ugtk2->new(N("Successfully added media %s.", 'Restricted'), grab => 1); - $w->_ask_okcancel(N("Successfully added media %s.", 'Restricted'), N("Ok"), undef); - ugtk2::main($w); - } - } -} - -sub no_rights_dialog() { - my $w = ugtk2->new(N("Adding an additional package medium"), width => $width + 20); - - fill_n_run_portable_dialog( - $w, - [ - get_banner(N("Adding an additional package medium")), - gtknew('Label_Left', text => N("Your Mandriva account does not have Powerpack download subscription enabled."), - @common), - gtknew('HButtonBox', layout => 'start', children_tight => [ - interactive::gtk::add_padding( - new_link_button('https://my.mandriva.com/powerpack/', N("More Information"))) - ]), - create_okcancel($w, N("Close"), undef), - ]); -} - -sub adding_media_failed { - $error = 1; - interactive->vnew->ask_warn(N("Error"), N("An error occurred while adding medium")); - goto &get_restricted_authentication; -} - -sub actually_add_restricted_medium { - my ($ref, $password, $arch) = @_; - $password = uri_escape($password); - my @options = get_urpmi_options(); - my $email = uri_escape($ref->{data}{email}); - my $uri = "https://$email:$password\@dl.mandriva.com/rpm/comm/$version/"; - run_program::raw(@options, "Restricted $arch " . int(rand(100000)), "$uri$arch") or return 0; - run_program::raw(@options, '--update', "Restricted Updates $arch " . int(rand(100000)), "${uri}updates/$arch"); -} |