Handle hostnames with upper-case letters
[webmin.git] / file / edit_html.cgi
1 #!/usr/local/bin/perl
2 # Show an HTML editor window
3
4 $trust_unknown_referers = 1;
5 require './file-lib.pl';
6 do '../ui-lib.pl';
7 $disallowed_buttons{'edit'} && &error($text{'ebutton'});
8 &ReadParse();
9
10 # Work out editing mode
11 if ($in{'text'} || $in{'file'} && !&is_html_file($in{'file'})) {
12         $text_mode = 1;
13         }
14
15 &popup_header($in{'file'} ? $text{'html_title'} : $text{'html_title2'},
16               undef, $text_mode ? undef : "onload='xinha_init()'");
17
18 # Output HTMLarea init code
19 print <<EOF;
20 <script type="text/javascript">
21   _editor_url = "$gconfig{'webprefix'}/$module_name/xinha/";
22   _editor_lang = "en";
23 </script>
24 <script type="text/javascript" src="xinha/XinhaCore.js"></script>
25
26 <script type="text/javascript">
27 xinha_init = function()
28 {
29 xinha_editors = [ "body" ];
30 xinha_plugins = [ ];
31 xinha_config = new Xinha.Config();
32 xinha_editors = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);
33 Xinha.startEditors(xinha_editors);
34 }
35 </script>
36 EOF
37
38 # Read the file
39 &switch_acl_uid_and_chroot();
40 $data = &read_file_contents($in{'file'});
41
42 # Output text area
43 print &ui_form_start("save_html.cgi", "form-data");
44 print &ui_hidden("text", $text_mode);
45 if ($in{'file'}) {
46         # Editing existing file
47         print &ui_hidden("file", $in{'file'});
48         $pc = 95;
49         }
50 else {
51         # Creating new, so prompt for path
52         print $text{'edit_filename'}," ",
53               &ui_textbox("file", $in{'dir'}, 70),"<br>\n";
54         $pc = 90;
55         }
56 if ($text_mode) {
57         # Show plain textarea
58         print "<textarea rows=20 cols=80 style='width:100%;height:$pc%' name=body>";
59         print &html_escape($data);
60         print "</textarea>\n";
61         print &ui_submit($text{'html_save'});
62         }
63 else {
64         # Show HTML editor
65         print "<textarea rows=20 cols=80 style='width:100%;height:$pc%' name=body id=body>";
66         print &html_escape($data);
67         print "</textarea>\n";
68         print "<table width=100%><tr>\n";
69         print "<td>",&ui_submit($text{'html_save'}),"</td>\n";
70         print "<td align=right><a href='edit_html.cgi?file=".
71              &urlize($in{'file'})."&text=1'>$text{'edit_textmode'}</a></td>\n";
72         print "</tr> </table>\n";
73         }
74 print &ui_form_end();
75
76 &popup_footer();
77
78 sub is_html_file
79 {
80 local ($file) = @_;
81 local @exts = split(/\s+/, $userconfig{'htmlexts'} || $config{'htmlexts'});
82 @exts = ( ".htm", ".html", ".shtml" ) if (!@exts);
83 foreach my $e (@exts) {
84         return 1 if ($file =~ /\Q$e\E$/i);
85         }
86 return 0;
87 }