#!/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"; &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; }