Last active
July 1, 2023 18:58
-
-
Save joewils/f4cb58200e761c6ea38508aa7bd5eb3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Old CGI script from 1996 | |
# https://web.archive.org/web/20000829140422id_/http://www.joecode.com/news/news_cgi.txt | |
# Usage | |
# /news.cgi?url=http://fullcoverage.yahoo.com/fc/Business/Internet_Taxes_and_Regulation/&subject=internet_tax&title=Internet%20Tax%20News: | |
if ($ENV{'REQUEST_METHOD'} eq 'GET') { | |
@pairs = split(/&/, $ENV{'QUERY_STRING'}); | |
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { | |
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); | |
@pairs = split(/&/, $buffer); | |
} else { | |
print "Content-type: text/html\n\n"; | |
print "<P>Use Post or Get"; | |
} | |
$count = 0; | |
foreach $pair (@pairs){ | |
($name, $value) = split(/=/, $pair); | |
$value =~ tr/+/ /; | |
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |
$name =~ tr/+/ /; | |
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |
@line[$count] = $name; | |
$IN{$name} = $value; | |
$count++; | |
} | |
print "Content-type: text/html\n\n"; | |
$URL = $IN{'url'}; | |
$TITLE = $IN{'title'}; | |
$SUBJECT = $IN{'subject'}; | |
# First we need to 'borrow' some news content from Yahoo! | |
use LWP::Simple; | |
$CONTENT = get($URL) or print "Could not get $URL"; | |
# Then we get rid of all the crap before the table | |
$CONTENT =~ s/.*?<a name="News_Stories">/ /s; | |
# Then we get rid of all the crap after the table | |
$CONTENT =~ s/<a name="Related_Web_Sites">(.*?)<\/html>/ /s; | |
# Do some html fixing (specific to Yahoo!) | |
$CONTENT =~ s/<td bgcolor="#dcdcdc">/<\/table>/s; | |
$CONTENT =~ s/>next</></s; | |
$CONTENT =~ s/<table cellpadding=2 cellspacing=0 width="100%">//s; | |
$CONTENT =~ s/<tr><td width="2%" valign=top> - <\/td>/<br>/g; | |
$CONTENT =~ s/<td width="98%">//g; | |
$CONTENT =~ s/<\/td>//g; | |
$CONTENT =~ s/<\/tr>//g; | |
$CONTENT =~ s/<\/table>//s; | |
$CONTENT =~ s/<tr><td><td align=right>//g; | |
$CONTENT =~ s/<\/table><table cellpadding=2 cellspacing=0 border=0 width="100%">//s; | |
$CONTENT =~ s/<\/table>//s; | |
$CONTENT =~ s/<tr>//s; | |
$CONTENT =~ s/News Stories//s; | |
$CONTENT =~ s/ - /<br>/g or print "can\'t complete regex.\n"; | |
# Lets open up our template page and update the content. | |
open(TEMPLATE, "$ENV{DOCUMENT_ROOT}/template/news/news.html") or print "can not open /template/news/news.html\n"; | |
while(<TEMPLATE>){ | |
$_ =~ s/\[title\]/$TITLE/s; | |
$_ =~ s/\[content\]/$CONTENT/s; | |
$print_to_file .= $_; | |
} | |
close(TEMPLATE); | |
# Lets open up our static html page and save it | |
open(STATIC_PAGE, ">$ENV{DOCUMENT_ROOT}/news/$SUBJECT.html") or print "can\'t open /news/$SUBJECT.html\n"; | |
print STATIC_PAGE $print_to_file; | |
close(STATIC_PAGE); | |
print $print_to_file; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment