This is the main script. Installation instructions are found below, which requires perl and access to a cgi-bin directory. You must set the variables at the top of the script or it will not function properly
Site hosted by Angelfire.com: Build your free website today!
#!/usr/bin/perl ############################################################################# ## Program Name: openjournal.cgi version 1.17 ## ## Open Journal (OJ) ## John M. Grohol ## Released: 10 Oct 1999 ## This version: 01 Mar 2001 ## http://grohol.com/ ## ## Copyright 1999-2001 John M. Grohol. ## Free to distribute or change, but you cannot charge for this work or any ## derivatives thereof. No warranties on this program are made or implied. ## ## Description: ## Allows you to keep a weblog with minimal maintenance. ## $mydir = "/home/my_directory/public_html"; # The directory where your homepage lives - no trailing slash $ojdir = "/openjournal"; # Where your journal will reside on your Website # - no trailing slash $baseurl = "http://www.myserver.com"; # Your Website's URL - no trailing slash $cgi_url = $baseurl . "/cgi-bin/openjournal.cgi"; # Change if necessary (cgi-bin dir) $title = "my open journal"; # Name of your journal $mesgdir = "story"; # Create a subdirectory under where your open journal lives # The default directory is called "story" $ext = "htm"; # If your system needs "html" extensions, change it here $mesgfile = "index." . $ext; # Default index file # Note: The auto-archiving function is very OS-specific and may not # work on your flavor of *nix if it doesn't support the latest options # available in modern versions of 'date'. Use the manual archive function # as an alternative. $daytoarchive = "5"; # 0=Sun, 1=Mon, 2=Tues, etc. if you only want to archive once a month, # set this variable to 30. ### !!!!! IMPORTANT !!!!!!! ############################ ### Change these defaults before you run this puppy! ### ### This is your login to add new entries to your ### ### journal. ### ######################################################## $username = "admin"; $password = "stupidboy"; # To log in as an administrator, go to: # # http://www.yourserver.com/cgi-bin/openjournal.cgi?admin=1 # Specify colors and background: $colors = qq~ bgcolor="#FFFFEE" text="#000000" link="#000044" vlink="#884400" ~; $background = qq~ background="" ~; # Pick a default font face, size, and table color to use: $font = "arial,helvetica"; $size = "-1"; $tcolor = " bgcolor=\"#CCCCAA\""; $tbcolor = " bgcolor=\"#005544\""; $tbfontcolor = "#FFFFFF"; $tbfont = "verdana,ms sans serif"; # Need to change where the "date" program on your system lives? $d = "/bin/date"; $ENV{"TZ"} = "EST5EDT"; $pt = 1; # Below is the printed date. Read your unix man page on date if you # want to customize this output. $long_date = `$d +"%A, %B %-d, %Y"`; chop($long_date); $w = `$d +"%w"`; chop($w); $today = `$d +"%d"`; chop($today); # Note: If your date system doesn't support the syntax below (Linux does!), # then this may not work. Sorry. $lastmonth = `$d --date '1 month ago' +"%m"`; chop($lastmonth); $nfn = `$d +"%m%d%y%H%M"`; chop($nfn); $lastweek = `$d --date '1 week ago' +"%B %-d, %Y"`; chop($lastweek); $ptime = `$d +"%r %Z"`; chop($ptime); $ngn = `$d +"%m%d"`; chop($ngn); $nyn = `$d --date '1 day ago' +"%m%d"`; chop($nyn); $blurbonly = 0; $basedir = $mydir . $ojdir; $john = $baseurl . "/"; $idxurl = $baseurl . "$ojdir/"; # v1.10 &ParseTags($ENV{'PATH_INFO'}); &ParseTags($ENV{'QUERY_STRING'}); &parse_form; $edit = $tags{'edit'}; if (!($edit)) { $edit = $FORM{'edit'}; } if ($edit) { &verify; exit 0; } if (!($tags{'admin'})) { &get_variables; if ($blurbonly eq 0) { &new_file; } &main_page; # 1.15 &return_html("entry added"); } else { &print_auth; } exit 0; #_______________________________________________________ sub get_variables { # v1.10 $fusername = $FORM{'username'}; if (!($fusername)) { $fusername = $tags{'username'}; } $fpassword = $FORM{'password'}; if (($tags{'auth'} eq "login") || ($FORM{'auth'} eq "login")) { &auth; } if ($fusername ne $username) { &error("Not logged in"); } if ($FORM{'etitle'}) { $etitle = "$FORM{'etitle'}"; $headtitle = $etitle; $etitle =~ s/"/\"/g; $etitle =~ s///g; $etitle =~ s/\&/\&/g; } if ($FORM{'bodyone'}) { $bodyone = "$FORM{'bodyone'}"; $bodyone =~ s/\cM//g; $bodyone =~ s/\n\n/

