Subversion Repositories ALCASAR

Rev

Rev 2454 | Rev 2564 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2454 Rev 2488
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-profil.sh 2454 2017-12-09 18:59:31Z tom.houdayer $
2
# $Id: alcasar-profil.sh 2488 2018-02-25 14:53:54Z lucas.echard $
3
 
3
 
4
# alcasar-profil.sh
4
# alcasar-profil.sh
5
# by Richard REY
5
# by Richard REY
6
# This script is distributed under the Gnu General Public License (GPL)
6
# This script is distributed under the Gnu General Public License (GPL)
7
 
7
 
8
# Gestion des comptes liés aux profiles
8
# Gestion des comptes liés aux profiles
9
# Manage the profil logins
9
# Manage the profil logins
10
 
10
 
-
 
11
DIR_BIN="/usr/local/bin" # scripts directory
11
ADM_PROFIL="admin"
12
ADM_PROFIL="admin"
12
PROFILS="backup manager"
13
PROFILS="backup manager"
13
ALL_PROFILS=`echo $ADM_PROFIL $PROFILS`
14
ALL_PROFILS=`echo $ADM_PROFIL $PROFILS`
14
DIR_KEY="/usr/local/etc/digest"
15
DIR_KEY="/usr/local/etc/digest"
15
SED="/bin/sed -i"
16
SED="/bin/sed -i"
16
Lang=`echo $LANG|cut -c 1-2`
17
Lang=`echo $LANG|cut -c 1-2`
-
 
18
REALM="ALCASAR Control Center (ACC)"
-
 
19
 
-
 
20
# génère le htdigest
-
 
21
function htdigest () {
-
 
22
	passwdfile="$1"
-
 
23
	username="$2"
-
 
24
 
-
 
25
	[ -f "$passwdfile" ] || touch "$passwdfile"
-
 
26
 
-
 
27
	[ $(grep -c "${username}:${REALM}:" "$passwdfile") ] && existing_user=0 || existing_user=1
-
 
28
 
-
 
29
	if [ $existing_user -eq 1 ]; then
-
 
30
		echo "Changing password for user $username in realm $REALM"
-
 
31
	else
-
 
32
		echo "Adding user $username in realm $REALM"
-
 
33
	fi
-
 
34
 
-
 
35
	equal=0
-
 
36
 
-
 
37
	while [ $equal -eq 0 ]; do
-
 
38
		echo -n "New password: "
-
 
39
		read -s pass_1
-
 
40
		echo
-
 
41
		echo -n "Confirm the new password: "
-
 
42
		read -s pass_2
-
 
43
		echo
-
 
44
 
-
 
45
		if [ "$pass_1" != "$pass_2" ]; then
-
 
46
			echo -e "\nThe passwords don't match.\n"
-
 
47
		else
-
 
48
			equal=1
-
 
49
		fi
-
 
50
	done
-
 
51
 
-
 
52
	digest="${username}:${REALM}:"
-
 
53
	digest+=$(echo -n "${username}:${REALM}:${pass_1}" | md5sum | cut -d" " -f1)
-
 
54
 
-
 
55
	if [ $existing_user -eq 0 ]; then
-
 
56
		echo "$digest" >> "$passwdfile"
-
 
57
	else 
-
 
58
		sed -i "s/${username}:${REALM}:.*/${digest}/" "$passwdfile"
-
 
59
	fi
-
 
60
}
17
 
61
 
18
# liste les comptes de chaque profile
62
# liste les comptes de chaque profile
19
function list () {
63
function list () {
20
	for i in $ALL_PROFILS
64
	for i in $ALL_PROFILS
21
	do
65
	do
Line 48... Line 92...
48
	cat $DIR_KEY/key_only_$ADM_PROFIL >> $DIR_KEY/key_all
92
	cat $DIR_KEY/key_only_$ADM_PROFIL >> $DIR_KEY/key_all
49
	chown -R root:apache $DIR_KEY
93
	chown -R root:apache $DIR_KEY
50
	chmod 640 $DIR_KEY/key_*
94
	chmod 640 $DIR_KEY/key_*
51
}
95
}
52
 
96
 
