Handle hostnames with upper-case letters
[webmin.git] / apache / manual_form.cgi
1 #!/usr/local/bin/perl
2 # manual.cgi
3 # Display a text box for manually editing directives
4
5 require './apache-lib.pl';
6 &ReadParse();
7 $access{'types'} eq '*' || &error($text{'manual_ecannot'});
8 if (defined($in{'virt'})) {
9         if (defined($in{'idx'})) {
10                 # directory within virtual server
11                 ($vconf, $v) = &get_virtual_config($in{'virt'});
12                 $d = $vconf->[$in{'idx'}];
13                 $title = &text('dir_header', &dir_name($d), &virtual_name($v));
14                 $return = "dir_index.cgi"; $rmsg = $text{'dir_return'};
15                 $file = $d->{'file'};
16                 $start = $d->{'line'}+1; $end = $d->{'eline'}-1;
17                 }
18         else {
19                 # virtual server (which can have multiple files!)
20                 ($conf, $v) = &get_virtual_config($in{'virt'});
21                 @files = &unique((map { $_->{'file'} } @$conf), $v->{'file'});
22                 $title = &text('virt_header', &virtual_name($v));
23                 $return = "virt_index.cgi"; $rmsg = $text{'virt_return'};
24                 $file = $in{'editfile'} || $v->{'file'};
25                 &indexof($file, @files) >= 0 ||
26                         &error($text{'manual_efile'});
27                 if ($file eq $v->{'file'}) {
28                         # Edit stuff include <Virtualhost>
29                         $start = $v->{'line'}+1; $end = $v->{'eline'}-1;
30                         }
31                 else {
32                         # Edit whole file
33                         $start = $end = undef;
34                         }
35                 }
36         }
37 else {
38         if (defined($in{'idx'})) {
39                 # files within .htaccess file
40                 $hconf = &get_htaccess_config($in{'file'});
41                 $d = $hconf->[$in{'idx'}];
42                 $file = $in{'file'};
43                 $start = $d->{'line'}+1; $end = $d->{'eline'}-1;
44                 $title = &text('htfile_header', &dir_name($d),
45                                "<tt>$in{'file'}</tt>");
46                 $return = "htaccess_index.cgi"; $rmsg = $text{'htindex_return'};
47                 }
48         else {
49                 # .htaccess file
50                 $file = $in{'file'};
51                 $title = &text('htindex_header', "<tt>$in{'file'}</tt>");
52                 $return = "htaccess_index.cgi"; $rmsg = $text{'htindex_return'};
53                 $dir = "files_index.cgi";
54                 }
55         }
56 @files = ( $file ) if (!@files);
57 &ui_print_header($title, $text{'manual_title'}, "");
58
59 foreach $h ('virt', 'idx', 'file') {
60         if (defined($in{$h})) {
61                 $hiddens .= &ui_hidden($h, $in{$h}),"\n";
62                 push(@args, "$h=$in{$h}");
63                 }
64         }
65 $args = join('&', @args);
66
67 # Show file selector (if needed)
68 if (@files > 1) {
69         print &ui_form_start("manual_form.cgi");
70         print $text{'manual_editfile'},"\n";
71         print &ui_select("editfile", $file,
72                          [ map { [ $_ ] } @files ]),"\n";
73         print &ui_submit($text{'manual_switch'});
74         print $hiddens;
75         print &ui_form_end();
76         }
77 else {
78         print &text('manual_header', "<tt>$file</tt>"),"<p>\n";
79         }
80
81 # Show actual editor form
82 print &ui_form_start("manual_save.cgi", "form-data");
83 print $hiddens;
84 print &ui_hidden("editfile", $in{'editfile'}),"\n";
85
86 $lref = &read_file_lines($file);
87 if (!defined($start)) {
88         $start = 0;
89         $end = @$lref - 1;
90         }
91 for($i=$start; $i<=$end; $i++) {
92         $buf .= $lref->[$i]."\n";
93         }
94 print &ui_textarea("directives", $buf, 15, 80, undef, undef,
95                    "style='width:100%'"),"<br>\n";
96 print &ui_submit($text{'save'});
97 print &ui_form_end();
98
99 &ui_print_footer("$return?$args", $rmsg);
100
101 # print_directives(&list, indent)
102 sub print_directives
103 {
104 foreach $c (@{$_[0]}) {
105         next if ($c->{'name'} eq 'dummy');
106         if ($c->{'type'}) {
107                 print $_[1],"<",$c->{'name'}," ",$c->{'value'},">\n";
108                 &print_directives($c->{'members'}, $_[1].' ');
109                 print $_[1],"</",$c->{'name'},">\n";
110                 }
111         else {
112                 print $_[1],$c->{'name'}," ",$c->{'value'},"\n";
113                 }
114         }
115 }
116