Commit d0686412 authored by Haarst, Jan van's avatar Haarst, Jan van
Browse files

Add option to add students (supervisors/end date)

parent 0fee53ee
......@@ -27,8 +27,50 @@ DN_ARRAY["AB"]="CN=USR_BIOINF_AB,OU=BioInformatics,OU=NoPolicy,OU=Servers,DC=wur
DB="${SCRIPTPATH}"/users.sqlite3.db
STUDENT=''
SUPERVISOR=''
END_DATE=''
# Six months in the future, last day of that month
DEFAULT_END_DATE=$(date -d "`date +%Y%m01` +7 month -1 day" +%F)
# Functions
# https://gist.github.com/davejamesmiller/1965569
function ask() {
local prompt default reply
if [[ ${2:-} = 'Y' ]]; then
prompt='Y/n'
default='Y'
elif [[ ${2:-} = 'N' ]]; then
prompt='y/N'
default='N'
else
prompt='y/n'
default=''
fi
while true; do
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read -r reply </dev/tty
# Default?
if [[ -z $reply ]]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
function ad_id_to_dn() {
echo $(ldapsearch -x -LLL -E pr=200/noprompt -H ldaps://ldap.wurnet.nl -D "$binddn" -w "${ADMINPASSWORD}" "(&(samAccountName="$1"))" -b "dc=wurnet,dc=nl" dn | sed -e '/^$/,$d' | sed ':a;N;$!ba;s/\n //g'| awk '{$1=""; print $0}')
}
......@@ -74,7 +116,22 @@ then
echo
fi
PS3="Select a DN: "
# Default to No if the user presses enter without giving an answer:
if ask "Is $NEW_USER a student ?" N; then
STUDENT="Y"
else
STUDENT="N"
fi
if [ "$STUDENT" == "Y" ]
then
read -p "Who is the supervisor of $NEW_USER ? " SUPERVISOR
read -p "What is the end date for access for $NEW_USER ? [${DEFAULT_END_DATE}] " END_DATE
END_DATE=${END_DATE:-${DEFAULT_END_DATE}}
echo
fi
PS3="Select a department to which $NEW_USER belongs: "
select DN_AVAIL in "${!DN_ARRAY[@]}"
do
......@@ -111,8 +168,7 @@ done
if [ -e "$DB" ]
then
echo "Adding $NEW_USER to database $DB"
# ACCOUNT|DEPARTMENT|SUPERVISOR|ADDED_BY|ENTRY_DATE|END_DATE
sqlite3 -batch "$DB" "insert into users (ACCOUNT,DEPARTMENT,ADDED_BY,SUPERVISOR,END_DATE) values ('"${NEW_USER}"','"${DN_AVAIL}"','"${SUDO_USER}"','','');"
sqlite3 -batch "$DB" "insert into users (ACCOUNT,DEPARTMENT,ADDED_BY,SUPERVISOR,END_DATE) values ('"${NEW_USER}"','"${DN_AVAIL}"','"${SUDO_USER}"','"${SUPERVISOR}"','"${END_DATE}"');"
fi
# TODO mail this automatically, using the right return adress
echo "Use this as mail template to mail $MAIL :"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment