Приглашаем посетить
Русский язык (rus-yaz.niv.ru)

Add Link

#!/usr/bin/perl
# AddLink v.1.2 (beta) for Unix
# Written by: Dave Palmer <dave@upstatepress.com>
# AddLink allows users to add their link to one of your pages
# This version is for Unix machines. A Windows version is available
# as well at: http://www.upstatepress.com/dave/perl.html
################################################################

# Define some variables first

# This is the file that has the links on it (nice grammer)
$linkfile = "/usr/home/upstate/public_html/addlink/usrlinks.html";

# This is the URL of the addlink.pl
$addlink = "/cgi-bin/addlink.cgi";

# This should be the URL of the addlink.html
$newlink = "http://www.upstatepress.com/newlink.html";

# Would you like to be notified by e-mail if some one posts a link? 
# Set this to "yes" or "no"
$notify = "yes";

# This is the path to the mail program. 
$mailprog = "/usr/sbin/sendmail";

# This should be your e-mail address
$my_email = 'dave@upstatepress.com';

# This should be your name
$my_name = 'Dave Palmer';

# This is the URL to the usrlinks.html file
$usrlink = "http://www.upstatepress.com/addlink/usrlinks.html";

# This should point to where you keep your cgi libraries
$library = "/usr/home/upstate/public_html/cgi-bin";

################################################################

require "$library/cgi-lib.pl";

# Get the form input
&ReadParse(*FORM);

# Translate the associative array references
$url = $FORM{'url'};
$sitename = $FORM{'sitename'};
$catagory = $FORM{'catagory'};
$descript = $FORM{'descript'};

if ($notify eq "yes") {
	&sendmail;
	}

# Lets do some error checking. I hate when people screw with us!
if ($url eq 'http://') { &missing_url; }
		&missing_url unless $url;
		&missing_title unless $sitename;

# Now, lets get rid of any HTML tags some one may have tried to enter
$sitename =~ s/<([^>]|\n)*>//g;
$descript =~ s/<([^>]|\n)*>//g;

#suck the linkpage and add the new link
open(FILE, "$linkfile") || die "I can't open $linkpage\n";
	@lines = <FILE>;
	close(FILE);
	$sizelines = @lines;

# Now, re-open the links file, and add the new link
open(FILE, ">$linkfile") || die "I can't open: $linkfile\n";
	
		for ($a = 0; $a <= $sizelines; $a++) {
	
		$_ = $lines[$a];

 	if (/<!--$catagory-->/) {
	
	print FILE $_;
	print FILE "<font size=-1><a href=\"$url\">$sitename</a><br>\n";
	print FILE "$descript</font><br>\n";

		} else {
			print FILE $_;
		}
	}
close(FILE);

print "Location: $usrlink\n\n";

######################
# Sub routines       #
######################

# First off, lets print the header
print "Content-type: text/html\n\n";

sub missing_url {
	print "Content-type: text/html\n\n";
	print "<html><head><title>Missing URL</title></head>\n";
	print "<body>\n";
	print "<font size=+4>You Forgot the URL!</font><br>\n";
	print "You forgot to enter the URL, or the URL you entered<br>\n";
	print "was not a valid URL. Please enter it below<br>\n";
	print "<form action=\"$addlink\" method=GET>\n";
	print "<input type=hidden name=\"sitename\" value=\"$sitename\">\n";
	print "<input type=hidde name=\"descript\" value=\"$descript\">\n";
	print "<input type=hidden name=\"catagory\" value=\"$catagory\">\n";
	print "URL:<input type=text name=\"url\" size=50>\n";
	print "<input type=submit name=\"submit\" value=\"submit\">\n";
	print "<input type=reset name=\"reset\" value=\"reset\"><br><hr><br>\n";
	print "<a href=\"$newlink\">Back to New Link page</a>\n";
	print "</form></body></html>\n";
	exit;
		}

sub missing_title {
	print "Content-type: text/html\n\n";
	print "<html><head><title>Missing Title</title></head>\n";
	print "<body>\n";
	print "<font size=+4>You Forgot the Title!</font><br>\n";
	print "You forgot to enter the title for your site!<br>\n";
	print "Please enter it below<br><hr noshade size=1 width=\"75%\"><br>\n";
	print "<form action=\"$addlink\" method=GET>\n";
	print "<input type=hidden name=\"descript\" value=\"$descript\">\n";
	print "<input type=hidden name=\"catagory\" value=\"$catagory\">\n";
	print "<input type=hidden name=\"url\" value=\"$url\">\n";
	print "Name of site:<input type=text name=\"sitename\" size=40><br>\n";
	print "<input type=submit name=\"submit\" value=\"submit\">\n";
	print "<input type=reset name=\"reset\" value=\"reset\"><br><hr size=1 noshade><br>\n";
	print "</form>\n";
	print "<a href=\"$newlink\">Back to Add Links page</a>\n";
	print "</body></html>\n";
	exit;
		}

sub sendmail {
open(MAIL, "| $mailprog -t") || die "I can't open $mailprog\n";
	print MAIL "To: $my_name <$my_email>\n";
	print MAIL "From: AddLink\n";
	print MAIL "Subject: Someone added a link\n";
	print MAIL "The following URL was added to your add link page\n";
	print MAIL "title: $sitename URL: $url\n";
	print MAIL "Description: $descript\n";
close(MAIL);
		}