aboutsummaryrefslogtreecommitdiffstats
path: root/packages/squid-head
diff options
context:
space:
mode:
authorFernando Lemos <fernandotcl@pfsense.org>2006-09-29 18:16:55 +0000
committerFernando Lemos <fernandotcl@pfsense.org>2006-09-29 18:16:55 +0000
commitfca3b7e3e5d32ccf2ca884aed47f8c1e88d56c70 (patch)
tree65483ea65e53251ff2de68770b3ae074a8188c7a /packages/squid-head
parentcb86f22499558f68b56e6d01555c6b6aca07ee79 (diff)
downloadpfsense-packages-fca3b7e3e5d32ccf2ca884aed47f8c1e88d56c70.tar.gz
pfsense-packages-fca3b7e3e5d32ccf2ca884aed47f8c1e88d56c70.tar.bz2
pfsense-packages-fca3b7e3e5d32ccf2ca884aed47f8c1e88d56c70.zip
Lots of updates, new options, some fixes... Should soon merge with the main package (hopefully).
Diffstat (limited to 'packages/squid-head')
-rw-r--r--packages/squid-head/squid.inc67
-rw-r--r--packages/squid-head/squid_traffic.xml28
2 files changed, 70 insertions, 25 deletions
diff --git a/packages/squid-head/squid.inc b/packages/squid-head/squid.inc
index c28fccc1..e738ef02 100644
--- a/packages/squid-head/squid.inc
+++ b/packages/squid-head/squid.inc
@@ -87,6 +87,7 @@ EOD;
foreach (array( SQUID_CONFBASE,
SQUID_LOGDIR,
SQUID_ACLDIR,
+ SQUID_CACHEDIR,
) as $dir) {
make_dirs($dir);
squid_chown_recursive($dir, 'proxy', 'proxy');
@@ -188,7 +189,7 @@ function squid_validate_nac($post, $input_errors) {
$allowed_subnets = explode(',', trim($post['allowed_subnets']));
foreach ($allowed_subnets as $subnet) {
$subnet = trim($subnet);
- if (!is_subnet($subnet))
+ if (!empty($subnet) && !is_subnet($subnet))
$input_errors[] = "'$subnet' is not a valid CIDR range";
}
@@ -220,10 +221,14 @@ function squid_validate_nac($post, $input_errors) {
}
function squid_validate_traffic($post, $input_errors) {
- $num_fields = array( 'max_download_size' => 'Maximum download size',
- 'max_upload_size' => 'Maximum upload size',
- 'perhost_throttling' => 'Per-host bandwidth throttling',
- 'overall_throttling' => 'Overall bandwidth throttling',
+ $num_fields = array(
+ 'max_download_size' => 'Maximum download size',
+ 'max_upload_size' => 'Maximum upload size',
+ 'perhost_capping' => 'Per-host bandwidth capping',
+ 'overall_capping' => 'Overall bandwidth capping',
+ 'perhost_throttling' => 'Per-host bandwidth throttling',
+ 'overall_throttling' => 'Overall bandwidth throttling',
+ 'initial_bucket_level' => 'Initial bucket level',
);
foreach ($num_fields as $field => $name) {
$value = trim($post[$field]);
@@ -492,24 +497,38 @@ function squid_resync_traffic() {
$conf .= "request_body_max_size $up_limit KB\n";
$conf .= 'reply_body_max_size ' . ($down_limit * 1024) . " allow all\n";
- // Only apply throttling past 10MB
- // XXX: Should this really be hardcoded?
- $threshold = 10 * 1024 * 1024;
- $overall = $settings['overall_throttling'];
- if (!isset($overall) || ($overall == 0))
- $overall = -1;
- else
- $overall *= 1024;
- $perhost = $settings['perhost_throttling'];
- if (!isset($perhost) || ($perhost == 0))
- $perhost = -1;
+ foreach (array('perhost', 'overall') as $field) {
+ $capping = $settings["{$field}_capping"];
+ $throttling = $settings["{$field}_throttling"];
+
+ if (!isset($capping) || $capping == 0)
+ $capping = '-1';
+ else
+ $capping *= 1024; // Kbytes
+
+ if (!isset($throttling) || $throttling == 0) {
+ if ($capping == '-1')
+ $throttling = '-1';
+ else
+ $throttling = $capping;
+ } else {
+ $throttling *= 1024; // Kbytes
+ }
+
+ $$field = "$throttling/$capping";
+ }
+
+ $initial_bucket_level = $settings['initial_bucket_level'];
+ if (!isset($initial_bucket_level) || $initial_bucket_level == 0)
+ $initial_bucket_level = '100%';
else
- $perhost *= 1024;
+ $initial_bucket_level *= 1024; // Kbytes
+
$conf .= <<<EOD
+delay_initial_bucket_level $initial_bucket_level
delay_pools 1
delay_class 1 2
-delay_parameters 1 $overall/$threshold $perhost/$threshold
-delay_initial_bucket_level 100%
+delay_parameters 1 $overall $perhost
EOD;
@@ -539,9 +558,11 @@ EOD;
$contents .= "\.$ext\$\n";
file_put_contents(SQUID_ACLDIR . '/throttle_exts.acl', $contents);
- $conf .= 'acl throttle_exts url_regex -i "' . SQUID_ACLDIR . '/throttle_exts.acl"';
- $conf .= "delay_access 1 allow throttle_exts\n";
- $conf .= "delay_access 1 deny all\n";
+ if (!empty($contents)) { // avoid crashing Squid
+ $conf .= 'acl throttle_exts url_regex -i "' . SQUID_ACLDIR . "/throttle_exts.acl\"\n";
+ $conf .= "delay_access 1 allow throttle_exts\n";
+ $conf .= "delay_access 1 deny all\n";
+ }
}
else
$conf .= "delay_access 1 allow all\n";
@@ -677,7 +698,7 @@ function squid_resync() {
file_put_contents(SQUID_CONFBASE . '/squid.conf', $conf);
- if (!is_dir(SQUID_CACHEDIR)) {
+ if (!is_dir(SQUID_CACHEDIR . '/0/0')) {
log_error(SQUID_CACHEDIR . ' does not exist. Creating.');
mwexec('/usr/local/sbin/squid -z');
}
diff --git a/packages/squid-head/squid_traffic.xml b/packages/squid-head/squid_traffic.xml
index f9ebcf5c..859420a9 100644
--- a/packages/squid-head/squid_traffic.xml
+++ b/packages/squid-head/squid_traffic.xml
@@ -38,7 +38,7 @@
<field>
<fieldname>max_download_size</fieldname>
<fielddescr>Maximum download size</fielddescr>
- <description>Limit the maximum total download size to the size specified here (in kilobytes). Set to 0 to disable.</description>
+ <description>Limit the maximum total download size to the size specified here (in kilobytes). Downloads bigger than the specified size will be denied. Set to 0 to disable.</description>
<default_value>0</default_value>
<required/>
<type>input</type>
@@ -46,7 +46,23 @@
<field>
<fieldname>max_upload_size</fieldname>
<fielddescr>Maximum upload size</fielddescr>
- <description>Limit the maximum total upload size to the size specified here (in kilobytes). Set to 0 to disable.</description>
+ <description>Limit the maximum total upload size to the size specified here (in kilobytes). Uploads bigger than the specified size will be denied. Set to 0 to disable.</description>
+ <default_value>0</default_value>
+ <required/>
+ <type>input</type>
+ </field>
+ <field>
+ <fieldname>overall_capping</fieldname>
+ <fielddescr>Overall capping</fielddescr>
+ <description>Caps the download speeds of the network that connects to the proxy as a whole at the specified size (in kilobytes per second). Set to 0 to disable.</description>
+ <default_value>0</default_value>
+ <required/>
+ <type>input</type>
+ </field>
+ <field>
+ <fieldname>perhost_capping</fieldname>
+ <fielddescr>Per-host capping</fielddescr>
+ <description>Caps the download speeds of each user that connects to the proxy at the specified size (in kilobytes per second). Set to 0 to disable.</description>
<default_value>0</default_value>
<required/>
<type>input</type>
@@ -68,6 +84,14 @@
<type>input</type>
</field>
<field>
+ <fieldname>initial_bucket_level</fieldname>
+ <fielddescr>Initial bucket level</fielddescr>
+ <description>The initial bucket level is used to determine how much is put in each bucket when a connection is established. Set to 0 to set the initial bucket level to 100%.</description>
+ <default_value>0</default_value>
+ <required/>
+ <type>input</type>
+ </field>
+ <field>
<fieldname>throttle_specific</fieldname>
<fielddescr>Throttle only specific extensions</fielddescr>
<description>Leave this checked to be able to choose the extensions that throttling will be applied to. Otherwise, all files will be throttled.</description>