From 97f23818bdefbcabbf8ca430ad8a3896a2622842 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sun, 24 Aug 2008 23:14:28 +0000 Subject: add Logrotation to squid, you can now chose the number of days the logs are kept... --- packages/squid/squid.inc | 66 ++++++++++++++++++++++++++++++++++++++++++++++-- packages/squid/squid.xml | 7 +++++ 2 files changed, 71 insertions(+), 2 deletions(-) (limited to 'packages/squid') 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 .= << /var/squid/log + + Log rotate + log_rotate + Defines how many days of logfiles will be kept. Rotation is disabled if left empty. + input + 5 + Proxy port proxy_port -- cgit v1.2.3