Dual-license your content for inclusion in The Perl 5 Wiki using this HOWTO, or join us for a chat on irc.freenode.net#PerlNet.

User:VandalBot

From PerlNet

Jump to: navigation, search

VandalBot is a bot operated by Paul Fenwick. It automatically reverts certain forms of common vandalism.

Comments regarding VandalBot, including any reports of incorrect operation, should be left on Paul's talk page.

VandalBot is currently run by hand. It ignores all patrolled edits. It will not touch pages that have been human modified since the vandalism occured.

TODO

Safe things:

  • Only scan for changes since the last VandalBot run.
  • Detect vandalism where the signature does not form the entire line.
  • Revert changes made to 'new' changes.
  • Only examine edits from anonymous users. (not appropriate, some spammers create accounts)
  • Mark spam as bot edits. This prevents their edits from showing up on the default Recentchanges page.

Dangerous things:

  • Possibly block the culprit.

This would be very bad if VandalBot were to accidently tag a human by mistake.

Source Code

#!/usr/bin/perl -w
use strict;
use lib '../lib';
use PerlNet::Bot;

# VandalBot, written by Paul Fenwick <pjf@cpan.org>, March 2005
#
# This program automatically finds and reverts certain types of
# vandalism found on PerlNet.  In particular it targets a particular
# signature seen by link-spammers.

use constant USER     => q{VandalBot};
use constant PASSWORD => q{SECRET};
use constant DEBUG    => 0;

use constant RECENT_CHANGES => q{http://perl.net.au/wiki/?title=Special:Recentchanges&hidepatrolled=1};

use constant ATTACK_SIGNATURE => qr{\Q<td class='diff-addedline'>&lt;div style=&quot;overflow:auto;height:1px;&quot;&gt;</td>\E};

my $bot = PerlNet::Bot->new(USER,PASSWORD,'VandalBot');

print "Login successful\n" if DEBUG;

# Find all the links that show diffs.

$bot->get(RECENT_CHANGES);

print "Fetched changes\n" if DEBUG;

my @links = $bot->find_all_links(
        url_regex => qr{/wiki/\?title=[^&]+&curid=\d+&diff=\d+&oldid=\d+}
);

# Walk through each link

foreach my $link (@links) {
        print $link->url,"\n" if DEBUG;
        $bot->get($link);
        my $rollback = $bot->find_link(text => 'rollback');

        # Skip this page unless it has a rollback link.  We don't
        # want to change anything that a user has already edited.
        if (not $rollback) {
                print "\tskipping, no rollback link\n" if DEBUG;
                next;
        }

        # Now search for an attack signature.  This is *really*
        # simple right now. As we get more attacks, these will need
        # to be broken out into their own area.

        if ($bot->content =~ ATTACK_SIGNATURE) {
                # Hey!  Looks like a spammer!  Get 'em!

                my ($pagename) = ($link->url =~ /title=([^&]+)/);

                print "Spam found at $pagename\n" if DEBUG;

                # By appending 'bot=1' to our rollback button, it
                # stops the original edit from showing on RecentChanges.

                # Click that rollback button.  ;)
                $bot->get($rollback->url(). "&bot=1");
        }
}

__END__

Personal tools