Mailing List Archive

svn commit: rev 6579 - in incubator/spamassassin/trunk: rules tools
Author: jm
Date: Sat Feb 7 20:40:12 2004
New Revision: 6579

Modified:
incubator/spamassassin/trunk/rules/70_cvs_rules_under_test.cf
incubator/spamassassin/trunk/tools/bayes_dump_to_trusted_networks
Log:
use Net::CIDR::Lite to consolidate into ranges where possible

Modified: incubator/spamassassin/trunk/rules/70_cvs_rules_under_test.cf
==============================================================================
--- incubator/spamassassin/trunk/rules/70_cvs_rules_under_test.cf (original)
+++ incubator/spamassassin/trunk/rules/70_cvs_rules_under_test.cf Sat Feb 7 20:40:12 2004
@@ -542,3 +542,5 @@
# affiliateid, aff_id, aff_sub_id etc.
uri T_URI_AFFILIATE /aff\w+id=/i

+body T_DEEP_DISC_MEDS /\bdeep discount med(?:s|ications)\b/i
+

Modified: incubator/spamassassin/trunk/tools/bayes_dump_to_trusted_networks
==============================================================================
--- incubator/spamassassin/trunk/tools/bayes_dump_to_trusted_networks (original)
+++ incubator/spamassassin/trunk/tools/bayes_dump_to_trusted_networks Sat Feb 7 20:40:12 2004
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w

=head1 NAME

@@ -52,6 +52,8 @@

=cut

+use strict;
+
use vars qw{
$IP_ADDRESS $IP_IN_RESERVED_RANGE
};
@@ -101,7 +103,7 @@
}

use vars qw(
- $opt_minham $opt_rdns $opt_help
+ $opt_minham $opt_rdns $opt_help
);

GetOptions(
@@ -114,6 +116,7 @@
$opt_rdns ||= 0;
$opt_minham ||= 3;

+my %class_cs = ();
while (<>) {
my ($prob, $nspam, $nham, $atime, $tok) = split;

@@ -125,15 +128,52 @@
next if ($ip =~ /$IP_IN_RESERVED_RANGE/o);
$ip =~ s/[^0-9\.\:]/_/gs; # sanitise!

- my $rdns = '';
- if ($opt_rdns) {
- my $host = `host $ip 2>&1`;
- $host =~ s/^.* domain name pointer (.+)\s*$/$1/gm;
- $host =~ s/\.$//;
- $rdns = "\t# $host";
- }
+ $ip =~ /^(.*)\.(\d+)/;

- print "trusted_networks $ip$rdns\n";
+ if (defined $class_cs{$1}) {
+ $class_cs{$1} .= " ".$2;
+ } else {
+ $class_cs{$1} = $2;
+ }
}

+use Net::CIDR::Lite; # used to consolidate into CIDR ranges
+foreach my $class_c (sort {
+ classc2long($a) <=> classc2long($b)
+ } keys %class_cs)
+{
+ my $cidr = Net::CIDR::Lite->new;
+ foreach my $octet (split (' ', $class_cs{$class_c})) {
+ my $ip = "$class_c.$octet";
+ $cidr->add_ip ($ip);
+ }
+ $cidr->clean();
+
+ my @ips = $cidr->list();

+ foreach my $ip (@ips) {
+ my $rdns = '';
+ if ($ip =~ s/\/32$//) {
+ if ($opt_rdns) {
+ my $host = `host -W 1 $ip 2>&1`;
+ $host =~ s/^.* domain name pointer (\S+)\s*$/$1/gm;
+ $host =~ s/^.*not found: .*$/(no rdns)/gs;
+ $host =~ s/\s+/ /gs; # (newlines)
+ $host =~ s/\.$//;
+ $rdns = "\t# $host";
+ }
+ } else {
+ if ($opt_rdns) {
+ $rdns = "\t# (range)";
+ }
+ }
+
+ print "trusted_networks $ip$rdns\n";
+ }
+}
+
+sub classc2long {
+ my $ip = shift;
+ ($ip =~ /^(\d+)\.(\d+)\.(\d+)$/) or return -1;
+ ($1 << 16) | ($2 << 8) | ($3);
+}