Subversion Repositories ALCASAR

Rev

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