projects
/
clearscm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed RecordHit to update last_hit
[clearscm.git]
/
maps
/
bin
/
maps
diff --git
a/maps/bin/maps
b/maps/bin/maps
index
52e234f
..
17047f4
100755
(executable)
--- a/
maps/bin/maps
+++ b/
maps/bin/maps
@@
-46,7
+46,8
@@
$Date: 2013/06/12 14:05:47 $
-v|erbose: Be verbose
-de|bug: Output debug messages
-v|erbose: Be verbose
-de|bug: Output debug messages
- -[no]e|xecute: Set execute mode.
+ -[no]e|xecute: Set execute mode.
+ -f|ile <file>: File to use as a test message
# (c) Copyright 2000-2021, Andrew@DeFaria.com, all rights reserved.
# (c) Copyright 2000-2021, Andrew@DeFaria.com, all rights reserved.
@@
-56,26
+57,29
@@
use strict;
use warnings;
use Getopt::Long;
use warnings;
use Getopt::Long;
+use Pod::Usage;
use Email::Valid;
use FindBin;
use File::Temp qw (tempfile);
use Net::Domain qw (hostdomain);
use Email::Valid;
use FindBin;
use File::Temp qw (tempfile);
use Net::Domain qw (hostdomain);
-use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../lib";
+use lib "$FindBin::Bin/../lib";
+use lib "$FindBin::Bin/../../lib";
use MAPS;
use MAPSLog;
use Display;
use MAPS;
use MAPSLog;
use Display;
+use Logger;
use Utils;
use Utils;
-my
$verbose = 0;
-my $execute = 1;
-
my $userid = $ENV{USER}
;
+my
%opts = (
+ execute => 1,
+
)
;
-my $
logpath = "$FindBin::Bin/../log"
;
-my $logfile = "$logpath/debug.log";
-my $
forwardto = $ENV{MAPS_FORWARDTO} || 'adefaria@gmail.com'
;
+my $
userid = $ENV{USER}
;
+
+my $
log
;
# For some reason I'm not parsing messages correctly but it only seems to
# happen when the message is piped in from the MTA. This routine will
# For some reason I'm not parsing messages correctly but it only seems to
# happen when the message is piped in from the MTA. This routine will
@@
-118,26
+122,21
@@
sub ValidDomainUser($) {
return defined $uid ? 1 : 0;
} # ValidDomainUser
return defined $uid ? 1 : 0;
} # ValidDomainUser
-sub ProcessMsgs ($$$) {
- my ($msgfile, $username, $user_email) = @_;
-
- return unless $execute;
+sub formatRule($) {
+ my ($rec) = @_;
- while (!eof *$msgfile) {
- my ($sender, $sender_long, $reply_to, $subject, $data) = ReadMsg (*$msgfile);
+ return "Rule: $rec->{pattern}\@$rec->{domain}:$rec->{sequence}/$rec->{hit_count}";
+} # formatRule
- #if ($forwardto) {
- # Forward a copy
- #open my $mail, '|', "/usr/lib/sendmail $forwardto"
- #or die "Unable to open pipe to sendmail - $!";
+sub ProcessMsgs ($$$) {
+ my ($msgfile, $username, $user_email) = @_;
-
#print $mail "$data\n"
;
+
return unless $opts{execute}
;
- #close $mail
- #or die "Unable to forward email to $forwardto - $!";
- #} # if
+ while (!eof $msgfile) {
+ my ($sender, $sender_long, $reply_to, $subject, $data) = ReadMsg ($msgfile);
- my ($onlist, $r
ule
, $sequence, $hit_count);
+ my ($onlist, $r
ec
, $sequence, $hit_count);
# Algorithm change: We now first check to see if the sender is not found
# in the message and skip it if so. Then we handle if we are the sender
# Algorithm change: We now first check to see if the sender is not found
# in the message and skip it if so. Then we handle if we are the sender
@@
-162,20
+161,24
@@
sub ProcessMsgs ($$$) {
if ($sender eq $user_email and
(lc ($sender_long) !~ lc ("\"$username\" <$user_email>") and
lc ($sender_long) !~ lc ("$username <$user_email>"))) {
if ($sender eq $user_email and
(lc ($sender_long) !~ lc ("\"$username\" <$user_email>") and
lc ($sender_long) !~ lc ("$username <$user_email>"))) {
- verbose "Nulllisting message from sender ($sender_long) pretending to be $user_email";
+ $log->msg("Nulllisting message from sender ($sender_long) pretending to be $user_email");
+
Nulllist $sender;
Nulllist $sender;
+
next;
} # if
# Check whitelist:
next;
} # if
# Check whitelist:
- ($onlist, $r
ule, $sequence, $hit_count
) = OnWhitelist $sender;
+ ($onlist, $r
ec
) = OnWhitelist $sender;
if ($onlist) {
if (ValidDomainUser $sender) {
if ($onlist) {
if (ValidDomainUser $sender) {
- verbose "Whitelisting $sender";
- Whitelist $sender, $data, $sequence, $hit_count;
+ $log->msg("Whitelisting $sender - Rule: " . formatRule($rec));
+
+ Whitelist $sender, $data, $rec->{sequence}, $rec->{hit_count};
} else {
} else {
- verbose "Sender from this domain but user not found";
+ $log->msg("Sender ($sender) from this domain but user not found");
+
Nulllist $sender;
} # if
Nulllist $sender;
} # if
@@
-183,16
+186,16
@@
sub ProcessMsgs ($$$) {
} # if
# Check blacklist:
} # if
# Check blacklist:
- ($onlist, $r
ule, $sequence, $hit_count
) = OnBlacklist $sender;
+ ($onlist, $r
ec
) = OnBlacklist $sender;
if ($onlist) {
if ($onlist) {
-
verbose "Blacklisting $sender"
;
+
$log->msg("Blacklisting $sender - Rule: " . formatRule($rec))
;
Blacklist(
userid => $userid,
sender => $sender,
Blacklist(
userid => $userid,
sender => $sender,
- sequence => $
sequence
,
- hit_count => $
hit_count
,
+ sequence => $
rec->{sequence}
,
+ hit_count => $
rec->{hit_count}
,
data => $data,
);
data => $data,
);
@@
-200,16
+203,19
@@
sub ProcessMsgs ($$$) {
} # if
# Check nulllist:
} # if
# Check nulllist:
- ($onlist, $r
ule, $sequence, $hit_count
) = OnNulllist $sender;
+ ($onlist, $r
ec
) = OnNulllist $sender;
if ($onlist) {
if ($onlist) {
- verbose "Nulllisting $sender";
- Nulllist $sender, $sequence, $hit_count;
+ $log->msg("Nulllisting $sender - Rule: " . formatRule($rec));
+
+ Nulllist $sender, $rec->{sequence}, $rec->{hit_count};
+
next;
} # if
# Return processing:
next;
} # if
# Return processing:
- verbose "Returning message from $sender";
+ $log->msg("Returning message from $sender");
+
ReturnMsg(
userid => $userid,
sender => $sender,
ReturnMsg(
userid => $userid,
sender => $sender,
@@
-222,12
+228,18
@@
sub ProcessMsgs ($$$) {
# Main
GetOptions(
# Main
GetOptions(
- 'user=s' => \$userid,
- 'verbose' => sub { set_verbose },
- 'debug' => sub { set_debug },
- 'execute!' => \$execute,
- 'forwardto=s' => \$forwardto
-) || Usage;
+ \%opts,
+ 'user=s',
+ 'verbose',
+ 'debug',
+ 'execute!',
+) or pod2usage;
+
+$log = Logger->new(
+ path => '/var/local/log',
+ timestamped => 'yes',
+ append => 'yes',
+);
my $msgfile;
my $msgfile;
@@
-235,18
+247,18
@@
if ($ARGV[0] and $ARGV[0] ne "") {
open $msgfile, '<', $ARGV[0];
unless ($msgfile) {
open $msgfile, '<', $ARGV[0];
unless ($msgfile) {
-
Error "Unable to open file ($ARGV[0]): $!\n"
;
+
$log->err("Unable to open file ($ARGV[0]): $!")
;
exit 1;
} # if
} else {
$msgfile = SaveStdin;
} # if
exit 1;
} # if
} else {
$msgfile = SaveStdin;
} # if
-verbose "Starting MAPS....";
+# Get user
+FindUser(userid => $userid);
-my %userOptions = SetContext $userid
- or die "$userid is not a registered MAPS user\n";
+my $user = GetUser;
-ProcessMsgs $msgfile, $user
Options{name}, $userOptions
{email};
+ProcessMsgs $msgfile, $user
->{name}, lc $user->
{email};
exit 0;
exit 0;