Handle hostnames with upper-case letters
[webmin.git] / file / upload.cgi
1 #!/usr/local/bin/perl
2 # upload.cgi
3 # Upload a file
4
5 require './file-lib.pl';
6 $disallowed_buttons{'upload'} && &error($text{'ebutton'});
7 &popup_header();
8 &ReadParse(\%getin, "GET");
9 $upid = $getin{'id'};
10 &ReadParseMime($upload_max, \&read_parse_mime_callback, [ $upid ]);
11
12 $realdir = &unmake_chroot($in{'dir'});
13 if (!$in{'file_filename'}) {
14         print "<p><b>$text{'upload_efile'}</b><p>\n";
15         }
16 elsif (!-d $realdir) {
17         print "<p><b>$text{'upload_edir'}</b><p>\n";
18         }
19 elsif ($running_as_root && !defined(getpwnam($in{'user'}))) {
20         print "<p><b>$text{'upload_euser'}</b><p>\n";
21         }
22 else {
23         $in{'file_filename'} =~ /([^\\\/]+)$/;
24         $path = "$in{'dir'}/$1";
25         $realpath = "$realdir/$1";
26         if (-e $realpath) {
27                 # File exists .. ask the user if he is sure
28                 &switch_acl_uid($running_as_root ? $in{'user'} : undef);
29                 $temp = &tempname();
30                 &open_tempfile(TEMP, ">$temp");
31                 if ($dostounix == 1 && $in{'dos'}) {
32                         $in{'file'} =~ s/\r\n/\n/g;
33                         }
34                 &print_tempfile(TEMP, $in{'file'});
35                 &close_tempfile(TEMP);
36                 print "<center>\n";
37                 print &ui_form_start("upload2.cgi");
38                 foreach $i (keys %prein) {
39                         print &ui_hidden($i, $prein{$i});
40                         }
41                 print &ui_hidden("dir", $in{'dir'});
42                 print &ui_hidden("path", $path);
43                 print &ui_hidden("temp", $temp);
44                 print &ui_hidden("zip", $in{'zip'});
45                 print &ui_hidden("user", $in{'user'});
46                 print &text('upload_already', "<tt>$path</tt>"),"<p>\n";
47                 print &ui_form_end([ [ "yes", $text{'yes'} ],
48                                      [ "no", $text{'no'} ] ]);
49                 print "</form>\n";
50                 print "</center>\n";
51                 }
52         else {
53                 # Go ahread and do it!
54                 &webmin_log("upload", undef, $path);
55                 &switch_acl_uid($running_as_root ? $in{'user'} : undef);
56                 if ($access{'ro'} || !&can_access($path)) {
57                         print "<p><b>",&text('upload_eperm', $path),"</b><p>\n";
58                         }
59                 elsif (-l $path && !&must_follow($realpath)) {
60                         print "<p><b>",&text('upload_elink', $path),"</b><p>\n";
61                         }
62                 elsif (!&open_tempfile(FILE, ">$realpath", 1)) {
63                         print "<p><b>",&text('upload_ewrite', $path, $!),"</b><p>\n";
64                         }
65                 else {
66                         if ($dostounix == 1 && $in{'dos'}) {
67                                 $in{'file'} =~ s/\r\n/\n/g;
68                                 }
69                         &print_tempfile(FILE, $in{'file'});
70                         &close_tempfile(FILE);
71                         &post_upload($path, $in{'dir'}, $in{'zip'});
72                         }
73                 }
74         }
75
76 &popup_footer();