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
854316b
..
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,6
+57,7
@@
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 Email::Valid;
use FindBin;
use File::Temp qw (tempfile);
@@
-68,11
+70,16
@@
use MAPS;
use MAPSLog;
use Display;
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 $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
@@
-115,15
+122,21
@@
sub ValidDomainUser($) {
return defined $uid ? 1 : 0;
} # ValidDomainUser
return defined $uid ? 1 : 0;
} # ValidDomainUser
+sub formatRule($) {
+ my ($rec) = @_;
+
+ return "Rule: $rec->{pattern}\@$rec->{domain}:$rec->{sequence}/$rec->{hit_count}";
+} # formatRule
+
sub ProcessMsgs ($$$) {
my ($msgfile, $username, $user_email) = @_;
sub ProcessMsgs ($$$) {
my ($msgfile, $username, $user_email) = @_;
- return unless $
execute
;
+ return unless $
opts{execute}
;
- while (!eof
*
$msgfile) {
- my ($sender, $sender_long, $reply_to, $subject, $data) = ReadMsg (
*
$msgfile);
+ 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
@@
-148,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
@@
-169,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,
);
@@
-186,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,
@@
-208,11
+228,18
@@
sub ProcessMsgs ($$$) {
# Main
GetOptions(
# Main
GetOptions(
- 'user=s' => \$userid,
- 'verbose' => sub { set_verbose },
- 'debug' => sub { set_debug },
- 'execute!' => \$execute,
-) || Usage;
+ \%opts,
+ 'user=s',
+ 'verbose',
+ 'debug',
+ 'execute!',
+) or pod2usage;
+
+$log = Logger->new(
+ path => '/var/local/log',
+ timestamped => 'yes',
+ append => 'yes',
+);
my $msgfile;
my $msgfile;
@@
-220,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;