8,6 → 8,7 |
# Gestion des comptes liés aux profiles |
# Manage the profil logins |
|
DIR_BIN="/usr/local/bin" # scripts directory |
ADM_PROFIL="admin" |
PROFILS="backup manager" |
ALL_PROFILS=`echo $ADM_PROFIL $PROFILS` |
14,7 → 15,50 |
DIR_KEY="/usr/local/etc/digest" |
SED="/bin/sed -i" |
Lang=`echo $LANG|cut -c 1-2` |
REALM="ALCASAR Control Center (ACC)" |
|
# génère le htdigest |
function htdigest () { |
passwdfile="$1" |
username="$2" |
|
[ -f "$passwdfile" ] || touch "$passwdfile" |
|
[ $(grep -c "${username}:${REALM}:" "$passwdfile") ] && existing_user=0 || existing_user=1 |
|
if [ $existing_user -eq 1 ]; then |
echo "Changing password for user $username in realm $REALM" |
else |
echo "Adding user $username in realm $REALM" |
fi |
|
equal=0 |
|
while [ $equal -eq 0 ]; do |
echo -n "New password: " |
read -s pass_1 |
echo |
echo -n "Confirm the new password: " |
read -s pass_2 |
echo |
|
if [ "$pass_1" != "$pass_2" ]; then |
echo -e "\nThe passwords don't match.\n" |
else |
equal=1 |
fi |
done |
|
digest="${username}:${REALM}:" |
digest+=$(echo -n "${username}:${REALM}:${pass_1}" | md5sum | cut -d" " -f1) |
|
if [ $existing_user -eq 0 ]; then |
echo "$digest" >> "$passwdfile" |
else |
sed -i "s/${username}:${REALM}:.*/${digest}/" "$passwdfile" |
fi |
} |
|
# liste les comptes de chaque profile |
function list () { |
for i in $ALL_PROFILS |
50,9 → 94,10 |
chmod 640 $DIR_KEY/key_* |
} |
|
usage="Usage: alcasar-profil.sh [-l|--list] [-a|--add] [-d|--del] [-p|--pass]" |
usage="Usage: alcasar-profil.sh [-l|--list] [-a|--add [profil]] [-d|--del] [-p|--pass]" |
nb_args=$# |
args=$1 |
arg1=$1 |
arg2=$2 |
|
# on met en place la structure minimale |
if [ ! -e $DIR_KEY/key_$ADM_PROFIL ] |
73,21 → 118,26 |
echo $usage |
exit 0 |
fi |
case $args in |
case $arg1 in |
-\? | -h* | --h*) |
echo "$usage" |
exit 0 |
;; |
--add|-a) |
# ajout d'un compte |
list |
if [ $Lang == "fr" ] |
if [ $nb_args -eq 1 ] |
then |
echo -n "Choisissez un profil ($ALL_PROFILS) : " |
# ajout d'un compte |
list |
if [ $Lang == "fr" ] |
then |
echo -n "Choisissez un profil ($ALL_PROFILS) : " |
else |
echo -n "Select a profile ($ALL_PROFILS) : " |
fi |
read profil |
else |
echo -n "Select a profile ($ALL_PROFILS) : " |
profil="$2" |
fi |
read profil |
if [ $Lang == "fr" ] |
then |
echo -n "Entrez le nom du compte à créer (profil '$profil') : " |
112,7 → 162,7 |
fi |
done |
done |
/usr/bin/htdigest $DIR_KEY/key_only_$profil "ALCASAR Control Center (ACC)" $account |
htdigest $DIR_KEY/key_only_$profil "$account" |
concat |
list |
;; |
151,8 → 201,8 |
for j in $tmp_account |
do |
if [ "$j" = "$account" ] |
then |
/usr/bin/htdigest $DIR_KEY/key_only_$i "ALCASAR Control Center (ACC)" $account |
then |
htdigest $DIR_KEY/key_only_$i "$account" |
fi |
done |
done |
159,7 → 209,7 |
concat |
;; |
--list|-l) |
# liste des comptes par profile |
# liste des comptes par profil |
list |
;; |
*) |