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
#!/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;
$etitle =~ s/\&/\&/g;
}
if ($FORM{'bodyone'}) {
$bodyone = "$FORM{'bodyone'}";
$bodyone =~ s/\cM//g;
$bodyone =~ s/\n\n/
~;
&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
~;
&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,"