[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-advocacy
Subject:    Improved SPEWS -> pf Perl script
From:       harrymcd () spamcop ! net
Date:       2002-09-18 10:17:58
[Download RAW message or body]

I actually got tired of cutting-and-pasting so last night I wrote a new script.

The file: header_for_harrypf_conf.txt contains the beginning of my pf rules.

This script adds the new SPEWS rules to my regular ones (of which there are
about 10.)

Harry 

-------------------------------------
# http://spews.org/spews_list_level2.txt

open(INFILE, 'spews_list_level2.txt') or die "Can't open input.\n";
open(OUTFILE, '>pfrules.txt') or die "Can't open output.\n";

while(<INFILE>) {

	@Hunks = split(/ /, $_);
	$Block = $Hunks[0];

		if(substr($Block,0,1) =~ /[0-9]/) {
			print OUTFILE "block in log quick on \$Ext proto tcp from ", $Block, " to any port
25\n";
			}
	}

close(INFILE);
close(OUTFILE);

# remove duplicates

open(INFILE, 'pfrules.txt') or die "Can't open input.\n";
open(OUTFILE, '>unipfrules.txt') or die "Can't open output.\n";

@Oneofakind=();

while (<INFILE>) {
unless($a{$_}++) { push(@Oneofakind, $_) }
	}

foreach $b (@Oneofakind) {
	print OUTFILE $b;
	}

close(INFILE);
close(OUTFILE);

# sort

open(INFILE, 'unipfrules.txt') or die "Can't open input.\n";
open(OUTFILE, '>sortunipfrules.txt') or die "Can't open output.\n";

print OUTFILE sort <INFILE>;

close(INFILE);
close(OUTFILE);

# add headers

open(INFILE, 'header_for_harrypf_conf.txt') or die "Can't open input.\n";
open(OUTFILE, '>harrypf.conf') or die "Can't open output.\n";

while (<INFILE>) {
	print OUTFILE $_;
	}

close(INFILE);
close(OUTFILE);

open(INFILE, 'sortunipfrules.txt') or die "Can't open input.\n";
open(OUTFILE, '>>harrypf.conf') or die "Can't open output.\n";

while (<INFILE>) {
	print OUTFILE $_;
	}

close(INFILE);
close(OUTFILE);

unlink('pfrules.txt');
unlink('unipfrules.txt');
unlink('sortunipfrules.txt');
------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic