From f45911beb603ae45e1a0e1244904c19ba523a084 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 2 Oct 2009 14:47:50 -0700 Subject: [PATCH] Confirmation page for package updates --- makedist.pl | 1 + package-updates/index.cgi | 13 +++- package-updates/lang/en | 5 ++ package-updates/package-updates-lib.pl | 26 ++++++-- package-updates/update.cgi | 90 ++++++++++++++++++++------ package-updates/view.cgi | 3 +- 6 files changed, 109 insertions(+), 29 deletions(-) diff --git a/makedist.pl b/makedist.pl index 068019d49..7e0ef0de1 100755 --- a/makedist.pl +++ b/makedist.pl @@ -71,6 +71,7 @@ else { "tunnel", "zones", "cluster-usermin", "dovecot", "syslog-ng", "mailcap", "blue-theme", "ldap-client", "phpini", "filter", "bacula-backup", "ldap-server", "exim", "tcpwrappers", + "package-updates", ); } @dirlist = ( "Webmin" ); diff --git a/package-updates/index.cgi b/package-updates/index.cgi index 3a0e14bb4..6e34e38ad 100755 --- a/package-updates/index.cgi +++ b/package-updates/index.cgi @@ -31,7 +31,9 @@ foreach $m ('all', 'updates', 'new', 'both', push(@grid, $text{'index_mode'}, &ui_links_row(\@mlinks)); # Show all selector -if (&show_all_option()) { +$showall = &show_all_option(); +if ($showall == 1) { + # Can show all, or just virtualmin $in{'all'} ||= 0; foreach $a (0, 1) { $amsg = $text{'index_all_'.$a}; @@ -46,13 +48,17 @@ if (&show_all_option()) { } push(@grid, $text{'index_allsel'}, &ui_links_row(\@alinks)); } +elsif ($showall == 2) { + # Always showing all + $in{'all'} = 2; + } # Show search box push(@grid, $text{'index_search'}, &ui_textbox("search", $in{'search'}, 30)." ". &ui_submit($text{'index_searchok'})); print &ui_form_start("index.cgi"); -print &ui_hidden("all", &show_all_option() ? 1 : 0); +print &ui_hidden("all", $showall ? 1 : 0); print &ui_hidden("mode", $in{'mode'}); print &ui_grid_table(\@grid, 2),"

\n"; print &ui_form_end(); @@ -128,7 +134,8 @@ foreach $p (sort { $a->{'name'} cmp $b->{'name'} } (@current, @avail)) { 'checked' => $need }, "{'name'})."&system=". - &urlize($p->{'system'})."'>$p->{'name'}", + &urlize($p->{'system'})."&search=". + &urlize($in{'search'})."'>$p->{'name'}", $p->{'desc'}, $msg, $source ? ( $source ) : $anysource ? ( "") : ( ), diff --git a/package-updates/lang/en b/package-updates/lang/en index 663045e9b..bf9d40a36 100644 --- a/package-updates/lang/en +++ b/package-updates/lang/en @@ -71,6 +71,11 @@ update_tgzuntardone=.. done update_tgzsetup=Running setup script .. update_tgzsetupdone=.. upgrade complete update_etgzsetup=.. upgrade failed! See the error message above for the reason why +update_rusure=Are you sure you wish to install the $1 packages listed below? This may include dependencies of packages that you selected. +update_oldver=Current version +update_newver=New version +update_confirm=Install Now +update_none=None sched_title=Scheduled Update sched_yes=Scheduled checking for updates is now active. diff --git a/package-updates/package-updates-lib.pl b/package-updates/package-updates-lib.pl index ea5bbaa84..763de284c 100644 --- a/package-updates/package-updates-lib.pl +++ b/package-updates/package-updates-lib.pl @@ -2,8 +2,9 @@ # update system. # # XXX cron job to collect .. actually use webmin module collector -# XXX confirmation form, showing all dependencies +# XXX re-check after package update # XXX test automatic notification +# XXX test on debian BEGIN { push(@INC, ".."); }; eval "use WebminCore;"; @@ -475,6 +476,21 @@ unlink($current_all_cache_file); return @rv; } +# list_package_operations(package, system) +# Given a package, returns a list of all dependencies that will be installed +sub list_package_operations +{ +my ($name, $system) = @_; +if (defined(&software::update_system_operations)) { + my @rv = &software::update_system_operations($name); + foreach my $p (@rv) { + $p->{'system'} = $system; + } + return @rv; + } +return ( ); +} + # list_possible_updates([nocache]) # Returns a list of updates that are available. Each element in the array # is a hash ref containing a name, version, description and severity flag. @@ -832,11 +848,13 @@ if ($pkg->{'system'} eq 'yum') { return undef; } -# Returns 1 if an option should be shown to list all packages. Only true for -# YUM and APT at the moment +# Returns 1 if an option should be shown to list all packages, 2 if all +# packages is the only option, or 0 if only virtualmin. sub show_all_option { -return $software::update_system eq 'apt' || $software::update_system eq 'yum'; +return !&foreign_check("virtual-server") ? 2 : + $software::update_system eq 'apt' || + $software::update_system eq 'yum' ? 1 : 0; } sub flush_package_caches diff --git a/package-updates/update.cgi b/package-updates/update.cgi index 7c67e55da..5c0c2cb25 100755 --- a/package-updates/update.cgi +++ b/package-updates/update.cgi @@ -29,29 +29,77 @@ else { @pkgs || &error($text{'update_enone'}); &ui_print_unbuffered_header(undef, $text{'update_title'}, ""); - foreach my $ps (@pkgs) { - ($p, $s) = split(/\//, $ps); - print &text('update_pkg', "$p"),"
\n"; - print "


