1
0

pureftpd_vhost.sh 5.8 KB

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