Skip to content

Instantly share code, notes, and snippets.

@artlung
Created April 11, 2021 19:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlung/74184de3c381966a14f97a8605d17572 to your computer and use it in GitHub Desktop.
Save artlung/74184de3c381966a14f97a8605d17572 to your computer and use it in GitHub Desktop.
~filo/stanford/940520/bin/index.html
#! /usr/local/bin/perl
require 'ctime.pl';
require 'newgetopt.pl';
#require '/usr/local/lib/perl5/ctime.pl';
#require '/usr/local/lib/perl5/newgetopt.pl';
#require '/usr/local/lib/perl5/sys/socket.ph';
#
# ----> parse_hotlist <----
# takes a file (default /chronos/c1/jerry/.hotlist
# with tabs as delimiters for depth
# and generate
# $MaxTabs -> number of levels
# %Keys -> array of keys per level
# %Topics -> array of topics
#
sub parse_hotlist
{
if (defined @_) {
$hotlist = $_[0];
}
else {
$hotlist = "hotlist";
}
open (IT2, "<$hotlist");
$CurTabs = 0;
$CurKey = "top_";
$MaxTabs = 0;
while (<IT2>) {
chop $_;
# print ("Parsing ::: $_\n");
#
# count the number of tabs on each line
#
for ($i =0; $i < length; $i++) {
if (substr($_,$i,1) ne "\t") {
$v = substr($_, $i);
last;
}
}
#
# if # tabs more than current
#
if ($i > $CurTabs) {
# print ("$i > $CurTabs, $CurKey\n");
$CurTabs = $i;
@tmp = split(/\000/, $Topic{$CurKey});
$CurKey .= "\000".$tmp[$#tmp];
}
#
# if # tabs less than current
#
if ($i < $CurTabs) {
# print ("$i < $CurTabs, $CurKey\n");
$CurTabs = $i;
@tmp = split (/\000/, $CurKey);
$CurKey = $tmp[0];
for ($j = 1; $j <= $i; $j++) {
$CurKey .= "\000".$tmp[$j];
}
}
#
# insert this into $Topic
#
while ($CurKey =~ /^(.*)<([a-z]*):(.*)>$/) {
$CurKey = $1;
}
# if ($CurKey=~ /^(.*)<comment:(.*)>$/) { # strip off comment fied
# $CurKey = $1; # assume that cannot have one with url...
# }
if (! defined($Topic{$CurKey})) {
$Topic{$CurKey} = $v;
}
else {
$Topic{$CurKey} .= "\000".$v;
}
# print ("inserting into $CurKey\n");
#
# check if maxtab is exceeded
#
if ($CurTabs > $MaxTabs) {
$MaxTabs = $CurTabs;
}
#
# insert CurKey into Key array
#
if (! defined($Key[$CurTabs])) {
$Key[$CurTabs] = $CurKey;
}
else {
@val = split(/\003/, $Key[$CurTabs]);
$no = 0;
foreach $z (@val) {
if ($CurKey eq $z) {
$no = 1;
last;
}
}
if ($no == 0) {
$Key[$CurTabs] .= "\003".$CurKey;
}
}
}
close IT2;
# print ("keys are :\n", join ("\n", keys(%Topic)), "\n");
# print ("MaxTabs is $MaxTabs\n");
# for ($i =0; $i <= $MaxTabs; $i++) {
# print ("$i, $Key[$i] \n");
# }
return;
}
#
# canonicalize a directory name
#
sub canon_path
{
local($path) = $_[0];
while ($path =~ /^(.*)<([a-z]*):(.*)>$/) {
$path = $1;
}
$path=~ s/[\']//g; # remove any bad chars ... (better way...)
$path =~ s/[\/]/+/g; # remove any bad chars ... (better way...)
return $path;
}
#
# prints output of parse_hotlist to files
#
sub print2file
{
undef($dirlist);
$dircnt=0;
if ($opt_update) {
open (HOTDOC, ">$hotstat") ;
$date = &ctime(time);
chop $date;
print HOTODC "<p>";
print HOTDOC "<i> Last modified on $date </i><br>\n";
close HOTDOC;
open (HOTDOC, ">$hotdoc") ;
}
# do the iterative thing here...
for ($i =0; $i <= $MaxTabs; $i++) {
if ($i != 0) {
#
#
# print ("=======($i, $Key[$i])=====\n");
#
#
print HOTDOC "<HEADER>\n<TITLE>Jerry and Dave\'s Guide to WWW </TITLE>\n</HEADER>\n<BODY>\n";
}
#
# big for loop to make appropriate directories
#
foreach $j (split (/\003/, $Key[$i])) {
#
#
# print ("($j, $Topic{$j}) \n");
#
#
if ($i != 0) {
#
# make sure this is same as below for references
#
@_ = split(/\000/, &canon_path($j));
shift(@_); # get rid of top_
$curdir = join("/",@_); # form directory path
$curdir =~ s/[\000\s]+$//g; # remove any trailing whitespace
$curdir =~ s/[\000\s]+/_/g; # sub white spaces with _
$curdir = $hotdir."/".$curdir;
if (!(-e $curdir)) {
$dirlist .= " ".$curdir;
$dircnt++;
if ($dircnt > 15) { # some random number i made up...
#
print "mkdir -m g+w $dirlist<br>\n";
#
system "mkdir -m g+w $dirlist";
$dirlist ="";
$dircnt=0;
}
}
}
}
if ($dircnt > 0) {
#
print "mkdir -m g+w $dirlist<br>\n";
#
system "mkdir -m g+w $dirlist";
$dirlist ="";
$dircnt=0;
}
#
# big for loop to create all files
#
foreach $j (split (/\003/, $Key[$i])) {
#
#
# print ("($j, $Topic{$j}) \n");
#
#
if ($i != 0) {
#
# make sure this is same as above for references
#
$curfile = &canon_path($j);
@_ = split(/\000/,$curfile);
shift(@_);
$curfile=join("/",@_);
$curfile =~ s/[\000\s]+$//g; # remove any trailing whitespace
$curfile =~ s/[\000\s]+/_/g; # sub white spaces with _
$curtitle = $curfile;
$curfile .= "/index.html"; # current file name
$curfile = $hotdir."/".$curfile;
$here = pop(@_);
#
# open up $curfile
#
open (HOTDOC, ">$curfile");
if (-w $curfile) {
#
# print "writing to file $curfile<br>\n";
#
}
else {
print "cannot write to file $curfile<br>\n";
}
print HOTDOC "<HEADER>\n<TITLE>$curtitle</TITLE>\n</HEADER>\n<BODY>\n";
print HOTDOC "<base href=\"http://akebono.stanford.edu$hottree/$curtitle\"<P>\n";
# print HOTDOC "<a name=\"begin_hotlist\"> <ISINDEX> </a> ";
$mod = $i % 3;
# horizontal menu bar
print HOTDOC "<a href=\"/~jerry/bin/myimagemap/hothead/$curtitle\"><img src=\"/~jerry/gifs/hothead.gif\" ismap></a>\n";
if ($i == 1) {
print HOTDOC "<H2><a href=\"$http_url#begin_hotlist\"> <img src=\"/~jerry/gifs/level$mod.gif\" >";
print HOTDOC join(": ", @_),"</a> $here</h2>\n";
}
else {
print HOTDOC "<H2><a href=\"$http_url#begin_hotlist\">";
print HOTDOC "<img src=\"/~jerry/gifs/level$mod.gif\" ></a><a href=\"./\">";
print HOTDOC join(": ", @_),"</a>: $here</h2>\n";
}
print HOTDOC "<UL>\n";
#
# put page specific stuff here...
#
}
else {
print HOTDOC "<a name=\"begin_hotlist\"> <ISINDEX> </a> ";
print HOTDOC "<img align=middle src=\"/~jerry/gifs/grad_line.gif\">\n";
print HOTDOC "<H3>\n";
}
foreach $k (sort(split(/\000/, $Topic{$j}))) {
if ($i == 0) {
$style = "<dd> <img src=\"/~jerry/gifs/redball.gif\">";
$endstyle = "</dd>";
}
else {
$style = "<LI>";
$endstyle = "";
}
undef(%field);
while ($k =~ /^(.*)<([a-z]*):(.*)>$/) {
$k = $1;
$field{$2} = $3;
}
#
# not defined
#
if (!defined($field{'url'}) && !defined($field{'link'})) {
if (!defined($Topic{$j."\000".$k})) {
print HOTDOC "$style $k $endstyle\n";
}
else {
$ref=&canon_path($j."\000".$k);
@_ = split(/\000/,$ref);
shift(@_);
$ref=join("/",@_);
$ref =~ s/[\s\000]+$//g;
$ref =~ s/[\s\000]+/_/g; # sub white spaces with _
print HOTDOC "$style <a href=\"$hottree/$ref/\"> <b> $k </b> </a> $endstyle";
}
}
#
# url is defined
#
elsif (defined($url=$field{'url'})) {
# url defined
print HOTDOC "$style <a href=\"$url\"> $k </a> $endstyle";
$num_url++ unless $seen{$url}++;
}
#
# link is defined
#
elsif (defined($path=&canon_path($field{'link'}))) {
#
# pointer to another subheading
#
$path =~ tr/\#/\//;
$path =~ s/[\s\000]+/_/g; # sub white spaces with _
$url = $hottree."/".$path."/";
print HOTDOC "$style <a href=\"$url\"> <b> $k@</b> </a> $endstyle";
}
#
# comment is defined
#
if (defined($comment=$field{'comment'})) {
print HOTDOC "- $comment";
}
#
# implement date, author
#
print HOTDOC "\n";
}
if ($i == 0) {
print HOTDOC "</H3>\n";
print HOTDOC "<img align=middle src=\"/~jerry/gifs/grad_line.gif\">\n";
}
else {
print HOTDOC"</UL>\n";
print HOTDOC"<hr><address><a href=\"/~jerry/\">jerry\@akebono.stanford.edu</a></address>\n";
}
close HOTDOC;
}
}
if ($opt_update) {
open (IT, ">>$hotstat");
print IT "<em> There are currently <b> $num_url </b> entries in the hotlist database </em>\n<br>";
close IT;
}
return;
}
#
# help
#
sub usage
{
print "-h = help\n";
print "-s <string> = filo's search for string\n";
print "-update = force an update from ~jerry/.hotlist\n";
return;
}
#
# main search mechanism
#
sub filo_search
{
#
# serach using filo's remote server...
#
@query = @_;
$pquery = join(" ", @query);
$pquery =~ s/\\(.)/$1/g;
#
# print out search strings to a log
#
open (SEARCH_LOG,">>$hotdir/search.log");
print SEARCH_LOG "$ENV{REMOTE_HOST} $pquery ", &ctime(time);
close SEARCH_LOG;
#
# talk to dave's server via socket 2345
#
$sockaddr_t = 'S n a4 x8';
$port = 2345;
$host = 'konishiki';
($x, $x, $proto) = getprotobyname('tcp');
socket(SEARCH, &AF_INET, &SOCK_STREAM, $proto) || die "socket: $!";
($name, $aliases, $type, $len, $thataddr) = gethostbyname($host);
$that = pack($sockaddr_t, &PF_INET, $port, $thataddr);
connect(SEARCH, $that) || die "connect: $!";
select((select(SEARCH), $| = 1)[0]);
print SEARCH "search\nkey $pquery\n\n";
$_ = <SEARCH>; # skip the first empty line
$_ = <SEARCH>;
if ($_ =~/error/) {
print "An error has occurred while searching for \`<b>$pquery</b>\':<p>\n";
while ($_ !~ /^$/) {
print $_;
$_ = <SEARCH>;
}
}
else {
print "Following items relevant to \`<b>$pquery</b>\' are found:<P>\n";
print "<DL>\n";
while ($_ !~ /^$/) {
if ($_ =~ /^path/) {
# chew up the path
undef($path);
undef($url);
undef($comment);
$_ =<SEARCH>;
while ($_ =~ /^\t/) {
chop;
$path .= $_;
$_ =<SEARCH>;
}
$path = &canon_path($path);
@p = split(/\t/,$path);
}
#
# wait for the next ^path
#
while ($_ !~ /^path/) {
if ($_ =~ /^$/) {
last;
}
if ($_ =~/^url (.*)$/) {
#chew up url
$url = $1;
}
if ($_ =~/^comment (.*)$/) {
#chew up comment
$comment = $1;
}
if ($_ =~/^date (.*)$/) {
#chew up date
$url_date = $1;
}
$_=<SEARCH>;
}
#
# print out the correct stuff...
#
if (defined($path)) {
if (defined($url)) {
$tail = pop @p;
$path = join ("/",@p);
$path =~ s/[\s\000]+/_/g; # sub white spaces with _
if (!$seen{$path}++) {
print "<h2> <a href=\"$http_url#begin_hotlist\">\n";
print "<img src=\"/~jerry/gifs/whiteball.gif\"></a>\n";
print "<a href=\"$hottree$path\">$path</a></h2>\n";
}
print "<ul><li><a href=\"$url\">$tail</a>\n";
}
else {
$path = join ("/",@p);
$path =~ s/[\s\000]+/_/g; # sub white spaces with _
if (!$seen{$path}++) {
print "<h2> <a href=\"$http_url#begin_hotlist\">\n";
print "<img src=\"/~jerry/gifs/whiteball.gif\"></a>\n";
print "<a href=\"$hottree/$path\">$path</a></h2>\n";
}
}
if (defined($comment)) {
print "- $comment\n";
}
print "</ul>\n";
}
if ($_ =~ /^$/) {
last;
}
}
}
close SEARCH;
}
#
# main routine
#
{
#
# definitions
#
$title = "Hotlist Search";
$http_url = "http://akebono.stanford.edu/~jerry/bin/index.html";
$htdocs_root = "/usr/local/etc/httpd/htdocs";
$hottree = "/users/www_server";
$hotdir = "/home/filo/public/stanford/940520";
$hotdoc = "$hotdir/hotdoc.html";
$hotstat = "$hotdir/hotstat.html";
$rootdoc = "$htdocs_root/users/jerry/stuff.html";
undef($MaxTabs);
undef($Topic);
undef($Key);
$num_url = 0;
#
# if there is an argument, process it...
#
if (defined @ARGV) {
&NGetOpt('h','update','s=s','search');
print "Content-type: text/html\n\n";
if ($opt_h) {
print "<HEAD>\n<TITLE>Help</TITLE>\n</HEAD>\n";
print "<body><h1>Help</h1>\n";
print "<pre>\n";
&usage;
print "</pre>\n";
}
elsif ($opt_update){
print "<HEAD>\n<TITLE>Update hotlist</TITLE>\n</HEAD>\n";
print "<body><h1>Updating hotlist</h1>\n";
print "<h3>This may take a while...</h3>\n";
# print ("umask is ", umask,"<br>\n");
umask((umask() & 0) | 75);
# print ("umask is ", umask,"<br>\n");
&parse_hotlist;
&print2file;
print "<a href=\"/~jerry/bin/index.html\">Reload</a> hotlist<br>\n";
}
else {
#
# do the search
#
print "<HEAD>\n<TITLE>Search of ", $title, "</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n<H1>", $title, "</H1>\n";
print "<base href=\"http://akebono.stanford.edu/~jerry/bin/index.html?-search\">\n";
#
print "Perl regular expressions can also be entered<br>\n";
print "The words will be matched against title, URL, and comments<br>\n";
print "Enter string(s) or substring(s) you wish to search for, and hit <b>return</b>.<br>\n";
print "<a name=\"begin_hotlist\"> <ISINDEX> </a> ";
if (!$opt_search) {
&filo_search(@ARGV);
}
#
print "<form method=\"POST\" action=\"http://akebono.stanford.edu/~jerry/bin/search-engine\">";
print "<img align=middle src=\"/~jerry/gifs/grad_line.gif\"><br>\n";
print "Press <input type=\"submit\" value=\"Here\"> to go to ";
print "<select name=\"search-engines\">\n";
print "<option selected> IS Workgroup Search Engines\n";
print "<option> SUSI II Search Engines\n";
print "<option> W3 Search Engines\n";
print "<option> DACLOD\n";
print "<option> World Wide Web Worm\n";
print "</select><br>\n";
print "<p></form>\n";
}
}
#
# no argument - just print out the list
#
else {
#
# print out the hotlist
#
$i = 0;
print "Content-type: text/html\n\n";
#
# foreach $k (keys(%ENV)) {
# print "$k=$ENV{$k}<p>\n";
# }
#
print "<HEADER>\n<TITLE>Jerry and Dave\'s Guide to WWW </TITLE>\n";
print "<base href=\"http://public.yahoo.com/filo/stanford/940520/\">\n";
print "</HEADER>\n";
print "<body>\n";
print "<H1>Jerry and Dave's WWW Interface... <I>(Always Under construction) </I></H1>";
if (defined($ENV{HTTP_FROM})) {
if ($ENV{HTTP_FROM}=~/(.+)@(.+)/) {
print "<h2> Welcome, $1 from $2 </h2><hr>";
}
else {
print "<h2> Welcome, $ENV{HTTP_FROM} </h2><hr>";
}
}
else {
print "<h2> Welcome, visitor from $ENV{REMOTE_HOST} </h2><hr>";
}
open (IT, "<$rootdoc");
while (<IT>) {
print ;
}
close IT;
# print "<h2> Please Read!!</h2>This is the <i>new</i> version of the hotlist with new directory organization. Please <a href=\"/~jerry/form.html\">tell me</a> of any bugs. Thanks.<hr>";
open (IT, "<$hotstat");
while (<IT>) {
print ;
}
close IT;
# print "<hr>\n";
open (HOTDOC, "<$hotdoc") || warn ("open: $hotdoc");
while (<HOTDOC>) {
print ;
$i++; # to handle the bug!!
sleep 1 unless ($i % 1400 ); # to handle the bug!!
}
close HOTDOC;
}
print "</body>\n";
}
@artlung
Copy link
Author

artlung commented Apr 11, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment