#!/bin/sh set -e usage() { echo "Usage: ${0} {tel|uid|uidNumber|cn|...} " echo "e.g. $0 uid dxk1" } #LDAP_SERVER="ldap.bfh.ch" #LDAP_SERVER="ldap-master.bfh.ch" #LDAP_SERVER="ldap1.bfh.ch" #LDAP_SERVER="ldap2.bfh.ch" #LDAP_SERVER="ldap3.bfh.ch" #LDAP_SERVER="ldapdmz1.bfh.ch" #LDAP_SERVER="ldapdmz2.bfh.ch" #LDAP_SERVER="ldapdmz3.bfh.ch" #LDAP_SERVER="ldap1.bfh.science" #LDAP_SERVER="ldap2.bfh.science" #LDAP_SERVER="ldap3.bfh.science" #LDAP_SERVER="ldap4.bfh.science" PASS="iPaw-e45zn" ACTION="${1}" PARAM="${2}" if [ $# -lt 1 ] then echo "Missing ARG(s)" usage exit 1 fi NAME=$(cat /etc/hostname) case "$NAME" in *bfh.science) LDAP_SERVER="ldap.bfh.science" AUTHSTRING="" DC="dc=bfh" ;; *bfh.ch) IP4=$(ip a | grep 147.87) || IP4="" IP6=$(ip a | grep 2a07:6b47) || IP6="" if [ -z "$IP4" ] && [ -z "$IP6" ]; then LDAP_SERVER="ldapdmz.bfh.ch" else LDAP_SERVER="ldap.bfh.ch" fi AUTHSTRING="-D 'cn=unix-nss,ou=srv-account,dc=bfh,dc=ch' -w $PASS" DC="dc=bfh,dc=ch" ;; *) LDAP_SERVER="ldapdmz.bfh.ch" AUTHSTRING="-D 'cn=unix-nss,ou=srv-account,dc=bfh,dc=ch' -w $PASS" DC="dc=bfh,dc=ch" ;; esac if [ -z "$PARAM" ] then ldapsearch -LLL -x -s sub "$AUTHSTRING" -H ldaps://"${LDAP_SERVER}":636 -b "$DC" "$ACTION" else case "${ACTION}" in tel|telephoneNumber) CMD="ldapsearch -LLL -x -s sub ${AUTHSTRING} -H ldaps://${LDAP_SERVER}:636 -b $DC telephoneNumber=*${PARAM} | grep --color=never -E '^(cn|telephoneNumber): '" ;; *) CMD="ldapsearch -LLL -x -s sub ${AUTHSTRING} -H ldaps://${LDAP_SERVER}:636 -b $DC $ACTION=${PARAM}" ;; esac fi eval "$CMD"