#!/usr/bin/perl # # Author: rasterboy # Email: raster@zymm.com # Web: http://rasterweb.net/raster/ # Date: 12.23.1998 # # Description: urls.cgi is a very simple perl script that reads and writes to a # text file a list consisting of two items per line - a title # and a url. Nothing fancy here folks, just a little learning tool. # If you're a beginner, you might find it useful, if you've # written cgi's in perl before, this'll all seem very trivial. # # License: This software is licensed under the GNU General Public License. # A copy of the GNU GPL can be found at: http://www.gnu.org/copyleft/gpl.txt # This software is open source. This software is free software. ##################################################### # Read input # Alternately you could use cgi-lib.pl or CGI.pm for this # 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; $value =~ s/~!/ ~!/g; $in{$name} = $value; } ##################################################### # Set up variables # This is where you'll need to determine if you # want a relative or absolute path for $url # and where the $file is located. $theurl = $in{'theurl'} if defined ($in{'theurl'}); $thetitle = $in{'thetitle'} if defined ($in{'thetitle'}); $theurl =~ s/\t//g; $thetitle =~ s/\t//g; $url = "urls.cgi"; $file = "path/to/the/file/urls.txt"; ##################################################### # These are the three subroutines we call &deletefromlist; &addtolist; &showlist; # This is really where the script ends # We just run these three subroutines, and that's it. # From here on down it's just the subroutines. ##################################################### # Show list of items subroutine sub showlist { open (FILE, "<$file"); @lines = ; close (FILE); ##################################################### # Here we print the top of the html page print < URLs
URLs
Delete URLs: HTMLTOP ##################################################### # Here we print items that we pulled in from the text file $linect = 0; foreach $line (@lines) { chop $line; ($linetitle, $lineurl) = split ("\t", $line); $linect++; print qq{}; print qq{$linetitle
\n}; } ##################################################### # Here we print the bottom of the html page print <
Add URL: Title:
URL:
HTMLBOT } ##################################################### # Add to the list of items subroutine sub addtolist { open (FILE, ">>$file"); print FILE "$thetitle\t$theurl\n" unless ($theurl eq ""); close (FILE); } ##################################################### # Delete from the list of items subroutine sub deletefromlist { open (FILE, "<$file"); @lines = ; close (FILE); open (FILE, ">$file"); $linect=0; foreach $line (@lines) { $linect++; chop $line; if ($in{$linect} ne "delete") { print FILE "$line\n"; } } close (FILE); } ##################################################### # END