aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fuchs <mfuchs@pfsense.org>2008-08-24 23:14:28 +0000
committerMartin Fuchs <mfuchs@pfsense.org>2008-08-24 23:14:28 +0000
commit97f23818bdefbcabbf8ca430ad8a3896a2622842 (patch)
tree04824625492713d2b1b060d65f4a37c993c814a0
parent6182ddebe44b3c741ff3fbb7f299f85463fca686 (diff)
downloadpfsense-packages-97f23818bdefbcabbf8ca430ad8a3896a2622842.tar.gz
pfsense-packages-97f23818bdefbcabbf8ca430ad8a3896a2622842.tar.bz2
pfsense-packages-97f23818bdefbcabbf8ca430ad8a3896a2622842.zip
add Logrotation to squid, you can now chose the number of days the logs are kept...
-rw-r--r--packages/squid/squid.inc66
-rw-r--r--packages/squid/squid.xml7
-rw-r--r--packages/squid3/squid.inc64
-rw-r--r--packages/squid3/squid.xml7
4 files changed, 141 insertions, 3 deletions
diff --git a/packages/squid/squid.inc b/packages/squid/squid.inc
index 5bfe57fb..44966271 100644
--- a/packages/squid/squid.inc
+++ b/packages/squid/squid.inc
@@ -4,6 +4,7 @@
squid.inc
Copyright (C) 2006 Scott Ullrich
Copyright (C) 2006 Fernando Lemos
+ Copyright (C) 2008 Martin Fuchs
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -247,10 +248,10 @@ EOD;
function squid_deinstall_command() {
global $config;
+ squid_install_cron(false);
$settings = $config['installedpackages']['squidcache']['config'][0];
$cachedir =($settings['harddisk_cache_location'] ? $settings['harddisk_cache_location'] : '/var/squid/cache');
$logdir = ($settings['log_dir'] ? $settings['log_dir'] : '/var/squid/log');
-
mwexec('rm -rf $cachedir');
mwexec('rm -rf $logdir');
mwexec('rm -f /usr/local/etc/rc.d/proxy_monitor.sh');
@@ -296,6 +297,10 @@ function squid_validate_general($post, $input_errors) {
if (strlen($post['log_dir']) <= 3)
$input_errors[] = "That is not a valid log location dir";
+ $log_rotate = trim($post['log_rotate']);
+ if (!empty($log_rotate) && !is_numeric($log_rotate))
+ $input_errors[] = 'You must enter a valid number of days \'Log rotate\' field';
+
$webgui_port = $config['system']['webgui']['port'];
if(($config['system']['webgui']['port'] == "") && ($config['system']['webgui']['protocol'] == "http")) {
$webgui_port = 80;
@@ -503,6 +508,51 @@ function squid_validate_auth($post, $input_errors) {
}
}
+function squid_install_cron($should_install) {
+ global $config, $g;
+ if($g['booting']==true)
+ return;
+ $is_installed = false;
+ if(!$config['cron']['item'])
+ return;
+ $x=0;
+ foreach($config['cron']['item'] as $item) {
+ if(strstr($item['command'], "/usr/local/sbin/squid")) {
+ $is_installed = true;
+ break;
+ }
+ $x++;
+ }
+ switch($should_install) {
+ case true:
+ if(!$is_installed) {
+ $cron_item = array();
+ $cron_item['minute'] = "0";
+ $cron_item['hour'] = "0";
+ $cron_item['mday'] = "*";
+ $cron_item['month'] = "*";
+ $cron_item['wday'] = "*";
+ $cron_item['who'] = "root";
+ $cron_item['command'] = "/usr/local/sbin/squid -k rotate";
+ $config['cron']['item'][] = $cron_item;
+ parse_config(true);
+ write_config("Squid Log Rotation");
+ configure_cron();
+ }
+ break;
+ case false:
+ if($is_installed == true) {
+ if($x > 0) {
+ unset($config['cron']['item'][$x]);
+ parse_config(true);
+ write_config();
+ }
+ configure_cron();
+ }
+ break;
+ }
+}
+
function squid_resync_general() {
global $g, $config, $valid_acls;
@@ -549,6 +599,18 @@ cache_mgr $email
access_log $logdir_access
cache_log $logdir_cache
cache_store_log none
+
+EOD;
+
+ if (!empty($settings['log_rotate'])) {
+ $conf .= "logfile_rotate {$settings['log_rotate']}\n";
+ squid_install_cron(true);
+ }
+ else {
+ squid_install_cron(false);
+ }
+
+ $conf .= <<<EOD
shutdown_lifetime 3 seconds
EOD;
@@ -576,7 +638,7 @@ EOD;
foreach ($altdns as $dnssrv) {
$conf .= $dnssrv." ";
}
- $conf .= "\n";
+// $conf .= "\n"; //Kill blank line after DNS-Servers
}
return $conf;
diff --git a/packages/squid/squid.xml b/packages/squid/squid.xml
index 6f20d586..e83084d2 100644
--- a/packages/squid/squid.xml
+++ b/packages/squid/squid.xml
@@ -191,6 +191,13 @@
<default_value>/var/squid/log</default_value>
</field>
<field>
+ <fielddescr>Log rotate</fielddescr>
+ <fieldname>log_rotate</fieldname>
+ <description>Defines how many days of logfiles will be kept. Rotation is disabled if left empty.</description>
+ <type>input</type>
+ <size>5</size>
+ </field>
+ <field>
<fielddescr>Proxy port</fielddescr>
<fieldname>proxy_port</fieldname>
<description>This is the port the proxy server will listen on.</description>
diff --git a/packages/squid3/squid.inc b/packages/squid3/squid.inc
index 7c816ce2..849693e9 100644
--- a/packages/squid3/squid.inc
+++ b/packages/squid3/squid.inc
@@ -248,6 +248,7 @@ EOD;
function squid_deinstall_command() {
global $config;
+ squid_install_cron(false);
$settings = $config['installedpackages']['squidcache']['config'][0];
$cachedir =($settings['harddisk_cache_location'] ? $settings['harddisk_cache_location'] : '/var/squid/cache');
$logdir = ($settings['log_dir'] ? $settings['log_dir'] : '/var/squid/log');
@@ -297,6 +298,10 @@ function squid_validate_general($post, $input_errors) {
if (strlen($post['log_dir']) <= 3)
$input_errors[] = "That is not a valid log location dir";
+ $log_rotate = trim($post['log_rotate']);
+ if (!empty($log_rotate) && !is_numeric($log_rotate))
+ $input_errors[] = 'You must enter a valid number of days \'Log rotate\' field';
+
$webgui_port = $config['system']['webgui']['port'];
if(($config['system']['webgui']['port'] == "") && ($config['system']['webgui']['protocol'] == "http")) {
$webgui_port = 80;
@@ -504,6 +509,51 @@ function squid_validate_auth($post, $input_errors) {
}
}
+function squid_install_cron($should_install) {
+ global $config, $g;
+ if($g['booting']==true)
+ return;
+ $is_installed = false;
+ if(!$config['cron']['item'])
+ return;
+ $x=0;
+ foreach($config['cron']['item'] as $item) {
+ if(strstr($item['command'], "/usr/local/sbin/squid")) {
+ $is_installed = true;
+ break;
+ }
+ $x++;
+ }
+ switch($should_install) {
+ case true:
+ if(!$is_installed) {
+ $cron_item = array();
+ $cron_item['minute'] = "0";
+ $cron_item['hour'] = "0";
+ $cron_item['mday'] = "*";
+ $cron_item['month'] = "*";
+ $cron_item['wday'] = "*";
+ $cron_item['who'] = "root";
+ $cron_item['command'] = "/usr/local/sbin/squid -k rotate";
+ $config['cron']['item'][] = $cron_item;
+ parse_config(true);
+ write_config("Squid Log Rotation");
+ configure_cron();
+ }
+ break;
+ case false:
+ if($is_installed == true) {
+ if($x > 0) {
+ unset($config['cron']['item'][$x]);
+ parse_config(true);
+ write_config();
+ }
+ configure_cron();
+ }
+ break;
+ }
+}
+
function squid_resync_general() {
global $g, $config, $valid_acls;
@@ -550,6 +600,18 @@ cache_mgr $email
access_log $logdir_access
cache_log $logdir_cache
cache_store_log none
+
+EOD;
+
+ if (!empty($settings['log_rotate'])) {
+ $conf .= "logfile_rotate {$settings['log_rotate']}\n";
+ squid_install_cron(true);
+ }
+ else {
+ squid_install_cron(false);
+ }
+
+ $conf .= <<<EOD
shutdown_lifetime 3 seconds
EOD;
@@ -577,7 +639,7 @@ EOD;
foreach ($altdns as $dnssrv) {
$conf .= $dnssrv." ";
}
- $conf .= "\n";
+// $conf .= "\n"; //Kill blank line after DNS-Servers
}
return $conf;
diff --git a/packages/squid3/squid.xml b/packages/squid3/squid.xml
index d3065b56..df1862f8 100644
--- a/packages/squid3/squid.xml
+++ b/packages/squid3/squid.xml
@@ -191,6 +191,13 @@
<default_value>/var/squid/log</default_value>
</field>
<field>
+ <fielddescr>Log rotate</fielddescr>
+ <fieldname>log_rotate</fieldname>
+ <description>Defines how many days of logfiles will be kept. Rotation is disabled if left empty.</description>
+ <type>input</type>
+ <size>5</size>
+ </field>
+ <field>
<fielddescr>Proxy port</fielddescr>
<fieldname>proxy_port</fieldname>
<description>This is the port the proxy server will listen on.</description>