#!/usr/bin/perl ############################################################################## # Cliff's Free Links Script Version 2.14 # # Copyright 1998 Shaven Ferret Productions # # Created 6/4/98 Last modified 1/5/2000 # # Available at http://www.shavenferret.com/scripts # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998 Shaven Ferret Productions All Rights Reserved. # # # # This script can be used\modified free of charge as long as you don't # # change this header or any of the parts that give me credit for writing # # this. If you really need to remove the return links, go to # # http://www.shavenferret.com/scripts/register.shtml # # By using this script you agree to indemnify me from any liability # # that might arise from its use. In simple English, if this script somehow # # makes your computer run amuck and kill the pope, it's not my fault. # # # # Redistributing\selling the code for this program without prior written # # consent is expressly forbidden. # ############################################################################## # Enter the PATH (not the URL) to the directory where you will keep the data # files. Do not include a trailing slash. $datadir = "linkdata"; # Enter the PATH (not the URL) to the links page. $linkspath = "/server/path/to/links.html"; # Enter the full URL of the links page. $linksurl = "http://www.yourdomain.com/links.html"; # Enter the URL of the uploaded links.cgi file. $scripturl = "/cgi-bin/links.cgi"; # Enter the path to your mail program. $mailprogram = "/usr/lib/sendmail"; ############################################################################## # Congratulations! You've finished defining the variables. If you want to, # # you can continue screwing with the script, but it isn't necessary. # ############################################################################## unless(-e "$datadir/setup.txt") { open (DATA, ">$datadir/setup.txt"); print DATA "#FFFFFF|#000000|#DD0000|#FF0000|#BB0000||shavenferret.com|No|No|138||My Free Links Page|||No|Yes|Yes|Yes|0\n"; print DATA "Business|This section is for business web pages.\n"; print DATA "Computers|This section is for pages that focus on computers.\n"; print DATA "Education|This section is for pages that focus on education.\n"; print DATA "Entertainment|This section is for pages that focus on entertainment.\n"; print DATA "Government|This section is for pages that focus on government.\n"; print DATA "Miscellaneous|This section is for pages that don't fit into any other catagory.\n"; print DATA "Personal|This section is for personal web pages.\n"; close(DATA); } unless(-e "$datadir/links.txt") { open (DATA, ">$datadir/links.txt"); print DATA "clifftm\@shavenferret.com|Cliff's Perl Script Collection|http://www.shavenferret.com/scripts/|A bunch of free, and somewhat useful perl scripts.|Computers|0|01:05:78|09/18/79\n"; print DATA "webmaster\@shavenferret.com|Shaven Ferret Productions|http://www.shavenferret.com/|Collection of tremendously violent animated gif movies|Entertainment|0|01:05:78|09/18/79\n"; print DATA "clifftm\@shavenferret.com|The Sacred Brotherhood of Cliff|http://www.shavenferret.com/cliff/|Veritas, Decus, et Tantus Oryx|Miscellaneous|0|02:05:23|10/19/98\n"; close(DATA); } { open (DATA, "$datadir/setup.txt"); my @sects = ; close(DATA); chomp($sects[0]); ($bgcolor,$text,$link,$alink,$vlink,$background,$password,$tellthem,$oneemail,$maxlinks,$youremail,$pagetitle,$head,$foot,$lcase,$notify1,$notify2,$notify3,$tellhits) = split(/\|/, shift(@sects)); foreach $sect(@sects) { chomp($sect); (my $x, my $y) = split(/\|/,$sect); push (@sectname,$x); push (@sectdesc,$y); } } if ($ENV{"REQUEST_METHOD"} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; unless ($name eq "head" || $name eq "foot") { $value =~ s/<([^>]|\n)*>//g; $value =~ s///g; } $value =~ s/\n/ /g; $FORM{$name} = $value; } unless ($FORM{'action'} eq "admin" || $FORM{'action'} eq "r") { &active; } if ($FORM{'action'} eq "add_link") { &add_link; } elsif ($FORM{'action'} eq "go") { &go; } elsif ($FORM{'action'} eq "admin") { &admin; } elsif ($FORM{'action'} eq "setup") { &setup; } elsif ($FORM{'action'} eq "add_section") { &add_section; } elsif ($FORM{'action'} eq "delete") { &delete; } elsif ($FORM{'action'} eq "email") { &email; } elsif ($FORM{'action'} eq "lockout") { &lockout; } elsif ($FORM{'action'} eq "unlockout") { &unlockout; } elsif ($FORM{'action'} eq "remove_section") { &remove_section; } elsif ($FORM{'action'} eq "search") { &search; } elsif ($FORM{'action'} eq "random") { &random; } elsif ($FORM{'action'} eq "showdelete") { &showdelete; } elsif ($FORM{'action'} eq "r") { &r; } sub add_link { print "Content-type: text/html\n\n"; $temp = $FORM{'email'}; $temp =~ s/-/a/g; $temp =~ s/_/a/g; unless ($temp =~ /\w+@\w+\.\w\w+/) { print "Bad E-Mail Address\n"; &body("STDOUT"); print "

