1#!/usr/local/bin/perl 2# update.cgi 3# Find and install usermin modules that need updating 4 5require './usermin-lib.pl'; 6$access{'upgrade'} || &error($text{'acl_ecannot'}); 7&ReadParse(); 8&error_setup($text{'update_err'}); 9 10# Validate inputs 11if ($in{'source'} == 0) { 12 $host = $update_host; 13 $port = $update_port; 14 $page = $update_page; 15 } 16else { 17 $in{'other'} =~ /^(http|https):\/\/([^:\/]+)(:(\d+))?(\/\S+)$/ || 18 &error($text{'update_eurl'}); 19 $ssl = $1 eq 'https'; 20 $host = $2; 21 $port = $3 ? $4 : $ssl ? 443 : 80; 22 $page = $5; 23 } 24 25# Retrieve the updates list (format is module version url support description ) 26$temp = &transname(); 27&http_download($host, $port, $page, $temp, undef, undef, $ssl); 28open(UPDATES, "<$temp"); 29while(<UPDATES>) { 30 if (/^([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+(.*)/) { 31 push(@updates, [ $1, $2, $3, $4, $5 ]); 32 } 33 } 34close(UPDATES); 35unlink($temp); 36@updates || &error($text{'update_efile'}); 37 38# Display the results and maybe take action 39&ui_print_unbuffered_header(undef, $text{'update_title'}, ""); 40 41print "<b>",&text('update_info'),"</b><p>\n"; 42foreach $u (@updates) { 43 next if ($u->[1] >= &get_usermin_base_version() + .01 || 44 $u->[1] < &get_usermin_base_version()); 45 $count++; 46 local %minfo = &get_usermin_module_info($u->[0]); 47 local %tinfo = &get_usermin_theme_info($u->[0]); 48 if (!%minfo && !%tinfo && !$in{'missing'}) { 49 print &text('update_mmissing', "<b>$u->[0]</b>"),"<p>\n"; 50 next; 51 } 52 if (%minfo && $minfo{'version'} >= $u->[1]) { 53 print &text('update_malready', "<b>$u->[0]</b>"),"<p>\n"; 54 next; 55 } 56 if (%tinfo && $tinfo{'version'} >= $u->[1]) { 57 print &text('update_malready', "<b>$u->[0]</b>"),"<p>\n"; 58 next; 59 } 60 local $osinfo = { 'os_support' => $u->[3] }; 61 if (!&check_usermin_os_support($osinfo)) { 62 print &text('update_mos', "<b>$u->[0]</b>"),"<p>\n"; 63 next; 64 } 65 if ($in{'show'}) { 66 # Just tell the user what would be done 67 print &text('update_mshow', "<b>$u->[0]</b>", "<b>$u->[1]</b>"), 68 "<br>\n"; 69 print " " x 10; 70 print $text{'update_fixes'}," : ",$u->[4],"<p>\n"; 71 } 72 else { 73 # Actually do the update .. 74 local (@mdescs, @mdirs, @msizes); 75 print &text('update_mok', "<b>$u->[0]</b>", "<b>$u->[1]</b>"), 76 "<br>\n"; 77 print " " x 10; 78 print $text{'update_fixes'}," : ",$u->[4],"<br>\n"; 79 $mssl = $ssl; 80 if ($u->[2] =~ /^(http|https):\/\/([^:\/]+)(:(\d+))?(\/\S+)$/) { 81 $mssl = $1 eq 'https'; 82 $mhost = $2; 83 $mport = $3 ? $4 : $mssl ? 443 : 80; 84 $mpage = $5; 85 } 86 elsif ($u->[2] =~ /^\/\S+$/) { 87 $mhost = $host; 88 $mport = $port; 89 $mpage = $u->[2]; 90 } 91 else { 92 $mhost = $host; 93 $mport = $port; 94 ($mpage = $page) =~ s/[^\/]+$//; 95 $mpage .= $u->[2]; 96 } 97 $mtemp = &transname(); 98 $progress_callback_url = $u->[2]; 99 $progress_callback_prefix = " " x 10; 100 &http_download($mhost, $mport, $mpage, $mtemp, undef, 101 \&progress_callback, $mssl); 102 $irv = &install_usermin_module($mtemp, 1, 0); 103 print " " x 10; 104 if (!ref($irv)) { 105 print &text('update_failed', $irv),"<p>\n"; 106 } 107 else { 108 print &text('update_mdesc', "<b>$irv->[0]->[0]</b>", 109 "<b>$irv->[2]->[0]</b>"),"<p>\n"; 110 } 111 } 112 } 113print &text('update_none'),"<br>\n" if (!$count); 114 115# Check if a new version of webmin itself is available 116$file = &transname(); 117&http_download('www.webmin.com', 80, '/index6.html', $file); 118open(FILE, "<$file"); 119while(<FILE>) { 120 if (/usermin-([0-9\.]+)\.tar\.gz/) { 121 $version = $1; 122 last; 123 } 124 } 125close(FILE); 126unlink($file); 127if ($version > &get_usermin_version()) { 128 print "<b>",&text('update_version', $version),"</b><p>\n"; 129 } 130 131print "<p>\n"; 132&ui_print_footer("", $text{'index_return'}); 133 134