1
0

pureftpd_vhost.sh 5.2 KB

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