#!/usr/bin/perl use strict; use warnings; use HTML::Form; require HTTP::Request; use LWP::UserAgent; # this and the regex might need configuring my $base_uri="http://www.spamcop.net/"; # there is also the login form, so using the first one won't work my $formname="sendreport"; # url for spamcop reporting form my $sc_url; my ($ua, $request, $response, @forms, $form, %sc_urls); while (<>) { if ($_ =~ m#${base_uri}sc\?id=[a-z0-9]+#) { chomp; $sc_urls{$_}=$_; } } die "no urls found in STDIN" unless %sc_urls; # iterate through report urls (usually only one, but why not support piping) for my $sc_url (values %sc_urls) { my $error=undef; @forms=(); print "$sc_url\n"; $request = HTTP::Request->new(GET => "$sc_url"); # and usually used like this: my $i=5; RETRY: while (!@forms && $i) { $ua = LWP::UserAgent->new; $response = $ua->request($request); if ($response->content =~ /(resolved this issue|Reports regarding this spam have already been sent)/) { print STDERR "$1\n"; last RETRY; } else { @forms = HTML::Form->parse($response, $base_uri); @forms = grep $_->attr("name") eq "$formname", @forms; if (!@forms) { sleep 10; } $i--; } } if (!@forms) { if ($i==0) { $error="No form named '$formname' found"; } else { next; } } else { $form = shift @forms; $form->value(notes => "Automatically submitted, script from http://tigerente.htu.tuwien.ac.at/~aoe/mystuff/spamcop-report.pl"); $ua = LWP::UserAgent->new; if ($request !~ /fsinf|fachschaft/) { $response = $ua->request($form->click); print "submitting\n"; if (!$response->is_success) { $error=$response->status_line; } } else { $error="not submitting - whitelist"; } } if (defined $error) { if (values %sc_urls == 1) { die $error; } else { print STDERR "$error\n"; system "logger -t spamcop-report -p warn ".$error; } } }