Created
February 2, 2011 07:33
-
-
Save dynax60/807369 to your computer and use it in GitHub Desktop.
Automate Spamcop Submission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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