change flags, l=logging (print vacation.pl messages), v=verbose (print report) d=debug (print filter)
This commit is contained in:
parent
e694766d87
commit
42464c57b1
@ -28,8 +28,8 @@ my $db_user = '';
|
||||
my $db_pass = '';
|
||||
my $db_name = '';
|
||||
|
||||
getopts('dv');
|
||||
our($opt_d, $opt_v);
|
||||
getopts('lvd');
|
||||
our($opt_l, $opt_v, $opt_d);
|
||||
|
||||
my $email = "";
|
||||
my $from = "";
|
||||
@ -45,7 +45,7 @@ sub gettime {
|
||||
return POSIX::strftime("%h %d %H:%M:%S ", localtime);
|
||||
}
|
||||
|
||||
open (my $fh, '>', "/tmp/virtualvacation.log") if ($opt_d);
|
||||
open (my $fh, '>', "/tmp/virtualvacation.log") if ($opt_l || $opt_v || $opt_d);
|
||||
select(STDOUT);
|
||||
$|++;
|
||||
select($fh);
|
||||
@ -59,12 +59,12 @@ while (my $line = <>) {
|
||||
next if ($line =~ m/^config/);
|
||||
chomp $line;
|
||||
if ($line =~ m/^report/) {
|
||||
print $fh (gettime() . "Virtual Vacation: $line\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $line\n") if ($opt_v);
|
||||
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 (gettime() . "Virtual Vacation: $sid created session\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid created session\n") if ($opt_l);
|
||||
if ($from =~ m/^(postmaster|hostmaster|noreply|no-reply|bounce.*)@/i) { $ooo{$sid} = 0; }
|
||||
} elsif ($event eq "tx-mail" && $code ne "ok") {
|
||||
$ooo{$sid} = 0;
|
||||
@ -73,38 +73,38 @@ while (my $line = <>) {
|
||||
$email = $address;
|
||||
} elsif ($event eq "tx-rcpt" && $code ne "ok") {
|
||||
delete $ooo{$sid};
|
||||
print $fh (gettime() . "Virtual Vacation: $sid removed session\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid removed session\n") if ($opt_l);
|
||||
}
|
||||
}
|
||||
if ($line =~ m/^filter/) {
|
||||
print $fh (gettime() . "Virtual Vacation: $line\n") if ($opt_v);
|
||||
print $fh (gettime() . "Virtual Vacation: $line\n") if ($opt_d);
|
||||
my ($stream, $version, $timestamp, $subsystem, $event, $sid, $token, $data) = split /\|/, $line;
|
||||
if ($line =~ m/data-line/) {
|
||||
if (!$data) { $data = ""; }
|
||||
if ($data =~ m/^precedence:\s+(bulk|list|junk)/i) {
|
||||
$ooo{$sid} = 0;
|
||||
print $fh (gettime() . "Virtual Vacation: $sid header found $data\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid header found $data\n") if ($opt_l);
|
||||
}
|
||||
if ($data =~ m/^list-(help|id|owner|post|subscribe|unsubscribe):.*/i) {
|
||||
$ooo{$sid} = 0;
|
||||
print $fh (gettime() . "Virtual Vacation: $sid header found $data\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid header found $data\n") if ($opt_l);
|
||||
}
|
||||
if ($data =~ m/^x-loop:\s+opensmtpd\ admin\ virtual\ vacation/i) { $ooo{$sid} = 0; }
|
||||
print STDOUT "filter-dataline|$sid|$token|$data\n";
|
||||
}
|
||||
if ($line =~ m/data-line/ && $data eq '.' && $ooo{$sid} == 1) {
|
||||
print $fh (gettime() . "Virtual Vacation: $sid to: $email, from: $from\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid to: $email, from: $from\n") if ($opt_l);
|
||||
my $query = qq{SELECT subject,body FROM vacation WHERE email='$email' and active=1};
|
||||
my $sth = doquery($query);
|
||||
my $rv = $sth->rows;
|
||||
if ($rv == 1) {
|
||||
print $fh (gettime() . "Virtual Vacation: $sid found OOO for $email\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid found OOO for $email\n") if ($opt_l);
|
||||
my @vacation_msg = $sth->fetchrow_array;
|
||||
$query = qq{SELECT cache FROM vacation WHERE email='$email' AND FIND_IN_SET('$from',cache)};
|
||||
$sth = doquery($query);
|
||||
$rv = $sth->rows;
|
||||
if ($rv == 0) {
|
||||
print $fh (gettime() . "Virtual Vacation: $sid sending OOO to $from\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid sending OOO to $from\n") if ($opt_l);
|
||||
$query = qq{UPDATE vacation SET cache=CONCAT(cache,',','$from') WHERE email='$email'};
|
||||
$sth = doquery($query);
|
||||
open my $fh_email, "|-", "/usr/sbin/sendmail -t";
|
||||
@ -117,11 +117,11 @@ while (my $line = <>) {
|
||||
close $fh_email;
|
||||
}
|
||||
delete $ooo{$sid};
|
||||
print $fh (gettime() . "Virtual Vacation: $sid removed session\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid removed session\n") if ($opt_l);
|
||||
}
|
||||
} elsif ($line =~ m/data-line/ && $data eq '.' && $ooo{$sid} == 0) {
|
||||
delete $ooo{$sid};
|
||||
print $fh (gettime() . "Virtual Vacation: $sid removed session\n") if ($opt_d);
|
||||
print $fh (gettime() . "Virtual Vacation: $sid removed session\n") if ($opt_l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user