From: (Dan Kogai)
[email protected]
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<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'
X<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">^M<HTML>^M<HEAD>^M^M<TITLE>Fi
#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:
[email protected]">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 (
[email protected])
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 (
[email protected])
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 (
[email protected])
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</title>\n";
X print "<h2><center>$numfound Items Found</center></h2>\n";
X print "You can directly download ";
X print "the file from the info-mac mirror site ";
X print "<a href=$post{'site'}>$post{'site'}</a>";
X print "by clicking the links below.<p>";
X print "<pre>\n";
X print "Date Size Name\n";
X print "<hr>\n";
X open(TMPFILE, "< $tmpfile");
X while(<TMPFILE>){
X print;
X }
X print "</pre>", "\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.fo
rm'
X<html>
X<title>Find Info-mac</title>
X<h2><center>Find File in Info-mac</center></h2>
X<hr>
X<form action=$action method=post>
X<b>Find items on</b>
X<select name=site width=50%>
X <option>
ftp://ftp.ims.ac.jp/pub/mac/info-mac
X <option>
ftp://ftp.lab.kdd.co.jp/info-mac
X <option>
ftp://ftp.center.osaka-u.ac.jp/info-mac
X <option>
ftp://ftp.web.ad.jp/info-mac
X <option>
ftp://ftp.iij.ad.jp/pub/info-mac
X <option>
ftp://ftp.pcvan.or.jp/pub/info-mac
X <option>
ftp://ftp.riken.go.jp/pub/mac/info-mac
X <option>--------
X <option>
ftp://ftp.ausom.net.au/pub/mirrors/info-mac
X <option>
ftp://archie.au/micros/mac/info-mac
X <option>-
X <option>
ftp://ftp.univie.ac.at/systems/mac/info-mac
X <option>--
X <option>
ftp://ftp.agt.net/pub/info-mac
X <option>
ftp://ftp.ucs.ubc.ca/pub/mac/info-mac
X <option>---
X <option>
ftp://ftp.funet.fi/pub/mac/info-mac
X <option>----
X <option>
ftp://ftp.francenet.fr/pub/miroirs/info-mac
X <option>
ftp://ftp.ibp.fr/pub/mac/info-mac
X <option>
ftp://ftp.jussieu.fr/pub/mac/info-mac
X <option>
ftp://ftp.calvacom.fr/pub/mac/info-mac
X <option>----
X <option>
ftp://ftp.informatik.rwth-aachen.de/pub/info-mac
X <option>
ftp://ftp.cs.tu-berlin.de/pub/mac/info-mac
X <option>
ftp://ftp.rrzn.uni-hannover.de/pub/info-mac
X <option>-----
X <option>
ftp://ftp.hk.super.net/pub/mirror/info-mac
X <option>
ftp://ftp.technion.ac.il/pub/unsupported/mac/info-mac
X <option>------
X <option>
ftp://cnuce-arch.cnr.it/pub/info-mac
X <option>-------
X <option>
ftp://hwarang.postech.ac.kr/pub/mac/info-mac
X <option>
ftp://math2.kaist.ac.kr/pub/mac/info-mac
X <option>---------
X <option>
ftp://ftp.euro.net/Mac/info-mac
X <option>
ftp://ftp.nic.surfnet.nl/mirror-archive/software/info-mac
X <option>
ftp://ftp.fenk.wau.nl/pub/mac/info-mac
X <option>----------
X <option>
ftp://ftp.vuw.ac.nz/info-mac
X <option>-----------
X <option>
ftp://ftp.bitcon.no/pub/micro/mac/info-mac
X <option>
ftp://mac.uio.no/info-mac
X <option>------------
X <option>
ftp://king.ncb.gov.sg/info-mac
X <option>
ftp://ftp.nus.sg/pub/mac
X <option>-------------
X <option>
ftp://ftp.uji.es/pub/mirror/mac/info-mac
X <option>
ftp://ftp.urv.es/pub/mirror/info-mac
X <option>--------------
X <option>
ftp://ftp.sunet.se/pub/mac/info-mac
X <option>---------------
X <option>
ftp://ftp.switch.ch/mirror/info-mac
X <option>-----------------
X <option>
ftp://nctuccca.edu.tw/Macintosh/info-mac
X <option>------------------
X <option>
ftp://ftp.bups.bilkent.edu.tr/pub/info-mac
X <option>-------------------
X <option>
ftp://src.doc.ic.ac.uk/packages/info-mac
X <option>--------------------
X <option>
ftp://ftp.amug.org/pub/mirrors/info-mac
X <option>
ftp://mirror.apple.com/mirrors/info-mac
X <option>
ftp://tornado.rfx.com/pub/info-mac
X <option>
ftp://fiesta.tsc.udel.edu/pub/mirrors/info-mac
X <option>
ftp://ftp.circa.ufl.edu/pub/software/ufmug/mirrors/info-mac
X <option>
ftp://ftp.hawaii.edu/mirrors/info-mac
X <option>
ftp://uiarchive.cso.uiuc.edu/pub/systems/mac/info-mac
X <option>
ftp://grind.isca.uiowa.edu/mac/infomac
X <option>
ftp://ftp.delphi.com/pub/mirrors/info-mac
X <option>
ftp://wuarchive.wustl.edu/systems/mac/info-mac
X <option>
ftp://ftp.orst.edu/pub/systems/info-mac
X <option>
ftp://ftp.dataplex.net/pub/info-mac
X <option>
ftp://ftp.pht.com/pub/mac/info-mac
X <option>
ftp://mirrors.aol.com/pub/info-mac
X <option>
ftp://ftp.uu.net/systems/mac/info-mac
X</select>
X<b>whose</b>
X<hr>
X<center>
X<table width=80%>
X<tr><th align=left width=25%>Name
X<td width=25%><select name=namehow>
X <option>in regexp matches
X </select>
X<td><input type=text name=filename>
X</tr>
X<tr><th align=left>Date uploaded
X<td><select name=datehow>
X <option>any time
X <option>-
X <option>is within 1 year of
X <option>--
X <option>is within 6 months of
X <option>is within 3 months of
X <option>is within 2 months of
X <option>is within 1 month of
X <option>---
X <option>is within 3 weeks of
X <option>is within 2 weeks of
X <option>is within 1 week of
X <option>----
X <option>is within 3 days of
X <option>is within 2 days of
X <option>is within 1 day of
X </select>
X<td><input type=text name=date value=$date>
X</tr>
X<tr>
X</table>
X
X<hr>
X
X<table width=80% align=center>
X<td> <input type=reset>
X<td align=right>
X <table border=2 cellpadding=1>
X <td align=center valign=center><input type=submit value=Find></td>
X </table>
X</table>
X</center>
X</form>
X</html>END-of-find-infomac.form
exit