/usr/share/perl5/EBox/Squid/Model/DelayPools.pm is in zentyal-squid 2.3.11+quantal1.
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 268 269 270 | # 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::DelayPools;
# Class: EBox::Squid::Model::DelayPools
#
# Rules to set the configuration for the delay pools
#
use base 'EBox::Model::DataTable';
use strict;
use warnings;
use integer;
use EBox::Gettext;
use EBox::Global;
use EBox::Types::Select;
use EBox::Types::Boolean;
use EBox::Squid::Types::UnlimitedInt;
use Math::BigInt;
# Group: Public methods
# Method: validateRow
#
# Overrides:
#
# <EBox::Model::DataTable::validateRow>
#
sub validateRow
{
my ($self, $action, %params) = @_;
if ($params{acl_object}) {
# check objects have members
my $srcObjId = $params{acl_object};
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}));
}
}
if ($params{global_enabled}) {
unless ($params{size} and $params{rate}) {
throw EBox::Exceptions::External(__('If global limit is enabled you need to specifiy its size and rate values'));
}
}
if ($params{clt_enabled}) {
unless ($params{clt_size} and $params{clt_rate}) {
throw EBox::Exceptions::External(__('If per-client limit is enabled you need to specifiy its size and rate values'));
}
}
# Check the clt_rate is always lower than rate (network)
if ($params{global_enabled} and $params{clt_enabled}) {
my $netRate = defined ($params{rate}) ? $params{rate} : Math::BigInt->binf();
my $cltRate = defined ($params{clt_rate}) ? $params{clt_rate} : Math::BigInt->binf();
if ($cltRate > $netRate) {
throw EBox::Exceptions::External(__x('Per-client rate ({clt_rate} KB/s) cannot be greater than global rate ({net_rate} KB/s)',
clt_rate => $cltRate,
net_rate => $netRate));
}
}
}
sub addedRowNotify
{
my ($self, $row) = @_;
$self->_setUndefinedValues($row);
}
sub updatedRowNotify
{
my ($self, $row) = @_;
$self->_setUndefinedValues($row);
}
sub _setUndefinedValues
{
my ($self, $row) = @_;
my $toStore;
unless ($row->valueByName('global_enabled')) {
$row->elementByName('size')->setValue(undef);
$row->elementByName('rate')->setValue(undef);
$toStore = 1;
}
unless ($row->valueByName('clt_enabled')) {
$row->elementByName('clt_size')->setValue(undef);
$row->elementByName('clt_rate')->setValue(undef);
$toStore = 1;
}
if ($toStore) {
$row->store();
}
}
# 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 => $self->modelGetter('objects', 'ObjectTable'),
foreignField => 'name',
foreignNextPageField => 'members',
editable => 1,
unique => 1,
),
new EBox::Types::Boolean(
fieldName => 'global_enabled',
printableName => __('Enable global limit for the object'),
editable => 1,
hiddenOnViewer => 1,
defaultValue => 0,
),
new EBox::Squid::Types::UnlimitedInt(
fieldName => 'size',
printableName => __('Maximum unlimited size'),
help => __('Maximum unthrottled download size for the whole network object.'),
size => 3,
editable => 1,
trailingText => __('MB'),
min => 0,
),
new EBox::Squid::Types::UnlimitedInt(
fieldName => 'rate',
printableName => __('Maximum download rate'),
help => __('Limited download rate after maximum size is reached for the whole network object.'),
size => 3,
editable => 1,
trailingText => __('KB/s'),
),
new EBox::Types::Boolean(
fieldName => 'clt_enabled',
printableName => __('Enable per client limit'),
editable => 1,
hiddenOnViewer => 1,
defaultValue => 0,
),
new EBox::Squid::Types::UnlimitedInt(
fieldName => 'clt_size',
printableName => __('Maximum unlimited size per client'),
help => __('Maximum unthrottled download size for each client.'),
size => 3,
editable => 1,
trailingText => __('MB'),
),
new EBox::Squid::Types::UnlimitedInt(
fieldName => 'clt_rate',
printableName => __('Maximum download rate per client'),
help => __('Limited download rate after maximum size is reached for each client.'),
size => 3,
editable => 1,
trailingText => __('KB/s'),
),
);
my $dataTable = {
'tableName' => 'DelayPools',
'printableTableName' => __('Bandwidth Throttling Rules'),
'defaultActions' => [ 'add', 'del', 'editField', 'changeView', 'move' ],
'modelDomain' => 'Squid',
'tableDescription' => \@tableHead,
'class' => 'dataTable',
# Priority field set the ordering through _order function
'order' => 1,
'pageTitle' => __('HTTP Proxy'),
'help' => __("Bandwith throttling allows you to control download rates for connections going though the HTTP proxy. The first rule to match is applied. If a connection doesn't match any rule, then no bandwidth throttling is applied."),
'rowUnique' => 1,
'printableRowName' => __('rule'),
'automaticRemove' => 1,
'enableProperty' => 1,
'defaultEnabledValue' => 1,
# XXX notifyForeignModelAction to normalize values on interface bw change
};
return $dataTable;
}
sub delayPools
{
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 => defined ($rate) ? $rate : -1,
size => defined ($size) ? $size : -1,
clt_rate => defined ($clt_rate) ? $clt_rate : -1,
clt_size => defined ($clt_size) ? $clt_size : -1,
object => $obj,
addresses => $addresses });
}
return \@pools;
}
# Method: viewCustomizer
#
# Overrides <EBox::Model::DataTable::viewCustomizer>
#
#
sub viewCustomizer
{
my ($self) = @_;
my $customizer = new EBox::View::Customizer();
$customizer->setModel($self);
$customizer->setOnChangeActions(
{
global_enabled =>
{
'on' => { enable => [ 'size', 'rate' ] },
'off' => { disable => [ 'size', 'rate' ] },
},
clt_enabled =>
{
'on' => { enable => [ 'clt_size', 'clt_rate' ] },
'off' => { disable => [ 'clt_size', 'clt_rate' ] },
},
});
return $customizer;
}
1;
|