#!/usr/bin/perl ################ # basic set up # ################ #$url = "http://your_url/"; #$dir = "/your_directory/public_html/"; #$smpath = "/usr/sbin/sendmail"; $addrss = 'your@mail.address'; $tool = "admin"; $pswd = "your_password"; $lfile = "link.html"; $tfile = "temp.dat"; $lock = 20; $exprs = 600; $erro0 = "This is not an error."; $erro1 = "Someone is adding a link to LazyLinksLimited right now."; $erro2 = "If it persists, please inform the webmaster."; $erro3 = "Fail to handle data/working file."; $erro4 = "The CGI stalled. This may be serious."; $erro5 = "You may retry but if it fails please inform the webmaster."; $erro6 = "Fail to handle directory."; $erro7 = "Unknown command or wrong password."; if ($ENV{'SERVER_NAME'}) { $self = "http://".$ENV{'SERVER_NAME'}.$ENV{'SCRIPT_NAME'}; } else { $self = $ENV{'SCRIPT_NAME'}; } if (!$url) {($url = $self) =~ s/[^\/]*$//;} $url .= $lfile; $lock = $lock/86400; ############### # main script # ############### if ($ENV{'QUERY_STRING'} eq $tool) { &tool; } elsif ($ENV{'REQUEST_METHOD'} ne 'POST') { print "Location: $url\n\n"; } else { ### get input ### read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pair = split(/&/, $input); foreach (@pair) { ($name, $value) = split(/=/); $value =~ tr/+/ /; $value =~ s/%0D%0A/
/g; $value =~ s/%0A/
/g; $value =~ s/%0D/
/g; $value =~ s/%09/     /g; $value =~ s/%3C/</g; $value =~ s/%3E/>/g; $value =~ s/%(..)/pack("c", hex($1))/ge; $data{$name} = $value; } if ($data{'do'} ne "edit") { &addurl; } elsif ($data{'pswd'} eq $pswd) { &edit; } else { &error1($erro7); } } exit; ########### # add url # ########### sub addurl { ### data preparation ### $newd = <<"NEW_URL";

$data{'title'}
$data{'descript'} NEW_URL $newd =~ s/[\t\n\r\f]/ /g; $newd = "\t".$newd; $group = $data{'group'}; &open; &lock; ### add new link ### while () { print LOCK; if (//) { print LOCK $newd."\n"; $thank = "URL has been successfully added."; $mlsub = "New link on LazyLinksLimited"; } } if (!$thank) { print LOCK "\n".$newd; $thank = "CGI couldn't find appropriate group. It may be fixed by the webmaster."; $mlsub = "LazyLinksLimited couldn't find group"; } &close; &thnks; ### mail notice ### if (smpath) { open (MAIL, "|$smpath -t -oi"); print MAIL <<"LINK_NOTICE"; To: $addrss Subject: $mlsub group: $data{'group'} link: $data{'url'} title: $data{'title'} $data{'descript'} by $data{'name'} <$data{'email'}> LINK_NOTICE close MAIL; } } ##################### # admin page starts # ##################### sub tool { $exprs = gmtime($exprs + time); $exprs =~ tr/ //s; ($wday,$mon,$mday,$hms,$year) = (split /\s/,$exprs); $exprs = sprintf ("%s, %02d %s %04d %s GMT",$wday,$mday,$mon,$year,$hms); print <<"ADMIN_HEAD"; Expires: $exprs Content-type: text/html Webmaster Only!

This is the webmaster's administrative page.

If you are here by mistake,
LazyLinksLimited is Here.
PLEASE ENTER

If you are here to hack the site, please don't.
ADMIN_HEAD &open; while () { if (/^/) { $lnkid = $1; if ($lnkid =~ /\D/) { print "

Group: $lnkid\n"; } elsif ($' =~ /^\t/) { print <<"ADMIN_BODY";

$'
DELETE this link


ADMIN_BODY } } } print <<"ADMIN_FOOT";

Password:

ADMIN_FOOT } ############# # edit link # ############# sub edit { &open; &lock; while () { unless ((/^\t/) and ($data{$1} eq "D")) { print LOCK; } } &close; $thank = "link page has been successfully edited."; &thnks; } ################## # open data file # ################## sub open { if ($dir) { chdir $dir or &error1("LINE-214",$erro6,$erro2,$!); } open(DATAF,"<$lfile") or &error1("LINE-216",$erro3,$erro2,$!); } ################## # open lock file # ################## sub lock { if ((-e $tfile) and (-M $tfile < $lock)) { &error1($erro0,$erro1,$erro2,$!); } open (LOCK, ">$tfile") or &error1("LINE-228",$erro3,$erro2,$!); } ######################## # close files & rename # ######################## sub close { close DATAF; close LOCK; if (-s $tfile) { rename $tfile, $lfile or &error2("LINE-240",$erro3,$erro2,$!); } else { &error2("LINE-242",$erro3,$erro2,$!); } } ##################### # thank you message # ##################### sub thnks { print <<"THANKS"; Content-type: text/html Thank you :-)

Hello there!

$thank

You may need to click the reload button to see the latest change on the link page. THANKS } ##################### # Error No1 message # ##################### sub error1 { print <<"ERROR_M"; Content-type: text/html Error!

Dear Guest,

Your command has been averted due :
$_[0]
$_[1]
$_[2]
$_[3] ERROR_M exit; } ##################### # Error No2 message # ##################### sub error2 { unlink $tfile or &error1($_[0],$erro4,$erro5,$!); &error1; } #-- End of link.cgi # # LazyLinksLimited, Version 2 # visitware (C) 1999-2002 B. Uchina # All rights reserved # http://www.visitware.com/sobaya/