技术文档

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

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

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

功能如下(pureftpd_vhost.sh):

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

代码如下:

  1. #!/bin/bash
  2. #Author:yeho<lj2007331ATgmail.com>
  3. #BLOG:https://blog.
  4. #
  5. #Notes:OneinStackforCentOS/RadHat5+Debian6+andUbuntu12+
  6. #
  7. #Projecthomepage:
  8. #http://
  9. #https://github.com/lj2007331/oneinstack
  10. exportPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  11. clear
  12. printf“
  13. #######################################################################
  14. #OneinStackforCentOS/RadHat5+Debian6+andUbuntu12+#
  15. #FTPvirtualuseraccountmanagement#
  16. #Formoreinformationpleasevisithttp://#
  17. #######################################################################
  18. “
  19. ../options.conf
  20. ../include/color.sh
  21. #Checkifuserisroot
  22. [$(id-u)!=“0”]&&{echo“${CFAILURE}Error:Youmustberoottorunthisscript${CEND}”;exit1;}
  23. [!-d“$pureftpd_install_dir”]&&{echo“${CFAILURE}Theftpserverdoesnotexist!${CEND}”;exit1;}
  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-ftpdisnotownpassworddatabase${CEND}”;exit1;}
  30. USER(){
  31. while:
  32. do
  33. echo
  34. read-p“Pleaseinputausername:”User
  35. if[-z“$User”];then
  36. echo“${CWARNING}usernamecan’tbeNULL!${CEND}”
  37. else
  38. break
  39. fi
  40. done
  41. }
  42. PASSWORD(){
  43. while:
  44. do
  45. echo
  46. read-p“Pleaseinputthepassword:”Password
  47. [-n“`echo$Password|grep‘[+|&]’`”]&&{echo“${CWARNING}inputerror,notcontainaplussign(+)and&${CEND}”;continue;}
  48. if((${#Password}>=5));then
  49. echo-e“${Password}\n$Password”>$FTP_tmp_passfile
  50. break
  51. else
  52. echo“${CWARNING}Ftppasswordleast5characters!${CEND}”
  53. fi
  54. done
  55. }
  56. DIRECTORY(){
  57. while:
  58. do
  59. echo
  60. read-p“Pleaseinputthedirectory(Defaultdirectory:$wwwroot_dir):”Directory
  61. if[-z“$Directory”];then
  62. Directory=”$wwwroot_dir”
  63. fi
  64. if[!-d“$Directory”];then
  65. echo“${CWARNING}Thedirectorydoesnotexist${CEND}”
  66. else
  67. break
  68. fi
  69. done
  70. }
  71. while:
  72. do
  73. printf“
  74. WhatAreYouDoing?
  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“Pleaseinputthecorrectoption:”Number
  84. if[[!$Number=~^[1-6,q]$]];then
  85. echo“${CFAILURE}inputerror!Pleaseonlyinput1~6andq${CEND}”
  86. else
  87. case“$Number”in
  88. 1)
  89. USER
  90. [-e“$Passwdfile”]&&[-n“`grep^${User}:$Passwdfile`”]&&{echo“${CQUESTION}[$User]isalreadyexisted!${CEND}”;continue;}
  91. PASSWORD;DIRECTORY
  92. $FTP_binuseradd$User-f$Passwdfile-u$run_user-g$run_user-d$Directory-m<$FTP_tmp_passfile
  93. $FTP_binmkdb$Puredbfile-f$Passwdfile>/dev/null2>&1
  94. echo“#####################################”
  95. echo
  96. echo“[$User]createsuccessful!“
  97. echo
  98. echo“Youusernameis:${CMSG}$User${CEND}”
  99. echo“YouPasswordis:${CMSG}$Password${CEND}”
  100. echo“Youdirectoryis:${CMSG}$Directory${CEND}”
  101. echo
  102. ;;
  103. 2)
  104. USER
  105. [-e“$Passwdfile”]&&[-z“`grep^${User}:$Passwdfile`”]&&{echo“${CQUESTION}[$User]wasnotexisted!${CEND}”;continue;}
  106. DIRECTORY
  107. $FTP_binusermod$User-f$Passwdfile-d$Directory-m
  108. $FTP_binmkdb$Puredbfile-f$Passwdfile>/dev/null2>&1
  109. echo“#####################################”
  110. echo
  111. echo“[$User]modifyasuccessful!“
  112. echo
  113. echo“Youusernameis:${CMSG}$User${CEND}”
  114. echo“Younewdirectoryis:${CMSG}$Directory${CEND}”
  115. echo
  116. ;;
  117. 3)
  118. USER
  119. [-e“$Passwdfile”]&&[-z“`grep^${User}:$Passwdfile`”]&&{echo“${CQUESTION}[$User]wasnotexisted!${CEND}”;continue;}
  120. PASSWORD
  121. $FTP_binpasswd$User-f$Passwdfile-m<$FTP_tmp_passfile
  122. $FTP_binmkdb$Puredbfile-f$Passwdfile>/dev/null2>&1
  123. echo“#####################################”
  124. echo
  125. echo“[$User]Passwordchangedsuccessfully!“
  126. echo
  127. echo“Youusernameis:${CMSG}$User${CEND}”
  128. echo“Younewpasswordis:${CMSG}$Password${CEND}”
  129. echo
  130. ;;
  131. 4)
  132. if[!-e“$Passwdfile”];then
  133. echo“${CQUESTION}Userwasnotexisted!${CEND}”
  134. else
  135. $FTP_binlist
  136. fi
  137. USER
  138. [-e“$Passwdfile”]&&[-z“`grep^${User}:$Passwdfile`”]&&{echo“${CQUESTION}[$User]wasnotexisted!${CEND}”;continue;}
  139. $FTP_binuserdel$User-f$Passwdfile-m
  140. $FTP_binmkdb$Puredbfile-f$Passwdfile>/dev/null2>&1
  141. echo
  142. echo“[$User]havebeendeleted!“
  143. ;;
  144. 5)
  145. if[!-e“$Passwdfile”];then
  146. echo“${CQUESTION}Userwasnotexisted!${CEND}”
  147. else
  148. $FTP_binlist
  149. fi
  150. ;;
  151. 6)
  152. USER
  153. [-e“$Passwdfile”]&&[-z“`grep^${User}:$Passwdfile`”]&&{echo“${CQUESTION}[$User]wasnotexisted!${CEND}”;continue;}
  154. $FTP_binshow$User
  155. ;;
  156. q)
  157. exit
  158. ;;
  159. esac
  160. fi
  161. done
©2020-2024   万云SSL证书  (www.sslssl.com.cn)  万云网络旗下平台   豫ICP备2020034358号-10