Handle hostnames with upper-case letters
[webmin.git] / apache / show_htaccess.cgi
1 #!/usr/local/bin/perl
2 # show_htaccess.cgi
3 # Show directives from a .htaccess
4
5 require './apache-lib.pl';
6 &ReadParse();
7 $conf = &get_htaccess_config($in{'file'});
8 $desc = &text('htindex_header', "<tt>$in{'file'}</tt>");
9 &ui_print_header($desc, $text{'show_title'}, "");
10
11 for($i=0; $i<$directive_type_count; $i++) {
12         foreach $e (&editable_directives($i, 'htaccess')) {
13                 foreach $n (split(/\s+/, $e->{'name'})) {
14                         $edit{lc($n)} = $e;
15                         push(@elist, { 'name' => $n, 'edit' => $e });
16                         }
17                 }
18         }
19 @elist = sort { $a->{'name'} cmp $b->{'name'} } @elist;
20
21 print "<table border><tr><td $cb><pre>\n\n";
22 &show_directives($conf, 0);
23 print "</pre></td></tr></table><p>\n";
24
25 print "<form action=edit_htaccess.cgi>\n";
26 print "<input type=hidden name=file value=\"$in{'file'}\">\n";
27 print "<b>$text{'show_edit'}</b>\n";
28 print "<select name=type>\n";
29 foreach $e (@elist) {
30         print "<option value=",$e->{'edit'}->{'type'},">",
31               $e->{'name'},"\n";
32         }
33 print "</select> <input type=submit value=\"$text{'show_ok'}\">\n";
34 print "</form>\n";
35
36 &ui_print_footer("htaccess_index.cgi?file=$in{'file'}", $text{'htindex_return'});
37
38 # show_directives(list, indent)
39 sub show_directives
40 {
41 local ($list, $ind) = @_;
42 local $idx;
43 for($idx=0; $idx<@$list; $idx++) {
44         local $d = $list->[$idx];
45         next if ($d->{'name'} eq "dummy");
46         $t = $edit{lc($d->{'name'})};
47         if ($d->{'type'}) {
48                 # Recurse into section
49                 local ($ed1, $ed2);
50                 print " " x $ind;
51                 if ($d->{'name'} =~ /Files/) {
52                         $ed1 = "<a href=\"files_index.cgi?idx=$idx&".
53                                "file=$in{'file'}\">";
54                         $ed2 = "</a>";
55                         }
56                 print $ed1,"&lt;",$d->{'name'}," ",$d->{'value'},
57                       "&gt;",$ed2,"\n";
58                 &show_directives($d->{'members'}, $ind+1);
59                 print " " x $ind;
60                 print "&lt;/",$d->{'name'},"&gt;\n";
61                 }
62         elsif ($_[1] || !$access_types{$t->{'type'}}) {
63                 # Directives in section are not editable
64                 &print_line($d, [ $d->{'name'}," ",$d->{'value'} ], $ind);
65                 }
66         else {
67                 next if (!$t);
68                 &print_line($d, [ $d->{'name'}," ",$d->{'value'} ], $ind,
69                             "edit_htaccess.cgi?file=$in{'file'}&type=$t->{'type'}");
70                 }
71         }
72 }
73