From: (Dan Kogai) dankogai@jms.jeton.or.jp Subject: Submitting find-infomac.cgi in shar format Find-infomac package is a perl-based cgi script that does "find file" on i nfo-mac. Since this cgi requires only a copy of all-files.txt, virtually an yone with a unix-based httpd access can put this cgi. I deliberately did so to reduce the traffic to each search engine. I encourage as many as possible to presesent, maintain, and enhance this c gi as possible. The best way to go is to let all public info-mac mirrors wi th httpd access has a cgi like this (doesn't have to be mine at all as long as it does what mine does). You can see the original version at http://www.dnsa.or.jp/~dankogai/find-infomac Dan the Info-Mac Subscriber [96.03.29 JST] #!/bin/sh # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # .htaccess # Makefile # index.html # README.html # makeidx # makesymlinks # find-infomac-lib.pl # find-infomac.cgi # find-infomac.conf # find-infomac.form # echo x - .htaccess sed 's/^X//' >.htaccess << 'END-of-.htaccess' X# This may also be "None", "All", or any combination of "Indexes", X# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews". X XOptions FollowSymLinks Includes ExecCGI XAddType application/x-httpd-cgi .cgi X X Xorder allow,deny Xallow from all X X X X X END-of-.htaccess echo x - Makefile sed 's/^X//' >Makefile << 'END-of-Makefile' X# Makefile X XMAKEIDX = ./makeidx XMAKESYMLINKS = ./makesymlinks XFILES = .htaccess Makefile index.html README.html makeidx makesymlinks\ X find-infomac-lib.pl find-infomac.cgi find-infomac.conf find-infomac.form XARCHIVE = find-infomac.tar.gz XSHARARC = find-infomac.shar Xindex: X ${MAKEIDX} X Xarchive: ${FILES} X rm -f ${ARCHIVE} X tar cvf find-infomac.tar ${FILES} X gzip find-infomac.tar X chmod 644 ${ARCHIVE} Xshar: ${FILES} X rm -f ${SHARARC} X shar ${FILES} > ${SHARARC} X chmod 644 ${SHARARC} Xsymlinks: X ${MAKESYMLINKS} X Xall:index X X END-of-Makefile echo x - index.html sed 's/^X//' >index.html << 'END-of-index.html' X^M^M^M^MFi #root@dan-pm75[]:/usr/local/www/find-infomac# ls total 2092 1 *.cgi.txt@ 16 find-infomac-lib.pl* 1 *.html.txt@ 16 find-infomac.cgi* 4 ./ 1 find-infomac.cgi.txt@ 2 ../ 16 find-infomac.conf 16 .htaccess 16 find-infomac.form 16 Makefile 48 find-infomac.shar 16 README.html 16 find-infomac.tar.gz 1 README.html.txt@ 16 index.html 16 access-log 1 index.html.txt@ 880 all-files.idx 16 makeidx 960 all-files.txt 16 makesymlinks 1 cgi-lib.pl@ #root@dan-pm75[151]:/usr/local/www/find-infomac# cat find-infomac.shar # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # .htaccess # Makefile # index.html # README.html # makeidx # makesymlinks # find-infomac-lib.pl # find-infomac.cgi # find-infomac.conf # find-infomac.form # echo x - .htaccess sed 's/^X//' >.htaccess << 'END-of-.htaccess' X# This may also be "None", "All", or any combination of "Indexes", X# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews". X XOptions FollowSymLinks Includes ExecCGI XAddType application/x-httpd-cgi .cgi X X<Limit GET POST> Xorder allow,deny Xallow from all X</Limit> X X X X END-of-.htaccess echo x - Makefile sed 's/^X//' >Makefile << 'END-of-Makefile' X# Makefile X XMAKEIDX = ./makeidx XMAKESYMLINKS = ./makesymlinks XFILES = .htaccess Makefile index.html README.html makeidx makesymlinks\ X find-infomac-lib.pl find-infomac.cgi find-infomac.conf find-infomac.form XARCHIVE = find-infomac.tar.gz XSHARARC = find-infomac.shar Xindex: X ${MAKEIDX} X Xarchive: ${FILES} X rm -f ${ARCHIVE} X tar cvf find-infomac.tar ${FILES} X gzip find-infomac.tar X chmod 644 ${ARCHIVE} Xshar: ${FILES} X rm -f ${SHARARC} X shar ${FILES} > ${SHARARC} X chmod 644 ${SHARARC} Xsymlinks: X ${MAKESYMLINKS} X Xall:index X X END-of-Makefile echo x - index.html sed 's/^X//' >index.html << 'END-of-index.html' I have created this cgi because search engines these days makes darn too many hi <LI>Compact--requires only a copy of all-files.txt. You don't have to h <LI>Fast--because it only searches file names of info-mac archive. Noth <LI>Easy to manage--you don't even have to have a knowlege of cgi to use me. By configuring find-infomac.form, you can customize the appearance of fron You can try find-infomac via form below or <A HREF="find-infomac.cgi">directly i <LI><A HREF="find-infomac.tar.gz">Get tar.gz version of whole package</A END-of-index.htmlor any use of the package.s are documented, andi</A> echo x - README.html sed 's/^X//' >README.html << 'END-of-README.html' <LI>A copy of <A HREF="http://www.bio.cam.ac.uk/cgi-lib/">cgi-lib.pl</A> , a perl library by Steven E. Brenner which helps cgi programming by perl so ea sy that you can't even think of writing a perl cgi without it. If you don't hav <LI>Permission to run cgi. You don't have to be a super-user. Most sit es allow user html files under <tt>~/public_html</tt> and with proper access con trol file (usually <tt>.htaccess</tt>) you can run user-specific cgi under the d irectory in which access control file resides. This package contains sample .ht <LI>A copy of all-files.txt, available under "help" directory of any info-ma mkdir ~/public_html # you don't have to if you alrea <LI>get a tar, gzip'ed copy of this package. Just click <A HREF="find-i <LI>extract the contents of the package you just downloaded in step 1. <LI>You are all set. Suppose your site is foobar.com and your login nam e is baz, find-infomac.cgi is now accessible via <i>http://foobar.com/~baz/find- <LI>You don't have to have a whole mirror of info-mac. Whoever accesses find-infomac can choose their favorite mirror sites via list (the list can be e asily customized by editting <A HREF="find-infomac.form">find-infomac.form</A>. However, you need to have a copy of all-files.txt, which gets updated every day . If you have an access to cron, you should make an entry to crontab which upda <LI>Whenever you updated all-files.txt, you have to update the index fil <LI>You can also customize<A HREF="find-infomac.conf">find-infomac.conf< /A>. For instance, if your site actually mirrors info-mac under /mirror/info-ma <LI><A HREF=".htaccess">.htaccess</A>--Access control file for NCSA/Apat <LI><A HREF="Makefile">Makefile</A>--currently supports "index", "archiv <LI><A HREF="find-infomac.cgi.txt">find-infomac.cgi</A>--the heart of th <LI><A HREF="find-infomac.conf">find-infomac.conf</A>--configuration fil <LI><A HREF="find-infomac-lib.pl">find-infomac-lib.pl</A>--library for f <LI><A HREF="find-infomac.form">find-infomac.form</A>--A form which is " print-merged" by find-infomac.cgi to present an input form. By editting this fo rm you can customize the appearance of input form without knowledge of Common Ga <LI><A HREF="makeidx">makeidx</A>--a perl script that converts all-files <LI><A HREF="makesymlinks">makesymlinks</a>--a simple perl script which makes a symlinks from *.html and *.cgi to *.txt; Useful when you want to publish <LI>"Month" of date field is actually 31 days; timelocal.pl that comes with perl doesn't accept negative values unlike that of SunOS c library. I am n <LI>For any other bugs, <A HREF="mailto:dankogai@dnsa.or.jp">click here< END-of-README.html. echo x - makeidx sed 's/^X//' >makeidx << 'END-of-makeidx' X#!/usr/local/bin/perl X# X# find-infomac.cgi X# X# (c) 1996 Dan Kogai (dankogai@dnsa.or.jp) X# X# Permission granted to use and modify this library so long as the X# copyright above is maintained, modifications are documented, and X# credit is given for any use of the library. X Xrequire './find-infomac-lib.pl'; Xrequire './find-infomac.conf'; X Xopen(ALLFILE, "< $allfile"); Xopen(IDXFILE, "| sort -r > $idxfile"); X Xwhile($line = <ALLFILE>){ X next if ($line =~ /^;/); X # next if ($line =~ /^lr/); X ($flag,$size,$mon,$date,$year,$file, $tmp, $symlink) = X split(/[ \t\n]+/, $line); X if ($tmp eq "->") { X printf(IDXFILE "%s %8d %s -> %s\n", X &shortdate($year,$mon,$date), $size, $file, $symlink); X }else{ X printf(IDXFILE "%s %8d %s\n", X &shortdate($year,$mon,$date), $size, $file); X } X} X Xchmod 00644, $idxfile; END-of-makeidx echo x - makesymlinks sed 's/^X//' >makesymlinks << 'END-of-makesymlinks' X#!/usr/local/bin/perl X Xopendir(DIR, '.'); Xforeach $f (readdir(DIR)){ X if ($f =~ /\.html$/ || $f =~ /\.cgi$/){ X $g = $f . '.txt'; X unlink $g; X symlink($f, $g); X } X} END-of-makesymlinks echo x - find-infomac-lib.pl sed 's/^X//' >find-infomac-lib.pl << 'END-of-find-infomac-lib.pl' X#!/usr/local/bin/perl X# X# library functions for find-infomac.cgi X# X# (c) 1996 Dan Kogai (dankogai@dnsa.or.jp) X# X# Permission granted to use and modify this library so long as the X# copyright above is maintained, modifications are documented, and X# credit is given for any use of the library. X X Xrequire 'timelocal.pl'; X X# A cgi version of Print Merge; Replaces any entry of "$variable" X# in the form specified with $in{'variable'} while leaving "\$variable" X# intact. X# X# example: X# &ReadParse(*myarray); X# $myarray{'form'} = "myform.form" #source form X# &PrintMerge(*myarray); X Xsub PrintMerge{ X local (*in) = @_ if @_; X die "No form is specified\n" if ($in{'form'} eq ""); X open(FORM, "< $in{'form'}") || die "Can't open $in{'form'}\n"; X while(<FORM>){ X foreach $key (sort keys (%in)){ X $_ =~ s/([^\\])(\$$key)/$1$post{$key}/g; X } X $_ =~ s/\\\$/\$/g; X print $_; X } X} X Xsub shortdate{ X local($year,$mon,$date) = @_; X local(%months) = X ('Jan',0, 'Feb',1, 'Mar',2, 'Apr',3, 'May',4, 'Jun',5, X 'Jul',6, 'Aug',7, 'Sep',8, 'Oct',9, 'Nov',10, 'Dec',11); X return sprintf("%04d/%02d/%02d", $year,$months{$mon} + 1, $date); X} X Xsub today{ X local($ss,$mm,$hh,$dd,$mm,$yy) = localtime(); X return sprintf("%04d/%02d/%02d", $yy + 1900, $mm + 1, $dd); X} X X1; END-of-find-infomac-lib.pl echo x - find-infomac.cgi sed 's/^X//' >find-infomac.cgi << 'END-of-find-infomac.cgi' X#!/usr/local/bin/perl X# X# find-infomac.cgi X# X# (c) 1996 Dan Kogai (dankogai@dnsa.or.jp) X# X# Permission granted to use and modify this library so long as the X# copyright above is maintained, modifications are documented, and X# credit is given for any use of the library. X Xrequire 'cgi-lib.pl'; Xrequire './find-infomac-lib.pl'; Xrequire './find-infomac.conf'; X X$tmpfile = "/tmp/find-infomac.$$"; X# rainy day fund Xsub sighandle{ X local($sig) = @_; X close(TMPFILE); X unlink($tmpfile); X print STDERR "find-infomac.cgi: Caught a SIG$sig--exitting.\n"; X exit(0); X} Xforeach $sig X ('HUP', 'INT', 'QUIT', 'ILL', 'TRAP', 'ABRT', 'EMT', 'FPE', X 'KILL', 'BUS', 'SEGV', 'SYS', 'PIPE', 'ALRM', 'TERM', 'URG', X 'STOP', 'TSTP', 'CONT', 'CHLD', 'TTIN', 'TTOU', 'POLL', 'XCPU', X 'XFSZ', 'VTALRM', 'PROF', 'WINCH', 'LOST', 'USR1', 'USR2') X{ X $SIG{$sig} = 'sighandle'; X} X# X Xprint &PrintHeader; X Xif (&ReadParse(*post)){ X open(IDXFILE, "< $idxfile") || CgiDie("can't open $idxfile"); X open(TMPFILE, "> $tmpfile") || CgiDie("can't open $tmpfile"); X &writelog() if ( -w $logfile ) ; X X $filename = $post{'filename'}; X $namehow = $post{'namehow'}; X $site = $post{'site'}; X X &initdate($post{'date'},$post{'datehow'}); X $numfound = 0; X idxloop: while($line = <IDXFILE>){ X ($date,$size,$file,$arrow,$symlink) = split(/[ \t\n]+/, $line); X if (&found){ X last idxloop if (&outofdate($date)); X $numfound++; X $found = $file; X $found =~ s/$filename/<b>$&<\/b>/gio if ($filename ne ".") ; X printf(TMPFILE "%s %8d <a href=%s/%s>%s</a> %s %s\n", X $date, $size, $site, $file, $found, $arrow, $symlink); X } X } X print "<title>Items Found\n"; X print "

$numfound Items Found

\n"; X print "You can directly download "; X print "the file from the info-mac mirror site "; X print "$post{'site'}"; X print "by clicking the links below.

"; X print "

\n";
X    print "Date           Size Name\n";
X    print "
\n"; X open(TMPFILE, "< $tmpfile"); X while(){ X print; X } X print "
", "\n"; X unlink($tmpfile); X}else{ X $post{'date'} = &today; X $post{'action'} = "find-infomac.cgi"; X $post{'form'} = "find-infomac.form"; X &PrintMerge(*post); X} X X Xsub found{ X return 1 if ($filename eq ""); X return ($file =~ /$filename/io); X} X Xsub initdate{ X ($sdate,$datehow) = @_; X $sdate =~ /(\d+)\/(\d+)\/(\d+)/; local($ys,$ms,$ds) = ($1,$2,$3); X $stime = &timelocal(0,0,0,$ds,$ms - 1, $ys - 1900); X $diff = 86400 if ($datehow =~ /1 day/); X $diff = 86400 * 2 if ($datehow =~ /2 day/); X $diff = 86400 * 3 if ($datehow =~ /3 day/); X $diff = 86400 * 7 if ($datehow =~ /1 week/); X $diff = 86400 * 7 * 2 if ($datehow =~ /2 week/); X $diff = 86400 * 7 * 3 if ($datehow =~ /3 week/); X $diff = 86400 * 31 if ($datehow =~ /1 month/); X $diff = 86400 * 31 * 2 if ($datehow =~ /2 month/); X $diff = 86400 * 31 * 3 if ($datehow =~ /3 month/); X $diff = 86400 * 31 * 6 if ($datehow =~ /6 month/); X $diff = 86400 * 366 if ($datehow =~ /year/); X} X Xsub outofdate{ X ($fdate) = @_; X return 0 if ($datehow =~ /any/); X $fdate =~ /(\d+)\/(\d+)\/(\d+)/; local($yf,$mf,$df) = ($1,$2,$3); X $ftime = &timelocal(0,0,0,$df,$mf - 1, $yf - 1900); X return 0 if ($stime - $ftime < $diff); X return 1; X} X Xsub writelog{ X open(LOGFILE, "| cat >> $logfile;") || CgiDie("can't open $logfile"); X local($ss,$mm,$hh,$dy,$mo,$yr) = localtime(); X printf(LOGFILE "%02d/%02d/%02d %02d:%02d:%02d", X $yr,$mo+1,$dy,$hh,$mm,$ss); X if ($logtype =~ /detail/){ X print LOGFILE "\n"; X foreach $key (sort keys(%ENV)){ X printf(LOGFILE "\t%s = %s\n", $key, $ENV{$key}); X } X foreach $key (sort keys(%post)){ X printf(LOGFILE "\t%s = %s\n", $key, $post{$key}); X } X }else{ X printf(LOGFILE "\t%s\t%s", $ENV{'REMOTE_ADDR'}, $ENV{'REMOTE_HOST'}); X } X print LOGFILE "\n"; X return 1; X} X X END-of-find-infomac.cgi echo x - find-infomac.conf sed 's/^X//' >find-infomac.conf << 'END-of-find-infomac.conf' X#!/usr/local/bin/perl X# X# configure file for find-infomac.cgi X# X X X# path to all-files.txt used by makeidx X X$allfile ="./all-files.txt"; X X# name of index file generated from all-files.txt by makeidx X X$idxfile = "./all-files.idx"; X X# path to log file. If not world-readeable writable (mode 666), X# simply no log gets created. To init log file, do something like; X# X# touch access-log ; chmod 666 access-log X# X# via shell. X X$logfile="./access-log"; X X# kind of logs to take. "detail" dumps every environment variable and X# every query to log file while "brief" puts only remote host. X X$logtype="brief"; X# $logtype="detail"; X X1; # don't delete me!END-of-find-infomac.conf echo x - find-infomac.form sed 's/^X//' >find-infomac.form << 'END-of-find-infomac.form' X XFind Info-mac X

Find File in Info-mac

X
X
XFind items on X Xwhose X
X
X X X X X
Name X X X
Date uploaded X X X
X X
X X X
X X X X
X
X
X
XEND-of-find-infomac.form exit .