Handle hostnames with upper-case letters
[webmin.git] / usermin / install_mod.cgi
1 #!/usr/local/bin/perl
2 # install_mod.cgi
3 # Download and install a usermin module
4
5 require './usermin-lib.pl';
6 $access{'umods'} || &error($text{'acl_ecannot'});
7 if ($ENV{REQUEST_METHOD} eq "POST") { &ReadParseMime(); }
8 else { &ReadParse(); $no_upload = 1; }
9
10 $| = 1;
11 $theme_no_table = 1 if ($in{'source'} == 2);
12 &ui_print_header(undef, $text{'install_title'}, "");
13
14 if ($in{'source'} == 0) {
15         # from local file
16         &error_setup(&text('install_err1', $in{'file'}));
17         $file = $in{'file'};
18         if (!(-r $file)) { &inst_error($text{'install_efile'}); }
19         }
20 elsif ($in{'source'} == 1) {
21         # from uploaded file
22         &error_setup($text{'install_err2'});
23         $file = &transname();
24         $need_unlink = 1;
25         if ($no_upload) {
26                 &inst_error($text{'install_ebrowser'});
27                 }
28         &open_tempfile(MOD, ">$file", 0, 1);
29         &print_tempfile(MOD, $in{'upload'});
30         &close_tempfile(MOD);
31         }
32 elsif ($in{'source'} == 2) {
33         # from ftp or http url
34         &error_setup(&text('install_err3', $in{'url'}));
35         $file = &transname();
36         $need_unlink = 1;
37         local $error;
38         $progress_callback_url = $in{'url'};
39         if ($in{'url'} =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
40                 $ssl = $1 eq 'https';
41                 $host = $2; $page = $3; $port = $ssl ? 443 : 80;
42                 if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
43                 &http_download($host, $port, $page, $file, \$error,
44                                \&progress_callback, $ssl);
45                 }
46         elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)(:21)?\/(.*)$/) {
47                 $host = $1; $ffile = $3;
48                 &ftp_download($host, $ffile, $file, \$error, \&progress_callback);
49                 }
50         else { &inst_error($text{'install_eurl'}); }
51         &inst_error($error) if ($error);
52         }
53
54 # Install the module(s)
55 $rv = &install_usermin_module($file, $need_unlink, $in{'nodeps'});
56 if (ref($rv)) {
57         @mdescs = @{$rv->[0]};
58         @mdirs = @{$rv->[1]};
59         @msizes = @{$rv->[2]};
60         }
61 else {
62         &inst_error($rv);
63         }
64
65 # Display something nice for the user
66 print "$text{'install_desc'} <p>\n";
67 print "<ul>\n";
68 for($i=0; $i<@mdescs; $i++) {
69         $mdirs[$i] =~ /\/([^\/]+)$/;
70         if (%minfo = &get_usermin_module_info($1)) {
71                 # Installed a module
72                 local $cat = $text{"category_".$minfo{'category'}};
73                 $cat = $text{"category_"} if (!$cat);
74                 print &text($minfo{'hidden'} ? 'install_line3' :
75                                 'install_line2', "<b>$mdescs[$i]</b>",
76                             "<tt>$mdirs[$i]</tt>", $msizes[$i], $cat),
77                             "<br>\n";
78                 }
79         elsif (%tinfo = &get_usermin_theme_info($1)) {
80                 # Installed a theme
81                 print &text('themes_line', "<b>$mdescs[$i]</b>",
82                             "<tt>$mdirs[$i]</tt>", $msizes[$i]),
83                             "<br>\n";
84                 }
85         }
86 print "</ul><p>\n";
87 &ui_print_footer("edit_mods.cgi?mode=install", $text{'mods_return'},
88                  "", $text{'index_return'});
89
90 sub inst_error
91 {
92 print "<b>$whatfailed : $_[0]</b> <p>\n";
93 &ui_print_footer("", $text{'index_return'});
94 exit;
95 }
96