Bad e-mail address

I'm sorry, but the e-mail\n"; print "address $FORM{'email'} appears to be invalid. Please\n"; print "click back and try again.\n"; exit; } unless ($FORM{'url'} =~ /^(f|ht)tp:\/\/.+\..+/) { print "Bad URL\n"; &body("STDOUT"); print "

Bad URL

\n"; print "I'm sorry, but the URL \n"; print "$FORM{'url'} appears to be invalid. Please click\n"; print "back and try again.\n"; exit; } open (FILE,"$datadir/lockout.txt"); @lockout = ; close(FILE); foreach $lock(@lockout) { chomp($lock); $lock =~ tr/A-Z/a-z/; @temp = ($FORM{'email'},$FORM{'url'},$FORM{'title'},$FORM{'description'}); for ($i = 0; $i <= 3; $i++) { $temp[$i] =~ tr/A-Z/a-z/; if ($temp[$i] =~ /$lock/) { print "Sorry, but that has been locked out.\n"; &body("STDOUT"); print "

Locked out

\n"; print "I'm sorry, but your link contains text that I have locked out.\n"; if ($tellthem eq "Yes") { print "The specific text was $lock\n"; } print "\n"; exit; } } } &readlinks; $i = 0; foreach $section(@sectname) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); $START{$section} = $i; while ($section eq $sect) { if ($FORM{'email'} eq $email && $oneemail eq "Yes") { print "You are limited to one link per e-mail address.\n"; &body("STDOUT"); print "

One link per e-mail address

I'm sorry,\n"; print "but I already have a link that was submitted by\n"; print "$email. The title\n"; print "of the link is $title, and it\n"; print "is described as $desc in my $FORM{'section'} section.\n"; print "\n"; exit; } if ($FORM{'url'} eq $url) { print "URL already listed\n"; &body("STDOUT"); print "

URL already listed

I'm sorry, but your URL\n"; print "is already listed as $title in\n"; print "my $sectname[$i] section. It is described as $desc.\n"; exit; } $i++; ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); } $STOP{$section} = $i; } &gettime; if ($lcase eq "Yes") { $FORM{'title'} =~ tr/A-Z/a-z/; $FORM{'description'} =~ tr/A-Z/a-z/; } splice(@links,$START{$FORM{'section'}},0,"$FORM{'email'}|$FORM{'title'}|$FORM{'url'}|$FORM{'description'}|$FORM{'section'}|0|$time|$date\n"); if ($maxlinks > 0) { while($STOP{$FORM{'section'}} - $START{$FORM{'section'}} >= $maxlinks) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$STOP{$FORM{'section'}}]); splice(@links,$STOP{$FORM{'section'}},1); if ($notify2 eq "Yes") { open(MAIL,"|$mailprogram -t"); print MAIL "To: $email\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Your link has expired.\n"; print MAIL "Unfortunately, I have the number of links\n"; print MAIL "per section limited to $maxlinks, and on $date\n"; print MAIL "at $time your link was rotated out. If you'd\n"; print MAIL "like to come back and add your link again, please\n"; print MAIL "go to $linksurl. Your link used to be:"; &desclink; if ($hits > $tellhits || $tellhits == 0) { print MAIL "While your page was listed, you received\n"; print MAIL "$hits hit(s).\n"; } print MAIL "Thanks for your time!\n\n"; &emailsig; } $STOP{$FORM{'section'}}--; } } &writelinks; &makepage; if ($notify1 eq "Yes") { open(MAIL,"|$mailprogram -t"); print MAIL "To: $FORM{'email'}\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Your link has been added.\n"; print MAIL "Your URL, $FORM{'url'}, has been\n"; print MAIL "successfully added to my links page at\n"; print MAIL "$linksurl. It is listed as:"; print MAIL "\n\nTitle: $FORM{'title'}\n"; print MAIL "URL: $FORM{'url'}\n"; print MAIL "Description: $FORM{'description'}\n"; print MAIL "Section: $FORM{'section'}\n"; print MAIL "Time added: $time\n"; print MAIL "Date added: $date\n\n"; if ($maxlinks > 0) { print MAIL "I have limited the number of links per\n"; print MAIL "section to $maxlinks. Once this number\n"; print MAIL "is reached, your link will be automatically\n"; print MAIL "removed."; if ($notify2 eq "Yes") { print MAIL " You will be notified by e-mail\n"; print MAIL "when this happens."; } } print MAIL "\n\n"; open (FILE,"$datadir/email.txt"); @lines = ; close(FILE); foreach $line(@lines) { print MAIL "$line"; } print MAIL "\n"; &emailsig; } print "Link Added\n"; &body("STDOUT"); print "

