/^rfc822Mailbox/ { tmp = substr($0, n) no_mparts = split(tmp, mailparts, "@") if (no_mparts == 2) { if ("'$EMAILUKORDER'" == "yes") { no_doms = split(mailparts[2], domains, ".") email = mailparts[1] "@" domains[no_doms] for (i = no_doms - 1; i > 0; i--) email = email "." domains[i] } else email = tmp } else email = tmp } END { if (gotentry == "TRUE") { longform[entry ",name"] = sprintf ("\n%-15s %s", "name:", name) if (deptname != "") longform[entry ",dept"] = sprintf ("%-15s %s", "department:", deptname) if (phone != "") longform[entry ",phone"] = sprintf ("%-15s %s", "phone: ", phone) if (email != "") longform[entry ",email"] = sprintf ("%-15s %s", "email: ", email) longform[entry ",org"] = sprintf ("%-15s %s", "organisation: ", org) shortform[entry] = sprintf ("%-20s %-20s %-s", name, phone, deptname) if (deptname == "") { shortform[entry] = shortform[entry] org shortform[entry ",org"] = "" } else shortform[entry ",org"] = org gotentry = "FALSE" } if (entry == 0) { printf("\nCannot find an entry with that name\n") exit } if (partialRes != "") { printf("\nThere are too many results to print.\n") printf("Try and be more specific with your query to reduce the number\n") printf("of results returned\n\n") exit } if (entry > 20) for (i=1; i <= entry; i++) { printf "%s", shortform[i] if ((noOfOrgs > 1) && (shortform[i ",org"] != "")) printf ",\n%44s%s", "", shortform[i ",org"] printf "\n" } else for (i=1; i <= entry; i++) { print longform[i ",name"] if (longform[i ",dept"]) print longform[i ",dept"] if (longform[i ",phone"]) print longform[i ",phone"] if (longform[i ",email"]) print longform[i ",email"] if (noOfOrgs > 1) print longform[i ",org"] } } ' /tmp/dscresults$pid | pg -e -n -p "RETURN for next screen; q to quit: " } dodepts () { grep "ou=" | sed 's/.*ou=//' | awk ' { print $0 } END { if (NR == 0) printf("\nNo such department\n") > "/tmp/nodept'$pid'" } ' } deptlist () { partial=`awk ' BEGIN { orgno = 0 partial = "FALSE" } /^\(Partial/ { partial = "TRUE" next } { n = index($0, "=") orgno++ org[orgno] = substr($0, n + 1) } END { if (orgno == 0) print "No departments!" > "/tmp/deptlist'$pid'" else for (i = 1;i <= orgno; i++) print org[i] > "/tmp/deptlist'$pid'" print partial } '` if [ -r /tmp/deptlist$pid ]; then sort /tmp/deptlist$pid | pg -e -n -p "RETURN for next screen; q to quit: " rm /tmp/deptlist$pid if [ "$partial" = "TRUE" ]; then echo echo "Too many departments to print ... " echo fi fi } dosites () { grep "o=" | sed 's/.*o=//' | awk ' { orgs[NR] = $0 } END { if ("'$site'" == "*") { printf("\nThese sites currently have entries in the Directory\n") > "/tmp/siteres'$pid'" for (i = 1; i <= NR; i++) print orgs[i] > "/tmp/siteres'$pid'" print "" > "/tmp/siteres'$pid'" } else if (NR == 0) printf("\nNo such site\n") > "/tmp/siteres'$pid'" else if (NR > 5) { printf("\nFound all the following sites - too many to search\n") > "/tmp/siteres'$pid'" printf("Try and specify the organisation name more precisely\n\n") > "/tmp/siteres'$pid'" for (i = 1; i <= NR; i++) print orgs[i] > "/tmp/siteres'$pid'" print "" > "/tmp/siteres'$pid'" } else for (i = 1; i <= NR; i++) print orgs[i] } ' } fuzzy="" connected="false" breakout="false" while true do rm -f /tmp/dscresults$pid /tmp/dscresults${pid}2 name="" while echo -n "Enter the person's name (or \"?\" for help, \"q\" to quit): "; read name do if [ "$name" = "?" ]; then showhelp name="" else break fi done if [ "$name" = "q" ]; then rm -f /tmp/dscresults$pid /tmp/dscresults${pid}2 break fi deptname="" echo -n "Enter department (\"Return\" to search all depts, * to list depts): " read deptname if [ "$deptname" != "" ]; then deptstring="ou=$deptname" if [ "$name" = "" ]; then name="*" fi fi echo -n "Enter site (\"Return\" for $SHORTSITE, * to list all sites): " read site if [ "$site" != "" ]; then if [ "$name" = "" -a "$deptname" = "" ]; then deptname="*" deptstring="ou=$deptname" fi fi if [ "$name" = "" -a "$deptname" = "" -a "$site" = "" ]; then if [ "$breakout" = "false" ]; then breakout="true" continue else break fi fi breakout="false" if [ "$connected" = "false" ]; then echo "Connecting to the directory ..." connected="true" fi matchtype="=" if [ "$name" = "*" ]; then searchname="*" else searchname="*$name*" fi if [ "$deptname" != "" ]; then searchdept="*$deptname*" fi if [ "$site" = "*" ]; then searchsitefilter="o=*" else searchsitefilter="o=*$site*" fi wait moveto "$CDN" -nocheck if [ "$site" != "" ] then #echo "Looking for sites..." # DEBUG IFS=$NewIFS search -nosizelimit -singlelevel -filter "$searchsitefilter & ! objectclass=dsa" -nopart 2>/dev/null | dosites > /tmp/sitelist$pid if [ -r "/tmp/siteres$pid" ]; then pg -e -n -p "RETURN for next screen; q to quit: " /tmp/siteres$pid rm /tmp/siteres$pid fi for SITE in `cat /tmp/sitelist$pid` do echo "Searching site: $SITE..." echo "organization - $SITE" >> /tmp/dscresults${pid} moveto "${CDN}@o=$SITE" -nocheck if [ "$deptname" = "*" ]; then echo " List of departments ..." search -nosizelimit -relative -type ou \ -filter "(objectclass=organizationalUnit)" 2>/dev/null | deptlist else if [ "$deptname" = "" ]; then search -nosizelimit -norelative -show -subtree \ -searchaliases -type commonName telephoneNumber rfc822Mailbox \ -filter "(cn=$searchname) & (! objectclass=dsa)" 2>/tmp/dscresults${pid}2 >>/tmp/dscresults$pid else search -nosizelimit -singlelevel -filter "(ou$matchtype$searchdept)" -nopart 2>/dev/null | dodepts > /tmp/depts$pid if [ -r "/tmp/nodept$pid" ]; then cat /tmp/nodept$pid rm /tmp/nodept$pid fi for ORGUNIT in `cat /tmp/depts$pid` do echo " Searching dept: $ORGUNIT..." moveto "${CDN}@o=$SITE@ou=$ORGUNIT" -nocheck > /dev/null 2>&1 search -nosizelimit -norelative -show -searchaliases \ -subtree -type commonName telephoneNumber rfc822Mailbox \ -filter "(cn$matchtype$searchname) & (! objectclass=dsa)" 2>>/tmp/dscresults${pid}2 >> /tmp/dscresults$pid done rm -f /tmp/depts$pid fi fi done rm -f /tmp/sitelist$pid IFS=$OldIFS else moveto "$ORGRDN" -nocheck if [ "$deptname" = "*" ]; then echo " List of departments ..." search -nosizelimit -relative -type ou \ -filter "(objectclass=organizationalUnit)" 2>/dev/null | deptlist else if [ "$deptname" = "" ]; then search -nosizelimit -norelative -show -subtree \ -searchaliases -type commonName telephoneNumber rfc822Mailbox \ -filter "(cn=$searchname) & (! objectclass=dsa)" 2>/tmp/dscresults${pid}2 >/tmp/dscresults$pid else IFS=$NewIFS search -nosizelimit -singlelevel -filter "(ou$matchtype$searchdept)" -nopart 2>/dev/null | dodepts > /tmp/depts$pid if [ -r "/tmp/nodept$pid" ]; then cat /tmp/nodept$pid rm /tmp/nodept$pid fi for ORGUNIT in `cat /tmp/depts$pid` do echo "Searching dept: $ORGUNIT..." moveto "$CDN@$ORGRDN@ou=$ORGUNIT" -nocheck >/dev/null 2>&1 search -nosizelimit -norelative -show -searchaliases \ -subtree -type commonName telephoneNumber rfc822Mailbox \ -filter "(cn=$searchname) & (! objectclass=dsa)" 2>>/tmp/dscresults${pid}2 >> /tmp/dscresults$pid done rm -f /tmp/depts$pid IFS=$OldIFS fi fi fi if [ ! "$deptname" = "*" ]; then if [ -r /tmp/dscresults$pid ]; then showentries fi fi echo "" done else echo -n "Do you need help?:(y/n) " read help case "$help" in y|yes|Y|YES) cat << ENDSUMMARY The 'advanced' user interface displays the commands (these are single letters) and the 'Search area', which is the area of the database to search. Initially this is '$LONGSITE'. The interface can be used to search for a person, department, organisation or place - this is selected by typing the 't' command until the required type is displayed. To search for an entry, type 's' then the entry, followed by Return. Entries that match will be listed (or the first 50, if there are more than this). The screen can be scrolled down by typing [ and back up by typing ]. Each entry has a number. To list an entry, type its number. After a search, the search area will change to reflect the current position in the database. The 'w' command is used to 'widen' the search, for example to move from a person's entry to the department, or from $SHORTSITE to GB, to search for other organisations that are running directory services. The searching uses fuzzy matching (and so is different from the 'simple' interface). The 'h' command will enter the help system, where a more detailed explanation of each command can be obtained. The 'q' command will exit. The advanced interface is a prototype, and many of the directory services at other organisations are still in an experimental stage. Type RETURN to continue ENDSUMMARY read junk;; esac sd fi cat << LOCALMESS