diff options
author | Martin Fuchs <mfuchs@pfsense.org> | 2008-08-24 23:14:28 +0000 |
---|---|---|
committer | Martin Fuchs <mfuchs@pfsense.org> | 2008-08-24 23:14:28 +0000 |
commit | 97f23818bdefbcabbf8ca430ad8a3896a2622842 (patch) | |
tree | 04824625492713d2b1b060d65f4a37c993c814a0 /packages/squid/squid.inc | |
parent | 6182ddebe44b3c741ff3fbb7f299f85463fca686 (diff) | |
download | pfsense-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...
Diffstat (limited to 'packages/squid/squid.inc')
-rw-r--r-- | packages/squid/squid.inc | 66 |
1 files changed, 64 insertions, 2 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; |