Handle hostnames with upper-case letters
[webmin.git] / apache / show_virt.cgi
1 #!/usr/local/bin/perl
2 # show_virt.cgi
3 # Show directives from a virtualhost section
4
5 require './apache-lib.pl';
6 &ReadParse();
7 ($conf, $v) = &get_virtual_config($in{'virt'});
8 $desc = &text('virt_header', &virtual_name($v));
9 &ui_print_header($desc, $text{'show_title'}, "");
10
11 for($i=0; $i<$directive_type_count; $i++) {
12         foreach $e (&editable_directives($i, 'virtual')) {
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_virt.cgi>\n";
26 print "<input type=hidden name=virt value=\"$in{'virt'}\">\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("virt_index.cgi?virt=$in{'virt'}", $text{'virt_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'} eq "VirtualHost") { next; }
52                 elsif ($d->{'name'} =~ /Location|Files|Directory/) {
53                         $ed1 = "<a href=\"dir_index.cgi?virt=$in{'virt'}&".
54                                "idx=$idx\">";
55                         $ed2 = "</a>";
56                         }
57                 print $ed1,"&lt;",$d->{'name'}," ",$d->{'value'},
58                       "&gt;",$ed2,"\n";
59                 &show_directives($d->{'members'}, $ind+1);
60                 print " " x $ind;
61                 print "&lt;/",$d->{'name'},"&gt;\n";
62                 }
63         elsif ($_[1] || !$access_types{$t->{'type'}}) {
64                 # Directives in section are not editable
65                 &print_line($d, [ $d->{'name'}," ",$d->{'value'} ], $ind);
66                 }
67         else {
68                 next if (!$t);
69                 &print_line($d, [ $d->{'name'}," ",$d->{'value'} ], $ind,
70                             "edit_virt.cgi?virt=$in{'virt'}&type=$t->{'type'}");
71                 }
72         }
73 }
74