#!/usr/local/bin/perl -w
#
# READ THE SECURITY NOTICE BELOW!
#
# This is for people that run around life with the all important voti
+ng nodelet turned off.
# Don't you hate suddenly seeing what appears to be an off-topic thre
+ad, only to realize
# that a new voting booth has been put up, and you're not in on the a
+ction?
#
# Well, thanks to Twitching Monk Software's latest release, you can b
+e 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 wi
+ll be yours (and
# remember... All your vote are belong to us!)
#
# This script gets the past polls page, compares it to the previous p
+age stored in the
# __DATA__ section of the script. If they're different, an email is
+sent, and if the email
# succeeds, the script rerites itself. I highly recommended that thi
+s 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 s
+cript 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 wan
+t other people re-
# writing it for you, with something far nastier th
+an checking for a
# new voting nodelet. Like, oh say, posting DiscoS
+tu 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.
#
# 2001/03/18 - 1.00.00 - Initial release
# 2001/03/18 - 1.10.00 - dkubb's optimized file handling, and fix of
+a potential bug if
# vroom ever started including \n's in the dis
+playtype=raw pages.
#
use strict;
use LWP::Simple;
use MIME::Lite;
#
# Tune these to your requirements
#
use constant cMailto => '"A. User Name" <pmuser@mysite.com>';
+ # who the mail goes to
use constant cMailfrom => '"A. User Name" <pmuser@mysite.com>';
+ # 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=p
+ast%20polls&displaytype=raw";
{
$LWP::Simple::FULL_LWP = 1;
my $newpage = get (cSite) or die "Eeek! Can't get page from site";
read DATA, my $oldpage, -s DATA;
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
#
open SELF, "+< $0" or die "Eeek! Can't open $0: $!";
{
local $/ = join '', $/, '__DATA__';
<SELF>;
}
(truncate SELF, tell SELF) || die "Eeek! Truncate failed: $!";
print SELF $/, $newpage;
close SELF;
}
}
__DATA__
Old version, prior to dkubbs suggestions
#!/usr/local/bin/perl -w
#
# READ THE SECURITY NOTICE BELOW!
#
# This is for people that run around life with the all important voti
+ng nodelet turned off.
# Don't you hate suddenly seeing what appears to be an off-topic thre
+ad, only to realize
# that a new voting booth has been put up, and you're not in on the a
+ction?
#
# Well, thanks to Twitching Monk Software's latest release, you can b
+e 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 wi
+ll be yours (and
# remember... All your vote are belong to us!)
#
# This script gets the past polls page, compares it to the previous p
+age 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 th
+is 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 s
+cript 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 wan
+t other people re-
# writing it for you, with something far nastier th
+an checking for a
# new voting nodelet. Like, oh say, posting DiscoS
+tu 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" <pmuser@mysite.com>';
+ # who the mail goes to
use constant cMailfrom => '"A. User Name" <pmuser@mysite.com>';
+ # 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=p
+ast%20polls&displaytype=raw";
{
$LWP::Simple::FULL_LWP = 1;
my $newpage = get (cSite) or die "Eeek! Can't get page from site";
my $oldpage = <DATA>;
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 = <FH>;
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__
|