#!/usr/bin/perl ############################################################################## # Cliff's Links Trader Version 1.52 # # Copyright 1998 Shaven Ferret Productions # # Created 7/02/98 Last Modified 11/30/98 # # 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 part that gives me credit for writing this. If # # you really need to change these things, go to # # http://www.shavenferret.com/scripts/registers.shtml . By using this script # # you agree to indemnify me from any liability that might arise from its use.# # # # Redistributing\selling the code for this program without prior written # # consent is expressly forbidden. # ############################################################################## # Enter the path to the data file. if you put the data file in the same # directory as the script, you can leave this as it is. $datafile = "/home/yutopian/html/links/linkt.txt"; # Enter the location of your mail program. $mailprogram = "/usr/sbin/sendmail"; # Enter the full URL of this script once it is uploaded $scripturl = "http://www.yutopian.com/cgi-bin/linkt.cgi"; # If you don't have libwww-perl on your system, delete the next line use LWP::Simple; $lwp = 1; ############################################################################## # Congratulations! You've finished defining the variables. If you want to, # # you can continue screwing with the script, but it isn't necessary. # ############################################################################## $| = -1; if ($ENV{"REQUEST_METHOD"} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } # Put the data into variables @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; $FORM{$name} = $value; } unless ($FORM{'action'} eq "go" || $FORM{'action'} eq "random") { print "Content-type: text/html\n\n"; } # Get the settings open (DATA, "$datafile"); flock(DATA,2); @data = ; close(DATA); chomp($data[0]); ($pagetitle,$bgcolor,$text,$link,$alink,$vlink,$background,$yourlink,$password,$notify1,$notify2,$notify3,$notify4,$youremail,$howmany) = split(/\|/, shift(@data)); srand(); # Decide what to do if ($FORM{'action'} eq "trade") { ™ } elsif ($FORM{'action'} eq "submit") { &submit; } elsif ($FORM{'action'} eq "admin") { &admin; } elsif ($FORM{'action'} eq "setup") { &setup; } elsif ($FORM{'action'} eq "approve") { &approve; } elsif ($FORM{'action'} eq "delete") { &delete; } elsif ($FORM{'action'} eq "check") { ✓ } elsif ($FORM{'action'} eq "go") { &go; } elsif ($FORM{'action'} eq "random") { &random; } else { &links; } sub links { print "$pagetitle\n"; &body; &sig; print "
\n"; print "

$pagetitle

\n"; if ($#data >= 0) { for ($i = 0; $i <= $#data; $i++) { $data[$i] = "$i|" . $data[$i];} } while(@data) { $i = int(rand(@data)); push(@temp, splice(@data, $i, 1)); } if ($howmany < 1) { $howmany = $#temp; print "All links are displayed\n"; } else { print "$howmany of the $#temp links are displayed on this page\n"; $howmany--; } print "
[Random Link]
\n"; if ($howmany > $#temp) { $howmany = $#temp; } print "\n"; print "\n"; print "\n"; for ($i = 0; $i <= $howmany; $i++) { ($num,$title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$temp[$i]); if ($approved) { print "\n"; } } print "
Title
Description
$title$desc
Webmasters: Click here to add your link!
\n"; &sig; print "
Administration
Password: \n"; print "
\n"; print "\n"; exit; } sub body { print "\n"; } sub sig { # Please DON'T change this sub, or any place where it is called # print "

Link Trader Script by Cliff, Shav"; # print "en Ferret Productions, and available @ http://"; # print "www.shavenferret.com/scripts/
\n"; } sub trade { print "
Add your link!\n"; &body; &sig; print "

Add Your URL

