#!/bin/sh #--------------------------------------------------------------------------- # /var/install/bin/eisportal-modules-set-user-rights # # Creation: 09.08.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. #--------------------------------------------------------------------------- #exec 2>/public/eisportal-trace$$.log #set -x . /etc/config.d/eisportal . /var/install/include/eislib if [ $# -lt 1 ] then mecho "" mecho -info "Usage: $0 USERNAME" mecho -info "USERNAME must be a username existing in the EisPortal user table" mecho "" exit 1 fi user_Name=$1 modulDir="/var/www/htdocs/eisportal/modules/" mysql_data_dir=/var/lib/mysql mysql_base_dir=/usr/local/mysql ### ------------------------------------------------------------------------- ### Iterate over all modules found in /var/www/htdocs/eisportal/modules/ ### ------------------------------------------------------------------------- setUserRights () { if [ ! -f /var/run/mysql.pid ] then mecho -error "Error! Cannot connect to MySQL server." exit 1 else callDir=`pwd` cd /var/www/htdocs/eisportal/modules # get ID of user 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 ID, name FROM eisportal_user WHERE ( name = '${user_Name}' ) "` user_ID=`echo "${userData}" | cut -s -f1` # mecho ${user_ID} #foundModules=`ls -l | cut -d' ' -f10` #mecho ${foundModules} foundModules=`dir` # mecho "foundModules: ${foundModules}" # check if every module exists in eisportal_modules for modul in ${foundModules} do modulExistsInModulTable=`${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 ID FROM eisportal_modules WHERE modulname = '${modul}'"` if [ -z ${modulExistsInModulTable} ] then mecho "Modul ${modul} not existing in table eisportal_modules" /var/install/bin/eisportal-modules-create-modul-entry ${modul} mecho "" fi done # iterate over all modules and check/set user rights ${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 ID, modulname FROM eisportal_modules " | while read modul_ID modul_Name do # get old role of user oldRole=`${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 modul_role FROM eisportal_rights WHERE user_ID = '${user_ID}' AND modul_ID = '${modul_ID}' "` # mecho "oldRole: $oldRole" if [ -z ${oldRole} ] then # no entry for this user found # must be a new user entryFound=false oldRole=0 else # old role exists in db entryFound=true fi # set human readable names for the roles if [ ${oldRole} -eq 0 ] then roleName="no rights" elif [ ${oldRole} -eq 1 ] then roleName="User" elif [ ${oldRole} -eq 2 ] then roleName="Modul-Admin" fi # say something to the admin mecho -n "User " mecho -n -info "${user_Name} " mecho -n "has actually for modul " mecho -n -info "${modul_Name} " mecho -n "the following rights: " mecho -info "${roleName}" mecho "Change role of this user?" mecho "Enter value or hit return " # and ask for modification changeRole=`/var/install/bin/ask "(0 = no rights, 1 = User, 2 = Modul-Admin): " "" "*" < /dev/tty` if [ -z ${changeRole} ] then # nothing entered # no change in users role newRole=${oldRole} else # something was given # check if this is a correct value if [ ${changeRole} -lt 0 -o ${changeRole} -gt 2 ] then mecho -info "You have not entered a correct role for user ${userName}!" mecho -info "No change on users role for ${modul}." newRole=${oldRole} else newRole=${changeRole} fi fi if [ ${entryFound} == true ] then # if entry exists in db then update this entry ${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_rights SET modul_role = '${newRole}' WHERE modul_ID = '${modul_ID}' AND user_ID = '${user_ID}' " else # if entry not exists then create a new entry ${mysql_base_dir}/bin/mysql -h ${EISPORTAL_DB_HOST} -D${EISPORTAL_DB_NAME} -u${EISPORTAL_DB_ADMIN_USER} -p${EISPORTAL_DB_ADMIN_PASS} -e"INSERT INTO eisportal_rights ( modul_ID , user_ID , modul_role ) VALUES ( '${modul_ID}', '${user_ID}', '${newRole}' ); " fi mecho "Role updated" mecho "" done fi # go back to the call directory cd ${callDir} } ###---------------------------------------------------------------------------- ### main ###---------------------------------------------------------------------------- setUserRights exit 0 ### --------------------------------------------------------------------------- ### End ###----------------------------------------------------------------------------