Handle hostnames with upper-case letters
[webmin.git] / squid / edit_pool.cgi
1 #!/usr/local/bin/perl
2 # edit_pool.cgi
3 # A form for editing or creating a delay pool
4
5 require './squid-lib.pl';
6 &ReadParse();
7 $access{'delay'} || &error($text{'delay_ecannot'});
8 $conf = &get_config();
9 if ($in{'new'}) {
10         &ui_print_header(undef, $text{'pool_title1'}, "", "edit_pool", 0, 0, 0,
11                 &restart_button());
12         }
13 else {
14         &ui_print_header(undef, $text{'pool_title2'}, "", "edit_pool", 0, 0, 0,
15                 &restart_button());
16         @pools = &find_config("delay_class", $conf);
17         ($pool) = grep { $_->{'values'}->[0] == $in{'idx'} } @pools;
18         @params = &find_config("delay_parameters", $conf);
19         ($param) = grep { $_->{'values'}->[0] == $in{'idx'} } @params;
20         @access = &find_config("delay_access", $conf);
21         @access = grep { $_->{'values'}->[0] == $in{'idx'} } @access;
22         }
23
24 print "<form action=save_pool.cgi>\n";
25 print "<input type=hidden name=new value='$in{'new'}'>\n";
26 print "<input type=hidden name=idx value='$in{'idx'}'>\n";
27
28 print "<table border width=100%>\n";
29 print "<tr $tb> <td><b>$text{'pool_header'}</b></td> </tr>\n";
30 print "<tr $cb> <td><table width=100%>\n";
31
32 print "<tr> <td><b>$text{'pool_num'}</b></td>\n";
33 if ($in{'new'}) {
34         $pools = &find_value("delay_pools", $conf);
35         print "<td>",$pools+1,"</td>\n";
36         }
37 else {
38         print "<td>$in{'idx'}</td>\n";
39         }
40 print "</tr>\n";
41
42 $cls = $pool->{'values'}->[1] || 1;
43 print "<tr> <td><b>$text{'pool_class'}</b></td>\n";
44 print "<td><select name=class>\n";
45 foreach $c (1 .. ($squid_version >= 3 ? 5 : 3)) {
46         printf "<option value=%s %s>%s - %s\n",
47                 $c, $cls == $c ? "selected" : "",
48                 $c, $text{"delay_class_$c"};
49         }
50 print "</select></td> </tr>\n";
51
52 print "<tr> <td><b>$text{'pool_agg'}</b></td>\n";
53 print "<td colspan=3>",&limit_field("agg",
54         $cls == 5 ? undef : $param->{'values'}->[1]),"</td>\n";
55
56 print "<tr> <td><b>$text{'pool_ind'}</b></td>\n";
57 print "<td colspan=3>",&limit_field("ind",
58         $param->{'values'}->[$cls == 2 ? 2 : 3]),"</td>\n";
59
60 print "<tr> <td><b>$text{'pool_net'}</b></td>\n";
61 print "<td colspan=3>",&limit_field("net",
62         $cls == 3 || $cls == 4 ? $param->{'values'}->[2] : undef),"</td>\n";
63
64 if ($squid_version >= 3) {
65         print "<tr> <td><b>$text{'pool_user'}</b></td>\n";
66         print "<td colspan=3>",&limit_field("user",
67                 $cls == 4 ? $param->{'values'}->[4] : undef),"</td>\n";
68
69         print "<tr> <td><b>$text{'pool_tag'}</b></td>\n";
70         print "<td colspan=3>",&limit_field("tag",
71                 $cls == 5 ? $param->{'values'}->[1] : undef),"</td>\n";
72
73         }
74
75 print "</table></td></tr></table>\n";
76
77 if (!$in{'new'}) {
78         print "<p><table border width=100%>\n";
79         print "<tr $tb> <td><b>$text{'pool_aclheader'}</b></td> </tr>\n";
80         print "<tr $cb> <td>\n";
81
82         if (@access) {
83                 print "<table border width=100%>\n";
84                 print "<tr $tb><td width=10%><b>$text{'eacl_act'}</b></td>\n";
85                 print "<td><b>$text{'eacl_acls1'}</b></td>\n";
86                 print "<td width=5%><b>$text{'eacl_move'}</b></td> </tr>\n";
87                 $hc = 0;
88                 foreach $h (@access) {
89                         @v = @{$h->{'values'}};
90                         if ($v[1] eq "allow") {
91                                 $v[1] = $text{'eacl_allow'};
92                         } else {
93                                 $v[1] = $text{'eacl_deny'};
94                         }
95                         print "<tr $cb>\n";
96                         print "<td><a href=\"pool_access.cgi?index=",
97                               "$h->{'index'}&idx=$in{'idx'}\">$v[1]</a></td>\n";
98                         print "<td>",&html_escape(join(' ', @v[2..$#v])),
99                               "</td>\n";
100                         print "<td>\n";
101                         if ($hc != @access-1) {
102                                 print "<a href=\"move_pool.cgi?$hc+1+",
103                                       "$in{'idx'}\"><img src=images/down.gif ",
104                                       "border=0></a>";
105                                 }
106                         else { print "<img src=images/gap.gif>"; }
107                         if ($hc != 0) {
108                                 print "<a href=\"move_pool.cgi?$hc+-1+",
109                                       "$in{'idx'}\"><img src=images/up.gif ",
110                                       "border=0></a>";
111                                 }
112                         print "</td></tr>\n";
113                         $hc++;
114                         }
115                 print "</table>\n";
116                 }
117         else {
118                 print "<b>$text{'pool_noacl'}</b><p>\n";
119                 }
120         print "<a href='pool_access.cgi?new=1&idx=$in{'idx'}'>",
121               "$text{'pool_add'}</a>\n";
122
123         print "</td></tr></table>\n";
124         }
125 print "<table width=100%><tr>\n";
126 if ($in{'new'}) {
127         print "<td><input type=submit value='$text{'create'}'></td>\n";
128         }
129 else {
130         print "<td><input type=submit value='$text{'save'}'></td>\n";
131         print "<td align=right><input type=submit name=delete ",
132               "value='$text{'delete'}'></td>\n";
133         }
134 print "</tr></table></form>\n";
135
136 &ui_print_footer("edit_delay.cgi", $text{'delay_return'},
137         "", $text{'index_return'});
138
139 # limit_field(name, value)
140 sub limit_field
141 {
142 local ($v1, $v2) = $_[1] =~ /^([0-9\-]+)\/([0-9\-]+)$/ ? ($1, $2) : ( -1, -1 );
143 local $unl = $v1 == -1 && $v2 == -1;
144 local $rv;
145 $rv .= sprintf "<input type=radio name=%s_def value=1 %s> %s\n",
146                 $_[0], $unl ? "checked" : "", $text{'delay_unlimited'};
147 $rv .= sprintf "<input type=radio name=%s_def value=0 %s>\n",
148                 $_[0], $unl ? "" : "checked";
149 $rv .= &unit_field("$_[0]_1", $unl ? "" : $v1).
150         $text{'pool_limit1'}."&nbsp;&nbsp;";
151 $rv .= &unit_field("$_[0]_2", $unl ? "" : $v2).$text{'pool_limit2'};
152 return $rv;
153 }
154
155 # unit_field(name, value)
156 sub unit_field
157 {
158 local ($rv, $i, $u);
159 local @ud = ( .125, 1, 125, 1000, 125000, 1000000 );
160 if ($_[1] > 0) {
161         for($u=@ud-1; $u>=1; $u--) {
162                 last if (!($_[1]%$ud[$u]));
163                 }
164         }
165 else {
166         $u = 1;
167         }
168 $rv .= sprintf "<input name=%s_n size=8 value='%s'>\n",
169                 $_[0], $_[1] > 0 ? $_[1]/$ud[$u] : $_[1];
170 $rv .= "<select name=$_[0]_u>\n";
171 for($i=0; $i<@ud; $i++) {
172         $rv .= sprintf "<option value=%s %s>%s\n",
173                 $i, $i == $u ? "selected" : "", $text{'pool_unit'.$i};
174         }
175 $rv .= "</select>\n";
176 return $rv;
177 }
178
179