/usr/share/perl5/EBox/Squid/Model/DelayPools2.pm is in zentyal-squid 2.3.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | # Copyright (C) 2010-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package EBox::Squid::Model::DelayPools2;
# Class: EBox::Squid::Model::DelayPools2
#
# Form to set the configuration for the delay pools class 2.
#
use base 'EBox::Model::DataTable';
use strict;
use warnings;
use integer;
use EBox::Gettext;
use EBox::Global;
use EBox::Types::Int;
use EBox::Types::IPAddr;
use EBox::Types::Union;
use EBox::Types::Union::Text;
use EBox::Model::ModelManager;
use Math::BigInt;
# Group: Public methods
# Constructor: new
#
# Create the new DelayPools2 model.
#
# Overrides:
#
# <EBox::Model::DataForm::new>
#
# Returns:
#
# <EBox::Squid::Model::DelayPools2> - the recently created model.
#
sub new
{
my $class = shift;
my $self = $class->SUPER::new(@_);
bless( $self, $class );
return $self;
}
# Method: validateTypedRow
#
# Overrides:
#
# <EBox::Model::DataTable::validateTypedRow>
#
# Exceptions:
#
# <EBox::Exceptions::InvalidData> - throw if parameter has
# invalid data.
#
sub validateTypedRow
{
my ($self, $action, $params, $allFields) = @_;
if ( defined ( $params->{acl_object} ) ) {
# check objects have members
my $srcObjId = $params->{acl_object}->value();
my $objects = EBox::Global->modInstance('objects');
unless ( @{$objects->objectAddresses($srcObjId)} > 0 ) {
throw EBox::Exceptions::External(
__x('Object {object} has no members. Please add at ' .
'least one to add rules using this object.',
object => $params->{acl_object}->printableValue()));
}
}
# Check if the row to edit/add is enabled prior to check this
if ( defined( $params->{enabled} ) and $params->{enabled}->value() ) {
# Check the same object is not used in first delay pool table
my $srcObjId = $allFields->{acl_object}->value();
my $squidMod = $self->parentModule();
my $delayPools1 = $squidMod->model('DelayPools1');
my $row = $delayPools1->findRow('acl_object' => $srcObjId);
if ( defined($row) and $row->valueByName('enabled') ) {
throw EBox::Exceptions::External(
__x('Object {object} has an enabled {row} in {table}. Delete it first '
. 'from there to add it here',
object => $allFields->{acl_object}->printableValue(),
row => $delayPools1->printableRowName(),
table => $delayPools1->printableName()));
}
}
# Check the rate/size are set both if unlimited
my @allParams = ( [qw(size rate)], [qw(rate size)], [qw(clt_rate clt_size)],
[qw(clt_size clt_rate)]);
foreach my $paramNames (@allParams) {
if ( defined( $params->{$paramNames->[0]} ) ) {
# Check the size is unlimited and the rate is unlimited
if ( $params->{$paramNames->[0]}->value() == -1
and $allFields->{$paramNames->[1]}->value() != -1) {
throw EBox::Exceptions::External(__x('If {first} is set unlimited, '
. 'then {second} must be set to unlimited as well',
first => $params->{$paramNames->[0]}->printableName(),
second => $allFields->{$paramNames->[1]}->printableName()));
}
}
}
# Check the clt_rate is always lower than rate (network)
if ( defined( $params->{rate} ) or defined( $params->{clt_rate} )) {
my $netRate = $allFields->{rate}->value();
$netRate = Math::BigInt->binf() if ($netRate == -1);
my $cltRate = $allFields->{clt_rate}->value();
$cltRate = Math::BigInt->binf() if ($cltRate == -1);
if ( $cltRate > $netRate ) {
throw EBox::Exceptions::External(__x('{clt_rate} is greater than {net_rate}',
clt_rate => $allFields->{clt_rate}->printableName(),
net_rate => $allFields->{rate}->printableName()));
}
}
}
# Group: Protected methods
# Method: _table
#
# Overrides:
#
# <EBox::Model::DataTable::_table>
#
sub _table
{
my ($self) = @_;
my @tableHead =
(
new EBox::Types::Select(
fieldName => 'acl_object',
printableName => __('Network object'),
foreignModel => \&_objectModel,
foreignField => 'name',
foreignNextPageField => 'members',
editable => 1,
unique => 1,
),
new EBox::Types::Int(
fieldName => 'rate',
printableName => __('Newtork download rate'),
size => 3,
editable => 1,
trailingText => __('KB/s'),
defaultValue => 0,
min => -1,
help => __('Maximum download rate for this network. Use -1 to disable this option.')
),
new EBox::Types::Int(
fieldName => 'size',
printableName => __('Network file size'),
size => 3,
editable => 1,
trailingText => __('KB'),
defaultValue => 0,
min => -1,
help => __('Maximum unthrottled download file size for this network. Use -1 to disable this option.')
),
new EBox::Types::Int(
fieldName => 'clt_rate',
printableName => __('Client download rate'),
size => 3,
editable => 1,
trailingText => __('KB/s'),
defaultValue => 0,
min => -1,
help => __('Maximum download rate per client. Use -1 to disable this option.')
),
new EBox::Types::Int(
fieldName => 'clt_size',
printableName => __('Client file size'),
size => 3,
editable => 1,
trailingText => __('KB'),
defaultValue => 0,
min => -1,
help => __('Maximum unthrottled download file size per client. Use -1 to disable this option.')
),
);
my $dataTable = {
'tableName' => 'DelayPools2',
'printableTableName' => __x('Client bandwidth rules (class 2 delay pools)'),
'defaultActions' => [ 'add', 'del', 'editField', 'changeView', 'move' ],
'modelDomain' => 'Squid',
'tableDescription' => \@tableHead,
'class' => 'dataTable',
# Priority field set the ordering through _order function
'order' => 1,
'help' => __('Once the download exceeds the file size then the HTTP Proxy will slow down the connection to the specified download rate. Both parameters can be defined for the whole network and on a per client basis. The client number is limited to 256.'),
'rowUnique' => 1,
'printableRowName' => __('rule'),
'automaticRemove' => 1,
'enableProperty' => 1,
'defaultEnabledValue' => 1,
# XXX notifyForeignModelAction to normalize values on interface bw change
};
return $dataTable;
}
# Get the object model from Objects module
sub _objectModel
{
return EBox::Global->modInstance('objects')->{objectModel};
}
sub delayPools2
{
my ($self) = @_;
my $objects = EBox::Global->modInstance('objects');
my @pools;
foreach my $pool (@{$self->enabledRows()}) {
my $row = $self->row($pool);
my $rate = $row->valueByName('rate');
my $size = $row->valueByName('size');
my $clt_rate = $row->valueByName('clt_rate');
my $clt_size = $row->valueByName('clt_size');
my $obj = $row->valueByName('acl_object');
my $addresses = $objects->objectAddresses($obj);
push (@pools, { id => $pool,
class => '2',
rate => $rate,
size => $size,
clt_rate => $clt_rate,
clt_size => $clt_size,
object => $obj,
addresses => $addresses });
}
return \@pools;
}
1;
|