Link Added

Your link has been added to my page.\n"; print "Please click back.\n"; exit; } sub body { $which = shift(@_); print $which "\n\n"; } sub makepage { open (FILE,">$linkspath"); print FILE "$pagetitle\n"; &body("FILE"); print FILE "$head\n"; print FILE "
\n"; print FILE "\n"; print FILE "
\n"; print FILE "

Add Your Link

\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; if ($#sectname > 0) { print FILE "\n"; } else { print FILE "\n"; } print FILE "\n"; print FILE "
Your e-mail address:\n"; print FILE "
Your page's URL:\n"; print FILE "
Your page's title:\n"; print FILE "
Your page's description:\n"; print FILE "
Please pick a section:\n"; print FILE "
\n"; print FILE "
\n"; print FILE "
\n"; print FILE "

\n"; print FILE "Search this page\\Go to a random link

\n"; print FILE "\n"; if ($#sectname > 0) { print FILE "\n"; } else { print FILE "\n"; } print FILE "\n"; print FILE "
What do you\n"; print FILE "want to do?Go to a random link
\n"; print FILE "Search for:\n"; print FILE "
What sections are\n"; print FILE "you interested in?\n"; foreach $sect(@sectname) { print FILE "$sect
\n"; } print FILE "
\n"; print FILE "
\n"; if ($#sectname > 0) { print FILE "

[ "; foreach $sect(@sectname) { print FILE "$sect"; unless ($sect eq $sectname[$#sectname]) { print FILE " | "; } } print FILE " ]

\n"; } if ($maxlinks > 0) { $temp = $#sectname + 1; if ($#sectname > 0) { print FILE "Each of the $temp sections"; } else { print FILE "This page"; } print FILE " can hold up to $maxlinks links
\n"; } &gettime; print FILE "Last link added on $date at $time
\n"; $temp = $#links + 1; print FILE "There are $temp links on this page\n"; &sig("FILE"); $j = 0; for ($i = 0; $i <= $#sectname; $i++) { print FILE "

\n"; print FILE "
\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; print FILE "
$sectname[$i]$sectdesc[$i]
\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$j]); while ($sect eq $sectname[$i]) { print FILE "\n"; $j++; ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$j]); } print FILE "
Title
Description
Added
"; print FILE "$title$desc"; print FILE "$atime $adate"; print FILE "
\n"; print FILE "

\n"; } &sig("FILE"); print FILE "$foot\n"; print FILE "

Administration

\n"; print FILE "Password:
\n"; print FILE "\n"; close(FILE); } sub gettime { ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6]; $mon++; $year += 1900; if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($mday < 10) { $mday = "0$mday"; } $date = "$mon/$mday/$year"; $time = "$hour:$min:$sec"; } sub emailsig { # Please DON'T screw with this sub, or any place where it is called. print MAIL "\n****************************************************\n"; print MAIL "* I'm using Cliff's Free Links Script. *\n"; print MAIL "* This FREE script is easy to manage, and has many *\n"; print MAIL "* useful features. If you'd like to use it too, *\n"; print MAIL "* go to http://www.shavenferret.com/scripts/links/ *\n"; print MAIL "****************************************************\n"; close(MAIL); } sub go { &readlinks; ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$FORM{'link'}]); $hits++; $links[$FORM{'link'}] = "$email|$title|$url|$desc|$sect|$hits|$atime|$adate"; &writelinks; print "Location: $url\n\n"; } sub admin { &checkpassword; print "Administration\n"; &body(STDOUT); unless(-e "$datadir/active.txt") { print "
\n"; print "\n"; print "\n"; print "
Hello. I am trying to keep track of how many people\n"; print "are using this script. Please click the button below to let\n"; print "me know that you are using it. After you do this, you will be\n"; print "able to access the real admin page.\n"; print "
\n"; print "\n"; exit; } print "
Rate this Script @ The CGI Resource Index
\n"; print "

