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

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

上一篇:

下一篇:

相关新闻

 

领取优惠
免费预约

申请试用SSL证书

提交成功!

咨询客服