zhurnalypost.cgi

 18th December 2022 at 9:42am

script to post to zhurnaly.com – needs filters/converters to avoid funky character problems with curly quotes, long dashes, etc!

#! /usr/bin/perl
# ^z - 14-28 Nov 2004
# revised ^z - 2008-03-08 to redirect to proper page
# revised ^z - 2016-08-02 to allow for \r\n in addition to \n - by removing the \n from $repl
#  ... and putting \n in the replacement pattern

# take an entry from zhurnalpost.html form and slot it into file "index.html"
# for now, only form data item we care about has name=z
# put the form contents after "$repl"
# with date/time appended in a standard format

undef $/;                           # grab entire files at once
$page = "../httpdocs/index.html";  # set this to main page, e.g. "../httpdocs/index.html"
$repl = "<!--begin-->";
$date_command = "/bin/date";
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chomp($date);

read(STDIN, $_, $ENV{CONTENT_LENGTH});  # works in Apache

my ($item, %item);
foreach $_ (split(/&/, $_)) {
	s/\+/ /g;
	s/\%(..)/pack('C', hex($1))/geo;
	($_, $item) = split (/=/, $_, 2);
	$item{$_} = $item;
}

open(F, "$page") or die "$page: $!";
$body = <F>;
close(F);

$body =~ s/$repl/$repl\n$item{"z"}\n<p> - $date\n<hr>\n/;

open(F, ">$page") or die "$page: $!";
print F $body;
close(F);

# new version to redirect to proper page
print "Content-type: text/html\n\n";
print "<head><meta http-equiv=\"Refresh\" content=\"0; url=http://zhurnaly.com/\"></head>";

# previous version that pseudo-echoed body
# print "Content-type: text/html\n\n";
# print $body;