"Lnmp One-click installation package" before adding a virtual Host account is saved in the database, so you must install PHP and the database to normal use, is now changed to Puredb mode (not dependent on PHP and MySQL), the user information stored in the local (non-database). But this way to manage the FTP virtual account requires hand-tapping commands, so write this script to visualize the management account.
Features are as follows (pureftpd_vhost.sh):
1. Create Account
2. Change Directory
3. Change Password
4. Delete Account
5. List all accounts
6. Show an Account details
Q. Exit
The following figure:
Ps://blog.linuxeye.com/wp-content/uploads/2015/05/pureftpd_vhost.gif "/>
The code is as follows:
#!/bin/bash
# Author:yeho <lj2007331 at gmail.com>
# Check If user is root
[$ (id-u)!= "0"] && {ECHO-E "\033[31merror:you must is root to run this script\033[0m"; exit 1;}
Export Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Clear
printf "
#######################################################################
# Lnmp/lamp/lanmp for Centos/radhat 5+ Debian 6+ and Ubuntu 12+ #
# FTP Virtual user account Management #
# For more information, please visit http://blog.linuxeye.com/31.html #
#######################################################################
"
. ./options.conf
[!-d ' $pureftpd _install_dir] && {echo-e ' \033[31mthe FTP server does not exist! \033[0m "; exit 1;}
ftp_conf= $pureftpd _install_dir/etc/pure-ftpd.conf
ftp_tmp_passfile= $pureftpd _install_dir/etc/pureftpd_ Psss.tmp
puredbfile= $pureftpd _install_dir/etc/pureftpd.pdb
passwdfile= $pureftpd _install_dir/etc/ PUREFTPD.PASSWD
ftp_bin= $pureftpd _install_dir/bin/pure-pw
[-Z ' grep ^puredb $FTP _conf '] && {echo-e \033[31MPURE-FTPD is not own password database\033[0m "; exit 1;}
USER () {
while:
do
echo
read-p "Please input a username:" User
if [-Z "$User"]; Then
echo-e "\033[ 31musername can ' t be null! \033[0m "
else
break
fi
Done
}
PASSWORD () {
while:
do
echo
read-p "Please input the password:" Password
[-n "EC Ho $Password | grep ' [+|&] ' "] && {ECHO-E" \033[31minput error,not contain a plus sign (+) and &\033[0m; continue;}
if ((${#Password} >= 5)) then
& nbsp; echo-e "${password}\n$password" > $FTP _tmp_passfile
Break
Else
echo-e "\033[31mftp Password least 5 characters! \033[0m "
fi
Done
}
DIRECTORY () {
While:
Todo
Echo
Read-p "Please input the directory (Default directory: $home _dir):" Directory
If [-Z "$Directory"]; Then
directory= "$home _dir"
Fi
if [!-d "$Directory"];then
Echo-e "\033[31mthe directory does not exist\033[0m"
Else
Break
Fi
Done
}
While:
Todo
Echo
Echo-e "What Are you doing?"
\t\033[32m1\033[0m. Useradd
\t\033[32m2\033[0m. Usermod
\t\033[32m3\033[0m. userpasswd
\t\033[32m4\033[0m. Userdel
\t\033[32m5\033[0m. Listalluser
\t\033[32m6\033[0m. Showuser
\t\033[32mq\033[0m. Exit "
Read-p "Please input the correct option:" Number
If [$Number '!= ' 1 '-a ' $Number '!= ' 2 '-a ' $Number '!= ' 3 '-a ' $Number '!= ' 4 '-a ' $Number '!= ' 5 '-a ' $Number '!= ' 6 ' -A "$Number"!= ' Q '];then
Echo-e "\033[31minput error! Please only input 1 ~ 8 and q\033[0m "
Else
Case "$Number" in
1)
USER
[E ' $Passwdfile] && [-N ' grep ^${user}: $Passwdfile '] && {echo-e ' \033[31m[$User] is already exi sted! \033[0m "; continue;}
Password;directory
$FTP _bin Useradd $User-F $Passwdfile-u $run _user-g $run _user-d $Directory-m < $FTP _tmp_passfile
$FTP _bin-f $Passwdfile-F $Puredbfile >/dev/null 2>&1
echo "#####################################"
Echo
echo "[$User] Create successful!"
Echo
echo "Your user name is: $User"
echo "You Password are: $Password"
echo "Your directory is: $Directory"
Echo
;;
2)
User;directory
$FTP _bin usermod $User-F $Passwdfile-D $Directory-M
$FTP _bin-f $Passwdfile-F $Puredbfile >/dev/null 2>&1
echo "#####################################"
Echo
echo "[$User] Modify a successful!"
Echo
echo "Your user name is: $User"
echo "Your new directory is: $Directory"
Echo
;;
3)
USER
[E ' $Passwdfile] && [-Z ' grep ^${user}: $Passwdfile '] && {echo-e ' \033[31m[$User] is not existed ! \033[0m "; continue;}
PASSWORD
$FTP _bin passwd $User-F $Passwdfile-m < $FTP _tmp_passfile
$FTP _bin-f $Passwdfile-F $Puredbfile >/dev/null 2>&1
echo "#####################################"
Echo
echo "[$User] Password changed successfully!"
Echo
echo "Your user name is: $User"
echo "You are new password is: $Password"
Echo
;;
4)
if [!-e ' $Passwdfile '];then
Echo-e "\033[31muser is not existed\033[0m"
Else
$FTP _bin List
Fi
USER
[E ' $Passwdfile] && [-Z ' grep ^${user}: $Passwdfile '] && {echo-e ' \033[31m[$User] is not existed ! \033[0m "; continue;}
$FTP _bin Userdel $User-F $Passwdfile-M
$FTP _bin-f $Passwdfile-F $Puredbfile >/dev/null 2>&1
Echo
echo "[$User] have been deleted!"
;;
5)
if [!-e ' $Passwdfile '];then
Echo-e "\033[31muser is not existed\033[0m"
Else
$FTP _bin List
Fi
;;
6)
USER
[E ' $Passwdfile] && [-Z ' grep ^${user}: $Passwdfile '] && {echo-e ' \033[31m[$User] is not existed ! \033[0m "; continue;}
$FTP _bin Show $User
;;
9)
Exit
;;
Q
Exit
;;
Esac
Fi
Done