#!/usr/bin/perl ################################################################################ # Mandriva Online # # # # Copyright (C) 2008 Mandriva # # # # Thierry Vignaud # # # # 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; foreach my $opt (@ARGV) { if ($opt =~ /--(rpm-root|urpmi-root)=(.*)/) { $::rpmdrake_options{$1}[0] = $2; } } prepare_add_restricted(); ugtk2::exit(0); sub prepare_add_restricted() { my $warn_me = text2bool($local_config{DO_NOT_ASK_FOR_RESTRICTED}); return if $warn_me; my $w = new_portable_dialog(N("New medium available")); my $res = fill_n_run_portable_dialog( $w, [ get_banner(), gtknew('Label_Left', text => N("You use '%s' distribution and therefore have privileged access to additional software.", N("Mandriva PowerPack")) . "\n\n" . N("Do you want to install this additional software repository?", ), @common), gtknew('CheckButton', text => N("Do not ask me next time"), active_ref => \$warn_me), create_okcancel($w, N("Next"), N("Cancel")), ]); setVar('DO_NOT_ASK_FOR_RESTRICTED', bool2text($warn_me)); $local_config{DO_NOT_ASK_FOR_RESTRICTED} = bool2text($warn_me); $res ? get_restricted_authentication() : 0; } sub get_restricted_authentication() { my $w = ugtk2->new(N("Adding an additional package medium"), width => $width + 20); my ($password_w, $email_w, $password); $password_w = gtknew('Entry'); $password_w->set_visibility(0); $w->{real_window}->signal_connect(destroy => sub { $password = $password_w->get_text }); require interactive::gtk; my $res = fill_n_run_portable_dialog( $w, [ get_banner(), 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, children => [ [ N("Your email"), $email_w = gtknew('Entry') ], [ 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")), ]); $res ? add_restricted_medium($email_w->get_text, $password) : 0; } sub get_from { my ($link, $header) = @_; my $ua = LWP::UserAgent->new; $ua->agent("mdkapplet (mdkonline-$mdkonlin::version)"); $ua->env_proxy; my $response = $ua->request(POST $link, $header); $response; } sub add_restricted_medium { my ($email, $password) = @_; my $res = get_from("https://my.mandriva.com/rest/authenticate", [ 'username', $email, 'password', $password ]); my $ref = XML::Simple->new->XMLin($res->{_content}); if ($ref->{code} != 0) { my $in = interactive->vnew; $in->ask_warn(N("Error"), N("An error occurred") . "\n" . $ref->{message}); goto &get_restricted_authentication; } else { my @options = ({ sensitive_arguments => 1 }, 'urpmi.addmedia'); my $uri = "https://" . uri_escape($ref->{data}{email}) . ":$password\@dl.mandriva.com/rpm/comm/2009.0/"; my $arch = urpm::cfg::get_arch(); run_program::raw(@options, 'Restricted ' . int(rand(100000)), "$uri$arch"); run_program::raw(@options, '--update', 'Restricted Updates ' . int(rand(100000)), "${uri}updates/$arch"); } }