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

脚本26阅读模式

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

功能如下(pureftpd_vhost.sh):

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

如下图:

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

代码如下:

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

 
  • 本文由 yeho 发表于 2015-05-18
  • 转载请务必保留本文链接:https://linuxeye.com/417.html
脚本

腾讯云COS上传、批量删除工具(Python)

腾讯云对象存储COS是类似于阿里云OSS,相比OSS,COS提供每月免费额度:存储空间50G、外网访问流量10G(内网免费)、免费读请求100万次、写请求10万次。对网站备份来说不错,但是,腾讯云提供...
    • hah
      hah

      service pureftpd restart
      service pureftpd status
      pure-config.pl 已死,但是 subsys 被锁

        • yeho
          yeho

          @ hah pureftpd-1.0.45及以上版本 没有pure-config.pl 。。应该得到解决

      匿名

      发表评论

      匿名网友
      确定

      取消

      拖动滑块以完成验证