技术文档

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