Administration

\n"; print "
\n"; print " \n"; print " \n"; print "\n"; print "
Want to be notified whenever I release a new version of this script?\n"; print "
Your e-mail:
\n"; print "
\n"; &readlinks; if (@links) { print "

Delete a link

\n"; print "To keep this page from getting to big, this feature\n"; print "has been moved to its own page. To go there, click\n"; print "\n"; print "\n"; print ".
\n"; print "

\n"; } $i = 0; $thits = 0; $ex[3] = -1; foreach $link(@links) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$link); $thits += $hits; if ($hits > $ex[0]) { $ex[0] = $hits; $ex[1] = $title; $ex[2] = $i; } if ($hits < $ex[3] || $ex[3] == -1) { $ex[3] = $hits; $ex[4] = $title; $ex[5] = $i; } $i++; } print "

Stats

    \n"; print "
  • Total outgoing hits: $thits\n"; $ex[6] = $#links + 1; print "
  • Total links: $ex[6]\n"; if ($ex[6] != 0) { $av = $thits / $ex[6]; } print "
  • Average hits per page: $av\n"; print "
  • Page receiving most hits: $ex[1] ($ex[0] hits)\n"; print "
  • Page receiving least hits: $ex[4] ($ex[3] hits)\n"; print "

Lock out text

\n"; print "\n"; print "\n"; print "
\n"; print "
Text to lock out:\n"; print "
\n"; print "Should I e-mail webmasters whose links are removed?\n"; print "
\n"; print "\n"; print "
\n"; print "

Un-lock out text

\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; open (FILE,"$datadir/lockout.txt"); @lockout = ; close(FILE); for($i = 0; $i <= $#lockout; $i++) { print "\n"; } print "
"; print "$lockout[$i]
\n"; print "

\n"; if ($#sectname > 0) { print "

Remove a section

\n"; print "\n"; print "\n"; print "
\n"; print "
What section do you want to remove?
What should I do with\n"; print "the links in that section?
Should I e-mail the people\n"; print "who have links in the section you are removing to let them know what\n"; print "is going on?
\n"; print "

\n"; } print "

Add a section

\n"; print "\n"; print "\n"; print "
\n"; print "
Name:\n"; print "
Description:\n"; print "
\n"; print "\n"; print "

\n"; print "

E-mail confirmation

\n"; print "\n"; print "\n"; print "When the script e-mails someone after their link is added, it will\n"; print "first tell them the basic information about their link, then if it will ever be\n"; print "rotated out, and then if they will be e-mailed when it is rotated out.\n"; print "After that, it will send whatever you put in the text area below.\n"; print "You might want to put a short description of your page, or request\n"; print "a link exchange (if you want a link exchange script, go \n"; print "here)
\n"; print "
\n"; print "

Setup

\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
1) Background color:
2) Text color:\n"; print "
3) Link color:\n"; print "
4) Active link color:\n"; print "
5) Visited link color:\n"; print "
6) URL of background image:\n"; print "
7) Administrative password:\n"; print "
8) When someone tries to add a link that contains locked-"; print "out text, should I tell them what that text was?\n"; print "
9) Should I limit people\n"; print "to one link per e-mail address?\n"; print "
10) What is the maximum\n"; print "number of links you want per section?
Enter 0 to keep them all\n"; print "
\n"; print "
11) What is your e-mail address?
12) What is the title for your free links page?\n"; print "
13) If you'd like anything displayed at the top of the page,\n"; print "enter the HTML here:\n"; print "
14) If you'd like anything displayed below\n"; print "the links, enter the HTML here:\n"; print "
15) Would you like me to convert all titles and\n"; print "descriptions to lower case?\n"; print "
17) Do you want the script to e-mail\n"; print "webmasters when their link is added?
18) Do you want the script to e-mail\n"; print "webmasters when their link is removed?
19) Do you want the script to e-mail\n"; print "you when someone tries to guess your password?
20) Do you want the script\n"; print "to tell webmasters how many hits their page received when their\n"; print "link is rotated out?
ignore this if you answered no for question 18
No
\n"; } else { print ">No
\n"; } print "Yes, but only if the page receives more than hits
\n"; print "\n"; print "
\n"; exit; } sub checkpassword { print "Content-type: text/html\n\n"; if ($FORM{'password'} eq "") { print "You need a password for that!\n"; &body("STDOUT"); print "I'm sorry, but you need the password to do that.\n"; exit; } elsif ($FORM{'password'} ne $password) { if (($ENV{'REMOTE_HOST'} eq $ENV{'REMOTE_ADDR'}) && ($ENV{'REMOTE_ADDR'} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/)) { $Address = pack('C4', $1, $2, $3, $4); $DNS_Address = (gethostbyaddr($Address, 2))[0]; $ENV{'REMOTE_HOST'} = $DNS_Address if $DNS_Address; } print "Bad password\n"; &body("STDOUT"); print "

