diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index cf95657..5aefc25 100755 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -20,6 +20,7 @@ use warnings; use autodie; use Getopt::Std; use DBI; +use POSIX qw(strftime); my $db_type = 'MariaDB'; my $db_host = ''; @@ -54,14 +55,14 @@ print STDOUT "register|ready\n"; while (my $line = <>) { next if ($line =~ m/^config/); chomp $line; - print $fh (scalar localtime() . " $line\n") if ($opt_v); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: $line\n") if ($opt_v); if ($line =~ m/^report/) { - print $fh (scalar localtime() . " $line\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: $line\n") if ($opt_d); my ($stream, $version, $timestamp, $subsystem, $event, $sid, $token, $code, $address) = split /\|/, $line; if ($event eq "tx-mail" && $code eq "ok") { $ooo{$sid} = 1; $from = $address; - print $fh (scalar localtime() . " Virtual Vacation: created session $sid\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: created session $sid\n") if ($opt_d); if ($from =~ m/^(postmaster|hostmaster|noreply|no-reply|bounce.*)@/i) { $ooo{$sid} = 0; } } elsif ($event eq "tx-mail" && $code ne "ok") { $ooo{$sid} = 0; @@ -70,7 +71,7 @@ while (my $line = <>) { $email = $address; } elsif ($event eq "tx-rcpt" && $code ne "ok") { delete $ooo{$sid}; - print $fh (scalar localtime() . " Virtual Vacation: removed session $sid\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: removed session $sid\n") if ($opt_d); } } if ($line =~ m/^filter/) { @@ -83,18 +84,18 @@ while (my $line = <>) { print STDOUT "filter-dataline|$sid|$token|$data\n"; } if ($line =~ m/data-line/ && $data eq '.' && $ooo{$sid} == 1) { - print $fh (scalar localtime() . " Virtual Vacation: To: $email, From: $from\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: To: $email, From: $from\n") if ($opt_d); my $query = qq{SELECT subject,body FROM vacation WHERE email='$email' and active=1}; my $sth = do_query($query); my $rv = $sth->rows; if ($rv == 1) { - print $fh (scalar localtime() . " Virtual Vacation: Found OOO for $email\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: Found OOO for $email\n") if ($opt_d); my @vacation_msg = $sth->fetchrow_array; $query = qq{SELECT cache FROM vacation WHERE email='$email' AND FIND_IN_SET('$from',cache)}; $sth = do_query($query); $rv = $sth->rows; if ($rv == 0) { - print $fh (scalar localtime() . " Virtual Vacation: Sending OOO to $from\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: Sending OOO to $from\n") if ($opt_d); $query = qq{UPDATE vacation SET cache=CONCAT(cache,',','$from') WHERE email='$email'}; $sth = do_query($query); open my $fh_email, "|-", "/usr/sbin/sendmail -t"; @@ -107,11 +108,11 @@ while (my $line = <>) { close $fh_email; } delete $ooo{$sid}; - print $fh (scalar localtime() . " Virtual Vacation: removed session $sid\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: removed session $sid\n") if ($opt_d); } } elsif ($line =~ m/data-line/ && $data eq '.' && $ooo{$sid} == 0) { delete $ooo{$sid}; - print $fh (scalar localtime() . " Virtual Vacation: removed session $sid\n") if ($opt_d); + print $fh (POSIX::strftime("%h %d %H:%M:%S ", localtime) . "Virtual Vacation: removed session $sid\n") if ($opt_d); } } }