#!/bin/sh #----------------------------------------------------------------------------- # /var/install/bin/eisportal-tools-userdata [username] # # Creation: 28.06.2006 ys # Last Update: $Id$ # # Copyright (c) 2005-2006 Yves Schumann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #----------------------------------------------------------------------------- #include eislib . /var/install/include/eislib . /etc/config.d/eisportal mysql_data_dir=/var/lib/mysql mysql_base_dir=/usr/local/mysql roleNoRights="disabled" roleUser="User" rolePortalAdmin="EisPortal Administrator" clrhome #----------------------------------------------------------------------------- # check for mysql #----------------------------------------------------------------------------- if [ ! -f /var/run/mysql.pid ] then mecho -error "Error! Cannot connect to MySQL server." else mecho "" mecho -info "Change details from EisPortal users" mecho "" #----------------------------------------------------------------------------- # if username was given, use this given name # else ask for username to change details #----------------------------------------------------------------------------- if [ $# -lt 1 ] then userToChangeData=`/var/install/bin/ask "Enter username: " "" "*"` mecho "" else userToChangeData=$1 fi if [ -z "$userToChangeData" ] then mecho -error "Empty username!" anykey exit 1 fi #----------------------------------------------------------------------------- # load user data #----------------------------------------------------------------------------- userData=`${mysql_base_dir}/bin/mysql --skip-column-names -h ${EISPORTAL_DB_HOST} -D${EISPORTAL_DB_NAME} -u${EISPORTAL_DB_ADMIN_USER} -p${EISPORTAL_DB_ADMIN_PASS} -e"SELECT name, fname, lname, role FROM eisportal_user WHERE (name = '${userToChangeData}');"` if [ "${userData}" != "" ] # is user existing? then # -> yes #----------------------------------------------------------------------------- # Extract user data #----------------------------------------------------------------------------- oldFName=`echo "${userData}" | cut -s -f2` oldLName=`echo "${userData}" | cut -s -f3` oldRole=`echo "${userData}" | cut -s -f4` #----------------------------------------------------------------------------- # Ask for new first name #----------------------------------------------------------------------------- mecho "Actual first name is ${oldFName}" newFName=`/var/install/bin/ask "Enter new first name or hit return: " "" "*"` mecho "" if [ -z ${newFName} ] then newFName=${oldFName} fi #----------------------------------------------------------------------------- # Ask for new family name #----------------------------------------------------------------------------- mecho "Actual family name is ${oldLName}" newLName=`/var/install/bin/ask "Enter new family name or hit return: " "" "*"` mecho "" if [ -z ${newLName} ] then newLName=${oldLName} fi #----------------------------------------------------------------------------- # Ask for role change #----------------------------------------------------------------------------- if [ "${oldRole}" == "0" ] then oldRoleName=${roleNoRights} elif [ "${oldRole}" == "1" ] then oldRoleName=${roleUser} elif [ "${oldRole}" == "3" ] then oldRoleName=${rolePortalAdmin} fi mecho "Actual role of ${userToChangeData} is \"${oldRoleName}\"" mecho "Change role of this user?" mecho -n "Enter value or hit return " changeRole=`/var/install/bin/ask "(0 = no rights, 1 = User, 2 = Portal-Admin): " "" "*"` if [ -z ${changeRole} ] then newRole=${oldRole} else if [ ${changeRole} -lt 0 -o ${changeRole} -gt 2 ] then mecho -info "You have not entered a correct role for the new user!" mecho -info "No change on users role." newRole=${oldRole} fi if [ ${changeRole} -eq 2 ] then # da der Modul-Admin (2) an dieser Stelle nicht festgelegt wird, # hier den Portal-Admin-Wert (3) eintragen newRole=3 fi fi #----------------------------------------------------------------------------- # ask for password change #----------------------------------------------------------------------------- mecho "" changePass=`/var/install/bin/ask "Change password of user \"${userToChangeData}\"?" "n"` if [ "${changePass}" == "yes" ] then mecho "" mecho -n "Enter password: " stty -echo read newPass stty echo mecho "" echo -n "Retype password: " stty -echo read rePass stty echo mecho "" #----------------------------------------------------------------------------- # check given new password #----------------------------------------------------------------------------- if [ "$userToChangeData" == "$newPass" ] then mecho -error "Username and Password could not be identical!" anykey exit 1 fi if [ "$newPass" != "$rePass" ] then mecho -error "Passwords not identical!" anykey exit 1 else #----------------------------------------------------------------------------- # create md5-Hash of the password #----------------------------------------------------------------------------- newPassMD5=`echo -n "$newPass" | md5sum | cut -d' ' -f1` #----------------------------------------------------------------------------- # update database with new password #----------------------------------------------------------------------------- mecho "" mecho -info -n "Updating details of user ${userToChangeData}... " ${mysql_base_dir}/bin/mysql -h ${EISPORTAL_DB_HOST} -D${EISPORTAL_DB_NAME} -u${EISPORTAL_DB_ADMIN_USER} -p${EISPORTAL_DB_ADMIN_PASS} -e"UPDATE eisportal_user SET pass = '${newPassMD5}' , fname = '${newFName}' , lname = '${newLName}' , role = '${newRole}' WHERE name = '${userToChangeData}';" mecho -info "Done." fi else #----------------------------------------------------------------------------- # update database without new password #----------------------------------------------------------------------------- mecho "" mecho -info -n "Updating details of user ${userToChangeData}... " ${mysql_base_dir}/bin/mysql -h ${EISPORTAL_DB_HOST} -D${EISPORTAL_DB_NAME} -u${EISPORTAL_DB_ADMIN_USER} -p${EISPORTAL_DB_ADMIN_PASS} -e"UPDATE eisportal_user SET fname = '${newFName}' , lname = '${newLName}' , role = '${newRole}' WHERE name = '${userToChangeData}';" mecho -info "Done." fi #----------------------------------------------------------------------------- # now update the rights of this user #----------------------------------------------------------------------------- mecho "" /var/install/bin/eisportal-modules-set-user-rights ${userToChangeData} else mecho -warn "This user doesn\`t exist, modification skipped." fi fi # check for mysql anykey exit 0 ### --------------------------------------------------------------------------- ### End ###----------------------------------------------------------------------------