Bad Password


\n"; print "The password you entered, $FORM{'password'}, is incorrect.\n"; if ($notify3 eq "Yes" && $youremail) { print "The following information has been mailed to the owner of\n"; print "this Free Links page.
    \n"; &gettime; print "
  • Date/Time: $date $time\n"; print "
  • Domain: $ENV{'REMOTE_HOST'}\n"; print "
  • IP Address: $ENV{'REMOTE_ADDR'}"; print "
  • Password: $FORM{'password'}\n"; print "
\n"; open (MAIL,"|$mailprogram -t"); print MAIL "To: $youremail\n"; print MAIL "From: hell.if\@i.know\n"; print MAIL "Subject: Attempted hack\n\n"; print MAIL "Someone has tried to guess your password for your\n"; print MAIL "Free Links page! The following information was logged:\n"; print MAIL "* Date/Time: $date $time\n"; print MAIL "* Domain: $ENV{'REMOTE_HOST'}\n"; print MAIL "* IP Address: $ENV{'REMOTE_ADDR'}\n"; print MAIL "* Password: $FORM{'password'}\n"; close (MAIL); } exit; } } sub setup { &checkpassword; open (DATA, ">$datadir/setup.txt"); if ($FORM{'tellhits'} == 0) { $FORM{'tellhits'} = $FORM{'th'}; } $temp = "$FORM{'bgcolor'}|$FORM{'text'}|$FORM{'link'}|$FORM{'alink'}|$FORM{'vlink'}|$FORM{'background'}|$FORM{'pw'}|$FORM{'tellthem'}|$FORM{'oneemail'}|$FORM{'maxlinks'}|$FORM{'youremail'}|$FORM{'pagetitle'}|$FORM{'head'}|$FORM{'foot'}|$FORM{'lcase'}|$FORM{'notify1'}|$FORM{'notify2'}|$FORM{'notify3'}|$FORM{'tellhits'}\n"; print DATA "$temp"; for ($i = 0; $i <= $#sectname; $i++) { print DATA "$sectname[$i]|$sectdesc[$i]\n"; } close(DATA); ($bgcolor,$text,$link,$alink,$vlink,$background,$password,$tellthem,$oneemail,$maxlinks,$youremail,$pagetitle,$head,$foot,$lcase,$notify1,$notify2,$notify3,$tellhits) = split(/\|/, $temp); &readlinks; &makepage; print "Setup changed\n"; &body("STDOUT"); print "

Setup changed

The setup has been changed.\n"; &goback($FORM{'pw'}); } sub goback { $pw = shift(@_); print "Click
\n"; print "\n"; print "
to go back.\n"; print "\n"; exit; } sub add_section { &checkpassword; push(@sectname,"$FORM{'name'}"); push(@sectdesc,"$FORM{'description'}"); open (DATA, ">$datadir/setup.txt"); print DATA "$bgcolor|$text|$link|$alink|$vlink|$background|$password|$tellthem|$oneemail|$maxlinks|$youremail|$pagetitle|$head|$foot|$lcase|$notify1|$notify2|$notify3|$tellhits\n"; for ($i = 0; $i <= $#sectname; $i++) { print DATA "$sectname[$i]|$sectdesc[$i]\n"; } close(DATA); &readlinks; &makepage; print "Section Added\n"; &body("STDOUT"); print "

Section Added

