Skip to content

Instantly share code, notes, and snippets.

@dynax60
Created February 2, 2011 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dynax60/807369 to your computer and use it in GitHub Desktop.
Save dynax60/807369 to your computer and use it in GitHub Desktop.
Automate Spamcop Submission
#!/usr/bin/env perl
# Automate Spamcop Submission
use FindBin;
use lib "$FindBin::Bin/mojo/lib";
use Mojo::Client;
$| = 1;
my $client = Mojo::Client->new;
my $url = 'http://www.spamcop.net/sc';
my $callback = sub {
my $tx = pop;
my $dom = $tx->res->dom;
my $form = {};
printf "Url: %s ", $tx->req->url;
# Find all the necessary parameters for form submission.
#
$dom->find('form[name="sendreport"]')->each(sub {
shift->find('input')->each(sub {
my $attrs = shift->attrs;
if ($attrs->{type} eq 'submit') {
$form->{submit} = $attrs->{value} if $attrs->{value} =~ /Send/;
} elsif ($attrs->{type} eq 'checkbox') {
$form->{ $attrs->{name} } = 'on';
} else {
$form->{ $attrs->{name} } = $attrs->{value};
}
} )
});
# Do we sent report recently?
#
my $already_sent = 0;
$dom->find('div[class="header"]')->until(sub{
$_->text =~ m/already been sent/ && ++$already_sent
}) ;
# Do we have any error?
#
my $error = $dom->at('div[class="error"]');
$client->post_form($url => $form) if !$already_sent;
print $error ? "Failed\n" . $error->text . "\n" :
$already_sent ? "Report have already been sent\n" : "OK\n";
};
while(<>) {
chomp;
$client->get($_ => {Connection => 'close'} => $callback) if /^http:/;
}
$client->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment