3 # Download and install a webmin module
5 require './webmin-lib.pl';
6 if ($ENV{REQUEST_METHOD} eq "POST") { &ReadParseMime(); }
7 else { &ReadParse(); $no_upload = 1; }
10 $theme_no_table = 1 if ($in{'source'} == 2 || $in{'source'} == 4);
11 &ui_print_header(undef, $text{'install_title'}, "");
13 if ($in{'source'} == 0) {
15 &error_setup(&text('install_err1', $in{'file'}));
17 if (!(-r $file)) { &inst_error($text{'install_efile'}); }
19 elsif ($in{'source'} == 1) {
21 &error_setup($text{'install_err2'});
24 &inst_error($text{'install_ebrowser'});
26 $file = &transname(&file_basename($in{'upload_filename'}));
29 print MOD $in{'upload'};
32 elsif ($in{'source'} == 2 || $in{'source'} == 4) {
33 # from ftp or http url (possible third-party)
34 $url = $in{'source'} == 2 ? $in{'url'} : $in{'third'};
35 &error_setup(&text('install_err3', $url));
36 $file = &transname(&file_basename($url));
39 $progress_callback_url = $url;
40 if ($url =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
42 $host = $2; $page = $3; $port = $ssl ? 443 : 80;
43 if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
44 &http_download($host, $port, $page, $file, \$error,
45 \&progress_callback, $ssl);
47 elsif ($url =~ /^ftp:\/\/([^\/]+)(:21)?\/(.*)$/) {
48 $host = $1; $ffile = $3;
49 &ftp_download($host, $ffile, $file, \$error, \&progress_callback);
51 else { &inst_error($text{'install_eurl'}); }
52 &inst_error($error) if ($error);
54 elsif ($in{'source'} == 3) {
56 &error_setup($text{'install_err4'});
57 $in{'standard'} =~ /^\S+$/ || &error($text{'install_estandard'});
61 # Find the URL of the package
62 $mods = &list_standard_modules();
63 ref($mods) || &error(&text('standard_failed', $error));
64 local ($info) = grep { $_->[0] eq $in{'standard'} } @$mods;
65 $info || &error($text{'install_emissing'});
66 if ($config{'standard_url'}) {
67 ($host, $port, $page, $ssl) = &parse_http_url(
68 $config{'standard_url'});
69 $host || &error($text{'standard_eurl'});
72 ($host, $port, $page, $ssl) = ($standard_host, $standard_port,
73 $standard_page, $standard_ssl);
75 ($host, $port, $page, $ssl) = &parse_http_url(
76 $info->[2], $host, $port, $page, $ssl);
77 $progress_callback_url = $info->[2];
78 $file = &transname($info->[2]);
79 &http_download($host, $port, $page, $file, \$error,
80 \&progress_callback, $ssl);
81 &inst_error($error) if ($error);
84 # Install the module(s)
85 $rv = &install_webmin_module($file, $need_unlink, $in{'nodeps'},
86 $in{'grant'} ? undef : [ split(/\s+/, $in{'grantto'}) ]);
88 @mdescs = @{$rv->[0]};
90 @msizes = @{$rv->[2]};
96 # Display something nice for the user
97 &read_file("$config_directory/webmin.catnames", \%catnames);
98 print "$text{'install_desc'} <p>\n";
100 for($i=0; $i<@mdescs; $i++) {
101 $mdirs[$i] =~ /\/([^\/]+)$/;
102 if (%minfo = &get_module_info($1)) {
104 my $cat = $catnames{$minfo{'category'}};
105 $cat = $text{"category_".$minfo{'category'}} if (!$cat);
106 $cat = $text{"category_"} if (!$cat);
107 print &text($minfo{'hidden'} ? 'install_line3' :
108 'install_line2', "<b>$mdescs[$i]</b>",
109 "<tt>$mdirs[$i]</tt>", $msizes[$i], $cat,
110 "../$minfo{'dir'}/"),
113 elsif (%tinfo = &get_theme_info($1)) {
115 print &text('themes_line', "<b>$mdescs[$i]</b>",
116 "<tt>$mdirs[$i]</tt>", $msizes[$i]),
122 if (defined(&theme_post_change_modules)) {
123 &theme_post_change_modules();
126 &ui_print_footer("edit_mods.cgi?mode=install", $text{'mods_return'},
127 "", $text{'index_return'});
131 print "<b>$main::whatfailed : $_[0]</b> <p>\n";
132 &ui_print_footer("", $text{'index_return'});