Handle hostnames with upper-case letters
[webmin.git] / squid / edit_acl.cgi
1 #!/usr/local/bin/perl
2 # edit_acl.cgi
3 # Display a list of all ACLs and restrictions using them
4
5 require './squid-lib.pl';
6 &ReadParse();
7 $access{'actrl'} || &error($text{'eacl_ecannot'});
8 &ui_print_header(undef, $text{'eacl_header'}, "", "edit_acl", 0, 0, 0, &restart_button());
9 $conf = &get_config();
10
11 # Start tabs for various ACL settings
12 $prog = "edit_acl.cgi";
13 @tabs = ( [ "acls", $text{'eacl_acls'}, $prog."?mode=acls" ],
14           [ "http", $text{'eacl_pr'}, $prog."?mode=http" ],
15           [ "icp", $text{'eacl_icpr'}, $prog."?mode=icp" ] );
16 if ($squid_version >= 2.5) {
17         push(@tabs, [ "external", $text{'eacl_ext'}, $prog."?mode=external" ],
18                     [ "reply", $text{'eacl_replypr'}, $prog."?mode=reply" ] );
19         }
20 print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || "acls", 1);
21
22 # List all defined access control directives
23 print &ui_tabs_start_tab("mode", "acls");
24 @acl = &find_config("acl", $conf);
25 if (@acl) {
26         print &ui_columns_start([ $text{'eacl_name'},
27                                   $text{'eacl_type'},
28                                   $text{'eacl_match'} ], 100);
29         foreach $a (@acl) {
30                 @v = @{$a->{'values'}};
31                 local @cols;
32                 push(@cols, "<a href=\"acl.cgi?index=$a->{'index'}\">".
33                             &html_escape($v[0])."</a>");
34                 push(@cols, $acl_types{$v[1]});
35                 if ($v[2] =~ /^"(.*)"$/ || $v[3] =~ /^"(.*)"$/) {
36                         push(@cols, &text('eacl_file', "<tt>$1</tt>"));
37                         }
38                 else {
39                         push(@cols, &html_escape(join(' ', @v[2..$#v])));
40                         }
41                 print &ui_columns_row(\@cols, [ "", "nowrap", "" ]);
42                 }
43         print &ui_columns_end();
44         }
45 else {
46         print "<b>$text{'eacl_noacls'}</b><p>\n";
47         }
48 print "<form action=acl.cgi>\n";
49 print "<input type=submit value=\"$text{'eacl_buttcreate'}\">\n";
50 print "<select name=type>\n";
51 foreach $t (sort { $acl_types{$a} cmp $acl_types{$b} } keys %acl_types) {
52         print "<option value=$t>$acl_types{$t}\n";
53         }
54 print "</select></form>\n";
55 print &ui_tabs_end_tab();
56
57 # List all HTTP restrictions, based on ACLs
58 print &ui_tabs_start_tab("mode", "http");
59 @http = &find_config("http_access", $conf);
60 if (@http) {
61         @tds = ( "width=5", "width=10%", undef, "width=32" );
62         print &ui_form_start("delete_http_accesses.cgi", "post");
63         print "<a href=http_access.cgi?new=1>$text{'eacl_addpr'}</a><br>\n";
64         print &ui_columns_start([ "",
65                                   $text{'eacl_act'},
66                                   $text{'eacl_acls1'},
67                                   $text{'eacl_move'} ], 100, 0, \@tds);
68         $hc = 0;
69         foreach $h (@http) {
70                 @v = @{$h->{'values'}};
71                 if ($v[0] eq "allow") {
72                         $v[0] = $text{'eacl_allow'};
73                         }
74                 else {
75                         $v[0] = $text{'eacl_deny'};
76                         }
77                 local @cols;
78                 push(@cols, "<a href=\"http_access.cgi?index=$h->{'index'}\">".
79                             "$v[0]</a>");
80                 push(@cols, &html_escape(join(' ', @v[1..$#v])));
81                 local $mover = &ui_up_down_arrows(
82                         "move_http.cgi?$hc+-1",
83                         "move_http.cgi?$hc+1",
84                         $hc != 0,
85                         $hc != @http-1
86                         );
87                 push(@cols, $mover);
88                 print &ui_checked_columns_row(\@cols, \@tds, "d",$h->{'index'});
89                 $hc++;
90                 }
91         print &ui_columns_end();
92         print "<a href=http_access.cgi?new=1>$text{'eacl_addpr'}</a><br>\n";
93         print &ui_form_end([ [ "delete", $text{'eacl_hdelete'} ] ]);
94         }
95 else {
96         print "<b>$text{'eacl_nopr'}</b><p>\n";
97         print "<a href=http_access.cgi?new=1>$text{'eacl_addpr'}</a><br>\n";
98         }
99 print &ui_tabs_end_tab();
100
101 # List all ICP restrictions, based on ACLs
102 print &ui_tabs_start_tab("mode", "icp");
103 @icp = &find_config("icp_access", $conf);
104 if (@icp) {
105         print &ui_form_start("delete_icp_accesses.cgi", "post");
106         @tds = ( "width=5", "width=10%", undef, "width=32" );
107         print "<a href=icp_access.cgi?new=1>$text{'eacl_addicpr'}</a><br>\n";
108         print &ui_columns_start([ "",
109                                   $text{'eacl_act'},
110                                   $text{'eacl_acls1'},
111                                   $text{'eacl_move'} ], 100, 0, \@tds);
112         $ic = 0;
113         foreach $i (@icp) {
114                 @v = @{$i->{'values'}};
115                 if ($v[0] eq "allow") {
116                         $v[0] = $text{'eacl_allow'};
117                         }
118                 else {
119                         $v[0] = $text{'eacl_deny'};
120                         }
121                 local @cols;
122                 push(@cols, "<a href=\"icp_access.cgi?index=$i->{'index'}\">".
123                             "$v[0]</a>");
124                 push(@cols, &html_escape(join(' ', @v[1..$#v])));
125                 local $mover = &ui_up_down_arrows(
126                         "move_icp.cgi?$ic+-1",
127                         "move_icp.cgi?$ic+1",
128                         $ic != 0,
129                         $ic != @icp-1);
130                 push(@cols, $mover);
131                 print &ui_checked_columns_row(\@cols, \@tds, "d",$i->{'index'});
132                 $ic++;
133                 }
134         print &ui_columns_end();
135         print "<a href=icp_access.cgi?new=1>$text{'eacl_addicpr'}</a><br>\n";
136         print &ui_form_end([ [ "delete", $text{'eacl_hdelete'} ] ]);
137         }
138 else {
139         print "<b>$text{'eacl_noicpr'}</b><p>\n";
140         print "<a href=icp_access.cgi?new=1>$text{'eacl_addicpr'}</a><br>\n";
141         }
142 print &ui_tabs_end_tab();
143
144 # List all HTTP REPLY restrictions, based on ACLs
145 if ($squid_version >= 2.5) {
146         print &ui_tabs_start_tab("mode", "reply");
147         @http_reply = &find_config("http_reply_access", $conf);
148         if (@http_reply) {
149                 @tds = ( "width=5", "width=10%", undef, "width=32" );
150                 print &ui_form_start("delete_http_reply_accesses.cgi", "post");
151                 print "<a href=http_reply_access.cgi?new=1>$text{'eacl_addpr'}</a><br>\n";
152                 print &ui_columns_start([ "",
153                                           $text{'eacl_act'},
154                                           $text{'eacl_acls1'},
155                                           $text{'eacl_move'} ], 100, 0, \@tds);
156                 $hc = 0;
157                 foreach $h (@http_reply) {
158                         @v = @{$h->{'values'}};
159                         if ($v[0] eq "allow") {
160                                 $v[0] = $text{'eacl_allow'};
161                                 }
162                         else {
163                                 $v[0] = $text{'eacl_deny'};
164                                 }
165                         local @cols;
166                         push(@cols, "<a href=\"http_reply_access.cgi?index=$h->{'index'}\">".
167                                     "$v[0]</a>");
168                         push(@cols, &html_escape(join(' ', @v[1..$#v])));
169                         local $mover;
170                         if ($hc != @http_reply-1) {
171                                 $mover .= "<a href=\"move_http_reply.cgi?$hc+1\">".
172                                           "<img src=images/down.gif border=0></a>";
173                                 }
174                         else {
175                                 $mover .= "<img src=images/gap.gif>";
176                                 }
177                         if ($hc != 0) {
178                                 $mover .= "<a href=\"move_http_reply.cgi?$hc+-1\">".
179                                           "<img src=images/up.gif border=0></a>";
180                                 }
181                         else {
182                                 $mover .= "<img src=images/gap.gif>";
183                                 }
184                         push(@cols, $mover);
185                         print &ui_checked_columns_row(\@cols, \@tds, "d",$h->{'index'});
186                         $hc++;
187                         }
188                 print &ui_columns_end();
189                 print "<a href=http_reply_access.cgi?new=1>$text{'eacl_addpr'}</a><br>\n";
190                 print &ui_form_end([ [ "delete", $text{'eacl_hdelete'} ] ]);
191                 }
192         else {
193                 print "<b>$text{'eacl_noprr'}</b><p>\n";
194                 print "<a href=http_reply_access.cgi?new=1>$text{'eacl_addprr'}</a><br>\n";
195                 }
196         print &ui_tabs_end_tab();
197         }
198
199 if ($squid_version >= 2.5) {
200         # Show table of external ACL types
201         print &ui_tabs_start_tab("mode", "external");
202         @ext = &find_config("external_acl_type", $conf);
203         if (@ext) {
204                 print &ui_columns_start([ $text{'eacl_cname'},
205                                           $text{'eacl_format'},
206                                           $text{'eacl_program'} ], 100);
207                 foreach $e (@ext) {
208                         $ea = &parse_external($e);
209                         print &ui_columns_row([
210                                 "<a href='edit_ext.cgi?index=$e->{'index'}'>".
211                                  "$ea->{'name'}</a>",
212                                 $ea->{'format'},
213                                 join(" ", $ea->{'program'}, @{$ea->{'args'}})
214                                 ]);
215                         }
216                 print &ui_columns_end();
217                 }
218         else {
219                 print "<b>$text{'eacl_noext'}</b><p>\n";
220                 }
221         print "<a href=edit_ext.cgi?new=1>$text{'eacl_addext'}</a>\n";
222         print &ui_tabs_end_tab();
223         }
224
225 print &ui_tabs_end(1);
226
227 &ui_print_footer("", $text{'eacl_return'});
228