Handle hostnames with upper-case letters
[webmin.git] / htaccess-htpasswd / edit_dir.cgi
1 #!/usr/local/bin/perl
2 # edit_dir.cgi
3 # Display information about a protected directory
4
5 require './htaccess-lib.pl';
6 &foreign_require($apachemod, "apache-lib.pl");
7 &ReadParse();
8 $can_create || &error($text{'dir_ecannotcreate'});
9 if ($in{'new'}) {
10         &ui_print_header(undef, $text{'dir_title1'}, "");
11         }
12 else {
13         &ui_print_header(undef, $text{'dir_title2'}, "");
14         @dirs = &list_directories();
15         ($dir) = grep { $_->[0] eq $in{'dir'} } @dirs;
16         &can_access_dir($dir->[0]) || &error($text{'dir_ecannot'});
17         }
18
19 print &ui_form_start("save_dir.cgi");
20 print &ui_hidden("new", $in{'new'});
21 print &ui_hidden_table_start($text{'dir_header'}, "width=100%", 2, "main", 1, [ "width=30%" ]);
22
23 # Directory to protect
24 if ($in{'new'}) {
25         print &ui_table_row($text{'dir_dir'},
26                 &ui_textbox("dir", $dir->[0], 50)." ".
27                 &file_chooser_button("dir", 1));
28         }
29 else {
30         print &ui_table_row($text{'dir_dir'},
31                 "<tt>".&html_escape($dir->[0])."</tt>");
32         print &ui_hidden("dir", $in{'dir'});
33         }
34
35 # File containing users
36 if ($can_htpasswd) {
37         # Allow choice of users file
38         if ($in{'new'}) {
39                 $ufile = &ui_radio("auto", 1, [ [ 1, $text{'dir_auto'}."<br>" ],
40                                                 [ 0, $text{'dir_sel'} ] ]);
41                 }
42         $ufile .= &ui_textbox("file", $dir->[1], 50)." ".
43                   &file_chooser_button("file", 0);
44         }
45 else {
46         # Always automatic
47         if ($in{'new'}) {
48                 $ufile = $text{'dir_auto'};
49                 }
50         else {
51                 $ufile = "<tt>".&html_escape($dir->[1])."</tt>";
52                 }
53         }
54 print &ui_table_row($text{'dir_file'}, $ufile);
55
56 # File containing groups
57 if ($can_htgroups) {
58         @opts = ( [ 2, "$text{'dir_none'}<br>" ] );
59         if ($in{'new'}) {
60                 push(@opts, [ 1, "$text{'dir_auto'}<br>" ]);
61                 }
62         push(@opts, [ 0, $text{'dir_sel'}." ".
63                          &ui_textbox("gfile", $dir->[4], 50)." ".
64                          &file_chooser_button("gfile", 0) ]);
65         print &ui_table_row($text{'dir_gfile'},
66                 &ui_radio("gauto", $dir->[4] ? 0 : 2, \@opts));
67         }
68
69 # If MD5 encryption is available, show option for it
70 @crypts = ( 0 );
71 push(@crypts, 1) if ($config{'md5'});
72 push(@crypts, 2) if ($config{'sha1'});
73 push(@crypts, 3) if ($config{'digest'});
74 if (@crypts > 1) {
75         print &ui_table_row($text{'dir_crypt'},
76                 &ui_radio("crypt", int($dir->[2]),
77                   [ map { [ $_, $text{'dir_crypt'.$_} ] } @crypts ]));
78         }
79 else {
80         print &ui_hidden("crypt", $crypts[0]);
81         }
82
83 # Authentication realm
84 if (!$in{'new'}) {
85         &switch_user();
86         $conf = &foreign_call($apachemod, "get_htaccess_config",
87                               "$dir->[0]/$config{'htaccess'}");
88         &switch_back();
89         $realm = &foreign_call($apachemod, "find_directive",
90                                "AuthName", $conf, 1);
91         }
92 print &ui_table_row($text{'dir_realm'},
93         &ui_textbox("realm", $realm, 50));
94
95 # Users and groups to allow
96 if (!$in{'new'}) {
97         $require = &foreign_call($apachemod, "find_directive_struct",
98                                  "require", $conf);
99         ($rmode, @rwho) = @{$require->{'words'}} if ($require);
100         }
101 else {
102         $rmode = "valid-user";
103         }
104 print &ui_table_row($text{'dir_require'},
105    &ui_radio("require_mode", $rmode,
106         [ [ "valid-user", $text{'dir_requirev'}."<br>" ],
107           [ "user", $text{'dir_requireu'}." ".
108             &ui_textbox("require_user",
109                 $rmode eq "user" ? join(" ", @rwho) : "", 40)."<br>" ],
110           [ "group", $text{'dir_requireg'}." ".
111             &ui_textbox("require_group",
112                 $rmode eq "group" ? join(" ", @rwho) : "", 40)."<br>" ] ]));
113
114 print &ui_hidden_table_end();
115
116 # Webmin synchronization mode
117 if ($can_sync) {
118         print &ui_hidden_table_start($text{'dir_header2'}, "width=100%", 2, "sync", 0, [ "width=30%" ]);
119
120         %sync = map { $_, 1 } split(/,/, $dir->[3]);
121         foreach $s ('create', 'update', 'delete') {
122                 print &ui_table_row($text{'dir_sync_'.$s},
123                         &ui_yesno_radio("sync_$s", $sync{$s} ? 1 : 0));
124                 }
125
126         print &ui_hidden_table_end();
127         }
128
129 if ($in{'new'}) {
130         print &ui_form_end([ [ undef, $text{'create'} ] ]);
131         }
132 else {
133         if (&foreign_available("apache")) {
134                 %aaccess = &get_module_acl(undef, "apache");
135                 if ($aaccess{'global'}) {
136                         @abutton = ( undef, [ 'apache', $text{'dir_apache'} ] );
137                         }
138                 }
139         print &ui_form_end([ [ undef, $text{'save'} ],
140                              [ 'delete', $text{'dir_delete'} ],
141                              [ 'remove', $dir->[4] ? $text{'dir_delete2'}
142                                                    : $text{'dir_delete3'} ],
143                              @abutton ]);
144         }
145
146 &ui_print_footer("", $text{'index_return'});
147