Handle hostnames with upper-case letters
[webmin.git] / file / save_html.cgi
1 #!/usr/local/bin/perl
2 # Write data from an HTML editor
3
4 require './file-lib.pl';
5 $disallowed_buttons{'edit'} && &error($text{'ebutton'});
6 &ReadParseMime();
7 &error_setup($text{'html_err'});
8
9 # Get the original file contents, in case we need to preserve the head
10 $p = $in{'file'};
11 &switch_acl_uid_and_chroot();
12 $olddata = &read_file_contents($p);
13 if ($olddata) {
14         ($oldhead, $oldbody, $oldfoot) = &html_extract_head_body($olddata);
15         }
16
17 # Try to write the file
18 if ($access{'ro'} || !&can_access($p)) {
19         &popup_error(&text('edit_eaccess', $p));
20         }
21 elsif (-l $p && !&must_follow($p)) {
22         &popup_error(&text('edit_efollow', $p));
23         }
24 elsif (!&open_tempfile(FILE, ">$p", 1)) {
25         &popup_error("$!");
26         }
27 else {
28         # Fix up HTML head, and write it out
29         $in{'body'} =~ s/\r//g;
30         $in{'body'} =~ s/^\s+//g;
31         $in{'body'} =~ s/\s+$//g;
32         if ($oldhead && $in{'body'} !~ /<body[\000-\377]*>/i) {
33                 &print_tempfile(FILE, $oldhead.$in{'body'}.$oldfoot);
34                 }
35         else {
36                 &print_tempfile(FILE, $in{'body'});
37                 }
38         &close_tempfile(FILE);
39
40         # Show JS to close page
41         &popup_header($text{'html_title'});
42
43         $info = &file_info_line($p);
44         print "<script>\n";
45         print "opener.document.FileManager.",
46               "upload_notify(\"$p\", \"$info\");\n";
47         print "close();\n";
48         print "</script>\n";
49
50         &popup_footer();
51         }