Handle hostnames with upper-case letters
[webmin.git] / usermin / install_theme.cgi
1 #!/usr/local/bin/perl
2 # install_theme.cgi
3 # Download and install a usermin theme
4
5 require './usermin-lib.pl';
6 $access{'themes'} || &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('themes_err1', $in{'file'}));
17         $file = $in{'file'};
18         if (!(-r $file)) { &inst_error($text{'themes_efile'}); }
19         }
20 elsif ($in{'source'} == 1) {
21         # from uploaded file
22         &error_setup($text{'themes_err2'});
23         $file = &transname();
24         $need_unlink = 1;
25         if ($no_upload) {
26                 &inst_error($text{'themes_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('themes_err3', $in{'url'}));
35         $file = &transname();
36         $need_unlink = 1;
37         $progress_callback_url = $in{'url'};
38         if ($in{'url'} =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
39                 $ssl = $1 eq 'https';
40                 $host = $2; $page = $3; $port = $ssl ? 443 : 80;
41                 if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
42                 &http_download($host, $port, $page, $file, \$error,
43                                \&progress_callback, $ssl);
44                 }
45         elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)(:21)?\/(.*)$/) {
46                 $host = $1; $ffile = $3;
47                 &ftp_download($host, $ffile, $file, \$error,
48                               \&progress_callback);
49                 }
50         else { &inst_error($text{'themes_eurl'}); }
51         &inst_error($error) if ($error);
52         }
53
54 # Install the theme(s)
55 $rv = &install_usermin_module($file, $need_unlink, 0);
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{'themes_done'} <p>\n";
67 print "<ul>\n";
68 for($i=0; $i<@mdescs; $i++) {
69         print &text('themes_line', "<b>$mdescs[$i]</b>",
70                     "<tt>$mdirs[$i]</tt>", $msizes[$i]),"<p>\n";
71         }
72 print "</ul><p>\n";
73 &ui_print_footer("", $text{'index_return'});
74
75 sub inst_error
76 {
77 print "<br><b>$whatfailed : $_[0]</b> <p>\n";
78 print &ui_hr();
79 &ui_print_footer("", $text{'index_return'});
80 exit;
81 }
82