Please follow these easy steps...

    \n"; print "
  1. We will add your site to our world famous search engine, plus link to your page from our main link page and another link page that matches the theme of your site.\n"; print "

    \n"; print "
  2. All we ask in return for this service is a link back to us. Please copy and paste the following text HTML onto your web page (before submitting this form). If you prefer button or banner links, get codes here:
    \n"; print "

    \n"; print "The code will produce one of the following links on your page:

    \n"; print "$yourlink
    \n"; print "Text Link
    \n"; print "
    \n"; print "
    \n"; print "Button Link
    \n"; print "
    \n"; print "
    \n"; print "Banner Link
    \n"; print "
    \n"; print "
    \n"; print "
  3. Fill out this form AFTER you've inserted our code onto you page so that we know what kind of link to return (banner, button, or text). All fields are required. Due to the high volume of request, application may take up to 6 weeks. Please don't reapply within this period or your application may be rejected by the system. We check our return links temporarily, your link will be dropped if you fail to return link to us.
    \n"; print "
    \n"; print "\n"; print "\n"; print "\n"; print "
    Your e-mail address:\n"; print "
    URL of your page that we should link to:\n"; print "
    URL of your page that links back to us:\n"; print "
    Your web page title:\n"; print "
    Description of your page:\n"; print "
    \n"; print "\n"; print "
    \n"; print "
    \n"; print "
  4. Please check everything over, and click \n"; &sig; print "
  5. \n"; exit; } sub submit { # Make sure everything's there. unless ($FORM{'title'} && $FORM{'desc'} && $FORM{'url'} && $FORM{'exchange'} && $FORM{'email'}) { print "Missing Information\n"; &body; print "

    Missing Information

    We're sorry, but it would appear\n"; print "that you've forgotten to fill something out. Please click\n"; print "back and try again.\n"; exit; } # Make sure the email and urls are valid $temp = $FORM{'email'}; $temp =~ s/-/a/g; $temp =~ s/_/a/g; unless ($temp =~ /\w+@\w+\.\w\w+/) { print "Bad e-mail\n"; &body; print "

    Bad e-mail

    The e-mail address that you've entered,\n"; print "$FORM{'email'}, is invalid. Please click back and try again\n"; exit; } $badurl = 0; for ($i = 0; $i < 2; $i++) { if ($i == 0) { $test = $FORM{'url'}; } else { $test = $FORM{'exchange'}; } $test =~ s/-/a/g; $test =~ s/_/a/g; unless ($test =~ /^(f|ht)tp:\/\/\w+\.\w\w+/) { print "Bad URL\n"; &body; print "

    Bad URL

    \n"; print "The URL you entered, $test, is invalid. Please click\n"; print "back and try again.\n"; exit; } } # add the link to the data file open (DATA, ">>$datafile"); flock(DATA,2); print DATA "$FORM{'title'}|$FORM{'desc'}|$FORM{'email'}|$FORM{'exchange'}|$FORM{'url'}|0|0\n"; close(DATA); # e-mail you if ($notify1 && $youremail) { open (MAIL,"|$mailprogram -t"); print MAIL "To: $youremail\n"; print MAIL "From: $FORM{'email'}\n"; print MAIL "Subject: Please approve link exchange\n"; print MAIL "$FORM{'email'} has stopped by your page\n"; print MAIL "and requested a link exchange. Please come to\n"; print MAIL "$scripturl and approve their link.\n"; close(MAIL); } if ($notify2) { open (MAIL,"|$mailprogram -t"); print MAIL "To: $FORM{'email'}\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Thank you!\n"; print MAIL "Thanks for submitting your link! If you haven't\n"; print MAIL "done so already, please copy and paste the following\n"; print MAIL "HTML into your page at $FORM{'exchange'}:\n\n"; print MAIL "$yourlink\n\n"; print MAIL "$Please note that due to popular demand, it takes\n\n"; print MAIL "$an average of six (6) weeks for your page to appear\n\n"; print MAIL "$on our site, thank you for being patient\n\n"; &emailsig; close(MAIL); } # prints out a response print "Thank you!\n"; &body; print "

    Thank you!

    Thanks for submitting your link!\n"; print "We will check it out as soon as possible.\n"; exit; } sub admin { &checkpassword; print "Administration\n"; &body; print "
    Rate this Script @ The CGI Resource Index
    \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"; print "

    Approve a link

    \n"; $notapproved = 0; $num = 0; foreach $line(@data) { chomp($line); ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$line); unless ($approved) { print "
    \n"; print "\n"; print "\n"; print "\n"; &linkhtml($line); if ($lwp) { $temp = get($exchange); $temp =~ s/\n/ /g; $temp =~ s/\s+/ /g; print "Your return link:\n"; if ($temp =~ /$yourlink/) { print "is up, but you might not want to trust this.\n"; } else { print "is not up, but you might not want to trust this.\n"; } } print "Should I convert the title and description to lower case?\n"; print "\n"; print "What should I do?\n"; print "\n"; print "If you chose to delete this link, what should I tell the webmaster?\n"; print "\n"; print "If you picked "Something else", what should I tell the webmaster?\n"; print "\n"; print "\n"; print "\n"; print "

    \n"; $notapproved++; } $num++; } print "


    Statistics

      \n"; $lowest[0] = 9999999; for ($i = 0; $i <= $#data; $i++) { ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$data[$i]); $total += $hits; if ($hits > $highest[0]) { $highest[0] = $hits; $highest[1] = $url; $highest[2] = $title; } if ($hits < $lowest[0]) { $lowest[0] = $hits; $lowest[1] = $url; $lowest[2] = $title; } } if (($#data + 1) != 0) { $average = ($total / ($#data + 1)); } else { $average = "N\A"; } print "
    • Number of links: $#data\n"; print "
    • Total outgoing hits: $total\n"; print "
    • Average hits per page: $average\n"; print "
    • Highest number of hits: $highest[2] ($highest[0] hits)\n"; print "
    • Lowest number of hits: $lowest[2] ($lowest[0] hits)\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 "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } else { print " selected>No\n"; print "\n"; } else { print " selected>No\n"; print "\n"; } else { print " selected>No\n"; print "\n"; } else { print " selected>No\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
      Title of links page:
      Background color:
      Text color:
      Link color:
      Active link color:
      Visited link color:
      URL of background image
      What should your return link say?
      What password do you want to use?
      Do you want to be notified by email when a link is submitted?
      Do you want to be notified by email when someone tries to guess your password?
      Do you want this script to automatically e-mail a reminder to add your link whenever someone submits a link?
      Do you want this script to automatically e-mail webmasters when their link is approved?
      Your e-mail address:
      How many links should I display on the page? Enter -1 to show them all.
      \n"; print "

      \n"; print "

      Modify approved links

      \n"; $num = 0; foreach $line(@data) { chomp($line); ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$line); if ($approved == 1) { print "
      \n"; print "\n"; print "\n"; print "\n"; &linkhtml($line); print "What should I do?\n"; print "\n"; print "If you chose to delete this link, what should I tell the webmaster?\n"; print "\n"; print "If you picked "Something else", what should I tell the webmaster?\n"; print "\n"; print "\n"; print "\n"; print "

      \n"; $appr++; } $num++; } unless ($appr > 0) { print "No approved links to modify with!\n"; } else { print "


      Check for return links

      \n"; if ($lwp) { print "This form can be used to make sure all the return link pages\n"; print "contain certain text, by default, your link, and let you know\n"; print "which pages have it and which don't.\n"; print "
      \n"; print "\n"; print "
      \n"; print "\n"; print "
      What text should I search the pages for?\n"; print "
      Warning: This may take some time. Expect to wait about 2.5 seconds per link\n"; $i = $appr * 2; print "($i seconds total)
      \n"; } else { print "
      Because you are not using libwww-perl, I cannot check the\n"; print "links for you. However, I can give you this wonderful list\n"; print "of where your return link is supposed to be. Each link will\n"; print "open in a new window...
        If you are\n"; print "a system administrator, and you'd like to get libwww-perl,\n"; print "you can find it at http://www.ics.uci.edu/pub/websoft/li"; print "bwww-perl/\n"; foreach $line(@data) { chomp($line); ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$line); if ($approved == 1) { print "
      • $title\n"; } } print "
      \n"; } } if ($lwp == 1 && $notapproved > 0) { &believe; } print "\n"; exit; } sub checkpassword { if ($FORM{'password'} eq "") { print "You need a password for that!\n"; 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(); print "

      Bad Password


      \n"; print "The password you entered, $FORM{'password'}, is incorrect.\n"; if ($notify2 && $youremail) { print "The following information has been mailed to the owner of\n"; print "this page.
        \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 "link trading page! The following information was grabbed:\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 (FILE,">$datafile"); flock(FILE,2); print FILE "$FORM{'pagetitle'}|$FORM{'bgcolor'}|$FORM{'text'}|$FORM{'link'}|$FORM{'alink'}|$FORM{'vlink'}|$FORM{'background'}|$FORM{'yourlink'}|$FORM{'pw'}|$FORM{'notify1'}|$FORM{'notify2'}|$FORM{'notify3'}|$FORM{'notify4'}|$FORM{'youremail'}|$FORM{'howmany'}\n"; foreach $line(@data) { print FILE "$line"; } close(FILE); print "Setup Changed.\n"; &body; print "The setup file has been changed. \n"; &back("pw"); exit; } sub approve { &checkpassword; if ($FORM{'lcase'} == -1) { $FORM{'title'} =~ tr/A-Z/a-z/; $FORM{'desc'} =~ tr/A-Z/a-z/; } open (FILE,">$datafile"); flock(FILE,2); print FILE "$pagetitle|$bgcolor|$text|$link|$alink|$vlink|$background|$yourlink|$password|$notify1|$notify2|$notify3|$notify4|$youremail|$howmany\n"; splice (@data, $FORM{'num'}, 1, ("$FORM{'title'}|$FORM{'desc'}|$FORM{'email'}|$FORM{'exchange'}|$FORM{'url'}|1|$FORM{'hits'}\n")); foreach $line(@data) { print FILE "$line"; } close(FILE); if ($FORM{'stage'} == 0) { $x = "approved"; if ($notify4) { open (MAIL,"|$mailprogram -t"); print MAIL "To: $FORM{'email'}\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Your link has been approved!\n"; print MAIL "Congratulations! Your link has been approved,\n"; print MAIL "and can be found at http://www.yutopian.com/Misc/links.html\n"; &emailsig; close(MAIL); } } if ($FORM{'stage'} == 1) { $x = "modified"; } print "Link $x\n"; &body; print "

      Link $x

      The link has been $x.\n"; &back("password"); } sub defemail { # this sub defines the e-mail messages. If you'd like to edit it, # remember to put a \ before any $ @ \ " characters. $response[0] = $FORM{'other'}; $response[1] = " because\n"; $response[1] .= "I could not find my return link. If you'd like to\n"; $response[1] .= "try again, please go to $scripturl\n\n"; $response[1] .= "Thanks for your time!\n"; $response[2] = " because\n"; $response[2] .= "I couldn't find any links to the page where my\n"; $response[2] .= "link was from your main page. If you'd like to\n"; $response[2] .= "try again, please go to $scripturl\n\n"; $response[2] .= "Thanks for your time!\n"; $response[3] = " because\n"; $response[3] .= "I cannot trade links with sites of that nature.\n\n"; $response[3] .= "Sorry about that.\n"; $response[4] = " because\n"; $response[4] .= "you did not use the correct link syntax. If you'd\n\n"; $response[4] .= "like to try again, please go to $scripturl\n\n"; $response[4] .= "Thanks for your time!\n"; $response[5] .= " because\n"; $response[5] .= "I was either unable to access your main page, or the\n"; $response[5] .= "page where my return link was. If you'd like to try\n"; $response[5] .= "again, please go to $scripturl\n\n"; $response[5] .= "Thanks for your time!\n"; return(@response); } sub delete { &checkpassword; print "Link Deleted\n"; &body; print "

      Link Deleted

      The link has been removed "; if ($FORM{'which'} != -1) { ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$data[$FORM{'num'}]); open (MAIL,"|$mailprogram -t"); print MAIL "To: $email\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Sorry\n"; if ($FORM{'which'} == 0) { print MAIL "$FORM{'other'}\n"; } else { if ($FORM{'stage'} == 0) { print MAIL "I'm sorry, but your link was not approved"; } else { print MAIL "I'm sorry, but your link was removed"; } @response = &defemail; print MAIL "$response[$FORM{'which'}]\n"; } &emailsig; close(MAIL); print ", and the webmaster has been e-mailed"; } splice (@data, $FORM{'num'}, 1); open (FILE,">$datafile"); flock(FILE,2); print FILE "$pagetitle|$bgcolor|$text|$link|$alink|$vlink|$background|$yourlink|$password|$notify1|$notify2|$notify3|$notify4|$youremail|$howmany\n"; foreach $line(@data) { print FILE "$line"; } close(FILE); &back("password"); } sub emailsig { # Please DON'T change this sub or any place where it is called print MAIL "*********************************************************\n"; print MAIL "* Thank you for exchanging links with Yutopian *\n"; print MAIL "* *\n"; print MAIL "* Yutopian Enterprises *\n"; print MAIL "* http://www.yutopian.com *\n"; print MAIL "*********************************************************\n"; } sub believe { print "
      \n"; print "Why you shouldn't trust it when it says your link is there
      \n"; print "My script will make sure that the text for your link appears somewhere\n"; print "in the specified page. However, there are a few things that it won't notice...\n"; print "
      • It won't notice if your link is between comment tags\n"; print "
      • It won't notice if your link is the same color as the background\n"; print "
      • It won't notice if your link is on a page that has no links to it\n"; print "
      • It won't notice if your link is so deeply burried in other links that it might as well not exist.\n"; print "
      \n"; print "

      \n"; print "Why you shouldn't trust it when it says your link isn't there
      \n"; print "Unless the exact text you've specified is on the page, my script will tell you the link is not there.\n"; } sub linkhtml { $line = shift(@_); ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$line); 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"; } sub back { $pass = shift(@_); print "\n"; print "\n"; print "\n"; print "Click to go back.\n"; print "\n"; exit; } sub check { &checkpassword; print "Deleted\n"; &body; print "

      Deleted

      The following links were deleted:
        \n"; $num = 0; for ($i = $#data; $i >= 0; $i--) { ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$data[$i]); if ($approved) { $page = get($exchange); $page =~ tr/A-Z/a-z/; $page =~ s/\n/ /g; $page =~ s/\s+/ /g; $FORM{'search'} =~ tr/A-Z/a-z/; unless ($page =~ /$FORM{'search'}/) { print "
      • $title (no return at $exchange)\n";; open (MAIL,"|$mailprogram -t"); print MAIL "To: $email\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Sorry\n"; print MAIL "I'm sorry, but your link was removed from my\n"; print MAIL "links page at $scripturl\n"; print MAIL "because I could not find my link on your page\n"; print MAIL "at $exchange\n\n"; &emailsig; close(MAIL); splice(@data,$i,1); open (FILE,">$datafile"); flock(FILE,2); print FILE "$pagetitle|$bgcolor|$text|$link|$alink|$vlink|$background|$yourlink|$password|$notify1|$notify2|$notify3|$notify4|$youremail\n"; foreach $line(@data) { print FILE "$line"; } close(FILE); } } } print "
      \n"; &back("password"); } sub go { chomp($data[$FORM{'link'}]); ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$data[$FORM{'link'}]); $hits++; $data[$FORM{'link'}] = "$title|$desc|$email|$exchange|$url|$approved|$hits\n"; open (FILE,">$datafile"); flock(FILE,2); print FILE "$pagetitle|$bgcolor|$text|$link|$alink|$vlink|$background|$yourlink|$password|$notify1|$notify2|$notify3|$notify4|$youremail|$howmany\n"; foreach $line(@data) { print FILE "$line"; } close(FILE); print "Location: $url\n\n"; exit; } sub random { while(-1) { $FORM{'link'} = int(rand(@data)); ($title,$desc,$email,$exchange,$url,$approved,$hits) = split(/\|/,$data[$FORM{'link'}]); if ($approved) { &go; } } }
      Title:
      Description:
      E-mail:
      Main URL:
      URL where you can find your link:
      Hits: