Viewing file: random.pl (24.73 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/perl
# Installation:
# 1. Unzip the package
# 2.Upload all files onto a cgi-bin directory of your server
# and chmod them 755. Some servers require the random.txt file to be
# chmoded 777.
# Type http://www.yourdomain.com/cgi-bin/dir_to_randompicker/random.pl at # the your browser´s URL prompt to start the banner rotation.
#
# Type
# http://www.yourdomain.com/cgi-bin/dir_to_randompicker/random.pl?admin at # the your browser´s URL prompt to log on to the admin area.
#
# You may change the admin password by changing the variable $passwd
# below
#
# If there is SSI enabled on your server set the option $ssi to "yes"
# add the code line
# <!--#exec cgi="/cgi-bin/dir_to_randompicker/random.pl"-->
# on the HTML page where the banner should appear
# and give it the extension sht or shtml or shtml.
#
# If no SSI is available set the option $ssi to "no" and place this
# line on the HTML page:
# <a href="/cgi-bin/dir_to_randompicker/random.pl?page"><img src="/cgi-bin/dir_to_randompicker/random.pl" border=0></a>
#
# Please note that when you use the non-SSI method the banner does not # include a link and a linked text below it!
require 'cgi-lib.pl';
&ReadParse(*contents);
&check_input;
&get_date;
$setupfile = "setup";
&read_setup;
$command = "$ENV{'QUERY_STRING'}";
$scripturl = "random.pl";
@yesno = ("yes","no");
################################################
# Do not edit below this line!! ################
################################################
$demo = "no";
$name_num = "0";
$text_num = "1";
$image_num = "2";
$link_num = "3";
if ($command eq "$passwd")
{
&admin_page;
}
if ($command eq "page")
{
&page;
}
elsif ($contents{'act'} eq "changesetup")
{
&changesetup;
}
elsif ($contents{'act'} eq "addthem")
{
&addthem;
}
elsif ($contents{'act'} eq "addthemmake")
{
&addthemmake;
}
elsif ($contents{'act'} eq "view")
{
&view;
}
elsif ($contents{'act'} eq "showlog")
{
&showlog;
}
elsif ($contents{'act'} eq "clearlog")
{
&clearlog;
}
elsif ($contents{'act'} eq "modify")
{
&modify;
}
elsif ($contents{'act'} eq "makemodify")
{
&makemodify;
}
elsif ($contents{'act'} eq "delete")
{
&delete;
}
else
{
&print_out;
exit;
}
# Done #
##############################################################################
sub admin_page
{
local ($confirm) = @_;
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
while (<FILE>)
{
$line = $_;
chop $line;
push (@banners,$line);
}
close(FILE);
@banners = sort(@banners);
foreach $b (@banners)
{
@fields = split (/\|/,$b);
$selectbanners .= "<option value=\"$b\">$fields[$name_num]";
}
&header;
print qq~
<a href="#install">Installation and Features</a>
<form action="$scripturl" method="post">
<table border=0 width=300>
<tr>
<th bgcolor=white colspan=2>
SETUP $confirm
</th>
</tr>
<tr>
<th bgcolor=white colspan=2>
Do not enter any pipe character (|) or quotation marks (")!
</th>
</tr>
<tr>
<th bgcolor=white valign=top>
Password:
</th>
<th bgcolor=white>
<INPUT TYPE="text" name="passwd" value="$passwd" size=15>
</th>
</tr>
<tr>
<th bgcolor=white valign=top>
Banner file:
</th>
<th bgcolor=white>
<INPUT TYPE="text" name="randomfile" value="$randomfile" size=15>
</th>
</tr>
<tr>
<th bgcolor=white valign=top>
Log file
</th>
<th bgcolor=white>
<INPUT TYPE="text" name="logfile" value="$logfile" size=15>
</th>
</tr>
<tr>
<th bgcolor=white valign=top>
SSI enabled?
</th>
<th bgcolor=white>
<select name="ssi">
~;
foreach $yn (@yesno)
{
if ($yn eq $ssi)
{
print qq~
<option value="$yn" selected>$yn
~;
}
else
{
print qq~
<option value="$yn">$yn
~;
}
}
print qq~
</select>
</th>
</tr>
<tr>
<th bgcolor=white valign=top>
Footer
</th>
<th bgcolor=white>
<INPUT TYPE="text" name="footer" value="$footer" size=45>
</th>
</tr>
<tr>
<th colspan=2 bgcolor=white>
<input type="hidden" NAME="act" value="changesetup">
<input type="submit" value="Change Setup"> <input type="reset">
</th>
</tr>
</form>
</table>
<hr>
<h3>Add New Banner(s)</h3>
<h4>Enter the number of banners you would like to add?</h4>
<form action="$scripturl" method="post">
<INPUT TYPE="text" name="howmany" size=15>
<input type="hidden" NAME="act" value="addthem">
<input type="submit" value="start"> <input type="reset">
</form>
<hr>
<h3>List all banners</h3>
<form action="$scripturl" method="post">
<input type="hidden" name="act" value="view">
<br>
<input type="submit" value=" View ">
</form>
<hr>
<h3>Delete Banners</h3>
<form action="$scripturl" method="post">
<input type="hidden" name="act" value="delete">
<select name="banner">
$selectbanners
</select>
<br>
<input type="submit" value="start"> <input type="reset">
</form>
<hr>
<h3>Modify Banners</h3>
<form action="$scripturl" method="post">
<input type="hidden" name="act" value="modify">
<select name="banner">
$selectbanners
</select>
<br>
<input type="submit" value="start"> <input type="reset">
</form>
<hr>
<h3>Log</h3>
<form action="$scripturl" method="post">
<input type="hidden" name="act" value="showlog">
<input type="submit" value="Show Log">
</form>
<form action="$scripturl" method="post">
<input type="hidden" name="act" value="clearlog">
<input type="submit" value="Clear Log">
</form>
<hr>
<a name="install"></a>
<table>
<tr>
<td>
<h3>Installation, features, requirements</h3>
<h4>Installation</h4>
<ol>
<li> Unzip the package. <br>a) Either you unzip them on your local disk or <br>b) you upload the entire package onto your server and unpack it using the command<br>
<tt>unzip random.zip</tt>
<li> It must contain following files:
<ul>
<li>samples: directory of sample HTML Files
<li>cgi-lib.pl: cgi-library
<li>$scripturl: main script
<li>log.txt: logfile
<li>random.txt: database of random banners
<li>setup: the setup file
</ul>
<li>Upload all files onto a cgi-bin directory of your server and chmod them 755. Some servers require the random.txt file to be chmoded 777.
<li> Type http://www.yourdomain.com/cgi-bin/dir_to_randompicker/random.pl at the your browser´s URL prompt to start the banner rotation as stand-alone (not within HTML documents, just as a test).
<li> Type
http://www.yourdomain.com/cgi-bin/dir_to_randompicker/random.pl?admin at your browser´s URL prompt to log on to the admin area.
<li>You may change the admin password and the location of the log- and random file (see Setup above)
<li> To start the banner rotation from HTML pages add the code
<br>
<tt><nobr><!--#exec cgi="/cgi-bin/dir_to_randompicker/random.pl"--></nobr></tt>
for SSI method, i.e. <b>if your server supports SSI-commands and you set the option SSI enabled to "yes"</b>
<br>
and give the document the extension sht or shtml or shtml <br>or ...
<p>
<tt><nobr><a href="/cgi-bin/dir_to_randompicker/random.pl?page"><img src="/cgi-bin/dir_to_randompicker/random.pl"></a></nobr></tt>
<br>for non-SSI method, i.e. <b>if your server does NOT support SSI-commands and you set the option SSI-enabled to "no".</b>
<p>
<b>Please note that when you use the non-SSI method the banners do not include linked texts below them!</b>
</ol>
<h4>Features</h4>
<ul>
<li> Add, modify and delete as many banners as you like (up to 10,000 banners)
<li> Super fast and super simple to install
<li> Supports SSI and non-SSI (image-tag)
<li> Supports auto-rotating banners (auto-reload)
<li> Checks for duplicates
<li> Sorts your banners alphabeticly
<li> Password protected Admin Area (this area)
<li> Displays the code to add on your HTML pages
<li> Logs each banner display
</ul>
<h4>Requirements</h4>
<ul>
<li> cgi-bin directory
<li> Perl 5.003 or higher installed on your server
</ul>
</td>
</tr>
</table>
~;
&footer;
exit;
}
sub addthem
{
&header;
$add_num = $contents{'howmany'}-1;
$add_numdis = $add_num+1;
print qq~
<h3>Add $add_numdis Banner(s)</h3>
<h4>* = required fields</h4>
<table width = \"500\" align=center border=3>
<FORM ACTION="$scripturl" METHOD="POST">
<tr>
<th>No</th>
<th>Name*</th>
<th>Text below banner</th>
<th>Image*<br>(http://www.expample/images/pic1.gif)</th>
<th>Link<br>(http://www.example.com)</th>
</tr>
~;
for ($num=0;$num<=$add_num;$num++)
{
$name = $num."name";
$text = $num."text";
$image = $num."image";
$link = $num."link";
$no = $num+1;
print qq~
<tr><td><b>$no</b></td>
<td valign=top><INPUT TYPE="text" NAME="$name" size=30></td>
<td><INPUT TYPE="text" NAME="$text" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="$image" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="$link" size=30></td>
~;
}
print qq~
</table>
<INPUT TYPE="hidden" NAME="howmany" VALUE=\"$add_num\">
<INPUT TYPE="hidden" NAME="act" VALUE=\"addthemmake\">
<INPUT TYPE="submit" value="Add them all"> <INPUT TYPE="Reset"
</FORM>
~;
&footer;
exit;
}
sub addthemmake
{
$add_num = $contents{'howmany'};
$countnot=0;
$count=0;
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
while (<FILE>)
{
$line = $_;
chop $line;
@fields = split (/\|/,$line);
for ($num=0;$num<=$add_num;$num++)
{
$name = $num."name";
$text = $num."text";
$image = $num."image";
$link = $num."link";
if ($contents{$name} eq $fields[$name_num] || $contents{$name} eq "" || $contents{$name} =~ /\|/g)
{
&exists("Name",$name);
}
elsif ($contents{$image} eq $fields[$image_num] || $contents{$image} eq "" || $contents{$image} =~ /\|/g)
{
&exists("Image",$image);
}
elsif ($contents{$link} ne "" && ($contents{$link} eq $fields[$link_num] || $contents{$link} =~ /\|/g))
{
&exists("Link",$link);
}
}
}
open(FILE,">>$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
for ($num=0;$num<=$add_num;$num++)
{
$name = $num."name";
$text = $num."text";
$image = $num."image";
$link = $num."link";
if ($contents{$image} eq "" && $contents{$text} eq "" && $contents{$link} eq "")
{
$countnot++;
}
else
{
$count++;
print FILE "$contents{$name}\|$contents{$text}\|$contents{$image}\|$contents{$link}\n";
}
}
close(FILE);
&header;
print qq~
<h3>Following $count banner(s) were added to $randomfile</h3>
<h4>$countnot were not added because the fields were left blank</h4>
<table width = \"500\" align=center border=3>
<tr><th>No.</th><th>Name</th><th>Text below banner</th><th>Image</th><th>Link</th></tr>
~;
for ($num=0;$num<=$add_num;$num++)
{
$name = $num."name";
$text = $num."text";
$image = $num."image";
$link = $num."link";
$no = $num+1;
print qq~
<tr><td>$no</td>
<td> $contents{$name}</td>
<td> $contents{$text}</td>
<td> $contents{$image}</td>
<td> $contents{$link}</td>
~;
}
print qq~
</table>
<p>
<b>
Click on this link <a href="$scripturl">to start Random Display</a>. <br>Then reload the page after each random banner.<br>
The code on your HTML documents must read in SSI mode:<br> <!--#exec="$ENV{'SCRIPT_NAME'}"-->
The code on your HTML documents must read in non-SSI mode:<br> <img src="$ENV{'SCRIPT_NAME'}">
</b>
~;
&footer;
exit;
}
sub view
{
&header;
print qq~
<h3>List of banners</h3>
<table width = \"500\" align=center border=3>
<tr><th>No.</th><th>Name</th><th>Text below banner</th><th>Image</th><th>Link</th></tr>
~;
$num=0;
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
while (<FILE>)
{
$num++;
$line = $_;
chop $line;
@fields = split (/\|/,$line);
print qq~
<tr><td>$num</td>
<td> $fields[$name_num]</td>
<td> $fields[$text_num]</td>
<td> <a href="$fields[$image_num]">$fields[$image_num]</a></td>
<td> <a href="$fields[$link_num]">$fields[$link_num]</a></td>
~;
}
print qq~
</table>
~;
&footer;
exit;
}
sub showlog
{
&header;
print qq~
<h3>Logfile</h3>
<table width = \"500\" align=center border=3>
<tr><th>No.</th>
<th width=150>Name</th>
<th>Text below banner</th>
<th>Image</th>
<th>Link</th><th>Date</th>
</tr>
~;
$num=0;
open(FILE,"$logfile") || &no_open ("",$logfile,__FILE__,__LINE__,"opening logfile");
while (<FILE>)
{
$line = $_;
chop $line;
push (@logfields,$line);
}
@logfields = sort(@logfields);
foreach $f (@logfields)
{
@fields = split(/\|/,$f);
$num++;
print qq~
<tr><td><b>$num</b></td>
~;
$no=0;
foreach $field (@fields)
{
if ($no > "0" && $no < $link_num+1)
{
$field = "<a href=\"$field\">$field</a>";
}
print qq~
<td> $field</td>
~;
$no++;
}
print "</tr>";
}
print qq~
</table>
~;
&footer;
exit;
}
sub clearlog
{
open(FILE,">$logfile") || &no_open ("",$logfile,__FILE__,__LINE__,"opening logfile");
print FILE "";
close(FILE);
&header;
print qq~
<h3>Logfile $logfile successfully cleared!</h3>
~;
&footer;
exit;
}
sub delete
{
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
while (<FILE>)
{
$line = $_;
chop $line;
@fields = split (/\|/,$line);
if ($line ne "$contents{'banner'}")
{
$newdata .= "$line\n";
}
elsif ($line eq "$contents{'banner'}")
{
$bannerfound = "$fields[$name_num]";
}
}
close(FILE);
open(FILE,">$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
print FILE "$newdata";
close(FILE);
&header;
if ($bannerfound ne "")
{
print qq~
<h3>Banner <i>$bannerfound</i> was successfully removed!</h3>
~;
}
elsif ($bannerfound eq "")
{
print qq~
<h3>Banner could not be removed<br> (probably it does not exist any more)</h3>
~;
}
&footer;
exit;
}
sub modify
{
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
while (<FILE>)
{
$line = $_;
chop $line;
@fields = split (/\|/,$line);
if ($line eq "$contents{'banner'}")
{
$founddata = "$line";
}
}
close(FILE);
($name,$text,$image,$link) = split(/\|/,$contents{'banner'});
&header;
print qq~
<h3>Modify this banner</h3>
<FORM ACTION="$scripturl" METHOD="POST">
<table width = \"500\" align=center border=3>
<tr>
<th>Name</th>
<th>Text below banner</th>
<th>Image</th>
<th>Link</th>
</tr>
<tr>
<td valign=top><INPUT TYPE="text" NAME="name" value="$name" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="text" value="$text" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="image" value="$image" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="link" value="$link" size=30></td>
</table>
<INPUT TYPE="hidden" NAME="banner" VALUE="$contents{'banner'}">
<INPUT TYPE="hidden" NAME="act" VALUE="makemodify">
<INPUT TYPE="submit" value="Modify"> <INPUT TYPE="Reset"
</FORM>
~;
&footer;
exit;
}
sub makemodify
{
### Delete the old record ###
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
while (<FILE>)
{
$line = $_;
chop $line;
@fields = split (/\|/,$line);
if ($line ne "$contents{'banner'}")
{
$newdata .= "$line\n";
}
elsif ($line eq "$contents{'banner'}")
{
$bannerfound = "$fields[$name_num]";
}
}
close(FILE);
open(FILE,">$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
print FILE "$newdata";
close(FILE);
### Write new record ###
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
while (<FILE>)
{
$line = $_;
chop $line;
@fields = split (/\|/,$line);
if ($contents{'image'} eq $fields[$image_num] || $contents{'image'} eq "")
{
&exists("Image","image");
}
elsif ($contents{'name'} eq $fields[$name_num] || $contents{'name'} eq "")
{
&exists("Name","name");
}
elsif ($contents{'link'} eq $fields[$link_num])
{
&exists("Link","link");
}
}
open(FILE,">>$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
print FILE "$contents{'name'}\|$contents{'text'}\|$contents{'image'}\|$contents{'link'}\n";
close(FILE);
&header;
print qq~
<h3>Banner was successfully modified</h3>
<table width = \"500\" align=center border=3>
<tr>
<th>Name</th>
<th>Text below banner</th>
<th>Image</th>
<th>Link</th>
</tr>
~;
print qq~
<tr>
<td> $contents{'name'}</td>
<td> $contents{'text'}</td>
<td> $contents{'image'}</td>
<td> $contents{'link'}</td>
</table>
<p>
<b>
~;
&footer;
exit;
}
sub print_out
{
# Open the file containing phrases and read it in.
open(FILE,"$randomfile") || &no_open ("",$randomfile,__FILE__,__LINE__,"opening random file");
@phrases = <FILE>;
close(FILE);
# Invoke srand; with a seed of the time and pid. If you are on a machine
# which doesn't put the pid into $$ (ie. Macintosh, Win NT, etc...), change
# this line to: srand(time ^ 22/7);
srand(time() ^ $$);
$num = rand(@phrases);
@printen = split(/\|/,$phrases[$num]);
chop $phrases[$num];
chop $printen[$link_num];
if ($ssi eq "yes")
{
print "Content-type: text/html\n\n";
print qq~
<a href="$printen[$link_num]" target="_top"><img src="$printen[$image_num]" border="0"></a>
<br>
<a href="$printen[$link_num]" target="_top">$printen[$text_num]</a>
~;
}
elsif ($ssi eq "no")
{
print "Location: $printen[$image_num]\n\n";
}
open(FILE,">>$logfile");
print FILE "$printen[$name_num]\|$printen[$text_num]\|$printen[$image_num]\|$printen[$link_num]\|$date_short\n";
close(FILE);
exit;
}
sub page
{
open(FILE,"$logfile");
@records = <FILE>;
close(FILE);
$rec_num = @records-1;
chop $records[$rec_num];
@fields = split (/\|/,$records[$rec_num]);
print "Location: $fields[$link_num]\n\n";
exit;
}
sub no_open {
local($dir,$files,$filename,$lineno,$action) = @_;
print "Content-type: text/html\n\n";
print qq~
<H2 align=center>Error in $filename at line $lineno while $action! <p>Couldn´t find or open required file or directory <i>$dir$files</i></h2>
<h2>Please check <ul>
<li> the path or name of this file or directory ,
<li> check its permissions (many files must be writable by the server or owner = chmod 6xx or higher): on some servers the directories and files must be chmod 777 to perform write and read operation within and on them
<li> or create the directory or file manually if it doesn´t exist and all trouble shooting before failed.
</ul>
</td></tr></table>
~;
exit;
}
sub exists
{
local ($action,$item) = @_;
&header;
print qq~
<h3>$action <i>$contents{$item}</i> already exists or is empty or you entered a pipe symbol (|) for this field. Check your entries and try again.</h3>
<table width = \"500\" align=center border=3>
<FORM ACTION="$scripturl" METHOD="POST">
<tr>
<th>No</th>
<th>Name*</th>
<th>Text below banner</th>
<th>Image*<br>(http://www.expample/images/pic1.gif)</th>
<th>Link<br>(http://www.example.com)</th>
</tr>
~;
for ($num=0;$num<=$add_num;$num++)
{
$name = $num."name";
$text = $num."text";
$image = $num."image";
$link = $num."link";
$no = $num+1;
print qq~
<tr>
<td><b>$no</b></td>
<td valign=top><INPUT TYPE="text" NAME="$name" value="$contents{$name}$contents{'name'}" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="$text" value="$contents{$text}$contents{'text'}" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="$image" value="$contents{$image}$contents{'image'}" size=30></td>
<td valign=top><INPUT TYPE="text" NAME="$link" value="$contents{$link}$contents{'link'}" size=30></td>
~;
}
print qq~
</table>
<INPUT TYPE="hidden" NAME="howmany" VALUE=\"$add_num\">
<INPUT TYPE="hidden" NAME="act" VALUE=\"addthemmake\">
<INPUT TYPE="submit" value="Add them all"> <INPUT TYPE="Reset"
</FORM>
~;
&footer;
exit;
}
sub header
{
print "Content-type: text/html\n\n";
print qq~
<html>
<head><title>RandomPicker</title></head>
<body bgcolor=e7e8e8>
<div align=center>
<font face=\"Helv\">
<h1>RandomPicker - Admin Area</font></h1>
<table width = \"500\" align=center>
<tr>
<td align=center colspan=4>
<font face=\"Helv\"></font>
~;
}
sub footer
{
print qq~
</td></tr></table>
<p>
<br>
$footer [<a href="javascript:history.back(1)">Back</a>] [<a href="$scripturl?$passwd">Admin Area</a>] </font><p>
<font size=2> Like this script? Help us and give it a high rating at CGI - Resources <br>(from 1 = poor to 10 = execellent):</font><br>
<table width=300 cellspacing=0 cellpadding=0 border=0> <tr>
<td bgcolor=#FF3232>Rate this Script @ The CGI Resource Index!</td></tr>
</table><table width=300 cellspacing=0 cellpadding=0 border=0> <tr>
<td width=20> </td> <td width=260 bgcolor=#FF3232>
<center><table border=0 cellpadding=0 cellspacing=0> <tr>
<td><form method=POST action="http://cgi-resources.com/rate/index.cgi">
<input type=hidden name="referer" value="http://www.citro.net/scripts/more.shtml">
<input type=hidden name="link_code" value="02256">
<input type=hidden name="category_name"
value="Programs and Scripts/Perl/Random Images/">
<input type=hidden name="link_name" value="RandomPicker">
<font face="Verdana,Arial,Helvetica" size=-1><b>Script Rating: </b>
</font> <select name="rating"> <option selected>--
<option>10 <option>9 <option>8 <option>7
<option>6 <option>5 <option>4 <option>3
<option>2 <option>1 </select> </td>
<td valign=center>
<input type="submit" value="Rate it"></td></tr>
</table></center></td> <td width=20> </td> </tr>
</table>
</form>
<p>
<font size=2>RandomPicker, Copyright Wolfgang Melchior <a href=http://www.citro.net>Citro Communications</a>, 1998</center></font></div></body></html>
~;
}
sub parse_form
{
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-0][a-fA-F0-0])/pack("C", hex($1))/eg;
$value =~ tr/,/ /;
$contents{$name} = $value;
}
}
}
sub get_date
{
# Define arrays for the day of the week and month of the year. #
@days_d = ('Sonntag','Montag','Dienstag','Mittwoch',
'Donnerstag','Freitag','Samstag');
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months_d = ('Januar','Februar','März','April','Mai','Juni','Juli',
'August','September','Oktober','November','Dezember');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
@month_num = ('1','2','3','4','5','6','7','8','9','10','11','12');
# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;
if ($hour < 10)
{
$hour = "0$hour";
}
if ($min < 10)
{
$min = "0$min";
}
if ($sec < 10)
{
$sec = "0$sec";
}
if ($mday < 10)
{
$mday = "0$mday";
}
# Format the date.
$date = "$days[$wday], $months[$mon] $mday th $year at $time";
$date_short = "@months[$mon]/$mday/$year, $hour:$min:$sec";
$date_for_exp = "@month_num[$mon]/$mday/$year";
}
sub read_setup
{
open(FILE,"$setupfile") || &no_open ("",$setupfile,__FILE__,__LINE__,"opening setup file");
$options = <FILE>;
close(FILE);
@options = split (/\|/,$options);
##### Admin Password #######
$passwd = "$options[0]";
##### Location of banner file #######
$randomfile = "$options[1]";
##### Location of log file #######
$logfile = "$options[2]";
##### SSI enabled?: yes or no #######
$ssi = "$options[3]";
##### Footer #######
$footer = "$options[4]";
}
sub changesetup
{
if ($demo eq "no")
{
open(FILE,">$setupfile") || &no_open ("",$setupfile,__FILE__,__LINE__,"writing setup file");
print FILE "$contents{'passwd'}\|$contents{'randomfile'}\|$contents{'logfile'}\|$contents{'ssi'}\|$contents{'footer'}";
close(FILE);
&read_setup;
&admin_page("<h3>New Setup written succesfully</h3>");
}
elsif ($demo eq "yes")
{
&admin_page("<h3>This is only a demo.<br> Of course your free copy will handle setup changes</h3>");
}
}
sub check_input
{
@vars = ('text','image','link','passwd','randomfile','logfile','ssi','footer','text');
foreach $var (@vars)
{
if ($contents{$var} =~ /\|/i || $contents{$var} =~ /\"/i)
{
&header;
print qq~
<h3><i>$contents{$var}</i> contains a pipe symbol (|) or quotation marks. Please, do NOT use these characters!</h3>
~;
&footer;
exit;
}
}
}
|