# SpamAssassin - ASN Lookup Plugin # # <@LICENSE> # Copyright 2006 dnswl.org, Matthias Leisi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # ########################################################################### =head1 NAME ASN - SpamAssassin plugin to look up Autonomous System Number of connecting IP address =head1 SYNOPSIS loadplugin ASN loadplugin ASN /path/to/ASN.pm B This directive I be put in a .pre file to ensure it is actually loaded when needed. =head1 DESCRIPTION TODO =head2 TEMPLATE TAGS Add a tag C<_ASN_> and C<_ASNCIDR_> which can be used in places where such tags can usually be used. add_header all ASN _ASN_ _ASNCIDR_ may add something like X-Spam-ASN: 24940 213.239.192.0/18 B The add_header directive I be put in a .pre file, but must be in C or some equivalent. =head1 Standard Configuration loadplugin ASN /path/to/ASN.pm ifplugin ASN header T__ASN eval:check_rbl_txt('asn-firsttrusted', 'asn.routeviews.org.', '.') describe T__ASN Lookup Autonomous System Number of connecting IP add_header all ASN _ASN_ _ASNCIDR_ endif # ifplugin ASN Note that you should not score on this rule - it is merely informational. =cut package ASN; use strict; use Mail::SpamAssassin; use Mail::SpamAssassin::Plugin; use Mail::SpamAssassin::Logger; our @ISA = qw(Mail::SpamAssassin::Plugin); sub new { my ($class, $mailsa) = @_; $class = ref($class) || $class; my $self = $class->SUPER::new($mailsa); bless ($self, $class); $self->set_config($mailsa->{conf}); return $self; } sub set_config { my($self, $conf) = @_; dbg("ASN: set_config\n"); my @cmds = (); $conf->{parser}->register_commands(\@cmds); } sub check_post_dnsbl { my ($self, $opts) = @_; dbg("ASN: check_post_dnsbl"); my $pms = $opts->{permsgstatus}; $pms->{tag_data}->{ASN} = 0; $pms->{tag_data}->{ASNCIDR} = '0.0.0.0/0'; my @lines = split(/\n/, $pms->{tag_data}->{REPORT}); my $count = -1; for (my $i = 0; $i < @lines; $i++) { if ($lines[$i] =~ /0.0 T__ASN RBL:/) { $count = $i + 1; last; } } if ($count > -1) { $lines[$count] =~ s/^.*\[//; dbg("ASN: Found " . $lines[$count]); my @items = split(/ /, $lines[$count]); for (my $i = 0; $i < @items; $i++) { $items[$i] =~ s/\"//g; $items[$i] =~ s/\[//g; $items[$i] =~ s/\]//g; } $pms->{tag_data}->{ASN} = $items[0]; $pms->{tag_data}->{ASNCIDR} = sprintf('%s/%s', $items[1], $items[2]); } return; } 1; =head1 SEE ALSO http://www.routeviews.org/ has all the information regarding routing, ASNs etc. but is not associated with this plugin. Check back at my blog http://matthias.leisi.net/ from time to time for eventual updates. =head1 AUTHOR Matthias Leisi =head1 VERSION Experimental