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.

98 lines
2.5 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. case $1 in
  20. -update)
  21. if [ ! -z "$3" ]; then
  22. $SEARCH "cn=*$2*$3" uid yearsPaid loginShell
  23. else
  24. echo "Usage: $SCRIPTNAME -fullname $FULLNAME"
  25. fi
  26. ;;
  27. -altmail)
  28. $SEARCH "altmail=$2" uid
  29. ;;
  30. -uid)
  31. $SEARCH "uid=$2"
  32. ;;
  33. -id)
  34. $SEARCH "id=$2" uid
  35. ;;
  36. -name)
  37. $SEARCH "cn=*$2*" uid
  38. ;;
  39. -nick)
  40. $SEARCH "gecos=*$2*" uid
  41. ;;
  42. -fullname)
  43. if [ ! -z "$3" ]; then
  44. $SEARCH "cn=*$2*$3" uid
  45. else
  46. echo "Usage: $SCRIPTNAME -fullname $FULLNAME"
  47. fi
  48. ;;
  49. -newbie)
  50. $SEARCH "newbie=TRUE" uid
  51. ;;
  52. -dcu)
  53. case $2 in
  54. username)
  55. SEARCH="cn=$3"
  56. dcusearch "$SEARCH"
  57. ;;
  58. fullname)
  59. if [ ! -z "$4" ]; then
  60. SEARCH="displayName=$3 $4"
  61. dcusearch "$SEARCH"
  62. else
  63. echo "Usage: $SCRIPTNAME -dcu fullname $FULLNAME"
  64. fi
  65. esac
  66. ;;
  67. -h)
  68. echo "Usage: $SCRIPTNAME [-altmail] [-uid] [-id] [-name] -[nick] -[fullname] query"
  69. echo "eg. $SCRIPTNAME -altmail $EMAIL"
  70. echo " $SCRIPTNAME -uid $USERNAME"
  71. echo " $SCRIPTNAME -fullname $FULLNAME"
  72. echo " $SCRIPTNAME -update $USERNAME"
  73. echo " $SCRIPTNAME -dcu username $USERNAME"
  74. echo " $SCRIPTNAME -dcu fullname $FULLNAME"
  75. echo ""
  76. echo "Only fullname takes 2 arguments."
  77. echo "All results will give just uid(s) apart from [-uid]"
  78. echo "[-uid] prints all ldap info for that uid"
  79. ;;
  80. *)
  81. echo "Usage: $SCRIPTNAME [-altmail] [-uid] [-id] [-name] [-nick] [-fullname] [-dcu [username] [fullname]] query"
  82. echo "eg. $SCRIPTNAME -altmail $EMAIL"
  83. echo " $SCRIPTNAME -uid $USERNAME"
  84. echo " $SCRIPTNAME -fullname $FULLNAME"
  85. echo " $SCRIPTNAME -update $USERNAME"
  86. echo " $SCRIPTNAME -dcu username $USERNAME"
  87. echo " $SCRIPTNAME -dcu fullname $FULLNAME"
  88. echo ""
  89. echo "Only fullname takes 2 arguments."
  90. echo "All results will give just uid(s) apart from [-uid]"
  91. ;;
  92. esac