Author: msergeant
Date: Thu Sep 25 15:48:25 2008
New Revision: 944
Added:
contrib/msergeant/
contrib/msergeant/plugins/
contrib/msergeant/plugins/enemies_list
Log:
Plugin for querying the EnemiesList module.
Added: contrib/msergeant/plugins/enemies_list
==============================================================================
--- (empty file)
+++ contrib/msergeant/plugins/enemies_list Thu Sep 25 15:48:25 2008
@@ -0,0 +1,86 @@
+#!perl -w
+
+=pod
+
+=head1 NAME
+
+enemies_list - plugin to query a local EnemiesList database
+
+=head1 DESCRIPTION
+
+This plugin queries the EnemiesList database for the C<HELO/EHLO> given at
+SMTP time and if an entry is found, stores the results in the transaction
+notes field C<el.found>.
+
+The value is a hash reference containing the following keys:
+
+ addr => IP address that an EL DNS query would have given
+ name => Name of the entry in the EL
+ tech => Type of the entry - e.g. cable, dialup, webhost
+
+=head1 CONFIGURATION
+
+The plugin requires a config file F<enemies_list.pats> which should contain
+a single line - a filename where to find the enemies list database. If the
+config is empty, or the file cannot be found and opened, then the plugin
+disables itself (with an error in the log).
+
+=cut
+
+use DNS::RE;
+
+sub hook_post_fork {
+ my ($self) = @_;
+
+ my $qp = $self->qp;
+
+ $self->log(LOGDEBUG, "Loading EnemiesList");
+
+ my $patfile = $qp->config('enemies_list.pats');
+ if (!$patfile) {
+ $self->log(LOGERROR, "Need enemies_list.pats config");
+ return DECLINED;
+ }
+ my $EL = DNS::RE->new();
+ $self->{EL} = $EL;
+
+ if (open(my $fh, $patfile)) {
+ while (<$fh>) {
+ chomp;
+ my ($name, $expr, $addr, $tech) = split(':');
+ $EL->insert($expr => {
+ name => $name,
+ addr => $addr,
+ tech => $tech,
+ });
+ }
+ }
+ else {
+ $self->log(LOGERROR, "open($patfile) failed: $!");
+ return DECLINED;
+ }
+
+ $self->log(LOGDEBUG, "EnemiesList all loaded and ready to rock");
+
+ return DECLINED;
+}
+
+sub hook_helo {
+ my ($self, $transaction, $hello_host) = @_;
+
+ return DECLINED unless $self->{EL}; # disabled due to startup errors
+
+ if (my $rv = $self->{EL}->search(lc($hello_host))) {
+ $self->log(LOGDEBUG, "Found EnemiesList match: $hello_host =>
$rv->{addr}");
+ $transaction->notes('el.found', $rv);
+ }
+ else {
+ # not found - we don't really need to do anything. Uncomment for extra
debug
+ $self->log(LOGDEBUG, "EnemiesList not found: $hello_host");
+ }
+
+ return DECLINED;
+}
+
+*hook_ehlo = \&hook_helo;
+