|
@@ -91,6 +91,7 @@ function altaUsuario {
|
|
|
if [ $? -eq 0 ]; then
|
|
|
#Ya existe
|
|
|
printf "ERROR: El usuario no esta disponible (ya existe).\n"
|
|
|
+ printf "\tEscribir \"usuarios\" para mostrar usuarios disponibles.\n"
|
|
|
return 1
|
|
|
fi
|
|
|
if [ -z $homeDir ]; then
|
|
@@ -214,6 +215,7 @@ function cambiarPassword {
|
|
|
existeUsuario
|
|
|
if [ $? -ne 0 ]; then
|
|
|
printf "ERROR: el usuario $User no existe.\n"
|
|
|
+ printf "\tEscribir \"usuarios\" para mostrar usuarios disponibles.\n"
|
|
|
return 1
|
|
|
fi
|
|
|
if [ -z $password ]; then
|
|
@@ -237,6 +239,96 @@ function listarUsuarios {
|
|
|
unset lista
|
|
|
}
|
|
|
|
|
|
+function bloquearUsuario {
|
|
|
+#Bloquea el usuario $User
|
|
|
+ if [ -z $User ]; then
|
|
|
+ listarUsuarios
|
|
|
+ printf "(USUARIO)> "
|
|
|
+ read User
|
|
|
+ fi
|
|
|
+ existeUsuario
|
|
|
+ if [ $? -ne 0 ]; then
|
|
|
+ printf "ERROR: el usuario $User no existe.\n"
|
|
|
+ printf "\tEscribir \"usuarios\" para mostrar usuarios disponibles.\n"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ estaBloqueado
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ printf "$User ya esta bloqueado (%s).\n" $(fechaBloqueado)
|
|
|
+ printf "Escribir \"desbloquear\" para desbloquear usuario.\n"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ if [ -z $expireDate ]; then
|
|
|
+ printf "(FECHA BLOQUEO [yyyy-mm-dd])> "
|
|
|
+ read expireDate
|
|
|
+ case $expireDate in
|
|
|
+ ""|now|NOW)
|
|
|
+ expireDate=1
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ ;;
|
|
|
+ esac
|
|
|
+ fi
|
|
|
+ usermod -e $expireDate $user
|
|
|
+ if [ $? -ne 0 ]; then
|
|
|
+ printf "ERROR FATAL: No se ha podido bloquear usuario $User.\n"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+function desbloquearUsuario {
|
|
|
+#Desbloquear el usuario $User
|
|
|
+ if [ -z $User ]; then
|
|
|
+ listarUsuarios
|
|
|
+ printf "(USUARIO)> "
|
|
|
+ read User
|
|
|
+ fi
|
|
|
+ existeUsuario
|
|
|
+ if [ $? -ne 0 ]; then
|
|
|
+ printf "ERROR: el usuario $User no existe.\n"
|
|
|
+ printf "\tEscribir \"usuarios\" para mostrar usuarios disponibles.\n"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ estaBloqueado
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ printf "$User no esta bloqueado.\n"
|
|
|
+ printf "Escribir \"bloquear\" para desbloquear usuario.\n"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ usermod -e "" $User
|
|
|
+ if [ $? -ne 0 ]; then
|
|
|
+ printf "ERROR FATAL: No se ha podido desbloquear usuario $User.\n"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+function estaBloqueado {
|
|
|
+#Comprueba si el usuario $User esta bloqueado (Usando Dias UNIX)
|
|
|
+ ahora=$(expr $(date --utc -d now +%s) / 86400)
|
|
|
+ locktime=$(grep ^$User: /etc/shadow | cut -d: -f8)
|
|
|
+ #printf "Ahora: $ahora\nLock: $locktime\n"
|
|
|
+ if [ -z $locktime ]; then
|
|
|
+ #No esta bloqueado
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ if [ $locktime -le $ahora ]; then
|
|
|
+ #Esta bloqueado
|
|
|
+ return 0
|
|
|
+ else
|
|
|
+ #No lo esta
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+function fechaBloqueado {
|
|
|
+#Muestra la fecha de bloqueo en formato humano yyyy-mm-dd
|
|
|
+ locktime=$(expr $(grep ^$User: /etc/shadow | cut -d: -f8) '*' 86400)
|
|
|
+ fecha=$(date -d @$locktime +%F)
|
|
|
+ printf "$fecha\n"
|
|
|
+}
|
|
|
+
|
|
|
function leerPassword {
|
|
|
#Lee contraseña y la guarda en $password
|
|
|
igual=false
|
|
@@ -295,6 +387,8 @@ function ayuda {
|
|
|
cambiar)
|
|
|
printf "cambiar: CAMBIAR contraseña de un usuario:\n"
|
|
|
printf "SINOPSIS: cambiar [user]\n"
|
|
|
+ printf "\t-p, --pasword\n"
|
|
|
+ printf "\t\tContraseña del usuario.\n"
|
|
|
;;
|
|
|
baja)
|
|
|
printf "baja: Dar de BAJA un usuario\n"
|
|
@@ -376,9 +470,17 @@ while [ $cont = true ]; do
|
|
|
;;
|
|
|
bloquear)
|
|
|
#Bloquear usuario
|
|
|
+ bloquearUsuario
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ printf "USUARIO $User BLOQUEADO CON EXITO.\n"
|
|
|
+ fi
|
|
|
;;
|
|
|
desbloquear)
|
|
|
#Desbloquear usuario
|
|
|
+ desbloquearUsuario
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ printf "USUARIO $User DESBLOQUEADO CON EXITO.\n"
|
|
|
+ fi
|
|
|
;;
|
|
|
usuarios)
|
|
|
#Lista todos los usuarios existentes
|