1
0

pureftpd_vhost.sh 5.6 KB

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