A continuación un script para gestionar usuarios de este servicio. Para echarle un ojo!
#!/bin/bash
USUARIO=vacio
PASSWORD=vacio
NOTVALID=1
#EVALUACION DE PARAMETROS
#------------------------
while getopts u:p: OPCION
do
if [ "$OPCION" = "u" ];then
USUARIO=$OPTARG
NOTVALID=2
fi
if [ "$OPCION" = "p" ];then
PASSWORD=$OPTARG
NOTVALID=2
fi
done
#FILTROS
if [ "$NOTVALID" = 2 ];then
if [ "$USUARIO" = "" ] || [ "$USUARIO" = "vacio" ];then
echo "[X] El usuaio introducido no es valido."
sleep 2
NOTVALID=1
fi
if [ "$PASSWORD" = "" ] || [ "$PASSWORD" = "vacio" ];then
echo "[X] El password introducido no es valido."
sleep 2
NOTVALID=1
fi
if [ "$NOTVALID" != 1 ];then
NOTVALID=0
fi
fi
#INTRODUCCION SI NO SE LE PASAN PARAMETROS
until [ "$NOTVALID" = 0 ]
do
clear
if [ "$USUARIO" = "vacio" ] || [ "$NOTVALID" = 1 ];then
echo "[i] Introduzca un nombre para el usuario:"
read USUARIO
echo "[i] Introduzca un password para el usuario $USUARIO:"
read PASSWORD
NOTVALID=0
fi
if [ "$USUARIO" = "" ];then
echo "[X] Usuario no valido."
NOTVALID=1
fi
if [ "$PASSWORD" = "" ];then
echo "[X] Password de $USUARIO no valido."
NOTVALID=1
fi
done
#Compruebo la existencia del fichero users.txt, si no existe, lo creo
test -f /etc/vsftpd/users.txt
EXISTE=$?
if [ "$EXISTE" = 1 ];then
>/etc/vsftpd/users.txt
fi
CONT=0
while read LINEA
do
let CONT=$CONT+1
let A=$CONT%2
if [ $A = 1 ];then
if [ "$LINEA" = "$USUARIO" ];then
echo "[X] El usuario introducido ya existe."
sleep 2
exit
fi
fi
done < /etc/vsftpd/users.txt echo "$USUARIO" >> /etc/vsftpd/users.txt
echo "$PASSWORD" >> /etc/vsftpd/users.txt
echo "[i] Añadiendo a $USUARIO ..."
sleep 2
/etc/init.d/vsftpd restart
db_load -T -t hash -f /etc/vsftpd/users.txt /etc/vsftpd/users.db
echo "Compilando fichero de usuarios..."
sleep 2
echo "auth required /lib/security/pam_userdb.so db=/etc/vsftpd/users" > /etc/pam.d/vsftpd
echo "account required /lib/security/pam_userdb.so db=/etc/vsftpd/users" >> /etc/pam.d/vsftpd
test -d /etc/vsftpd/users
EXISTE2=$?
if [ "$EXISTE2" = 1 ];then
echo "Creando directorio para las configuraciones de los usuarios..."
sleep 2
mkdir /etc/vsftpd/users
fi
#Crea el fichero de configuracion del usuario
>/etc/vsftpd/users/$USUARIO
echo "Creando fichero de configuracion para $USUARIO ..."
sleep 2
mkdir /home/ftpvirtual/$USUARIO
chown ftpvirtual /home/ftpvirtual/$USUARIO
echo "Dando permisos necesarios al directorio /home/ftpvirtual/$USUARIO ..."
sleep 2
echo "local_root=/home/ftpvirtual/$USUARIO" >> /etc/vsftpd/users/$USUARIO
clear
echo "[?] ¿Desea que $USUARIO tenga permisos de escritura en el directorio? (s/n)"
echo "Respuesta:"
read ANSW
if [ "$ANSW" = "s" ];then
echo "write_enable=YES" >> /etc/vsftpd/users/$USUARIO
else
echo "write_enable=NO" >> /etc/vsftpd/users/$USUARIO
fi
ANSW=0
echo "[?] ¿Desea que $USUARIO descargue archivos del servidor ftp? (s/n)"
echo "Respuesta:"
read ANSW
if [ "$ANSW" = "s" ];then
echo "download_enable=YES" >> /etc/vsftpd/users/$USUARIO
else
echo "download_enable=NO" >> /etc/vsftpd/users/$USUARIO
fi
domingo 30 de noviembre de 2008
Suscribirse a:
Enviar comentarios (Atom)
0 comentarios:
Publicar un comentario en la entrada