#!/usr/local/bin/perl ### # Demo for pushing html pages 8/18/96 # nph-pages.cgi - by David Efflandt - efflandt@xnet.com # # 'nph-' prefix (non-parsed headers) may be required for unbuffered # output on NCSA or Apache server (not req'd Netscape servers). ### # Change this to full URL of this script $url = 'http://www.xnet.com/~efflandt/nph-pages.cgi'; # Pause between pages in seconds (probably longer than this normally). # Setting depends upon how frequently info needs to update. $pause = 15; # Netscape server push $refresh = 15; # Mosaic and similar client pull # Following line is for 'nph-' (NCSA and Apache): print "$ENV{'SERVER_PROTOCOL'} 200 OK\n"; # Note added 2/5/00 - comment out above line if not using nph- prefix # Apache 1.3.x no longer buffers output, so does not need nph- # Send single page if not Netscape 1.1 or later $agent = $ENV{'HTTP_USER_AGENT'}; undef($agent) if (lc($agent) =~ /compat/); # fake Mozilla ($agent =~ /Mozilla\/(\S*)/) && ($agent = $1); unless ($agent > 1) { &page1; exit; } # Push pages $sep = 'ThisRandomString'; # boundary separator $|=1; # unbuffered print "Content-type: multipart/x-mixed-replace;boundary=$sep\n"; print "\n--$sep\n"; &page1; print "\n--$sep\n"; sleep $pause; while(&newpage) { sleep $pause; } ### Subroutines sub now { local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime; local($tz) = "CST"; # Set for your local time zone $tz =~ s/ST/DT/ if ($isdst); # Automatic daylight savings time $sec = "0".$sec if ($sec < 10); # Leading 0 if < 10 $min = "0".$min if ($min < 10); $mon++; $year += 1900; return "$mon/$mday/$year $hour:$min:$sec $tz"; } sub page1 { local($date) = &now; $page = 1; print "Content-type: text/html\n\n"; # Client pull tag for non-Netscape browsers unless ($agent > 1) { print qq(\n); } # Add code here to update the page. # Following test block prints "as is" except for variables # until it reaches label (EOF) at left margin: print < Push/Pull Test

Automatic Push/Pull Page Update

$date

This is the first page for Netscape browsers which should update every $pause seconds.

Other browsers capable of client pull may see the date change about every $refresh seconds. EOF # EOF must be at left margin (no spaces or tabs) } sub newpage { # Add code here to check if new page needed. # Follow with statement similar to: # return 1 unless ($newinfo); local($date) = &now; $page++; print "Content-type: text/html\n\n"; # Following test block prints "as is" except for variables # until it reaches label (EONP) at left margin: print < Page $page

New Page $page

$date

This page updates every $pause seconds for Netscape browsers.

Notice the page number and time change.

Hit the browser's Stop button to stop updates. EONP # EONP must be at left margin (no spaces or tabs) print "\n--$sep\n"; }