/g; $bodyone =~ s/<//g; } else { &error("No blurb"); } if ($FORM{'body'}) { $body = "$FORM{'body'}"; $body =~ s/\cM//g; $body =~ s/\n\n/

/g; $body =~ s/<//g; } if (length($body) < 5) { $blurbonly = 1; } if (length($etitle) < 2) { $etitle = ""; } } # Write a new article routine sub new_file { open(NEWFILE,">$basedir/$mesgdir/$nfn\.$ext") || die &error("Error writing file $basedir/$mesgdir/$nfn\.$ext - Please check your permissions. Sorry."); print NEWFILE qq~ $title: $headtitle $title
home . archives

Open Journal is open source software by J. Grohol.

~; close(NEWFILE); chmod 0755, "$basedir/$mesgdir/$nfn\.$ext"; } # Adds article to index page sub main_page { # Time to archive? &lastarchive; $lastarchmon = substr($lastarch,0,2); # 1.15 if ( ($edit eq 2) || (($lastarch ne $ngn) && ( ( ($daytoarchive ne 30) && ($w eq ($daytoarchive+1)) ) || ( ($daytoarchive eq 30) && ( ($today eq 01) || ($lastarchmon eq $lastmonth)) ))) ) { $result = `mv $basedir/$mesgfile $basedir/$mesgdir/idx$nfn\.$ext`; $result = `cp $basedir/oj\.template $basedir/$mesgfile`; open(AMAIN,"$basedir/$mesgdir/$mesgfile") || die &error("Error writing file $basedir/$mesgdir/$mesgfile - Please check your permissions. Sorry."); @amain = ; close(AMAIN); open(AMAIN,">$basedir/$mesgdir/$mesgfile") || die &error("Error writing file $basedir/$mesgdir/$mesgfile - Please check yourpermissions. Sorry."); foreach $amain_line (@amain) { if ($amain_line =~ //) { print AMAIN "\n"; print AMAIN "Week of $lastweek
\n"; } else { print AMAIN "$amain_line"; } } close(AMAIN); &archive; } # 1.15 - If just archiving, return if ($edit eq 2) { return; } # Add entry to main index page &lastupdate; if ($lastupdate ne $ngn) { $newday = 1; } else { $newday = 0; } open(MAIN,"$basedir/$mesgfile") || die &error("Error writing file $basedir/$mesgfile - Please check your permissions. Sorry."); @main =
; close(MAIN); open(MAIN,">$basedir/$mesgfile") || die &error("Error writing file $basedir/$mesgfile - Please check your permissions. Sorry."); foreach $main_line (@main) { if (($newday eq 0) && ($main_line =~ //)) { print MAIN "\n\n\n\n"; if ($blurbonly eq 1) { if ($etitle) { print MAIN "$etitle
$bodyone
\n"; if ($pt eq 1) { print MAIN "
(Posted at $ptime.)

"; } else { print MAIN "

"; } } else { print MAIN "$bodyone\n"; if ($pt eq 1) { print MAIN "
(Posted at $ptime.)

"; } else { print MAIN "

"; } } } else { print MAIN "$etitle
$bodyone
\n"; if ($pt eq 1) { print MAIN "
(Posted at $ptime.)

"; } else { print MAIN "

"; } } } elsif (($newday eq 1) && ($main_line =~ //)) { print MAIN "\n\n\n\n"; print MAIN "
\n"; print MAIN " $long_date

\n\n\n"; if ($blurbonly eq 1) { if ($etitle) { print MAIN "$etitle
$bodyone
\n"; if ($pt eq 1) { print MAIN "
(Posted at $ptime.)

"; } else { print MAIN "

"; } } else { print MAIN "$bodyone\n"; if ($pt eq 1) { print MAIN "
(Posted at $ptime.)

"; } else { print MAIN "

"; } } } else { print MAIN "$etitle
$bodyone
\n"; if ($pt eq 1) { print MAIN "
(Posted at $ptime.)

"; } else { print MAIN "

"; } } } else { print MAIN "$main_line"; } } close(MAIN); &update; } sub return_html { $error = $_[0]; &header("$error"); print "

$title: $error

\n"; print "

\n"; &footer; } sub error { $error = $_[0]; &header(error); print "

error: $error

\n"; exit(0); } sub header { $subtitle = $_[0]; print "Content-type: text/html\n\n"; print "$title: $subtitle\n"; } sub footer { print ""; } sub ParseTags { local($_) = @_; local(@terms, $tag, $val); s|^/||; @terms = split('&'); foreach $term (@terms) { ($tag,$val) = split('=',$term,2); if ((length($tag) > 100) || (length($val) > 100)) { &error("Variable length problem in line input"); } $val =~ tr/+/ /; $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $val =~ s///g; $val =~ s/<([^>]|\n)*>//g; # may override previous value $tags{$tag} = $val; } } sub parse_form { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); if ((length($name) > 100) || (length($value) > 1000000)) { &error("Variable length problem in form input"); } $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # $value =~ s///g; unless (($name eq 'body') || ($name eq 'bodyone')) { $value =~ s/<([^>]|\n)*>//g; } $FORM{$name} = $value; } } sub print_auth { &header(Login); print qq~

 

$title: login

Username:
Password:
~; &footer; } sub auth { # v1.10 open(NUMBER,"$basedir/.phtmp"); $numm = ; close(NUMBER); if (($tags{'v'} eq $numm) || (($fusername eq $username) && ($fpassword eq $password))) { &addform; } else { &error("Not authorized"); } } sub lastarchive { open(FILE,"$basedir/lastarchive.txt"); $lastarch=; close(FILE); } sub archive { open DEX,">$basedir/lastarchive.txt"; print DEX "$ngn"; close(DEX); } sub lastupdate { open(FILE,"$basedir/lastupdate.txt"); $lastupdate=; close(FILE); } sub update { open DEX,">$basedir/lastupdate.txt"; print DEX "$ngn"; close(DEX); } sub addform { &header("Add new entry"); # v1.10 $num = ""; srand(time ^ $$); $num = int(rand(10000000000)); open(NUM,">$basedir/.phtmp") || &error("Couldn't write data file in $basedir"); print NUM "$num"; close(NUM); # 1.15 print qq~

$title: add new entry

System date: $long_date
(If this date isn't being displayed properly, the date variable in the script needs tweaking.)
Archive now | Edit your journal | My Journal
Title:
Blurb:
Story:
~; &footer; exit 0; } # v1.10 sub verify { open(NUMBER,"$basedir/.phtmp"); $numm = ; close(NUMBER); $v = $tags{'v'}; if (!($v)) { $v = $FORM{'v'}; } $ct = $FORM{'ct'}; if ($v ne $numm) { &error("Not logged in"); } # 1.15 elsif ($edit eq 2) { &main_page; $blurbonly = 1; &return_html("index successfully archived"); exit 0; } elsif (!($ct)) { &header("Choose a directory to edit"); print qq~

$title: choose a directory to edit

Directories:
~; &footer; exit 0; } elsif ($ct eq 1) { &header("Choose a directory to edit"); $dir = $FORM{'dir'}; print qq~

$title: choose a file to edit
$dir

~; opendir(DIR,"$dir") || &error("in get1 I could not open the directory $basedir"); @ls=readdir(DIR); closedir(DIR); $_ = $line; $files = "\.$ext"; foreach $dfile(@ls) { $dfile =~ s/[\s]+//g; if ($dfile =~ /$files/ && $dfile !~ /[ ]+/ && $dfile !~ /\n|\r/) { # next if $dfile =~ /index.html?/i; next if $dfile =~ /.txt?/i; next if $dfile =~ /<|>/; open(T,"$dir/$dfile") ||&error("in get1 I could not open the file $basedir$dfile"); URL: { while() { if (/([\S\s]+)<\/title>/i) { next if $1 =~ /\$/i; push(@urls,"<option value=\"$dir/$dfile\">$dfile - $1\n"); last URL; close(T); } else { next; } } } } } print qq~ <form method="post" action="$cgi_url"> <select name="go" size="10"> ~; foreach(@urls) { print; } print qq~ </select> <input type=hidden name=v value="$v"> <input type=hidden name=edit value="1"> <input type=hidden name=ct value="2"><br><br><input type="submit" value="Edit this File"></form>\n ~; &footer; exit 0; } elsif ($ct eq 2) { $eiei = rindex($FORM{'go'},"/") +1; $editedfn = substr($FORM{'go'},$eiei); $fileBeingUpdated = $FORM{'go'}; $pathToDbase = "$fileBeingUpdated"; open(INFILE,"$pathToDbase") || open(INFILE,">$pathToDbase") || &print_error("Cannot open $pathToDbase in INFILE"); @infile = (<INFILE>); close(INFILE); $size_all = (@infile + 10); &header("Editing $editedfn"); print qq~ <center><div align=center> <h3><font face="$font">$title: edit a file: $editedfn</font></h3> <blockquote> <p align="center"> <font face="$font" size="$size"> Press the <b>Publish the Page</b> button when you're ready to publish it. </font></p> <form method="post" action="$cgi_url"> <input type=hidden name="go" value="$fileBeingUpdated"> <TEXTAREA NAME="body" ROWS="30" COLS="65" wrap="physical"> ~; foreach(@infile) { print "$_"; } print qq~ </textarea> <input type=hidden name=v value="$v"> <input type=hidden name=edit value="1"> <input type=hidden name=ct value="3"> <p><center><input type="submit" name="submit" value="Publish the Page"></center></form> </blockquote> ~; &footer; exit 0; } elsif ($ct eq 3) { $eiei = rindex($FORM{'go'},"/") +1; $editedfn = substr($FORM{'go'},$eiei); $eoeo = rindex($FORM{'go'},"/",$eiei-2); $editeddir = substr($FORM{'go'},$eoeo); $pathToDbase = "$FORM{'go'}"; &header("File Successfully Updated"); print qq~ <center><div align=center> <h3><font face="$font">$title: successfully edited<br>$dir</font></h3> ~; local(@temp) = split(/\n/,$FORM{'body'}); foreach (@temp) { $_ =~ s/\cM//; $_ =~ s/^[\s]+//g; $infile .= "$_\n"; push(@toprint,"$_\n"); } open(BINFILE,">$pathToDbase") || &error("Cannot open $pathToDbase in INFILE"); print BINFILE "@toprint"; close(BINFILE); print qq~ <p><font face="$font" size="$size">Go to ~; if ($editeddir =~ /$mesgdir/) { print " <a href=\"$idxurl$mesgdir/$editedfn\">$editedfn</a> "; } else { print " <a href=\"$idxurl$editedfn\">$editedfn</a> "; } print qq~ to view the changes <br><br>or add a <a href="$cgi_url?v=$v&auth=login&username=$username">New entry</a>.<br><br> <b>Note:</b> You may have to Reload the page when you get there to see your changes. </font> ~; &footer; exit 0; } } # endsub </body> </html>