-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzmbaccmgt
61 lines (55 loc) · 1.57 KB
/
zmbaccmgt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
###############################################################################
# Script to mass manage ZCS accounts
#
# Version: 1.0
# Date: 07/02/2012
# Author: Diego Lima <[email protected]>
###############################################################################
ZMBUSR="zimbra"
MGTPREFIX="/etc/4linux"
MGTLOG="$MGTPREFIX/activity.log"
MGTUSERLIST="`ls $MGTPREFIX/*.list`"
# doEnableAccount ACCOUNT
#
# Unlocks the given ACCOUNT to enable the user to log in
doEnableAccount(){
local ACCOUNT="$1"
echo "`date +%Y%m%d%H%M` - Enabling $ACCOUNT" | tee -a $MGTLOG
su - $ZMBUSR -c "zmprov ma $ACCOUNT zimbraAccountStatus active" || echo "`date +%Y%m%d%H%M` - Error enabling $ACCOUNT" | tee -a $MGTLOG
}
# doDisableAccount ACCOUNT
#
# Locks the given ACCOUNT to prevent the user from logging in
doDisableAccount(){
local ACCOUNT="$1"
echo "`date +%Y%m%d%H%M` - Disabling $ACCOUNT" | tee -a $MGTLOG
su - $ZMBUSR -c "zmprov ma $ACCOUNT zimbraAccountStatus locked" || echo "`date +%Y%m%d%H%M` - Error Disabling $ACCOUNT" | tee -a $MGTLOG
}
# doReadAccounts
#
# Generates an account list based on *.list files present on $MGTPREFIX
# and takes an action based on how the script was invoked from the command
# line.
doReadAccounts(){
local ACTION="$1"
local ACCOUNT=""
local LIST=""
for LIST in $MGTUSERLIST; do
for ACCOUNT in `cat $LIST`; do
case $ACTION in
"enable")
doEnableAccount "$ACCOUNT"
;;
"disable")
doDisableAccount "$ACCOUNT"
;;
*)
echo "Unsupported option"
exit 1
;;
esac
done
done
}
doReadAccounts $1