53
usage="Usage: alcasar-profil.sh [-l|--list] [-a|--add] [-d|--del] [-p|--pass]"
97
usage="Usage: alcasar-profil.sh [-l|--list] [-a|--add [profil]] [-d|--del] [-p|--pass]"
54
nb_args=$#
98
nb_args=$#
55
args=$1
99
arg1=$1
-
 
100
arg2=$2
56
 
101
 
57
# on met en place la structure minimale
102
# on met en place la structure minimale
58
if [ ! -e $DIR_KEY/key_$ADM_PROFIL ]
103
if [ ! -e $DIR_KEY/key_$ADM_PROFIL ]
59
then
104
then
60
	touch $DIR_KEY/key_$ADM_PROFIL
105
	touch $DIR_KEY/key_$ADM_PROFIL
Line 71... Line 116...
71
if [ $nb_args -eq 0 ]
116
if [ $nb_args -eq 0 ]
72
then
117
then
73
	echo $usage
118
	echo $usage
74
	exit 0
119
	exit 0
75
fi
120
fi
76
case $args in
121
case $arg1 in
77
	-\? | -h* | --h*)
122
	-\? | -h* | --h*)
78
		echo "$usage"
123
		echo "$usage"
79
		exit 0
124
		exit 0
80
		;;
125
		;;
81
	--add|-a)
126
	--add|-a)
82
		# ajout d'un compte
-
 
83
		list
-
 
84
		if [ $Lang == "fr" ]
127
		if [ $nb_args -eq 1 ]
85
		then
128
		then
-
 
129
			# ajout d'un compte
-
 
130
			list
-
 
131
			if [ $Lang == "fr" ]
-
 
132
			then
86
			echo -n "Choisissez un profil ($ALL_PROFILS) : "
133
				echo -n "Choisissez un profil ($ALL_PROFILS) : "
-
 
134
			else
-
 
135
				echo -n "Select a profile ($ALL_PROFILS) : "
-
 
136
			fi
-
 
137
			read profil
87
		else
138
		else
88
			echo -n "Select a profile ($ALL_PROFILS) : "
139
			profil="$2"
89
		fi
140
		fi
90
		read profil
-
 
91
		if [ $Lang == "fr" ]
141
		if [ $Lang == "fr" ]
92
		then
142
		then
93
			echo -n "Entrez le nom du compte à créer (profil '$profil') : "
143
			echo -n "Entrez le nom du compte à créer (profil '$profil') : "
94
		else
144
		else
95
			echo "Enter the name of the account to create (profile '$profil') : "
145
			echo "Enter the name of the account to create (profile '$profil') : "
Line 110... Line 160...
110
						fi
160
						fi
111
					exit 0
161
					exit 0
112
				fi
162
				fi
113
				done
163
				done
114
		done
164
		done
115
		/usr/bin/htdigest $DIR_KEY/key_only_$profil "ALCASAR Control Center (ACC)" $account
165
		htdigest $DIR_KEY/key_only_$profil "$account"
116
		concat
166
		concat
117
		list
167
		list
118
		;;
168
		;;
119
	--del|-d)
169
	--del|-d)
120
		# suppression d'un compte
170
		# suppression d'un compte
Line 149... Line 199...
149
		do
199
		do
150
			tmp_account=`cat $DIR_KEY/key_only_$i | cut -d':' -f1`
200
			tmp_account=`cat $DIR_KEY/key_only_$i | cut -d':' -f1`
151
			for j in $tmp_account
201
			for j in $tmp_account
152
				do
202
				do
153
				if [ "$j" = "$account" ]
203
				if [ "$j" = "$account" ]
154
					then
204
				then
155
					/usr/bin/htdigest $DIR_KEY/key_only_$i "ALCASAR Control Center (ACC)" $account
205
					htdigest $DIR_KEY/key_only_$i "$account"
156
				fi
206
				fi
157
				done
207
				done
158
		done
208
		done
159
		concat
209
		concat
160
		;;
210
		;;
161
	--list|-l)
211
	--list|-l)
162
		# liste des comptes par profile
212
		# liste des comptes par profil
163
		list
213
		list
164
		;;
214
		;;
165
	*)
215
	*)
166
		if [ $Lang == "fr" ]
216
		if [ $Lang == "fr" ]
167
		then
217
		then