#!/bin/sh #----------------------------------------------------------------------------- # /var/install/bin/eisportal-tools-useradd [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 clrhome #----------------------------------------------------------------------------- # check for mysql #----------------------------------------------------------------------------- if [ ! -f /var/run/mysql.pid ] then mecho -error "Error! Cannot connect to MySQL server." else mecho "" mecho -info "Add user to EisPortal" mecho "" #----------------------------------------------------------------------------- # if username was given, use this given name # else ask for username to add #----------------------------------------------------------------------------- if [ $# -lt 1 ] then newName=`/var/install/bin/ask "Enter username: " "" "*"` mecho "" else newName=$1 fi #check if something was entered if [ -z "$newName" ] then mecho -error "Empty username!" anykey exit 1 fi #----------------------------------------------------------------------------- # ask for firstname #----------------------------------------------------------------------------- firstName=`/var/install/bin/ask "Enter users first name: " "" "+"` #----------------------------------------------------------------------------- # ask for lastname #----------------------------------------------------------------------------- lastName=`/var/install/bin/ask "Enter users family name: " "" "+"` #----------------------------------------------------------------------------- # Rechte des neuen Users abfragen. Hier wird aber nur ermittelt, ob es sich # um einen Portal-Admin handelt. Modul-Admins werden durch den Portal-Admin # eingestellt. # # 0 .. keine Rechte # 1 .. User # 2 .. Modul-Admin (Rechte werden im jeweiligen Modul gesetzt) # 3 .. Portal-Admin #----------------------------------------------------------------------------- mecho "" newRole=`/var/install/bin/ask "Enter role (0 = no rights, 1 = User, 2 = Portal-Admin): " "" "*"` if [ -z "$newRole" ] then mecho -info "You have not entered a role for the new user!" mecho -info "Setting role to standard user." newRole=1 fi if [ ${newRole} -lt 0 -o ${newRole} -gt 2 ] then mecho -info "You have not entered a correct role for the new user!" mecho -info "Setting role to standard user." newRole=1 fi if [ ${newRole} -eq 2 ] then # da der Modul-Admin hier nicht ermittelt wird, # hier den Admin-Wert eintragen newRole=3 fi #----------------------------------------------------------------------------- #ask for password #----------------------------------------------------------------------------- mecho "" mecho -n "Enter password: " stty -echo read newPass stty echo mecho "" echo -n "Retype password: " stty -echo read rePass stty echo mecho "" if [ "$newName" == "$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 mecho "" #----------------------------------------------------------------------------- # create md5-Hash of the password #----------------------------------------------------------------------------- newPassMD5=`echo -n "$newPass" | md5sum | cut -d' ' -f1` #----------------------------------------------------------------------------- # insert new user into user table #----------------------------------------------------------------------------- # is user existing? user_exists=`${mysql_base_dir}/bin/mysql -h ${EISPORTAL_DB_HOST} -D${EISPORTAL_DB_NAME} -u${EISPORTAL_DB_ADMIN_USER} -p${EISPORTAL_DB_ADMIN_PASS} -e"SELECT name FROM eisportal_user WHERE (name = '${newName}');" | grep ${newName} -c` if [ ${user_exists} -lt 1 ] then mecho -info -n "Inserting user into user table... " ${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_user ( name , pass , fname , lname , role ) VALUES ( '${newName}', '${newPassMD5}', '${firstName}', '${lastName}', '${newRole}');" mecho -info "Done." else mecho -warn "User exists, creation skipped." fi mecho "" fi fi # check for mysql # now set the rights of the new user for every modul /var/install/bin/eisportal-modules-set-user-rights ${newName} anykey exit 0 ### --------------------------------------------------------------------------- ### End ###----------------------------------------------------------------------------