#! /usr/bin/perl # spamcopautosubmit.pl # 2005.12.16 by [yoh] # Copyright (c) 2005 MATSUDA Yoh-ichi # # automatic completes reporting submission tool for SpamCop. # # Thanks to: Ishioka san, Yoshifuji san, topia tan. # # History: # 2005.12.16 initial version. # 2006.02.13 add lockfile routine. # # Requirement: # # - Posix-like OS or almost same environment: # Linux, FreeBSD, cygwin, ... # - Perl # - curl # # - For your convenience, you have better get & install SpamAssassin. # # Usage: # # (-1) Before using, you have to get SpamCop account. # After getting the account, you have to write your userID and # Password into this script below. # # (0) Before using, you have better using SpamAssassin. # Uh? You don't install SA? Install! # # After you installed SA, you have to write # 'spamcop_from_address' and 'spamcop_to_address' into your # ~/.spamassassin/user_prefs. # # ex. # #--- # spamcop_from_address yoh@flcl.org # spamcop_to_address submit.usodapyon@spam.spamcop.net # #--- # # (1) Report spam. # $ spamassassin -r spam.txt # # (2) A few minutes later, execute this script. # # (3) You had better execute this script through cron. # # ex. # #--- # 0-59/5 * * * * perl /home/yoh/bin/spamcopautosubmit.pl >> /home/yoh/log/spamcopsubmit.log 2>&1 # #--- # ################################################################### # User Configuration variable: # $userid='your@userid'; $passwd='your_password'; $useragent='"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"'; $debugout00='debugout00.txt'; $debugout01='debugout01.txt'; $debugout02='debugout02.txt'; $schtml='sc.html'; $seedhtml='seed.html'; # ################################################################### $execstr = sprintf('curl --user-agent %s -s --user %s:%s --trace-ascii %s http://members.spamcop.net/', $useragent, $userid, $passwd, $debugout00); $lockfile = "$0.lock"; open(LOCK, ">$lockfile"); if (!flock(LOCK, 6)){ print "ERROR+!!\n"; exit 1; } open(FHCURL, "$execstr|"); open(FHSC, ">$schtml"); while () { # print $_; print FHSC $_; chomp; # strip record separator if (/sc\?id=/) { s/^.+href=\"/http:\/\/members.spamcop.net/; s/\">//; # print $_; $uri = $_; } } print "debug0: $uri\n"; close(FHSC); close(FHCURL); # if (length($uri) > 0) { while (length($uri) > 0) { $execstr = sprintf('curl --user-agent %s -s --user %s:%s --trace-ascii %s %s', $useragent, $userid, $passwd, $debugout01, $uri); open(FHCURL, "$execstr|"); open(FHSC, ">$seedhtml"); $str = sprintf('curl --user-agent %s -s --http1.0 --user %s:%s --trace-ascii %s', $useragent, $userid, $passwd, $debugout02); $[ = 1; # set array base to 1 $, = ' '; # set output field separator # $\ = "\n"; # set output record separator $flag = 0; line: while () { print FHSC $_; chomp; # strip record separator @Fld = split(' ', $_, 9999); if (/= 4) { if ($flag == 1 && /)//g; $value = $_; $value =~ s/^.+value=\"//; $value =~ s/\">//; $str = sprintf("%s --form-string \"%s=%s\"", $str, $name, $value); # print "debug0.2: $_ $name $value $str\n"; next line; } # if ($flag == 1 && /)//g; # print "debug0.3: $_ $str\n"; next line; } if ($flag == 1 && / value=\"/ && $#Fld == 1) { $value = $Fld[1]; $value =~ s/(value=|\"|>)//g; $str = sprintf("%s --form-string \"%s=%s\"", $str, $name, $value); # print "debug0.4: $_ $name $value $str\n"; next line; } } close(FHSC); close(FHCURL); # $str = sprintf('%s http://members.spamcop.net/sc > sc.html', $str); $str = sprintf('%s http://members.spamcop.net/sc', $str); print "debug1: $str\n"; # system($str); open(FHCURL, "$str|"); open(FHSC, ">$schtml"); $uri=""; while () { print FHSC $_; chomp; # strip record separator if (/sc\?id=/) { s/^.+href=\"/http:\/\/members.spamcop.net/; s/\">//; # print $_; print "debug10: $_\n"; $uri = $_; } } close(FHSC); close(FHCURL); } close(LOCK); unlink $lockfile if -r $lockfile;