Handle hostnames with upper-case letters
[webmin.git] / webmin / install_theme.cgi
1 #!/usr/local/bin/perl
2 # themes_theme.cgi
3 # Download and install a webmin theme
4
5 require './webmin-lib.pl';
6 if ($ENV{REQUEST_METHOD} eq "POST") { &ReadParseMime(); }
7 else { &ReadParse(); $no_upload = 1; }
8
9 $| = 1;
10 $theme_no_table = 1 if ($in{'source'} == 2);
11 &ui_print_header(undef, $text{'install_title'}, "");
12
13 if ($in{'source'} == 0) {
14         # from local file
15         &error_setup(&text('themes_err1', $in{'file'}));
16         $file = $in{'file'};
17         if (!(-r $file)) { &inst_error($text{'themes_efile'}); }
18         }
19 elsif ($in{'source'} == 1) {
20         # from uploaded file
21         &error_setup($text{'themes_err2'});
22         $need_unlink = 1;
23         if ($no_upload) {
24                 &inst_error($text{'themes_ebrowser'});
25                 }
26         $file = &transname(&file_basename($in{'upload_filename'}));
27         open(MOD, ">$file");
28         print MOD $in{'upload'};
29         close(MOD);
30         }
31 elsif ($in{'source'} == 2) {
32         # from ftp or http url
33         &error_setup(&text('themes_err3', $in{'url'}));
34         $file = &transname(&file_basename($in{'url'}));
35         $need_unlink = 1;
36         $progress_callback_url = $in{'url'};
37         if ($in{'url'} =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
38                 $ssl = $1 eq 'https';
39                 $host = $2; $page = $3; $port = $ssl ? 443 : 80;
40                 if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
41                 &http_download($host, $port, $page, $file, \$error,
42                                \&progress_callback, $ssl);
43                 }
44         elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)(:21)?\/(.*)$/) {
45                 $host = $1; $ffile = $3;
46                 &ftp_download($host, $ffile, $file, \$error,
47                               \&progress_callback);
48                 }
49         else { &inst_error($text{'themes_eurl'}); }
50         &inst_error($error) if ($error);
51         }
52
53 # Install the theme(s)
54 $rv = &install_webmin_module($file, $need_unlink, 0, undef);
55 if (ref($rv)) {
56         @mdescs = @{$rv->[0]};
57         @mdirs = @{$rv->[1]};
58         @msizes = @{$rv->[2]};
59         }
60 else {
61         &inst_error($rv);
62         }
63
64 # Display something nice for the user
65 print "$text{'themes_done'} <p>\n";
66 print "<ul>\n";
67 for($i=0; $i<@mdescs; $i++) {
68         print &text('themes_line', "<b>$mdescs[$i]</b>",
69                     "<tt>$mdirs[$i]</tt>", $msizes[$i]),"<p>\n";
70         }
71 print "</ul><p>\n";
72 &ui_print_footer("edit_themes.cgi", $text{'themes_return'},
73                  "", $text{'index_return'});
74
75 sub inst_error
76 {
77 print "<br><b>$whatfailed : $_[0]</b> <p>\n";
78 &ui_print_footer("", $text{'index_return'});
79 exit;
80 }
81