admin scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.1 KiB

  1. #!/bin/bash
  2. # Quick ldap search tool
  3. # ver 0.1 sonic - I will never ever update this
  4. # ver 0.2 koffee - quick update & shell checking
  5. # ver 0.3 butlerx - add support for dcu AD
  6. SCRIPTNAME="rbsearch"
  7. EMAIL="bill.gates@hotmail.com"
  8. USERNAME="microbg"
  9. FULLNAME="Bill Gates"
  10. SEARCH="ldapsearch -D cn=root,ou=ldap,o=redbrick -xLLL -y /etc/ldap.secret"
  11. function dcusearch () {
  12. if [ ! -z "$2" ]; then
  13. SEARCH="$1 $2"
  14. else
  15. SEARCH=$1
  16. fi
  17. ldapsearch -x -h ad.dcu.ie -D "CN=rblookup,OU=Service Accounts,DC=ad,DC=dcu,DC=ie" -w "$(</etc/ldap_dcu.secret)" -b "OU=Students,DC=ad,DC=dcu,DC=ie" -s sub "($SEARCH)" cn gecos mail
  18. }
  19. function usage () {
  20. echo "Usage: $SCRIPTNAME [-altmail] [-uid] [-id] [-name] [-nick] [-fullname] [--dcu [username] [fullname]] query"
  21. echo "eg. $SCRIPTNAME -altmail $EMAIL"
  22. echo " $SCRIPTNAME -uid $USERNAME"
  23. echo " $SCRIPTNAME -fullname $FULLNAME"
  24. echo " $SCRIPTNAME -update $USERNAME"
  25. echo " $SCRIPTNAME -dcu username $USERNAME"
  26. echo " $SCRIPTNAME -dcu fullname $FULLNAME"
  27. echo ""
  28. echo "Only fullname takes 2 arguments."
  29. echo "All results will give just uid(s) apart from [-uid]"
  30. echo "[-uid] prints all ldap info for that uid"
  31. }
  32. case $1 in
  33. -update)
  34. if [ ! -z "$3" ]; then
  35. $SEARCH "cn=*$2*$3" uid yearsPaid loginShell
  36. else
  37. echo "Usage: $SCRIPTNAME -fullname $FULLNAME"
  38. fi
  39. ;;
  40. -altmail)
  41. $SEARCH "altmail=$2" uid
  42. ;;
  43. -uid|--user|-u)
  44. $SEARCH "uid=$2"
  45. ;;
  46. -id)
  47. $SEARCH "id=$2" uid
  48. ;;
  49. -name)
  50. $SEARCH "cn=*$2*" uid
  51. ;;
  52. -nick)
  53. $SEARCH "gecos=*$2*" uid
  54. ;;
  55. -fullname)
  56. if [ ! -z "$3" ]; then
  57. $SEARCH "cn=*$2*$3" uid
  58. else
  59. echo "Usage: $SCRIPTNAME -fullname $FULLNAME"
  60. fi
  61. ;;
  62. -newbie)
  63. $SEARCH "newbie=TRUE" uid
  64. ;;
  65. --dcu)
  66. case $2 in
  67. username)
  68. SEARCH="cn=$3"
  69. dcusearch "$SEARCH"
  70. ;;
  71. fullname)
  72. if [ ! -z "$4" ]; then
  73. SEARCH="displayName=$3 $4"
  74. dcusearch "$SEARCH"
  75. else
  76. echo "Usage: $SCRIPTNAME -dcu fullname $FULLNAME"
  77. fi
  78. esac
  79. ;;
  80. -h|--help)
  81. usage
  82. ;;
  83. *)
  84. usage
  85. ;;
  86. esac