\n"; - } - if (@got) { - print &text('update_ok', scalar(@got)),"

\n"; - } - else { - print $text{'update_failed'},"

\n"; - } - - # Refresh collected package info - if (&foreign_check("virtual-server") && @got) { - &foreign_require("virtual-server", "virtual-server-lib.pl"); - if (defined(&virtual_server::refresh_possible_packages)) { - &virtual_server::refresh_possible_packages(\@got); + # Work out what will be done, if possible + @ops = ( ); + if (!$in{'confirm'}) { + foreach my $ps (@pkgs) { + ($p, $s) = split(/\//, $ps); + push(@ops, &list_package_operations($p, $s)); } } - &webmin_log("update", "packages", scalar(@got), - { 'got' => \@got }); + if (@ops) { + # Ask first + print &ui_form_start("update.cgi", "post"); + print &ui_hidden("all", $in{'all'}); + print &ui_hidden("mode", $in{'mode'}); + print &ui_hidden("search", $in{'search'}); + foreach $ps (@pkgs) { + print &ui_hidden("u", $ps); + } + print &text('update_rusure', scalar(@ops)),"

\n"; + print &ui_form_end([ [ "confirm", $text{'update_confirm'} ] ]); + + # Show table of all depends + @current = $in{'all'} ? &list_all_current(1) + : &list_current(1); + print &ui_columns_start([ $text{'index_name'}, + $text{'update_oldver'}, + $text{'update_newver'}, + $text{'index_desc'}, + ], 100); + foreach $p (@ops) { + ($c) = grep { $_->{'name'} eq $p->{'name'} && + $_->{'system'} eq $p->{'system'} } @current; + if (!$c && !@avail) { + # Only get available if needed + @avail = &list_available(0, $in{'all'}); + } + ($a) = grep { $_->{'name'} eq $p->{'name'} && + $_->{'system'} eq $p->{'system'} } @avail; + print &ui_columns_row([ + $p->{'name'}, + $c ? $c->{'version'} + : "$text{'update_none'}", + $p->{'version'}, + $c ? $c->{'desc'} : + $a ? $a->{'desc'} : '', + ]); + } + print &ui_columns_end(); + } + else { + # Do it + foreach my $ps (@pkgs) { + ($p, $s) = split(/\//, $ps); + print &text('update_pkg', "$p"),"
\n"; + print "


\n"; + } + if (@got) { + print &text('update_ok', scalar(@got)),"

\n"; + } + else { + print $text{'update_failed'},"

\n"; + } + + # Refresh collected package info + # XXX call webmin + + &webmin_log("update", "packages", scalar(@got), + { 'got' => \@got }); + } + &ui_print_footer($redir, $text{'index_return'}); } diff --git a/package-updates/view.cgi b/package-updates/view.cgi index d8869acae..f63ae67d9 100644 --- a/package-updates/view.cgi +++ b/package-updates/view.cgi @@ -73,6 +73,7 @@ elsif ($a && !$c) { } print &ui_form_end(\@buts); -&ui_print_footer("index.cgi?all=$in{'all'}&mode=$in{'mode'}", +&ui_print_footer("index.cgi?all=$in{'all'}&mode=$in{'mode'}&search=". + &urlize($in{'search'}), $text{'index_return'});