summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2009-06-03 13:36:25 +0000
committerThierry Vignaud <tv@mandriva.org>2009-06-03 13:36:25 +0000
commit45a01f2cf907398a69b5aaee4d5d4bc476bff0b6 (patch)
tree8f9f9acae9356a082af44c6b37f7359a8c7d9245
parentf90c78a72aea827f83d561db51c7ffa61a21ee5f (diff)
downloadmgaonline-45a01f2cf907398a69b5aaee4d5d4bc476bff0b6.tar
mgaonline-45a01f2cf907398a69b5aaee4d5d4bc476bff0b6.tar.gz
mgaonline-45a01f2cf907398a69b5aaee4d5d4bc476bff0b6.tar.bz2
mgaonline-45a01f2cf907398a69b5aaee4d5d4bc476bff0b6.tar.xz
mgaonline-45a01f2cf907398a69b5aaee4d5d4bc476bff0b6.zip
add a wrapper in order to add update media from authenticated server on MES5
-rwxr-xr-xmdkapplet49
-rwxr-xr-xmdkapplet-enterprise-update-helper171
2 files changed, 219 insertions, 1 deletions
diff --git a/mdkapplet b/mdkapplet
index 703aa4fa..06434b96 100755
--- a/mdkapplet
+++ b/mdkapplet
@@ -148,6 +148,12 @@ my %state = (
menu => [ 'check' ],
tt => [ N_("No medium found. You must add some media through 'Software Media Manager'.") ],
},
+ no_enterprise_update_medium => {
+ colour => [ 'noconf' ],
+ changes => [ 'okay', 'busy', 'critical', 'disconnected' ],
+ menu => [ 'add_enterprise_update_medium' , 'check' ],
+ tt => [ N("An additional package medium is available for your distribution.") ]
+ },
no_enabled_medium => {
colour => [ 'noconf' ],
changes => [ 'okay', 'busy', 'critical', 'disconnected' ],
@@ -202,11 +208,17 @@ my %comm_codes = (
status => 'unconfigured_restricted_media',
log => "Missing restricted media\n",
},
+ no_enterprise_update_medium => {
+ code => 10,
+ status => 'no_enterprise_update_medium',
+ log => "Missing enterprise update media\n",
+ },
);
my %actions = (
'update' => { name => N("Install updates"), launch => sub { installUpdates() } },
'add_restricted_media' => { name => N("Add additional package medium"), launch => \&prepare_add_restricted },
+ 'add_enterprise_update_medium' => { name => N("Add additional package medium"), launch => \&prepare_add_enterprise_update_media },
'check' => { name => N("Check Updates"), launch => \&checkUpdates },
'confNetwork' => { name => N("Configure Network"), launch => sub { configNetwork() } },
'upgrade_distro' => { name => N("Upgrade the system"), launch => \&upgrade },
@@ -222,6 +234,7 @@ $icon->signal_connect(activate => sub {
my %actions = (
unconfigured_restricted_media => \&prepare_add_restricted,
no_update_medium => \&add_media,
+ no_enterprise_update_medium => \&prepare_add_enterprise_update_media,
no_enabled_medium => \&add_media,
updates => \&installUpdates,
new_distribution => \&upgrade,
@@ -231,6 +244,7 @@ $icon->signal_connect(activate => sub {
if ($action eq 'new_distribution' && $sub_state eq 'updates') {
$action = 'updates';
}
+
$actions{$action}->() if ref $actions{$action};
});
foreach my $opt (@ARGV) {
@@ -525,7 +539,12 @@ sub silentCheck() {
urpm::media::configure($urpm, if_(!is_it_a_devel_distro(), update => 1));
my @update_medias = get_update_medias($urpm);
if (!@update_medias) {
- checker_exit('no_update_medium');
+ get_product_id();
+ if ($product_id->{type} eq 'Enterprise' && $product_id->{product} eq 'Server') {
+ checker_exit('no_enterprise_update_medium');
+ } else {
+ checker_exit('no_update_medium');
+ }
} elsif (!any { ! $_->{ignore} } @update_medias) {
checker_exit('no_enabled_medium');
}
@@ -646,6 +665,8 @@ sub setState {
$bubble->add_action('clicked', N("Install updates"), \&installUpdates);
} elsif ($state eq 'unconfigured_restricted_media') {
$bubble->add_action('clicked', N("More Information"), \&prepare_add_restricted);
+ } elsif ($state eq 'no_enterprise_update_medium') {
+ $bubble->add_action('clicked', N("More Information"), \&prepare_add_enterprise_update_media);
} elsif (member($state, qw(no_enabled_medium no_update_medium))) {
$bubble->add_action('clicked', N("Add media"), \&add_media);
}
@@ -757,3 +778,29 @@ sub prepare_add_restricted() {
$local_config{DO_NOT_ASK_FOR_RESTRICTED} = bool2text($warn_me);
$res ? really_prepare_add_restricted() : 0;
}
+
+
+sub really_prepare_add_restricted() {
+ $mdv_update_pid = run_program::raw({ detach => 1 }, 'mdkapplet-enterprise-update-helper', join('', @$product_id{qw(type product version)}));
+}
+
+sub prepare_add_enterprise_update_media() {
+ my $warn_me = text2bool($local_config{DO_NOT_ASK_FOR_ENTERPRISE_UPDATE_MEDIA});
+ return if $warn_me;
+ my $w = new_portable_dialog(N("New medium available"));
+ my $res =
+ fill_n_run_portable_dialog(
+ $w,
+ [
+ get_banner(N("New medium available")),
+ gtknew('Label_Left', text =>
+ N("You use '%s' distribution and therefore have privileged access to additional software.",
+ N("Mandriva Linux Enterprise Server")) . "\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_ENTERPRISE_UPDATE_MEDIA', bool2text($warn_me));
+ $local_config{DO_NOT_ASK_FOR_ENTERPRISE_UPDATE_MEDIA} = bool2text($warn_me);
+ $res ? really_prepare_add_restricted() : 0;
+}
diff --git a/mdkapplet-enterprise-update-helper b/mdkapplet-enterprise-update-helper
new file mode 100755
index 00000000..66731f29
--- /dev/null
+++ b/mdkapplet-enterprise-update-helper
@@ -0,0 +1,171 @@
+#!/usr/bin/perl
+################################################################################
+# Mandriva Online #
+# #
+# Copyright (C) 2009 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;
+
+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";
+
+get_restricted_authentication();
+
+ugtk2::exit(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(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 = 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")),
+ ]);
+
+ my $email = $email_w->get_text;
+ if ($res) {
+ if ($email && $password) {
+ add_enterprise_update_medium($email, $password);
+ } else {
+ interactive->vnew->ask_warn(N("Error"), N("Password and email cannot be empty."));
+ goto &get_restricted_authentication;
+ }
+ } else {
+ ugtk2::exit(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;
+}
+
+my $error;
+sub add_enterprise_update_medium {
+ my ($email, $password) = @_;
+
+ my $res = get_from("https://my.mandriva.com/rest/authenticate", [ 'username', $email, 'password', $password,
+ 'return', 'userdata' ]);
+ 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;
+ } elsif ($ref->{data}{'can-access-restricted-repositories'} ne 'YES') {
+ no_rigths_dialog();
+ } else {
+ $error = 0;
+ my $arch = urpm::cfg::get_arch();
+ actually_add_enterprise_update_medium($ref, $password, $arch)
+ 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_rigths_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_enterprise_update_medium {
+ my ($ref, $password, $arch) = @_;
+ my @options = ({ sensitive_arguments => 1 }, 'urpmi.addmedia', '--xml-info', 'always');
+ my $uri = "https://" . uri_escape($ref->{data}{email}) . ":$password\@download.mandriva.com/$version/rpms/$arch/";
+ run_program::raw(@options, '--update', '--distrib', $uri);
+}