The section has been added.\n"; &goback($FORM{'password'}); } sub delete { &checkpassword; &readlinks; for ($i = $#links; $i >= 0; $i--) { if ($FORM{$i} eq "delete") { if ($FORM{'email'} eq "Yes") { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); open(MAIL,"|$mailprogram -t"); print MAIL "To: $email\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Your link has been removed.\n"; print MAIL "Hello. This is to let you know that your link has been\n"; print MAIL "removed from my free links page at $linksurl\n"; if ($FORM{'why'} eq "something else.") { $FORM{'why'} = $FORM{'other'}; } print MAIL "$FORM{'why'}\n\n"; print MAIL "Your link was:"; &desclink; &emailsig; } splice(@links,$i,1); } } &writelinks; &makepage; print "Deleted\n"; &body("STDOUT"); print "

Deleted

All checked off links have been deleted.\n"; &goback($FORM{'password'}); } sub desclink { print MAIL "\n\nTitle: $title\n"; print MAIL "URL: $url\n"; print MAIL "Description: $desc\n"; print MAIL "Section: $sect\n"; print MAIL "Time added: $atime\n"; print MAIL "Date added: $adate\n"; } sub email { &checkpassword; open (FILE,">$datadir/email.txt"); print FILE "$FORM{'email'}\n"; close(FILE); print "E-mail Confirmation Changed.\n"; &body("STDOUT"); print "The following will go out in confirmation e-mails:\n"; print "
\n";
        print "$FORM{'email'}
\n"; &goback($FORM{'password'}); } sub sig { # Please DON'T screw with this sub, or any place where it is called. $which = shift(@_); print $which "

Free Links script by Cliff(tm), Shaven "; print $which "Ferret Productions, and can be found at http://www."; print $which "shavenferret.com/scripts.
\n"; } sub lockout { &checkpassword; open (FILE,">>$datadir/lockout.txt"); print FILE "$FORM{'lockout'}\n"; close(FILE); &readlinks; for ($i = $#links; $i >= 0; $i--) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); $FORM{'lockout'} =~ tr/A-Z/a-z/; @temp = ($title,$desc,$email,$url); for ($j = 0; $j <= 3; $j++) { $temp[$j] =~ tr/A-Z/a-z/; if ($temp[$j] =~ /$FORM{'lockout'}/) { splice (@links,$i,1); if ($FORM{'email'} > 0) { open(MAIL,"|$mailprogram -t"); print MAIL "To: $email\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Your link has been removed.\n"; print MAIL "Hello. Your link:"; &desclink; print MAIL "has been removed from my links page at\n"; print MAIL "$linksurl because\n"; print MAIL "the title, description, or URL contained"; print MAIL " text that I have locked out."; if ($FORM{'email'} == 2) { print MAIL " That\ntext was $FORM{'lockout'}\n"; } &emailsig; } } } } &writelinks; &makepage; print "Locked out\n"; &body("STDOUT"); print "

Locked Out

The text has been locked out, and all\n"; print "pages containing it have been removed.\n"; &goback($FORM{'password'}); } sub unlockout { &checkpassword; open (FILE,"$datadir/lockout.txt"); @locks = ; close(FILE); for ($i = $#locks; $i >= 0; $i--) { if ($FORM{$i} == -1) { splice(@locks,$i,1); } } open (FILE,">$datadir/lockout.txt"); foreach $lock(@locks) { print FILE "$lock"; } close(FILE); print "Un-Locked out\n"; &body("STDOUT"); print "

Un-Locked Out

The text has been un-locked out.\n"; &goback($FORM{'password'}); } sub remove_section { &checkpassword; if ($FORM{'kill'} eq $FORM{'do'}) { print "Can't do that...\n"; &body("STDOUT"); print "

Sorry

