# mod_bandwidth.pl
# Editors for bandwidth-limiting directives
sub mod_bandwidth_directives
{
local $rv;
$rv = [ [ 'BandWidthDataDir', 0, 1, 'global', undef, -1 ],
[ 'BandWidthModule', 0, 1, 'virtual' ],
[ 'BandWidth', 1, 1, 'directory htaccess' ],
[ 'LargeFileLimit', 1, 1, 'directory htaccess' ],
[ 'MaxConnection', 0, 1, 'directory htaccess' ],
# [ 'MinBandWidth', 1, 1, 'directory htaccess' ]
[ 'BandWidthPulse', 0, 1, 'virtual' ]
];
return &make_directives($rv, $_[0], "mod_bandwidth");
}
sub edit_BandWidthDataDir
{
return (2,
$text{'mod_band_dir'},
&opt_input($_[0]->{'value'}, "BandWidthDataDir", $text{'default'}, 40));
}
sub save_BandWidthDataDir
{
if (!$in{'BandWidthDataDir_def'}) {
-d $in{'BandWidthDataDir'} || &error($text{'mod_band_edir'});
local $sd;
foreach $sd ('master', 'link') {
-d "$in{'BandWidthDataDir'}/$sd" ||
&error(&text('mod_band_esubdir', $sd));
}
}
return &parse_opt("BandWidthDataDir");
}
sub edit_BandWidthModule
{
return (1, $text{'mod_band_enable'},
&choice_input($_[0]->{'value'}, "BandWidthModule", "",
"$text{'yes'},on", "$text{'no'},off", "$text{'default'},"));
}
sub save_BandWidthModule
{
return &parse_choice("BandWidthModule");
}
sub edit_BandWidth
{
local ($rv, $i, $max);
$rv = "
\n";
return (2, $text{'mod_band_bandwidth'}, $rv);
}
sub save_BandWidth
{
local ($i, $bw, $client, $all, @rv);
for($i=0; defined($bw = $in{"BandWidth_bw_$i"}); $i++) {
$client = $in{"BandWidth_$i"};
$all = $in{"BandWidth_all_$i"};
next if ($bw eq "");
$bw =~ /^\d+$/ || &error(&text('mod_band_ebw', $bw));
$all || $client =~ /^[a-z0-9\.\-\_\/]+$/i ||
&error(&text('mod_band_eclient', $bw));
push(@rv, ($all ? "all" : $client)." ".$bw);
}
return ( \@rv );
}
sub edit_LargeFileLimit
{
local ($rv, $i, $max);
$rv = "\n";
return (2, $text{'mod_band_sizelimit'}, $rv);
}
sub save_LargeFileLimit
{
local ($i, $bw, $size, @rv);
for($i=0; defined($bw = $in{"LargeFileLimit_bw_$i"}); $i++) {
$size = $in{"LargeFileLimit_$i"};
next if ($bw eq "");
$bw =~ /^\d+$/ || &error(&text('mod_band_ebw', $bw));
$size =~ /^\d+$/ || $size == -1 || &error(&text('mod_band_esize', $bw));
push(@rv, "$size $bw");
}
return ( \@rv );
}
sub edit_MaxConnection
{
return (1,
$text{'mod_band_max'},
&opt_input($_[0]->{'value'}, "MaxConnections", $text{'default'}, 4));
}
sub save_MaxConnection
{
return &parse_opt("MaxConnections", '^\d+$',
$text{'mod_band_emax'});
}
sub edit_BandWidthPulse
{
return (1,
$text{'mod_band_pulse'},
&opt_input($_[0]->{'value'}, "BandWidthPulse", $text{'default'}, 4));
}
sub save_BandWidthPulse
{
return &parse_opt("BandWidthPulse", '^\d+$',
$text{'mod_band_epulse'});
}
1;