3 # A form for editing or creating a delay pool
5 require './squid-lib.pl';
7 $access{'delay'} || &error($text{'delay_ecannot'});
10 &ui_print_header(undef, $text{'pool_title1'}, "", "edit_pool", 0, 0, 0,
14 &ui_print_header(undef, $text{'pool_title2'}, "", "edit_pool", 0, 0, 0,
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;
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";
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";
32 print "<tr> <td><b>$text{'pool_num'}</b></td>\n";
34 $pools = &find_value("delay_pools", $conf);
35 print "<td>",$pools+1,"</td>\n";
38 print "<td>$in{'idx'}</td>\n";
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"};
50 print "</select></td> </tr>\n";
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";
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";
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";
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";
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";
75 print "</table></td></tr></table>\n";
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";
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";
88 foreach $h (@access) {
89 @v = @{$h->{'values'}};
90 if ($v[1] eq "allow") {
91 $v[1] = $text{'eacl_allow'};
93 $v[1] = $text{'eacl_deny'};
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])),
101 if ($hc != @access-1) {
102 print "<a href=\"move_pool.cgi?$hc+1+",
103 "$in{'idx'}\"><img src=images/down.gif ",
106 else { print "<img src=images/gap.gif>"; }
108 print "<a href=\"move_pool.cgi?$hc+-1+",
109 "$in{'idx'}\"><img src=images/up.gif ",
112 print "</td></tr>\n";
118 print "<b>$text{'pool_noacl'}</b><p>\n";
120 print "<a href='pool_access.cgi?new=1&idx=$in{'idx'}'>",
121 "$text{'pool_add'}</a>\n";
123 print "</td></tr></table>\n";
125 print "<table width=100%><tr>\n";
127 print "<td><input type=submit value='$text{'create'}'></td>\n";
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";
134 print "</tr></table></form>\n";
136 &ui_print_footer("edit_delay.cgi", $text{'delay_return'},
137 "", $text{'index_return'});
139 # limit_field(name, value)
142 local ($v1, $v2) = $_[1] =~ /^([0-9\-]+)\/([0-9\-]+)$/ ? ($1, $2) : ( -1, -1 );
143 local $unl = $v1 == -1 && $v2 == -1;
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'}." ";
151 $rv .= &unit_field("$_[0]_2", $unl ? "" : $v2).$text{'pool_limit2'};
155 # unit_field(name, value)
159 local @ud = ( .125, 1, 125, 1000, 125000, 1000000 );
161 for($u=@ud-1; $u>=1; $u--) {
162 last if (!($_[1]%$ud[$u]));
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};
175 $rv .= "</select>\n";