#!/usr/bin/perl
# #!/usr/local/bin/perl
# ^~~ use this on top instead if script not working
# Cookie-less Notebook version 2.0 Released 2-9-2001
# by NESGamepro http://www.wtv-zone.com/nesgamepro
# Rename this file to anything .pl or anything.cgi and Change
# Permissions (CHMOD) to 755
# START Optional Settings
# color settings
$bgcolor = "#181818";
$text = "#44ee66";
$textarea = "gold";
$buttons = "blue";
# number of pages the notebook has
$pages = 5;
# name of the directory that you want the data to be stored in
$dbase ="db";
# END Optional Settings
# WARNING: If you edit between the the warning #
# signs, you do so at your own risk. #
# The URL of this File
$scripturl = "$ENV{'SCRIPT_NAME'}";
$fullurl = 'http://' . $ENV{'SERVER_NAME'} . $scripturl;
# Make New Database if there is not one already.
if (!-e "$dbase") { mkdir("$dbase", 0777); $noexist=1;
open(INDEX,">$dbase/index.html");
print INDEX "\n
\nPlease Press Back\n\n
\n\nPlease Press Back
\n\n\n";
close(INDEX);
}
# Get the data from method=post and split into pairs
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
# Split the data pairs into name-value pairs and assign key to hash
foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair);
# Translate plus signs and %-encoding
$value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s///g; # dis-allow SSI
$DAT{$name} = $value;
}
$mode = $DAT{'action'};
$notedata = $DAT{'notedata'};
# Get Selected NotePad Cookie
use CGI; $q = new CGI;
$theCookie = $q->cookie('SelectBox');
# Get Correct NotePad File
if ($DAT{'file'}) { $file = $DAT{'file'}; }
elsif ($theCookie) { $file = $theCookie; }
else { $file = "notebook1.txt"; }
# Save or Update Cookie
$newCookie = $q->cookie(
-name => "SelectBox",
-value => "$file",
-expires => "+1y");
print "Set-Cookie:$newCookie\n";
if ($mode eq "save") {
open(DATA,">$dbase/$file") || &NotePad("ERROR! Could not save data to $file: $!");
print DATA "$notedata"; close(DATA); &NotePad("Notes Saved");
}
elsif ($mode eq "delete") {
unlink("$dbase/$file") || &NotePad("ERROR! Could not delete $file: $!");
&NotePad("Notes Deleted"); $notedata="";
}
elsif ($mode eq "view") { &View($notedata); }
elsif ($mode eq "print") { print "Location: $dbase/$file\n\n"; }
else {
if (!$notedata) {
open(DATA,"$dbase/$file") || NotePad("There is no data saved in this file.");
@data = ; close(DATA); $notedata = join('', @data);
if ($notedata) { &NotePad; }
else { &NotePad("There is no data saved in this file."); }
}
else { &NotePad; }
}
sub NotePad { $reason = "@_";
# get information about file
($Fsize, $Lview, $Lmod) = ( stat("$dbase/$file") )[7,8,9]; # Lview not used yet
@dow = qw(Sun Mon Tue Wed Thu Fri Sat);
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
# todays date
($sec,$min,$hour,$day,$month,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
if ($day==1 || $day==21 || $day==31) { $end="st"; }
elsif ($day==2 || $day==22) { $end="nd"; }
elsif ($day==3 || $day==23) { $end="rd"; }
else { $end = "th"; }
if ($year < 2000) { $year = $year + 1900; }
$min = sprintf("%02d", $min);
$sec = sprintf("%02d", $sec);
$thetime = "$dow[$wday], $months[$month] $day$end, $year $hour:$min:$sec";
# last modified date
($sec,$min,$hour,$day,$month,$year,$wday) = (localtime($Lmod))[0,1,2,3,4,5,6];
if ($day==1 || $day==21 || $day==31) { $end="st"; }
elsif ($day==2 || $day==22) { $end="nd"; }
elsif ($day==3 || $day==23) { $end="rd"; }
else { $end = "th"; }
if ($year < 2000) { $year = $year + 1900; }
$min = sprintf("%02d", $min);
$sec = sprintf("%02d", $sec);
$LastMod = "$dow[$wday], $months[$month] $day$end, $year $hour:$min:$sec";
# correct problem characters for display
$lt = "lt"; $gt = "gt"; $tamp = "amp";
$notedata =~ s/&/\&$tamp\;/g;
$notedata =~ s##\&$lt\;/textarea\&$gt\;#gi;
# disable buttons and info if there is no data
if (!-e "$dbase/$file" || $notedata eq "") { $disable = " disabled";
$FileInfo = qq~There is no data saved in this note.\\n($file)~; }
else { $FileInfo = qq~Info about this note\\n($file):\\n\\nFile Size: $Fsize bytes\\n\\nCurrent Date/Time:\\n$thetime\\n\\nLast Modified:\\n$LastMod~; }
print "Content-type: text/html\n\n";
# HM KILL - 1st line of javascript
print qq~
Cookie-less Notebook
~;
if ($noexist || $reason) { print qq~| ~; }
if ($noexist) { print qq~A directory called $dbase has been created to store your information. Do not share the URL of this notebook with anyone else, unless you want them to be able to edit your notes also. This message will not appear again unless you erase the $dbase directory. ~; }
if ($reason) { print " $reason"; }
if ($noexist || $reason) { print qq~ |
~; }
print qq~ |
|
|