#!/usr/local/bin/perl # edit_pool.cgi # A form for editing or creating a delay pool require './squid-lib.pl'; &ReadParse(); $access{'delay'} || &error($text{'delay_ecannot'}); $conf = &get_config(); if ($in{'new'}) { &ui_print_header(undef, $text{'pool_title1'}, "", "edit_pool", 0, 0, 0, &restart_button()); } else { &ui_print_header(undef, $text{'pool_title2'}, "", "edit_pool", 0, 0, 0, &restart_button()); @pools = &find_config("delay_class", $conf); ($pool) = grep { $_->{'values'}->[0] == $in{'idx'} } @pools; @params = &find_config("delay_parameters", $conf); ($param) = grep { $_->{'values'}->[0] == $in{'idx'} } @params; @access = &find_config("delay_access", $conf); @access = grep { $_->{'values'}->[0] == $in{'idx'} } @access; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'pool_header'}
\n"; print "\n"; if ($in{'new'}) { $pools = &find_value("delay_pools", $conf); print "\n"; } else { print "\n"; } print "\n"; $cls = $pool->{'values'}->[1] || 1; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; if ($squid_version >= 3) { print "\n"; print "\n"; print "\n"; print "\n"; } print "
$text{'pool_num'}",$pools+1,"$in{'idx'}
$text{'pool_class'}
$text{'pool_agg'}",&limit_field("agg", $cls == 5 ? undef : $param->{'values'}->[1]),"
$text{'pool_ind'}",&limit_field("ind", $param->{'values'}->[$cls == 2 ? 2 : 3]),"
$text{'pool_net'}",&limit_field("net", $cls == 3 || $cls == 4 ? $param->{'values'}->[2] : undef),"
$text{'pool_user'}",&limit_field("user", $cls == 4 ? $param->{'values'}->[4] : undef),"
$text{'pool_tag'}",&limit_field("tag", $cls == 5 ? $param->{'values'}->[1] : undef),"
\n"; if (!$in{'new'}) { print "

\n"; print "\n"; print "
$text{'pool_aclheader'}
\n"; if (@access) { print "\n"; print "\n"; print "\n"; print "\n"; $hc = 0; foreach $h (@access) { @v = @{$h->{'values'}}; if ($v[1] eq "allow") { $v[1] = $text{'eacl_allow'}; } else { $v[1] = $text{'eacl_deny'}; } print "\n"; print "\n"; print "\n"; print "\n"; $hc++; } print "
$text{'eacl_act'}$text{'eacl_acls1'}$text{'eacl_move'}
{'index'}&idx=$in{'idx'}\">$v[1]",&html_escape(join(' ', @v[2..$#v])), "\n"; if ($hc != @access-1) { print ""; } else { print ""; } if ($hc != 0) { print ""; } print "
\n"; } else { print "$text{'pool_noacl'}

\n"; } print "", "$text{'pool_add'}\n"; print "

\n"; } print "\n"; if ($in{'new'}) { print "\n"; } else { print "\n"; print "\n"; } print "

\n"; &ui_print_footer("edit_delay.cgi", $text{'delay_return'}, "", $text{'index_return'}); # limit_field(name, value) sub limit_field { local ($v1, $v2) = $_[1] =~ /^([0-9\-]+)\/([0-9\-]+)$/ ? ($1, $2) : ( -1, -1 ); local $unl = $v1 == -1 && $v2 == -1; local $rv; $rv .= sprintf " %s\n", $_[0], $unl ? "checked" : "", $text{'delay_unlimited'}; $rv .= sprintf "\n", $_[0], $unl ? "" : "checked"; $rv .= &unit_field("$_[0]_1", $unl ? "" : $v1). $text{'pool_limit1'}."  "; $rv .= &unit_field("$_[0]_2", $unl ? "" : $v2).$text{'pool_limit2'}; return $rv; } # unit_field(name, value) sub unit_field { local ($rv, $i, $u); local @ud = ( .125, 1, 125, 1000, 125000, 1000000 ); if ($_[1] > 0) { for($u=@ud-1; $u>=1; $u--) { last if (!($_[1]%$ud[$u])); } } else { $u = 1; } $rv .= sprintf "\n", $_[0], $_[1] > 0 ? $_[1]/$ud[$u] : $_[1]; $rv .= "\n"; return $rv; }