Приглашаем посетить
Guestbook Admin Script
#!/usr/local/bin/perl
# Name: Selena Sol's Guestbook Admin Script
#
# Version: 1.0
#
# Last Modified: 10-02-97
#
# Copyright Info: This application was written by Selena Sol
# (selena@eff.org, http://www.eff.org/~erict) having been inspired by
# countless other Perl authors. Feel free to copy, cite, reference,
# sample, borrow, resell or plagiarize the contents. However, if you
# don't mind, please let me know where it goes so that I can at least
# watch and take part in the development of the memes. Information
# wants to be free, support public domain freware. Donations are
# appreciated and will be spent on further upgrades and other public
# domain scripts.
#######################################################################
# Define Implementation Specific Variables. #
#######################################################################
# Before you run this you must modify a few
# variables so that it will work with your
# particular implementation.
#
# However, before you run this script, make sure
# to backup all files involved. You never know
# what might happen and you don't want to lose a
# month's worth of entries :)
#
# $guestbook_file is the location of your
# guestbook.html file.
#
# $current_century is the current century.
$guestbook_file = "guestbook.html";
$current_century = "20";
# Next we will define some variables which you
# needn't change but which we will utilize
# throught this program.
#
# $should_i_print will help the script determine
# what lines from the guestbook file it should
# keep in the guestbook.html and which lines it
# should transfer to the archived guestbook file.
#
# $date will be set equal to the current date
# Month-day-year.
#
# $archived_guestbook_filename is the name we will
# use for the archived file we create.
#
# $guestbook_contents and
# $archived_guestbook_contents are used to hold
# the lines of the guestbook file which will be
# written to the two new files.
$should_i_print = "yes";
$date = &get_date;
$archived_guestbook_filename = "$date.html";
$guestbook_contents = "";
$archived_guestbook_contents = "";
#######################################################################
# Read the Current Guestbook File #
#######################################################################
open (GUESTBOOK_FILE, "$guestbook_file");
while (<GUESTBOOK_FILE>)
{
if ($should_i_print eq "yes")
{
$guestbook_contents .= "$_";
$archived_guestbook_contents .= "$_";
}
if ($should_i_print eq "no")
{
$archived_guestbook_contents .= "$_";
}
if ($_ =~ /\<\!--begin--\>/)
{
$should_i_print = "no";
}
if ($_ =~ /\<\!--end of guestbook entries--\>/)
{
$guestbook_contents .= "\n\n\n$_";
$archived_guestbook_contents .= "$_";
$should_i_print = "yes";
}
}
close (GUESTBOOK_FILE);
#######################################################################
# Reset the Guestbook File and Write-out the Archived File #
#######################################################################
open (ARCHIVED_GUESTBOOK_FILE, ">$archived_guestbook_filename");
print ARCHIVED_GUESTBOOK_FILE "$archived_guestbook_contents";
close (ARCHIVED_GUESTBOOK_FILE);
open (GUESTBOOK_FILE, ">$guestbook_file");
print GUESTBOOK_FILE "$guestbook_contents";
close (GUESTBOOK_FILE);
#################################################################
# get_date Subroutine #
#################################################################
sub get_date
{
# The subroutine begins by defining some local working
# variables
local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date);
local (@days, @months);
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
'Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
# Next, it uses the localtime command to get the current
# time, from the value returned by the time
# command, splitting it into variables.
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
# Then the script formats the variables and assign them to
# the final $date variable. Note that $current_century
# is defined in web_store.setup. Since the 20th centruy
# is really 1900-1999, we'll need to subtract 1 from this
# value in order to format the year correctly.
if ($hour < 10)
{
$hour = "0$hour";
}
if ($min < 10)
{
$min = "0$min";
}
if ($sec < 10)
{ $sec = "0$sec";
}
$year = ($current_century-1) . "$year";
$date = "$months[$mon]-$mday-$year-guestbook";
return $date;
}