#!perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Cookies;
use HTTP::Response;
use HTTP::Request::Common;
use XML::Simple;
my $URL;
my $SRC;
my $username;
my $password;
#
# Here is where you customize the script ...
#
# 1. URL is the location of the mt-blacklist.cgi file on your site
# 2. SRC is the URL for the raw blacklist RSS feed you want to add
# 3. username is your blog username
# 4. password is your blog password
#
$URL = 'http://your.site.com/MT/mt-blacklist.cgi';
$SRC = 'http://www.jayallen.org/comment_spam/feeds/blacklist-changes.rdf';
$username = 'USERNAME';
$password = 'PASSWORD';
#
# No need to change anything below, unless you just want to. I've tried to comment every
# step of the way in case you want to modify it for yourself.
#
my $request;
my $ua;
my $result;
my $cookie_jar;
my $entrylist;
my $xml;
my $xmlitem;
my $additions="";
my @deletions;
$ua = new LWP::UserAgent;
$ua->env_proxy();
#
# Format the query to get the RDF list
#
$request = new HTTP::Request GET => $SRC;
#
# Try to get it
#
$result = $ua->request( $request );
#
# Where we successful?
#
if ( $result->is_success ) {
#
# Save the XML string
#
$entrylist = $result->content;
}
#
# Now, parse it into a HASH
#
$xml=XMLin($entrylist);
#
# Iterate through each of the items
#
foreach $xmlitem (@{$xml->{item}})
{
#
# First, delete the last three periods, if they are there
#
$xmlitem->{description}=~s/(.*)\.\.\.$/$1/;
#
# See if it is an addition or deletion
#
if($xmlitem->{"dc:subject"}=~/addition/i)
{
$additions="$additions"."$xmlitem->{description}\n";
}
else
{
if($xmlitem->{"dc:subject"}=~/deletion/i)
{
push(@deletions, $xmlitem->{description});
}
}
}
#
# Do we have anything to do?
#
if(length($additions)>0 || length($deletions[0])>0)
{
#
# get logged into MT
#
$cookie_jar = new HTTP::Cookies;
#
# make the request to get the cookie ...
#
$request = HTTP::Request::Common::POST $URL,
[
username => $username,
password => $password,
];
#
# send the request
#
$result = $ua->request($request);
#
# get the cookie
#
$cookie_jar->extract_cookies($result);
#
# Now, do the additions if we have any
#
if(length($additions)>0)
{
$request = HTTP::Request::Common::POST $URL,
[
__mode => 'add_confirm',
entryimport => "$additions",
];
#
# include the cookie with the request
#
$cookie_jar->add_cookie_header($request);
$result = $ua->request($request);
#
# You can test the results here if you want to
#
}
#
# Do the deletions, if we have any
#
if(length($deletions[0])>0)
{
#
# Deleting is a GET with a long querystring
#
my $URLparameters = '__mode=quickdelete&=Delete+checked+entries&.cgifields=deleteEntry';
foreach my $deletethis (@deletions)
{
$URLparameters.="&deleteEntry=".$deletethis;
}
$request = new HTTP::Request GET => $URL."?".$URLparameters;
$result = $ua->request($request);
#
# You can test the results here if you want to
#
}
}
syntax highlighted by Code2HTML, v. 0.9.1