Handle hostnames with upper-case letters
[webmin.git] / apache / virt_index.cgi
1 #!/usr/local/bin/perl
2 # virt_index.cgi
3 # Display a menu for some specific virtual server, or the default server
4
5 require './apache-lib.pl';
6 &ReadParse();
7 ($conf, $v) = &get_virtual_config($in{'virt'});
8 &can_edit_virt($v) || &error($text{'virt_ecannot'});
9 $desc = &text('virt_header', &virtual_name($v));
10 &ui_print_header($desc, $text{'virt_title'}, "", undef, undef, undef, undef, &restart_button());
11
12 # Display header and icons
13 $sw_icon = { "icon" => "images/show.gif",
14              "name" => $text{'virt_show'},
15              "link" => "show.cgi?virt=$in{'virt'}" };
16 if ($in{'virt'} && $access{'types'} eq '*') {
17         $ed_icon = { "icon" => "images/edit.gif",
18                      "name" => $text{'virt_edit'},
19                      "link" => "manual_form.cgi?virt=$in{'virt'}" };
20         }
21 &config_icons("virtual", "edit_virt.cgi?virt=$in{'virt'}&", $sw_icon,
22               $ed_icon ? $ed_icon : ());
23
24 # Display per-directory options
25 @dir = ( &find_directive_struct("Directory", $conf) ,
26          &find_directive_struct("DirectoryMatch", $conf),
27          &find_directive_struct("Files", $conf),
28          &find_directive_struct("FilesMatch", $conf),
29          &find_directive_struct("Location", $conf),
30          &find_directive_struct("LocationMatch", $conf),
31          &find_directive_struct("Proxy", $conf) );
32 if (@dir) {
33         print &ui_hr();
34         print &ui_subheading($text{'dir_title'});
35         foreach $d (@dir) {
36                 $what = &dir_name($d);
37                 substr($what, 0, 1) = uc(substr($what, 0, 1));
38                 push(@links, "dir_index.cgi?idx=".&indexof($d, @$conf).
39                              "&virt=$in{'virt'}");
40                 push(@titles, $what);
41                 push(@icons, "images/dir.gif");
42                 push(@types, $d->{'name'});
43                 }
44         if ($config{'show_list'}) {
45                 # Show as list
46                 print &ui_columns_start([ $text{'virt_path'},
47                                           $text{'virt_type'} ]);
48                 for($i=0; $i<@links; $i++) {
49                         print &ui_columns_row([
50                           "<a href='$links[$i]'>$titles[$i]</a>",
51                           $text{'virt_'.$types[$i]} ]);
52                         }
53                 print &ui_columns_end();
54                 }
55         else {
56                 # Show as icons
57                 &icons_table(\@links, \@titles, \@icons, 3);
58                 }
59         print "<p>\n";
60         }
61
62 # Show form to create a dir
63 print &ui_form_start("create_dir.cgi", "post");
64 print &ui_hidden("virt", $in{'virt'});
65 print &ui_table_start($text{'virt_adddir'}, undef, 2);
66
67 print &ui_table_row($text{'virt_type'},
68         &ui_select("type", undef,
69           [ map { [ $_, $text{'virt_'.$_} ] }
70                   $httpd_modules{'core'} >= 2.0 ?
71                         ( "Directory", "Files", "Location", "Proxy" ) :
72                   $httpd_modules{'core'} >= 1.2 ?
73                         ( "Directory", "Files", "Location" ) :
74                         ( "Directory", "Location" ) ]));
75
76 if ($httpd_modules{'core'} >= 1.2) {
77         print &ui_table_row($text{'virt_regexp'},
78                 &ui_radio("regexp", 0, [ [ 0, $text{'virt_exact'} ],
79                                          [ 1, $text{'virt_re'} ] ]));
80         }
81
82 print &ui_table_row($text{'virt_path'},
83         &ui_textbox("path", undef, 50));
84
85 print &ui_table_end();
86 print &ui_form_end([ [ "", $text{'create'} ] ]);
87
88 if ($in{'virt'} && $access{'vaddr'}) {
89         # Show form for changing virtual server
90         print &ui_hr();
91         print &ui_form_start("save_vserv.cgi");
92         print &ui_hidden("virt", $in{'virt'});
93         print &ui_table_start($text{'virt_opts'}, undef, 2);
94
95         $val = $v->{'value'};
96         if ($val =~ /\s/) {
97                 $addrs = $val;
98                 }
99         if ($val =~ /^\[(\S+)\]:(\d+)$/) {
100                 # IPv6 address and port
101                 $addr = $1; $port = $2;
102                 }
103         elsif ($val =~ /^\[(\S+)\]$/) {
104                 # IPv6 address
105                 $addr = $1;
106                 }
107         elsif ($val =~ /^(\S+):(\d+)$/) {
108                 # IPv4 address or hostname and port
109                 $addr = $1; $port = $2;
110                 }
111         else {
112                 # IPv4 address or hostname
113                 $addr = $val;
114                 }
115
116         if ($addrs) {
117                 # Multiple addresses and ports
118                 print &ui_table_row($text{'vserv_addrs'},
119                         &ui_textarea("addrs", join("\n", split(/\s+/, $addrs)),
120                                     4, 30));
121                 }
122         else {
123                 # Address and port
124                 print &ui_table_row($text{'vserv_addr'},
125                         &ui_radio("addr_def", $addr eq "_default_" ? 1 :
126                                               $addr eq "*" ? 2 : 0,
127                           [ [ 1, $text{'vserv_addr1'} ],
128                             [ 2, $text{'vserv_any'} ],
129                             [ 0, &ui_textbox("addr",
130                                         $addr eq "*" || $addr eq "_default_" ?
131                                                 "" : $addr, 40) ] ]));
132
133                 print &ui_table_row($text{'vserv_port'},
134                      &choice_input($port eq "*" ? 1 : $port > 0 ? 2 : 0,
135                                    "port_mode", "0", "$text{'vserv_default'},0",
136                                    "$text{'vserv_any'},1", ",2").
137                      &ui_textbox("port", $port > 0 ? $port : "", 5));
138                 }
139
140         # Document directory
141         $root = &find_directive_struct("DocumentRoot", $v->{'members'});
142         print &ui_table_row($text{'vserv_root'},
143                 &opt_input($root->{'words'}->[0], "root",
144                                           $text{'vserv_default'}, 50).
145                 &file_chooser_button("root", 1, 1));
146         print &ui_hidden("old_root", $root->{'words'}->[0]);
147
148         # Server name
149         $name = &find_directive("ServerName", $v->{'members'});
150         print &ui_table_row($text{'vserv_name'},
151                 &opt_input($name, "name", $text{'vserv_default'}, 30));
152
153         print &ui_table_end();
154         print &ui_form_end([ [ undef, $text{'save'} ],
155                              [ "delete", $text{'delete'} ] ]);
156         }
157
158 &ui_print_footer("", $text{'index_return'});
159