Subversion Repositories ALCASAR

Rev

Rev 1769 | Rev 1794 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
672 richard 1
#/bin/bash
63 franck 2
# $Id: alcasar-profil.sh 1790 2016-02-07 16:10:13Z franck $
3
 
672 richard 4
# alcasar-profil.sh
5
# by Richard REY
6
# This script is distributed under the Gnu General Public License (GPL)
7
 
8
# Gestion des comptes liés aux profiles
9
# Manage the profil logins
10
 
1 root 11
ADM_PROFIL="admin"
12
PROFILS="backup manager"
13
ALL_PROFILS=`echo $ADM_PROFIL $PROFILS`
434 richard 14
DIR_KEY="/usr/local/etc/digest"
1 root 15
SED="/bin/sed -i"
1790 franck 16
#HOSTNAME=`uname -n`
17
HOSTNAME="ALCASAR Control Center (ACC)"
1353 richard 18
Lang=`echo $LANG|cut -c 1-2`
518 stephane 19
 
1 root 20
# liste les comptes de chaque profile
21
function list () {
22
	for i in $ALL_PROFILS
23
	do
1369 richard 24
		if [ $Lang == "fr" ]
25
       		then
26
			echo -n "Comptes liés au profil '$i' : "
1353 richard 27
 
1369 richard 28
		else
29
	       		echo -n "accounts linked with profile '$i' : "
30
		fi
31
		account_list=`cat $DIR_KEY/key_only_$i | cut -d':' -f1|sort`
32
		for account in $account_list
33
		do
34
			echo -n "$account " 
35
		done
36
	echo
1 root 37
	done
38
}
27 franck 39
# ajoute les comptes du profil "admin" aux autres profils
316 richard 40
# crée le fichier de clés contenant tous les compte (pour l'accès au centre de gestion)
1 root 41
function concat () {
509 richard 42
	> $DIR_KEY/key_all
1 root 43
	for i in $PROFILS
44
	do
45
		cp -f $DIR_KEY/key_only_$ADM_PROFIL $DIR_KEY/key_$i
46
		cat $DIR_KEY/key_only_$i >> $DIR_KEY/key_$i
316 richard 47
		cat $DIR_KEY/key_only_$i >> $DIR_KEY/key_all
1 root 48
	done
49
	cp -f $DIR_KEY/key_only_$ADM_PROFIL $DIR_KEY/key_$ADM_PROFIL
316 richard 50
	cat $DIR_KEY/key_only_$ADM_PROFIL >> $DIR_KEY/key_all
1 root 51
	chown -R root:apache $DIR_KEY
52
	chmod 640 $DIR_KEY/key_*
53
}
54
 
1769 richard 55
usage="Usage: alcasar-profil.sh [-l|--list] [-a|--add] [-d|--del] [-p|--pass]"
1 root 56
nb_args=$#
57
args=$1
58
 
59
# on met en place la structure minimale
60
if [ ! -e $DIR_KEY/key_$ADM_PROFIL ]
61
then
62
	touch $DIR_KEY/key_$ADM_PROFIL
63
fi
64
cp -f $DIR_KEY/key_$ADM_PROFIL $DIR_KEY/key_only_$ADM_PROFIL
65
for i in $PROFILS
66
do
67
	if [ ! -e $DIR_KEY/key_only_$i ]
316 richard 68
	then
1 root 69
		touch $DIR_KEY/key_only_$i
70
	fi
71
done
72
concat
73
if [ $nb_args -eq 0 ]
74
then
75
	echo $usage
76
	exit 0
77
fi
78
case $args in
79
	-\? | -h* | --h*)
80
		echo "$usage"
81
		exit 0
82
		;;
1769 richard 83
	--add|-a)	
1 root 84
		# ajout d'un compte
85
		list
1353 richard 86
		if [ $Lang == "fr" ]
87
	       	then
88
			echo -n "Choisissez un profil ($ALL_PROFILS) : "
89
		else
90
			echo -n "Select a profile ($ALL_PROFILS) : "
91
		fi
1 root 92
		read profil
1353 richard 93
		if [ $Lang == "fr" ]
94
		then
95
			echo -n "Entrez le nom du compte à créer (profil '$profil') : "
96
		else
97
		       	echo "Enter the name of the account to create (profile '$profil') : "
98
		fi
1 root 99
		read account
100
		# on teste s'il n'existe pas déjà
101
		for i in $ALL_PROFILS
102
		do
103
			tmp_account=`cat $DIR_KEY/key_only_$i | cut -d':' -f1`
104
			for j in $tmp_account
105
				do
106
				if [ "$j" = "$account" ]
1353 richard 107
					then if [ $Lang == "fr" ]
108
						then
109
							echo "Ce compte existe déjà"
110
						else
111
							echo "This account already exists"
112
						fi
1 root 113
					exit 0
114
				fi
115
				done
116
		done
1353 richard 117
		/usr/bin/htdigest $DIR_KEY/key_only_$profil $HOSTNAME $account
1 root 118
		concat
119
		list
120
		;;
1769 richard 121
	--del|-d)
1 root 122
		# suppression d'un compte
123
		list
1353 richard 124
		if [ $Lang == "fr" ]
125
		then
126
			echo -n "entrez le nom du compte à supprimer : "
127
		else
128
			echo -n "enter the name of the account to remove : "
129
		fi
1 root 130
		read account
131
		for i in $ALL_PROFILS
132
			do
133
			$SED "/^$account:/d" $DIR_KEY/key_only_$i
134
			done
135
		concat
136
		list
137
		;;
1769 richard 138
	--pass|-p)
1 root 139
		# changement du mot de passe d'un compte
140
		list
1353 richard 141
		if [ $Lang == "fr" ]
142
		then
143
			echo "Changement de mot de passe"
144
			echo -n "Entrez le nom du compte : "
145
		else
146
			echo "Password change"
147
			echo -n "Enter the name of the account : "
148
		fi
1 root 149
		read account
150
		for i in $ALL_PROFILS
151
		do
152
			tmp_account=`cat $DIR_KEY/key_only_$i | cut -d':' -f1`
153
			for j in $tmp_account
154
				do
155
				if [ "$j" = "$account" ]
156
					then
1353 richard 157
					/usr/bin/htdigest $DIR_KEY/key_only_$i $HOSTNAME $account
1 root 158
				fi
159
				done
160
		done
161
		concat
162
		;;
1769 richard 163
	--list|-l)
1 root 164
		# liste des comptes par profile
165
		list
166
		;;
167
	*)
1353 richard 168
		if [ $Lang == "fr" ]
169
		then
170
			echo "Argument inconnu :$1";
171
		else
172
			echo "Unknown argument : $i";
173
		fi
1 root 174
		echo "$usage"
175
		exit 1
176
		;;
177
esac