售前咨询
技术支持
渠道合作

Pure-FTPd虚拟用户管理脚本(PureDB)

《lnmp一键安装包》之前添加虚拟主机账号是保存在数据库,因此必须安装php和数据库才能正常使用,现更改为PureDB方式(不依赖php和MySQL),将用户信息保存在本地(非数据库)。但是这种方式管理ftp虚拟账号需要手工敲命令,于是写这个脚本来可视化的管理账号。

功能如下(pureftpd_vhost.sh):

  • 1.创建账号
  • 2.更改目录
  • 3.更改密码
  • 4.删除账号
  • 5.列出所有账号
  • 6.显示某个账号详细信息
  • q. 退出

代码如下:

  1. #!/bin/bash
  2. # Author:  yeho <lj2007331 AT gmail.com>
  3. # BLOG:  https://blog.trustauth.cn
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. #       http://trustauth.cn
  9. #       https://github.com/lj2007331/oneinstack
  10. export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  11. clear
  12. printf “
  13. #######################################################################
  14. #       OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+      #
  15. #                 FTP virtual user account management                 #
  16. #       For more information please visit http://trustauth.cn       #
  17. #######################################################################
  18. “
  19. . ./options.conf
  20. . ./include/color.sh
  21. # Check if user is root
  22. [ $(id -u) != “0” ] && { echo “${CFAILURE}Error: You must be root to run this script${CEND}”; exit 1; }
  23. [ ! -d “$pureftpd_install_dir” ] && { echo “${CFAILURE}The ftp server does not exist! ${CEND}”; exit 1; }
  24. FTP_conf=$pureftpd_install_dir/etc/pure-ftpd.conf
  25. FTP_tmp_passfile=$pureftpd_install_dir/etc/pureftpd_psss.tmp
  26. Puredbfile=$pureftpd_install_dir/etc/pureftpd.pdb
  27. Passwdfile=$pureftpd_install_dir/etc/pureftpd.passwd
  28. FTP_bin=$pureftpd_install_dir/bin/pure-pw
  29. [ -z “`grep ^PureDB $FTP_conf`” ] && { echo “${CFAILURE}pure-ftpd is not own password database${CEND}” ; exit 1; }
  30. USER() {
  31. while :
  32. do
  33.     echo
  34.     read -p “Please input a username: ” User
  35.     if [ -z “$User” ]; then
  36.         echo “${CWARNING}username can’t be NULL! ${CEND}”
  37.     else
  38.         break
  39.     fi
  40. done
  41. }
  42. PASSWORD() {
  43. while :
  44. do
  45.     echo
  46.     read -p “Please input the password: ” Password
  47.     [ -n “`echo $Password | grep ‘[+|&]’`” ] && { echo “${CWARNING}input error,not contain a plus sign (+) and &${CEND}”; continue; }
  48.     if (( ${#Password} >= 5 ));then
  49.         echo -e “${Password}\n$Password” > $FTP_tmp_passfile
  50.         break
  51.     else
  52.         echo “${CWARNING}Ftp password least 5 characters! ${CEND}”
  53.     fi
  54. done
  55. }
  56. DIRECTORY() {
  57. while :
  58. do
  59. echo
  60.     read -p “Please input the directory(Default directory: $wwwroot_dir): ” Directory
  61.     if [ -z “$Directory” ]; then
  62.         Directory=”$wwwroot_dir”
  63.     fi
  64.     if [ ! -d “$Directory” ];then
  65.         echo “${CWARNING}The directory does not exist${CEND}”
  66.     else
  67.         break
  68.     fi
  69. done
  70. }
  71. while :
  72. do
  73.     printf “
  74. What Are You Doing?
  75. \t${CMSG}1${CEND}. UserAdd
  76. \t${CMSG}2${CEND}. UserMod
  77. \t${CMSG}3${CEND}. UserPasswd
  78. \t${CMSG}4${CEND}. UserDel
  79. \t${CMSG}5${CEND}. ListAllUser
  80. \t${CMSG}6${CEND}. ShowUser
  81. \t${CMSG}q${CEND}. Exit
  82. “
  83.     read -p “Please input the correct option: ” Number
  84.     if [[ ! $Number =~ ^[1-6,q]$ ]];then
  85.         echo “${CFAILURE}input error! Please only input 1 ~ 6 and q${CEND}”
  86.     else
  87.         case “$Number” in
  88.         1)
  89.             USER
  90.             [ -e “$Passwdfile” ] && [ -n “`grep ^${User}: $Passwdfile`” ] && { echo “${CQUESTION}[$User] is already existed! ${CEND}”; continue; }
  91.             PASSWORD;DIRECTORY
  92.             $FTP_bin useradd $User -f $Passwdfile -u $run_user -g $run_user -d $Directory -m < $FTP_tmp_passfile
  93.             $FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
  94.             echo “#####################################”
  95.             echo
  96.             echo “[$User] create successful! “
  97.             echo
  98.             echo “You user name is : ${CMSG}$User${CEND}”
  99.             echo “You Password is : ${CMSG}$Password${CEND}”
  100.             echo “You directory is : ${CMSG}$Directory${CEND}”
  101.             echo
  102.             ;;
  103.         2)
  104.             USER
  105.             [ -e “$Passwdfile” ] && [ -z “`grep ^${User}: $Passwdfile`” ] && { echo “${CQUESTION}[$User] was not existed! ${CEND}”; continue; }
  106.             DIRECTORY
  107.             $FTP_bin usermod $User -f $Passwdfile -d $Directory -m
  108.             $FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
  109.             echo “#####################################”
  110.             echo
  111.             echo “[$User] modify a successful! “
  112.             echo
  113.             echo “You user name is : ${CMSG}$User${CEND}”
  114.             echo “You new directory is : ${CMSG}$Directory${CEND}”
  115.             echo
  116.             ;;
  117.         3)
  118.             USER
  119.             [ -e “$Passwdfile” ] && [ -z “`grep ^${User}: $Passwdfile`” ] && { echo “${CQUESTION}[$User] was not existed! ${CEND}”; continue; }
  120.             PASSWORD
  121.             $FTP_bin passwd $User -f $Passwdfile -m < $FTP_tmp_passfile
  122.             $FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
  123.             echo “#####################################”
  124.             echo
  125.             echo “[$User] Password changed successfully! “
  126.             echo
  127.             echo “You user name is : ${CMSG}$User${CEND}”
  128.             echo “You new password is : ${CMSG}$Password${CEND}”
  129.             echo
  130.             ;;
  131.         4)
  132.             if [ ! -e “$Passwdfile” ];then
  133.                 echo “${CQUESTION}User was not existed! ${CEND}”
  134.             else
  135.                 $FTP_bin list
  136.             fi
  137.             USER
  138.             [ -e “$Passwdfile” ] && [ -z “`grep ^${User}: $Passwdfile`” ] && { echo “${CQUESTION}[$User] was not existed! ${CEND}”; continue; }
  139.             $FTP_bin userdel $User -f $Passwdfile -m
  140.             $FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
  141.             echo
  142.             echo “[$User] have been deleted! “
  143.             ;;
  144.         5)
  145.             if [ ! -e “$Passwdfile” ];then
  146.                 echo “${CQUESTION}User was not existed! ${CEND}”
  147.             else
  148.                 $FTP_bin list
  149.             fi
  150.             ;;
  151.         6)
  152.             USER
  153.             [ -e “$Passwdfile” ] && [ -z “`grep ^${User}: $Passwdfile`” ] && { echo “${CQUESTION}[$User] was not existed! ${CEND}”; continue; }
  154.             $FTP_bin show $User
  155.             ;;
  156.         q)
  157.             exit
  158.             ;;
  159.         esac
  160.     fi
  161. done

上一篇:

下一篇:

相关新闻

领取优惠
免费预约

申请试用SSL证书

提交成功!

咨询客服