1
0

pureftpd_vhost.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Version: 1.0-Alpha Jun 15,2015 lj2007331 AT gmail.com
  6. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  7. #
  8. # Project home page:
  9. # http://oneinstack.com
  10. # Check if user is root
  11. [ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; }
  12. export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  13. clear
  14. printf "
  15. #######################################################################
  16. # OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+ #
  17. # FTP virtual user account management #
  18. # For more information please visit http://oneinstack.com #
  19. #######################################################################
  20. "
  21. . ./options.conf
  22. [ ! -d "$pureftpd_install_dir" ] && { echo -e "\033[31mThe ftp server does not exist! \033[0m"; 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 -e "\033[31mpure-ftpd is not own password database\033[0m" ; 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 -e "\033[31musername can't be NULL! \033[0m"
  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 -e "\033[31minput error,not contain a plus sign (+) and &\033[0m"; continue; }
  47. if (( ${#Password} >= 5 ));then
  48. echo -e "${Password}\n$Password" > $FTP_tmp_passfile
  49. break
  50. else
  51. echo -e "\033[31mFtp password least 5 characters! \033[0m"
  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 -e "\033[31mThe directory does not exist\033[0m"
  65. else
  66. break
  67. fi
  68. done
  69. }
  70. while :
  71. do
  72. echo
  73. echo -e "What Are You Doing?
  74. \t\033[32m1\033[0m. UserAdd
  75. \t\033[32m2\033[0m. UserMod
  76. \t\033[32m3\033[0m. UserPasswd
  77. \t\033[32m4\033[0m. UserDel
  78. \t\033[32m5\033[0m. ListAllUser
  79. \t\033[32m6\033[0m. ShowUser
  80. \t\033[32mq\033[0m. Exit"
  81. read -p "Please input the correct option: " Number
  82. if [ "$Number" != '1' -a "$Number" != '2' -a "$Number" != '3' -a "$Number" != '4' -a "$Number" != '5' -a "$Number" != '6' -a "$Number" != 'q' ];then
  83. echo -e "\033[31minput error! Please only input 1 ~ 8 and q\033[0m"
  84. else
  85. case "$Number" in
  86. 1)
  87. USER
  88. [ -e "$Passwdfile" ] && [ -n "`grep ^${User}: $Passwdfile`" ] && { echo -e "\033[31m[$User] is already existed! \033[0m"; 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 -f $Passwdfile -F $Puredbfile > /dev/null 2>&1
  92. echo "#####################################"
  93. echo
  94. echo "[$User] create successful! "
  95. echo
  96. echo "You user name is : $User"
  97. echo "You Password is : $Password"
  98. echo "You directory is : $Directory"
  99. echo
  100. ;;
  101. 2)
  102. USER;DIRECTORY
  103. $FTP_bin usermod $User -f $Passwdfile -d $Directory -m
  104. $FTP_bin -f $Passwdfile -F $Puredbfile > /dev/null 2>&1
  105. echo "#####################################"
  106. echo
  107. echo "[$User] modify a successful! "
  108. echo
  109. echo "You user name is : $User"
  110. echo "You new directory is : $Directory"
  111. echo
  112. ;;
  113. 3)
  114. USER
  115. [ -e "$Passwdfile" ] && [ -z "`grep ^${User}: $Passwdfile`" ] && { echo -e "\033[31m[$User] is not existed! \033[0m"; continue; }
  116. PASSWORD
  117. $FTP_bin passwd $User -f $Passwdfile -m < $FTP_tmp_passfile
  118. $FTP_bin -f $Passwdfile -F $Puredbfile > /dev/null 2>&1
  119. echo "#####################################"
  120. echo
  121. echo "[$User] Password changed successfully! "
  122. echo
  123. echo "You user name is : $User"
  124. echo "You new password is : $Password"
  125. echo
  126. ;;
  127. 4)
  128. if [ ! -e "$Passwdfile" ];then
  129. echo -e "\033[31mUser is not existed\033[0m"
  130. else
  131. $FTP_bin list
  132. fi
  133. USER
  134. [ -e "$Passwdfile" ] && [ -z "`grep ^${User}: $Passwdfile`" ] && { echo -e "\033[31m[$User] is not existed! \033[0m"; continue; }
  135. $FTP_bin userdel $User -f $Passwdfile -m
  136. $FTP_bin -f $Passwdfile -F $Puredbfile > /dev/null 2>&1
  137. echo
  138. echo "[$User] have been deleted! "
  139. ;;
  140. 5)
  141. if [ ! -e "$Passwdfile" ];then
  142. echo -e "\033[31mUser is not existed\033[0m"
  143. else
  144. $FTP_bin list
  145. fi
  146. ;;
  147. 6)
  148. USER
  149. [ -e "$Passwdfile" ] && [ -z "`grep ^${User}: $Passwdfile`" ] && { echo -e "\033[31m[$User] is not existed! \033[0m"; continue; }
  150. $FTP_bin show $User
  151. ;;
  152. 9)
  153. exit
  154. ;;
  155. q)
  156. exit
  157. ;;
  158. esac
  159. fi
  160. done