#!/usr/local/bin/rexx
/*
 QLANADMIN.rexx - Jim Dutton - 02/17/2000

 query an LDAP database for specific LAN Admin data, and
 display results in somewhat nice, line-mode format

 Requires: REXX (obviously) and LDAPSEARCH (UMich, Netscape?, OpenLDAP)
*/
Address 'UNIX'
If arg() = 0  then
  Do
    say; say "Usage (one of the following):"
    say "    qlanadmin <subdomain name>"
    say "    qlanadmin <organization/department name>"
    say "    qlanadmin <router subnet number>"
    say "    qlanadmin <organizational unit name>"
    say "    qlanadmin <AppleTalk Zone>"
    say "    qlanadmin <LAN Admin firstname lastname>"
    say; exit;
  End
Else
  parse arg s

ldapcmd    = "/usr/local/bin/ldapsearch"; ldaphost = "-h <LDAP host>"
ldapbase   = "-b o=<org>,c=US"
filter     = "'(|(dc="s")(subnet="s")(o="s")(ou="s")(appletalkzone="s")(cn="s"))'"
attributes = "lanadmin postofficebox telephonenumber dnsadmin o"
dnsadmin   = "None"; lanadmin = "Unknown"; telephonenumber = "Unknown"
mailaddr   = "Unknown"; organization = "Unknown"; org_seen = 0; cntag = "cn="

ldapcmd ldaphost ldapbase filter attributes "| rxstack"
If rc \= 0  then
  Do
    say "*** LDAPSEARCH ERROR (rc="rc") ***"
    say "--- search terminated ---"; Exit rc
  End

Do queued()
  parse pull attr "=" remainder
  Select
    When attr = ""                 then  Call DisplayResult
    When attr = "dc"               then  Call Process_LDAP_DN
    When attr = "lanadmin"         then  Call Process_lanadmin
    When attr = "postofficebox"    then  mailaddr = remainder
    When attr = "telephonenumber"  then  telephonenumber = remainder
    When attr = "dnsadmin"         then  Call Process_dnsadmin
    When attr = "o"                then  Call Process_organization
  End
End

Call DisplayResult
Exit

Process_LDAP_DN:
  parse var remainder subdomain "," . "=" protocol "," .
  If protocol \= "AppleTalk"  then  protocol = "IP"
Return

Process_lanadmin:
  If substr(remainder,1,3) = cntag  then  parse var remainder "=" lanadmin "," .
  Else lanadmin = remainder
Return

Process_dnsadmin:
  If substr(remainder,1,3) = cntag  then  parse var remainder "=" dnsadmin "," .
  Else dnsadmin = remainder
Return

Process_organization:
  If org_seen = 1  then  Return /* only show first organization attribute */
  Else;            Do; org_seen = 1;  organization = remainder; End
Return

DisplayResult:
  say "=================================================================="
  say "Subdomain        :" subdomain
  say "Network Protocol :" protocol
  say "LAN Administrator:" lanadmin
  say "Department       :" organization
  say "E-mail Address   :" mailaddr
  say "Telephone Number :" telephonenumber
  say "DNS Administrator:" dnsadmin
  say "=================================================================="; say
dnsadmin = "None"; lanadmin = "Unknown"; telephonenumber = "Unknown"
mailaddr = "Unknown"; organization = "Unknown"; org_seen = 0
Return
