#!/usr/local/bin/perl -w # # READ THE SECURITY NOTICE BELOW! # # This is for people that run around life with the all important voting nodelet turned off. # Don't you hate suddenly seeing what appears to be an off-topic thread, only to realize # that a new voting booth has been put up, and you're not in on the action? # # Well, thanks to Twitching Monk Software's latest release, you can be a member of the # trendy 'Vote Early, Vote Often' crowd. Simply tune the parameters below for your # mail server and account, toss it in a cron job, and voting glory will be yours (and # remember... All your vote are belong to us!) # # This script gets the past polls page, compares it to the previous page stored in the # __DATA__ section of the script. If they're different, an email is sent, and if the email # succeeds, the script rewrites itself. I highly recommended that this be set to '600' # permission set. # # I'd probably recommend that a copy of the script be made, once you've set the parameters, # just in case it manages to corrupt itself somehow. It's not likely, but anything is # possible with a TMS release. If you felt really tricky, when the script is first run # with nothing after the data section, it would get the length of the script, and write # that as part of the data section. Then, after it stripped off the old __DATA__, it would # perform a check to see if it's still the same length as what it was, and abort if not. # # SECURITY NOTICE: Set this script to 600 permission. You don't want other people re- # writing it for you, with something far nastier than checking for a # new voting nodelet. Like, oh say, posting DiscoStu quality articles # under your user ID... Or erasing all your tetris high scores. # # Requires the following modules: # LWP::Simple # MIME::Lite # # Copyright 2000,2001(c) J.C.Wren jcwren@jcwren.com # A production of Twitching Monk Software # No rights reserved, use as you see fit. I'd like to know about it, though, just for kicks. # use strict; use LWP::Simple; use MIME::Lite; # # Tune these to your requirements # use constant cMailto => '"A. User Name" '; # who the mail goes to use constant cMailfrom => '"A. User Name" '; # from is the same as to, for me use constant cMailsubject => 'Perlmonks.org New Voting Booth Up!'; # subject line in message use constant cMailserver => 'localhost'; # mailserver to use use constant cMailtext => "New voting booth is up at the monastery."; # what to send in the body use constant cSite => "http://www.perlmonks.org/index.pl?node=past%20polls&displaytype=raw"; { $LWP::Simple::FULL_LWP = 1; my $newpage = get (cSite) or die "Eeek! Can't get page from site"; my $oldpage = ; if (!defined ($oldpage) || $oldpage ne $newpage) { MIME::Lite->send ('smtp', cMailserver, Timeout=>60); my $msg = MIME::Lite->new (From => cMailfrom, To => cMailto, Subject => cMailsubject, Type => 'TEXT', Encoding => '7bit', Data => cMailtext) or die "Eeek! MIME::Lite->new failed"; $msg->send or die "Eeek! MIME::Lite->send failed."; # # Only update if we actually sent the message # { local $/ = undef; open (FH, "<$0") or die "Eeek! Can't open myself for reading!"; my $self = ; close (FH); $self =~ s/(^__DATA__$).*/$1/m; $self .= $newpage; open (FH, ">$0") or die "Eeek! Can't open myself for writing!"; print FH $self; close (FH); } } } __DATA__