home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet 1996 World Exposition
/
park.org.s3.amazonaws.com.7z
/
park.org.s3.amazonaws.com
/
cgi-bin
/
nph-channel
< prev
next >
Wrap
Text File
|
2017-09-21
|
6KB
|
321 lines
#!/usr/local/bin/perl
#
# file: nph-channel
#
# auth: Brad Burdick
# desc: dynamically generate HTML pages based on the currently selected
# audio *channel*
#
eval 'exec /usr/local/bin/perl -s $0 ${1+"$@"}'
if 0;
# who am i?
($prog = $0) =~ s#.*/##;
# where we find local WWW libraries
push(@INC, '/usr/local/etc/httpd/cgi-bin');
# used to parse form input and to display HTML header/trailer
require 'cgi-lib.pl';
# non-zero for debug output
$debug = 0;
# where the data lives
$host = 'town.hall.org';
# supported audio formats
%audio_fmts = (
'au', 'Sun audio (.au)',
'au.gsm', 'GSM encoded Sun audio (.gsm)',
'ram', 'RealAudio (.ra)',
);
# default audio format
$default_fmt = 'au';
# display HTTP header
&print_HTTPheader('HTTP/1.0', 'NCSA/1.5b7', 'text/html');
if ($ENV{'CONTENT_LENGTH'} > 0 || $ENV{'QUERY_STRING'} ne "") {
# process input from audio selector form
&parse_request;
# get HTML src and audio format, if available
($src_html, $fmt) = split(',', $ENV{'PATH_INFO'});
# use default format if no format info available
$fmt = $default_fmt unless $fmt;
# check for valid format value
local($fmt_ok) = 0;
foreach $good_fmt (sort keys %audio_fmts) {
if ($fmt eq $good_fmt) {
$fmt_ok = 1;
last;
}
}
# use default format if format value is no good
if (! $fmt_ok) {
$fmt = $default_fmt;
}
undef $fmt_ok;
&process_form(*query, $src_html, $fmt);
} elsif ($ENV{'PATH_TRANSLATED'}) {
# path to HTML src and current audio format
($src_html, $fmt) = split(',', $ENV{'PATH_INFO'});
# use default format if no format info available
$fmt = $default_fmt unless $fmt;
# check for valid format value
local($fmt_ok) = 0;
foreach $good_fmt (sort keys %audio_fmts) {
if ($fmt eq $good_fmt) {
$fmt_ok = 1;
last;
}
}
# use default format if format value is no good
if (! $fmt_ok) {
$fmt = $default_fmt;
}
undef $fmt_ok;
# generate specified HTML page
&gen_page($src_html, $fmt);
}
exit 0;
#
# process FORM query
#
sub process_form {
local(*query) = shift;
local($src_html) = shift;
local($fmt) = shift;
# get audio selection based upon map coordinates from selector image
if (defined($query{'x'}) && $query{'x'} > 135) {
$fmt = 'ram';
} elsif (defined($query{'x'}) && $query{'x'} > 68) {
$fmt = 'au.gsm';
} elsif (defined($query{'x'})) {
$fmt = 'au'; # default format
} elsif (defined($query{'_Channel'})) {
$fmt = $query{'_Channel'};
}
&gen_page($src_html, $fmt);
}
#
# display error message
#
sub errmsg {
local($msg) = shift;
print $msg, "\r\n";
}
#
# print HTTP headers (no server parsing on this output)
#
sub print_HTTPheader {
local($protocol, $server, $type) = @_;
local($savout) = $|;
$| = 1;
print <<EndOfHTTP;
$protocol 200 OK
Server: $server
Content-type: $type
EndOfHTTP
$| = $savout;
}
#
# display HTML header
#
sub print_HTMLheader {
local($src_html, $fmt, $title) = @_;
print <<EndOfHeader;
<html>
<head>
<title>$title</title>
</head>
<body>
EndOfHeader
&print_AudioSelector($src_html, $fmt);
}
# display HTML trailer
#
sub print_HTMLtrailer {
print <<EndOfTrailer;
<p>
<center>
<hr size="2" width="90%">
<address><a href="/">Expo96</a> / <a href="/Tibet">Tibet</a></address>
</center>
</body>
</html>
EndOfTrailer
}
#
# display audio selector form
#
sub print_AudioSelector {
local($src_html, $fmt) = @_;
# remove leading '/'s as they are added below
$src_html =~ s#^[/]+##g;
if ($ENV{'HTTP_ACCEPT'} =~ m#image/#io) {
print <<EndOfForm;
<!-- Audio selection form -->
<center>
<form method="GET" action="/cgi-bin/nph-channel/$src_html">
<input type="image"
src="/Images/$fmt.gif"
alt="[$fmt audio format selector]"
align="center"
width="200" height="27"
hspace="0" vspace="0"
border="0">
<p>
<font size="-2">
Current audio selection: $audio_fmts{$fmt}
</font>
</form>
</center>
<!-- End audio selection form -->
EndOfForm
} else {
local($aufmt, $gsmfmt, $rafmt);
$aufmt = ($fmt eq 'au') ? "checked" : "";
$gsmfmt = ($fmt eq 'au.gsm') ? "checked" : "";
$rafmt = ($fmt eq 'ram') ? "checked" : "";
print <<EndOfForm;
<!-- Audio selection form [non-image] -->
<center>
<form method="GET" action="/cgi-bin/nph-channel/$src_html">
<hr size="2" width="80%">
<input name="_Channel" type="radio" value="au" $aufmt> Sun audio (.au)
<input name="_Channel" type="radio" value="au.gsm" $gsmfmt> GSM encoded Sun audio (.gsm)
<input name="_Channel" type="radio" value="ram" $rafmt> RealAudio (.ra)
<br clear=all>
<input name="_Submit" type="submit" value="Select Format">
<p>
Current audio selection: $audio_fmts{$fmt}
<hr size="2" width="80%">
</form>
</center>
<!-- End audio selection form -->
EndOfForm
}
}
#
# generate specified page
#
sub gen_page {
local($src_html, $fmt) = @_;
local($real_src, $real_fmt) = split(',', $ENV{'PATH_TRANSLATED'});
local($title);
local(@src);
# display body of page
open(SRC, $real_src) || (&errmsg("$src_html: $!\n"), return);
# display audio selector before normal HTML page
while (<SRC>) {
# s/\015$//;
# allow for multiline body tags
if (/<body>/io) {
print "$_";
&print_AudioSelector($src_html, $fmt);
last;
} elsif (/<body/io) {
print "$_";
while (<SRC>) {
# s/\015$//;
print "$_";
last if />$/;
}
&print_AudioSelector($src_html, $fmt);
last;
}
print "$_";
}
# extra info for debugging...
if ($debug) {
print "<pre>\n";
for (sort keys(%ENV)) {
print "$_: $ENV{$_}\n";
}
print "</pre>\n";
}
# slurp in the rest of the src
@src = <SRC>;
# substitute current audio format for placeholder ($FMT)
for (@src) {
local($size);
if (/\$SIZE/) {
# TODO: determine approx. size of audio file
$size = "??? Mb";
}
if (/<\/body>/) {
# display HTML trailer
&print_HTMLtrailer;
last;
}
# substitions in HTML templates
s/\$FMTNAME/$audio_fmts{$fmt}/ego;
s/\$FMT/$fmt/ego;
s/\$SIZE/$size/ego;
print "$_";
}
}