#!/bin/sh
# GR snail mail finder. (c) Steve Braham
#
#.. To support an ISINDEX type search, set search string if given
# an argument on the command line
#
mailfile="/usr/local/lib/addresses/grplaces"
safeit="/usr/local/http/support/safeitgr"
unescape="/usr/local/http/support/unescape"
if [ $# -gt 0 ]; then
PREFIX="search="
fi
#
#.. Check that a query has been made
#
#date>/tmp/a
if [ $QUERY_STRING ]; then
#
#.. Strip the variables out from the query string,
# and assign them into the environment, prefixed by 'QS_'
#
# o sed removes any ' that would upset quoted assignment
#
# o awk ensures that
# - all variables passed have legal names
# - special characters are not interpreted by sh
#
# First a security strip search
SAFE_QUERY=`$safeit QUERY_STRING`
#echo $QUERY_STRING >>/tmp/a
#echo $SAFE_QUERY >>/tmp/a
eval `echo $PREFIX$SAFE_QUERY | sed -e 's/'"'"'/%27/g' |awk '
BEGIN{RS="&";FS="="; seclist = ""}
$1~/^[a-zA-Z][a-zA-Z0-9_]*$/ {
printf "QS_%s=%c%s%c\n",$1,39,$2,39}' `
#
#.. Output header
#
cat << EOM
Content-type: text/html
GR address search output
Search Results
EOM
# Unescape search string, extract first word. Further safety check.
allpars=`$unescape "$QS_search"`
export allpars
allpars=`$safeit allpars`
firstpar=`echo "$allpars"|awk '{print $1}'`
export firstpar
firstpar=`$safeit firstpar`
# Now set search type. (regex or plain)
# A single unknown will be interpreted as an ISINDEX search with
# a plain search, case insensitive.
case $QS_method in
advanced) searcher=egrep ;;
simple) searcher=fgrep ;;
*) searcher=fgrep ;;
esac
case $QS_case in
sensitive) sea="$searcher" ;;
insensitive) sea="$searcher -i" ;;
*) sea="$searcher -i" ;;
esac
#ok, do it
$sea "$allpars" $mailfile | awk -F\& 'BEGIN {found="0"}
found=="0" {print "
Match found.";
print"Click on highlighted text to see people";
print "at each address.
";
print "Extended Search Key:";
print "";
print "= Related addresses,";
print "";
print "= People at related addresses.";
print "";
found="1"}
{print "
"}
$3 == "" {print "- ", $2, ""}
$3 != "" {if ($2 == "Z")
print "
- ", $1, "";
else {
print "
- ", $1, "";
print "";
print "";
print "";
print "";};}
{print "
- ";
for (i=4; i<=NF; ++i) {
if ($i!="") print $i"
"};
print ""}
END { if (found == "0") {
print "
Sorry, no information found for: "allpars".";
print "Can attempt";
print "people,";
print "journal or";
print "address";
print "search for "firstpar"."} else print "
";
}' allpars="$allpars" firstpar="$firstpar"
# OK, it's done. Now just give a few options.
cat <New Searches:
GR People
GR Journal
GR Address
EOE
else
#
#.. The script was called without a query.
# Provide an ISINDEX type response for browsers
# without form support.
#
cat << EOM
Content-type: text/html
GRaddress Gateway
General Relativity Mail Addresses
This is a simple interface into the General Relativity
mailing address list. This service is provided by the
UBC
GR group, but the list itself is kept by
Malcolm MacCallum. It performs searches
on the list of snail mail addresses for GR institutions.
Simply type a piece of text into the dialog box
and GRaddress will then display any
entry that has that particular string in any field. Case does not
matter, and all
available entries will be displayed, but only a single field
will be matched.
Or go to:
GR People
GR Journal
HyperSpace
EOM
fi
echo "
"
ls -l $mailfile|awk '{
print "E-mail database last modified on "$5" "$6" "$7"."}'
echo "In case of problems, contact:
The Web Master (theoryweb@physics.ubc.ca)
Software written by
Steve Braham (braham@physics.ubc.ca)"