#!/usr/bin/perl # # Author: rasterboy # Email: raster@zymm.com # Web: http://rasterweb.net/raster/ # Date: 11.21.1998 # # Description: todo.cgi is a very simple perl script that reads and writes to a # text file a 'to do' list, consisting of one item per line. # 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. $todo = $in{'todo'} if defined ($in{'todo'}); $url = "todo.cgi"; $file = "path/to/the/file/todo.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 "Content-type: text/html\n\n"; print < To Do List
To Do List
Delete Items: HTMLTOP ##################################################### # Here we print items that we pulled in from the text file $linect = 0; foreach $line (@lines) { chop $line; $linect++; print qq{ $line
\n}; } ##################################################### # Here we print the bottom of the html page print <
Add Item:
HTMLBOT } ##################################################### # Add to the list of items subroutine sub addtolist { open (FILE, ">>$file"); print FILE "$todo\n" unless ($todo 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