Приглашаем посетить
Simple Base
#!/usr/bin/perl
#SimpleBase v.3.0.1 created: 8/16/96 revised: 2/4/97
#written by: David Palmer <dave@upstatepress.com>
#http://www.upstatepress.com/dave/perl.shtml
#######################################################################
# SimpleBase is a program that will allow you to keep a rather simple #
# database of your visitors in HTML format. In essence SimpleBase #
# presents the user with a fill-in form, that asks for the basics #
# like, name, last name, address, e-mail, anything they are involved #
# in etc. Then it creates a new HTML document with that information. #
# Also, SimpleBase maintains another HTML document that is an index #
# of all those who have made an entry to your database. Also, #
# SimpleBase sends you an e-mail message telling you that someone has #
# submited an entry, and giving you the information in the message #
# so you can get the gist of what they entered without having to act- #
# ually browse to your database index. SimpleBase is rather simple to #
# setup. Please refer to the README file for instructions. #
#######################################################################
#some variables need to be defined first. These must be set to your
#This should point to your home directory, where you store you html files
$base_dir = "/usr/home/upstate/public_html/database";
#Name of number.txt
$data = "numbers.txt";
#this is the name of the dirctory where the new entries will go
$entries = "entries";
#database text file
$dbase = "$base_dir/dbase.sdb";
#This is the URL of your index of entries (usrlink.html)
$base_url = "http://www.upstatepress.com/database";
#This is the url where you will store you database entries
$index = "$base_url/entries";
#This should point to where you are going to store usrlink.html.
$link_page = "$base_dir/usrlink.html";
# This is the URL of the new entry form
$new_entry_url = "http://www.upstatepress.com/newentry.html";
# Would you like to be notified by e-mail each time there's a new entry?
$notify = "yes"; # enter "yes" or "no"
# Do you want to create a comma delimited text file for use with MS Access?
# Simply enter "yes" or "no" If you enter "yes" then SimpleBase will write
# each entry to a comma delimited text file so that you can easily import
# the data into MS Access. Each field will also be enclosed in double quotes
# (" ") to make field creation in MS Access easier.
$msaccess = "yes";
# Enter what Operating system you have. UNIX or WINDOWS
$os = "UNIX";
#This should point to where your system's sendmail program is stored.
# If you're a windows user, you'll need Blat.exe (i.e. 'c:/blat/blat.exe';)
$mailprog = '/usr/sbin/sendmail';
#This should point to your system's date utility
# For Windows users, enter this: localtime(time);
$date = '/bin/date';
#don't change this, this is the extension which all new files will end with
$ext = 'html';
#This should be your home URL
$my_url = 'http://www.upstatepress.com';
#This is the name of your home page
$my_title = 'Upstate Press';
#Enter your e-mail address here
$my_email = 'dave@upstatepress.com';
#Enter your name here
$my_name = 'Dave Palmer';
##################################################################################
# The look of your database entries
# These do NOT have to be changed in order for SimpleBase to operate
# These options only change the apperance of your Database entries.
$bgcolor = "#ffffff";
$bgimage = ""; #if no image simple delete everything between the quotes
$linkcolor = "#000000"; # this is black
$visitedlink = "#000000"; # this one too
$activelink = "#ff0000";
# This is it. From here on down is the guts of the program. If you want to change
# anything below this point, ask first, okay?
###################################################################################
# Get the form input
read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $input);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
#lets translate the decoded input into nice simple scalars
#this just eliminates a lot of excessive typing!
$usrname = $FORM{'usrname'};
$last_name = $FORM{'last_name'};
$info = $FORM{'info'};
$address = $FORM{'address'};
$site_name = $FORM{'site_name'};
$url = $FORM{'url'};
$email = $FORM{'email'};
$city = $FORM{'city'};
$state = $FORM{'state'};
$zip = $FORM{'zip'};
$action = $FORM{'action'};
# Before we go too far, lets do some error checking
# its limited now, this will be expanded
&missing_entry(missing_name) unless $usrname;
&missing_entry(missing_last_name) unless $last_name;
&missing_entry(missing_email) unless $email;
&missing_entry(missing_address) unless $address;
&missing_entry(missing_city) unless $city;
&missing_entry(missing_state) unless $state;
&missing_entry(missing_zipcode) unless $zip;
#Get the date
if ($os eq "UNIX") {
&get_date;
}
#send an e-mail
if ($notify eq "yes") {
&sendmail;
}
if ($msaccess eq "yes") {
&msaccess; }
# Get the number from number.txt (we need this to
# name our new file
&number;
# Increment the number
&plus_one;
# Suck the index page and add the new entry reference
&update_index;
# Send the user a response
&respond;
# Create the searchable database
&create_dbase;
# Create the HTML page for the new entry
&create_entry;
########################
# Sub Routines #
########################
sub update_index {
#Suck the usrlink.html file into an array, adding the new link
#and re-write it with the new link.
open (HTMLDOC, "$link_page") || die "Can't open $link_page\n";
@lines = <HTMLDOC>;
close(HTMLDOC);
$sizelines = @lines;
open (HTMLDOC, ">$link_page") || die "I can't open that now\n";
for ($a = 0; $a <= $sizelines; $a++) {
$_ = $lines[$a];
if (/<!--begin-->/) {
print HTMLDOC "<!--begin-->\n";
print HTMLDOC "$usrname $last_name added to this on $date<br>\n";
print HTMLDOC "<a href=\"$base_url/$entries/$number\.$ext\">View the entry</a><br>\n";
print HTMLDOC "<hr size=1 noshade>\n";
} else {
print HTMLDOC $_;
}
}
close(HTMLDOC);
}
sub respond {
print "Content-type: text/html\n\n";
print "<html><head><title>Thank You!</title></head>\n";
print "<body bgcolor=ffffff background=\"back.GIF\">\n";
print "<center>\n";
print "<font size=+3>Thank's for adding yourself to our little database!</font><br>\n";
print "<hr size=1 noshade width=75%>\n";
print "<font size=+4>$usrname $last_name</font><br>\n";
print "<hr size=1 noshade width=75%>\n";
print "We will keep in touch!<br>\n";
print "<hr size=1 noshade>\n";
print "<font size=+2><a href=\"http://www.upstatepress.com\">Upstate Press</a></font><br>\n";
print "<a href=\"$index/$number\.$ext\">Check out your entry</a>\n";
print "</center>\n";
print "</body>\n";
print "</html>\n";
}
sub number {
open(NUMBER, "$base_dir/$data");
$number = <NUMBER>;
close(NUMBER);
if ($number == 99999) {
$number = "1";
}
else {
$number++;
}
}
sub plus_one {
open(NUMBER,">$base_dir/$data") || die "I can't open that file!\n";;
print NUMBER "$number";
close(NUMBER);
}
sub create_dbase {
# Create dbase text file
open(DBASE, ">>$dbase") || die "I can't creat $dbase\n";
print DBASE "$usrname&&$last_name&&$email&&$address&&$city&&$state&&$zip&&$index/$number\.$ext\n";
close(DBASE);
}
sub create_entry {
#Lets create a new entry. This creates a new HTML file with the user's input
open(NEWFILE, ">$base_dir/$entries/$number\.$ext") || die "I can't create that file\n";
print NEWFILE "<html>\n";
print NEWFILE "<head>\n";
print NEWFILE "<title> $usrname\'s crucial data\n";
print NEWFILE "</title></head>\n";
print NEWFILE "<body bgcolor=$bgcolor background=\"$bgimage\" vlink=\"$visitedlink\"\n";
print NEWFILE "link=\"$linkcolor\">\n";
print NEWFILE "<center>\n";
print NEWFILE "<font size=+3>$usrname $last_name has entered this information</font><br>\n";
print NEWFILE "<hr size=1 noshade>\n";
print NEWFILE "$usrname $last_name added this bit of information:<br>\n";
print NEWFILE "$info<br>\n";
print NEWFILE "$usrname $last_name can be reached at<br>\n";
print NEWFILE "$address<br>\n";
print NEWFILE "<a href=\"mailto:$email\">$usrname $last_name</a><br>\n";
print NEWFILE "<a href=\"$url\">$site_name</a><br>\n";
print NEWFILE "</center>\n";
print NEWFILE "<hr size=1 noshade 75%>\n";
print NEWFILE "<font size=-1><i><a href=\"$my_url\">$my_title<br></a>\n";
print NEWFILE "This script was written by\n";
print NEWFILE "<a href=\"mailto:dave@upstatepress.com\">David Palmer</a>\n";
print NEWFILE "</font></i></body></html>\n";
close(NEWFILE);
}
# Return the user an error if they missed one of our required fields
sub missing_entry {
local($missing) = @_;
print "Content-type: text/html\n\n";
print "<html><head><title>You missed something!</title></head>\n";
print "<body>\n";
print "<font size=4>$missing!</font><br>\n";
print "<hr noshade size=1><br>\n";
print "<a href=\"$new_entry_url\">Click here to go back</a>\n";
print "</body></html>\n";
exit;
}
#Lets send ourselves some e-mail!
sub sendmail {
local($tempfile) = "$base_dir/temp.dat";
if ($os eq "UNIX") {
open(MAIL, "|$mailprog -t") || die "Can't open $mailprog\n";
print MAIL "To: $my_name <$my_email>\n";
print MAIL "From: $usrname $last_name<$email>\n";
print MAIL "Subject: SimpleBase Report!\n";
print MAIL "$usrname $last_name filled added an entry on $date\n";
print MAIL "$usrname\'s email is: $email\n";
print MAIL "--------------------------------------------------------\n";
print MAIL "$usrname $last_name can be reached at: $address\n";
print MAIL "________________________________________________________\n\n";
close (MAIL);
}
else {
open(MAIL, ">$tempfile") || die "I can't $!\n";
print MAIL "$usrname $last_name filled added an entry on $date\n";
print MAIL "$usrname\'s email is: $email\n";
print MAIL "--------------------------------------------------------\n";
print MAIL "$usrname $last_name can be reached at: $address $city $state $zip\n";
print MAIL "________________________________________________________\n\n";
exec("$mailprog $tempfile -s \"SimpleBase Report\" -t $my_email \n\n");
close(MAIL);
}
}
sub msaccess {
open(FILE, ">>$base_dir/msaccess.txt") || die "I can't $!\n";
print FILE "\"$usrname\",\"$last_name\",\"$email\",\"$address\",\"$city\",\"$state\",\"$zip\"\n";
close(FILE);
}
sub get_date {
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('January','Feburary','March','April','May','June','July','August','September',
'October','November','December');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
if($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
$date = "$days[$wday], $months[$mon] $mday, 19$year";
}