#!/usr/bin/perl -w # Quote Of The Day # Copyright (C) 1999 Matt Chisholm - matt@theory.org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; use vars qw( %FILE %input $wwwroot $qroot $dbfile $password $cgi ); use CGI; # ------------------------------------------------------------------- # # user configuration section # # ------------------------------------------------------------------- # $wwwroot = "/var/www/"; # web root directory # $qroot = $wwwroot."/perl/qotd/"; # quote of the day root directory # $dbfile = $qroot."qotd"; # name of database # $password = "pwmqn5OBuyKy2"; # password for adding new quotes # # ------------------------------------------------------------------- # print "Content-type: text/html\n\n"; $cgi = new CGI; map { $input{$_} = $cgi->param($_) } $cgi->param(); dbmopen %FILE, $dbfile, 0777 or die "Can't open $dbfile: $!\n"; if ( !( defined $input{'mode'} ) ) { print &qotd; #quote of the day } elsif ( $input{'mode'} eq "archive" ) { print &archive; #archive of quotes } elsif ( $input{'mode'} eq "new" ) { print &new; #adding new quotes } elsif ( $input{'mode'} eq "add" ) { print &add; #form for adding } else { print &qotd; #quote of the day } dbmclose %FILE; # ---------------------------------------- # # subroutines # # ---------------------------------------- # sub qotd { #display qotd my ($date, $who, $qotd, $format, $page); $_ = ( reverse sort keys %FILE )[0]; ( $date, $who ) = split /_/; $qotd = $FILE{$_}; my $printdate = &printdate($date); ( $format = &readfile( $qroot."qotd.html") ) =~ s/QOTD/$qotd/g; ; $format =~ s/WHO/$who/g; $format =~ s/DATE/$printdate/g; return $format; } sub archive { #display archive my $archiveitem = &readfile($qroot."archive-item.html"); my ( $list, $not1st ); foreach (reverse sort keys %FILE) { if ( $not1st ) { ( my $thisitem = $archiveitem ) =~ s/QUOTE/$FILE{$_}/g; my ( $date, $who ) = split /_/; my $printdate = &printdate($date); $thisitem =~ s/WHO/$who/g; $thisitem =~ s/DATE/$printdate/g; $list .= $thisitem; } else { $not1st = "1"; } } ( my $archive = &readfile($qroot."archive.html") ) =~ s/ARCHIVE/$list/g; return $archive; } sub add { #display add-quote page return &readfile($qroot."add.html"); } sub new { #add new quote, then display it if ( crypt ( $input{'password'}, "pw" ) ne $password ) { return"