SF.net SVN: postfixadmin:[677] trunk/VIRTUAL_VACATION/vacation.pl
Brought to you by:
christian_boltz,
gingerdog
From: <Gin...@us...> - 2009-06-29 07:58:54
|
Revision: 677 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=677&view=rev Author: GingerDog Date: 2009-06-29 07:58:50 +0000 (Mon, 29 Jun 2009) Log Message: ----------- vacation.pl: fix https://sourceforge.net/tracker/?func=detail&aid=2796067&group_id=191583&atid=937964 - remove usage of file in /tmp; abort if logfile is not writeable, or we cannot create it Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-06-11 13:56:29 UTC (rev 676) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-06-29 07:58:50 UTC (rev 677) @@ -87,6 +87,16 @@ # http://dag.wieers.com/home-made/apt/packages.php # +use DBI; +use MIME::Base64; +use MIME::EncWords qw(:all); +use Email::Valid; +use strict; +use Mail::Sendmail; +use Getopt::Std; +use Log::Log4perl qw(get_logger :levels); +use File::Basename; + # ========== begin configuration ========== # IMPORTANT: If you put passwords into this script, then remember @@ -101,8 +111,8 @@ our $db_host = ''; # connection details -our $db_username = 'dg'; -our $db_password = 'gingerdog'; +our $db_username = 'user'; +our $db_password = 'password'; our $db_name = 'postfix'; our $vacation_domain = 'autoreply.example.org'; @@ -115,12 +125,13 @@ # path to logfile, when empty logging is supressed # change to e.g. /dev/null if you want nothing logged. -# if we can't write to this, we try /tmp/vacation.log instead -our $logfile='/var/spool/vacation/vacation.log'; +# if we can't write to this, and $log_to_file is 1 (below) the script will abort. +our $logfile='/var/log/vacation.log'; # 2 = debug + info, 1 = info only, 0 = error only our $log_level = 2; +# Whether to log to file or not, 0 = do not write to a log file +our $log_to_file = 1; - # notification interval, in seconds # set to 0 to notify only once # e.g. 1 day ... @@ -137,18 +148,13 @@ # =========== end configuration =========== -if ( ! -w $logfile ) { - $logfile = "/tmp/vacation.log"; +if($log_to_file == 1) { + if (( ! -w $logfile ) && (! -w dirname($logfile))) { + # Cannot log; no where to write to. + die("Cannot create logfile : $logfile"); + } } -use DBI; -use MIME::Base64; -use MIME::EncWords qw(:all); -use Email::Valid; -use strict; -use Mail::Sendmail; -use Getopt::Std; -use Log::Log4perl qw(get_logger :levels); my ($from, $to, $cc, $replyto , $subject, $messageid, $lastheader, $smtp_sender, $smtp_recipient, %opts, $spam, $test_mode, $logger); @@ -175,16 +181,18 @@ $logger->debug("Test mode enabled"); } else { - # log to file. - my $appender = Log::Log4perl::Appender->new( - 'Log::Dispatch::File', - filename => $logfile, - mode => 'append'); - $logger = get_logger(); - $appender->layout($log_layout); - $logger->add_appender($appender); + if($log_to_file == 1) { + # log to file. + my $appender = Log::Log4perl::Appender->new( + 'Log::Dispatch::File', + filename => $logfile, + mode => 'append'); + $appender->layout($log_layout); + $logger->add_appender($appender); + } + if($syslog == 1) { my $syslog_appender = Log::Log4perl::Appender->new( 'Log::Dispatch::Syslog', This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |