Zarafa create user script for the DB plugin

From Zarafa wiki

(Difference between revisions)
Jump to: navigation, search
m
 
(8 intermediate revisions not shown)
Line 1: Line 1:
-
The Zarafa create user script.
+
{{Infobox
 +
|title        = Article information
 +
|image        = [[File:Logo_zarafa.jpg]]
-
This is a script that can be used to create users in a more friendly way for people who are new to Linux.
+
|header1 = Applies to:
 +
|label2  = Zarafa Version(s)
 +
|data2  = 6.40.x
 +
|label3  = OS version(s)
 +
|data3  = Any recent Linux version
 +
|label4  = Tested on
 +
|data4  = Ubuntu 10.04.1
 +
}}
 +
 
 +
This is a script that can be used to create users in a more friendly way for people who are new to Linux or have trouble remembering the various zarafa-admin variables.
The script will ask what values you want to give to a user, like:
The script will ask what values you want to give to a user, like:
-
User name, Password, full name, email address, administrator or not and if the user is non-active or active.
+
* User name
 +
* Password
 +
* full name
 +
* email address
 +
* administrator or not
 +
* and if the user is non-active or active.
Also when a non-active user is created the resource attributes will be asked. (auto accept meeting request and declining recurring and/or conflicting).
Also when a non-active user is created the resource attributes will be asked. (auto accept meeting request and declining recurring and/or conflicting).
-
To use the script run it as root. (Zarafa-server needs to be running)
+
To use the script, copy paste the text below into a new file, give the file executable rights (chmod +x). Then, run it as root (Zarafa-server needs to be running).
-
Feel free to improve the script.  
+
Feel free to improve the script (there are still some TODO's in there!).  
Line 19: Line 35:
# Script to create a user in Zarafa with the DB user plugin.
# Script to create a user in Zarafa with the DB user plugin.
-
# Version (date / time): 20110107-13:00
+
# Version (date / time): 20110114-13:00
#
#
# WARNING: DO NOT use this script when using the UNIX, LDAP or
# WARNING: DO NOT use this script when using the UNIX, LDAP or
# Active Directory plugin!
# Active Directory plugin!
-
echo 'This script will help you creating a new Zarafa user.'
 
-
echo 'DISCLAIMER: This script is only suitable for use with the DB plugin.'
 
-
echo 'Creating a new Zarafa user. Please enter the details of the user.'
 
# Check if the user is root (required to run the zarafa-admin tool).
# Check if the user is root (required to run the zarafa-admin tool).
Line 34: Line 47:
exit 0
exit 0
fi
fi
 +
 +
echo 'This script will help you creating a new Zarafa user.'
 +
echo 'DISCLAIMER: This script is only suitable for use with the DB plugin.'
 +
echo ' '
 +
echo 'Creating a new Zarafa user. Please enter the details of the user.'
#The user name. Input needed is the user name.
#The user name. Input needed is the user name.
echo
echo
while [ -z $username ] ;do  
while [ -z $username ] ;do  
-
echo -n 'User name of the new user:'
+
echo -n 'User name of the new user: '
read username
read username
done
done
 +
 +
#
 +
# TODO: create check if username is valid (doesn't exist, has valid characters etc.).
 +
# If valid, continue. If not valid, provide relevant feedback and return to previous step.
 +
#
#The password.
#The password.
while [ -z $password ] ;do
while [ -z $password ] ;do
-
       echo -n 'Password (will not be visible on input):'
+
       echo -n 'Password (will not be visible on input): '
read -s password
read -s password
echo ' '
echo ' '
done
done
 +
 +
#
 +
# TODO: create check if password is valid (meets security policies etc.).
 +
# If valid, continue. If not valid, provide relevant feedback and return to previous step.
 +
#
 +
#The full name. No " "  needed for full names with spaces
#The full name. No " "  needed for full names with spaces
-
while [ -z $full ] ;do
+
while [ -z "$full" ] ;do
-
         echo -n 'Full name of the new user (without quotes, can have spaces):'
+
         echo -n 'Full name of the new user (without quotes, can have spaces): '
         read full
         read full
done
done
Line 57: Line 86:
#The email address.  
#The email address.  
while [ -z $email ] ;do
while [ -z $email ] ;do
-
echo -n 'Email address of the new user:'
+
echo -n 'Email address of the new user: '
read email
read email
done
done
 +
#
 +
# TODO: create check if email address is valid (doesn't exist, has valid format etc.).
 +
# If valid, continue. If not valid, provide relevant feedback and return to previous step.
 +
#
-
#The admin attribute 1 for admin or 0 for no admin role. 2 can also be given this will make it a system admin.
+
#The admin attribute 1 for admin or 0 for no admin role. 2 can also be given, this will make the user a system admin.
while [ -z $admin ] ;do
while [ -z $admin ] ;do
echo 'Should the user have administrator rights?'
echo 'Should the user have administrator rights?'
-
echo 'Enter 1 for yes, 0 for no (The default is no):'
+
echo 'Enter 1 for yes, 0 for no (The default is no): '
read admin
read admin
admin="${admin:-0}"
admin="${admin:-0}"
Line 73: Line 106:
while [ -z $non ] ;do
while [ -z $non ] ;do
echo 'Should the non active bit be set for this user? This is common for resources.'
echo 'Should the non active bit be set for this user? This is common for resources.'
-
echo 'Enter 1 for yes, 0 for no (The default is no):'
+
echo 'Enter 1 for yes, 0 for no (The default is no): '
read non
read non
non="${non:-0}"
non="${non:-0}"
done
done
 +
 +
#
 +
# TODO: create option to add the user to extra groups, besides 'Everyone'.
 +
# If answer is no, continue. If answer is yes, display (a numbered list of?) currently available groups.
 +
# To select a group, input it's number. After hitting enter, display the list of groups the user is now in, and the list of remaining groups.
 +
# This 'loop' can be continued until user has been added to all desired groups.
 +
# Also provide option to create a new group if the desired group is not in the list.
 +
# When done, provide a way to exit the loop and continue
 +
#
 +
 +
#
 +
# TODO: create option to add quotas (warn / soft / hard quotas and override sytem quota, if set) to user.
 +
#
 +
 +
#
 +
# TODO: create option to set user's visibility in address book.
 +
#
 +
#The zarafa-admin command to create the user with the input given by the user.
#The zarafa-admin command to create the user with the input given by the user.
 +
echo 'Creating user... '
zarafa-admin -c "$username" -p "$password" -f "$full" -e "$email" -a "$admin" -n "'$non"
zarafa-admin -c "$username" -p "$password" -f "$full" -e "$email" -a "$admin" -n "'$non"
-
# Here we add the resource attributes if you want to.
+
#
 +
# TODO: create check if zarafa-admin exited successfully.
 +
# If yes, continue. If no, provide relevant feedback and exit.
 +
#
 +
 
 +
# Here we add the resource attributes if the user is non-active.
if [ $non == "1" -o $non == "1" ]; then
if [ $non == "1" -o $non == "1" ]; then
   echo  'This user is non active. Please set the resource attributes as well.'
   echo  'This user is non active. Please set the resource attributes as well.'
-
   echo  'Would you like to use this resource as a bookable room? Yes/No:'
+
   echo  'Would you like to use this resource as a bookable room? Yes/No: '
   read accept
   read accept
# If the resource is set to auto accept you might want to set these options aswell.
# If the resource is set to auto accept you might want to set these options aswell.
   if [ $accept == "yes" ]; then
   if [ $accept == "yes" ]; then
-
     echo -n 'Would you like to make the resource decline recurring appointments? Yes/No:'
+
     echo -n 'Would you like to make the resource decline recurring appointments? Yes/No: '
     read recurring
     read recurring
-
     echo -n 'Would you like to make the resource decline conflicting appointments? Yes/No:'
+
     echo -n 'Would you like to make the resource decline conflicting appointments? Yes/No: '
     read conflict
     read conflict
     zarafa-admin -u "$username" --mr-accept "$accept" --mr-decline-conflict "$conflict" --mr-decline-recurring "$recurring"  
     zarafa-admin -u "$username" --mr-accept "$accept" --mr-decline-conflict "$conflict" --mr-decline-recurring "$recurring"  
   fi
   fi
-
   echo "done"
+
   echo "Done."
fi
fi
-
#The details of the user will now be displayed:
+
#Show the details of the newly created user
echo 'User created with the following details:'
echo 'User created with the following details:'
zarafa-admin --details "$username"
zarafa-admin --details "$username"
 +
 +
#
 +
# TODO: create option to restart the script if another user should be created.
 +
#
exit;
exit;
</pre>
</pre>

Latest revision as of 12:10, 14 February 2011

Article information
Logo zarafa.jpg
Applies to:
Zarafa Version(s) 6.40.x
OS version(s) Any recent Linux version
Tested on Ubuntu 10.04.1

This is a script that can be used to create users in a more friendly way for people who are new to Linux or have trouble remembering the various zarafa-admin variables.

The script will ask what values you want to give to a user, like:

  • User name
  • Password
  • full name
  • email address
  • administrator or not
  • and if the user is non-active or active.

Also when a non-active user is created the resource attributes will be asked. (auto accept meeting request and declining recurring and/or conflicting).

To use the script, copy paste the text below into a new file, give the file executable rights (chmod +x). Then, run it as root (Zarafa-server needs to be running).

Feel free to improve the script (there are still some TODO's in there!).


The script:

#!/usr/bin/env bash

# Script to create a user in Zarafa with the DB user plugin.
# Version (date / time): 20110114-13:00
#
# WARNING: DO NOT use this script when using the UNIX, LDAP or
# Active Directory plugin!

# Check if the user is root (required to run the zarafa-admin tool).
if [ $USER != 'root' ]
then
echo
echo "You need root privileges to run this script. Exiting."
exit 0
fi

echo 'This script will help you creating a new Zarafa user.'
echo 'DISCLAIMER: This script is only suitable for use with the DB plugin.'
echo ' '
echo 'Creating a new Zarafa user. Please enter the details of the user.'

#The user name. Input needed is the user name.
echo
while [ -z $username ] ;do 
	echo -n 'User name of the new user: '
	read username
done

#
# TODO: create check if username is valid (doesn't exist, has valid characters etc.). 
# If valid, continue. If not valid, provide relevant feedback and return to previous step.
#

#The password.
while [ -z $password ] ;do
       	echo -n 'Password (will not be visible on input): '
	read -s password
	echo ' '
done

#
# TODO: create check if password is valid (meets security policies etc.). 
# If valid, continue. If not valid, provide relevant feedback and return to previous step.
#


#The full name. No " "  needed for full names with spaces
while [ -z "$full" ] ;do
        echo -n 'Full name of the new user (without quotes, can have spaces): '
        read full
done

#The email address. 
while [ -z $email ] ;do
	echo -n 'Email address of the new user: '
	read email
done

#
# TODO: create check if email address is valid (doesn't exist, has valid format etc.). 
# If valid, continue. If not valid, provide relevant feedback and return to previous step.
#

#The admin attribute 1 for admin or 0 for no admin role. 2 can also be given, this will make the user a system admin.
while [ -z $admin ] ;do
	echo 'Should the user have administrator rights?'
	echo 'Enter 1 for yes, 0 for no (The default is no): '
	read admin
	admin="${admin:-0}"
done

#The non-active attribute for non-active users (resources) 
while [ -z $non ] ;do
	echo 'Should the non active bit be set for this user? This is common for resources.'
	echo 'Enter 1 for yes, 0 for no (The default is no): '
	read non
	non="${non:-0}"
done

#
# TODO: create option to add the user to extra groups, besides 'Everyone'. 
# If answer is no, continue. If answer is yes, display (a numbered list of?) currently available groups.
# To select a group, input it's number. After hitting enter, display the list of groups the user is now in, and the list of remaining groups.
# This 'loop' can be continued until user has been added to all desired groups.
# Also provide option to create a new group if the desired group is not in the list.
# When done, provide a way to exit the loop and continue
#

#
# TODO: create option to add quotas (warn / soft / hard quotas and override sytem quota, if set) to user. 
# 

#
# TODO: create option to set user's visibility in address book. 
# 


#The zarafa-admin command to create the user with the input given by the user.
echo 'Creating user... '
zarafa-admin -c "$username" -p "$password" -f "$full" -e "$email" -a "$admin" -n "'$non"

#
# TODO: create check if zarafa-admin exited successfully. 
# If yes, continue. If no, provide relevant feedback and exit.
#

# Here we add the resource attributes if the user is non-active.
if [ $non == "1" -o $non == "1" ]; then
  echo  'This user is non active. Please set the resource attributes as well.'
  echo  'Would you like to use this resource as a bookable room? Yes/No: '
  read accept

# If the resource is set to auto accept you might want to set these options aswell.
   if [ $accept == "yes" ]; then
     echo -n 'Would you like to make the resource decline recurring appointments? Yes/No: '
     read recurring
     echo -n 'Would you like to make the resource decline conflicting appointments? Yes/No: '
     read conflict
     zarafa-admin -u "$username" --mr-accept "$accept" --mr-decline-conflict "$conflict" --mr-decline-recurring "$recurring" 

  fi
  echo "Done."

fi


#Show the details of the newly created user
echo 'User created with the following details:'
zarafa-admin --details "$username"

#
# TODO: create option to restart the script if another user should be created.
#

exit;
Personal tools