You asked me to move all links from the\n"; print "section that you're deleting to the section you're deleting.\n"; &goback($FORM{'password'}); } &readlinks; for($i = $#links; $i >= 0; $i--) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); if ($sect eq $FORM{'kill'}) { if ($FORM{'do'} ne "delete") { $links[$i] = "$email|$title|$url|$desc|$FORM{'do'}|$hits|$atime|$adate"; splice(@moves,0,0,$links[$i]); } splice(@links,$i,1); if ($FORM{'email'} eq "Yes") { open(MAIL,"|$mailprogram -t"); print MAIL "To: $email\n"; print MAIL "From: $youremail\n"; if ($FORM{'do'} eq "delete") { print MAIL "Subject: Your link has been removed.\n"; } else { print MAIL "Subject: Your link has been moved.\n"; } print MAIL "Hello. Your link,"; &desclink; if ($FORM{'do'} eq "delete") { print MAIL "has been deleted from my page\nat $linksurl\n"; } else { print MAIL "has been moved to the $FORM{'do'} section\nof my links page at $linksurl\n"; } print MAIL "because I have removed my $FORM{'kill'} section.\n"; &emailsig; } } } open (DATA, ">$datadir/setup.txt"); print DATA "$bgcolor|$text|$link|$alink|$vlink|$background|$password|$tellthem|$oneemail|$maxlinks|$youremail|$pagetitle|$head|$foot|$lcase|$notify1|$notify2|$notify3|$tellhits\n"; for ($i = 0; $i <= $#sectname; $i++) { unless($FORM{'kill'} eq $sectname[$i]) { print DATA "$sectname[$i]|$sectdesc[$i]\n"; } else { splice(@sectname,$i,1); $i--; } } $i = 0; foreach $section(@sectname) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); $START{$section} = $i; while ($section eq $sect) { $i++; ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); } } if ($FORM{'do'} ne "delete") { foreach $move(@moves) { splice(@links,$START{$FORM{'do'}},0,$move); } } &writelinks; close(DATA); &makepage; print "Section Removed\n"; &body("STDOUT"); print "

Section Removed

The section has been removed.\n"; &goback($FORM{'password'}); } sub search { $FORM{'search'} =~ tr/A-Z/a-z/; &readlinks; print "Content-type: text/html\n\n"; print "Results\n"; &body("STDOUT"); print "

Results

The following pages contained the text $FORM{'search'}:\n"; &sig("STDOUT"); print "
\n"; print "\n"; print "\n"; print "\n"; for($i = 0; $i <= $#links; $i++) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); $url =~ tr/A-Z/a-z/; $desc =~ tr/A-Z/a-z/; $title =~ tr/A-Z/a-z/; if (($title =~ /$FORM{'search'}/ || $url =~ /$FORM{'search'}/ || $desc =~ /$FORM{'search'}/) && ($FORM{$sect} == -1)) { print "\n"; print "\n"; print "\n"; } } print "
Section
Title
Description
$sect$title$desc
\n"; &sig("STDOUT"); print "\n"; } sub random { &readlinks; for($i = 0; $i <= $#links; $i++) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$i]); if ($FORM{$sect}) { push(@results,$i); } } unless ($#results >= 0) { print "Content-type: text/html\n\n"; print "Please try again\n"; &body("STDOUT"); print "

Please try again

I'm sorry, but I don't have any\n"; print "links in the section(s) you checked off. Please click back\n"; print "and try again.\n"; exit; } else { srand(); $i = int(rand($#results+1)); ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$links[$results[$i]]); $hits++; $links[$results[$i]] = "$email|$title|$url|$desc|$sect|$hits|$atime|$adate"; &writelinks; print "Location: $url\n\n"; } } sub writelinks { open (FILE,">$datadir/links.txt"); flock (FILE, 2); foreach $line(@links) { print FILE "$line"; } close(FILE); } sub readlinks { open (FILE,"$datadir/links.txt"); @links = ; close(FILE); } sub showdelete { &checkpassword; print "Delete a link.\n"; &body("STDOUT"); print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; &readlinks; $i = 0; $thits = 0; $ex[3] = -1; foreach $link(@links) { ($email,$title,$url,$desc,$sect,$hits,$atime,$adate) = split(/\|/,$link); $thits += $hits; if ($hits > $ex[0]) { $ex[0] = $hits; $ex[1] = $title; $ex[2] = $i; } if ($hits < $ex[3] || $ex[3] == -1) { $ex[3] = $hits; $ex[4] = $title; $ex[5] = $i; } print "\n"; $i++; } print "
"; print "$title"; print "$desc$hits hits
\n"; print "\n"; print "\n"; print "
\n"; print "Should I e-mail the webmasters whose links are removed?\n"; print "
\n"; print "If you answered yes, why are you deleting this link?
\n"; print "If you answered "something else", please explain why you\n"; print "are deleting this link.\n"; print "
\n"; print "\n"; } sub active { unless(-e "$datadir/active.txt") { print "Content-type: text/html\n\n"; print "Please activate the script first\n"; &body("STDOUT"); print "Please go to the admin page and activate the script, first.\n"; print "\n"; exit; } } sub r { open(FILE,">$datadir/active.txt"); close(FILE); &admin; }