v_list_web_domain_ssl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # info: list web domain ssl certificate
  3. # options: user domain [format]
  4. #
  5. # The function of obtaining domain ssl files.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. domain=$2
  12. format=${3-shell}
  13. # Importing variables
  14. source $VESTA/conf/vars.conf
  15. source $V_FUNC/shared.func
  16. source $V_FUNC/domain.func
  17. # Json function
  18. json_list_ssl() {
  19. i='1' # iterator
  20. echo '{'
  21. echo -e "\t\"$domain\": {"
  22. echo " \"CRT\": \"$crt\","
  23. echo " \"KEY\": \"$key\","
  24. echo " \"CA\": \"$ca\""
  25. echo -e "\t}\n}"
  26. }
  27. # Shell function
  28. shell_list_ssl() {
  29. if [ ! -z "$crt" ]; then
  30. echo -e "$crt"
  31. fi
  32. if [ ! -z "$key" ]; then
  33. echo -e "\n$key"
  34. fi
  35. if [ ! -z "$ca" ]; then
  36. echo -e "\n$ca"
  37. fi
  38. }
  39. #----------------------------------------------------------#
  40. # Verifications #
  41. #----------------------------------------------------------#
  42. # Checking args
  43. check_args '2' "$#" 'user domain [format]'
  44. # Checking user
  45. is_user_valid
  46. # Checking domain exist
  47. is_web_domain_valid
  48. #----------------------------------------------------------#
  49. # Action #
  50. #----------------------------------------------------------#
  51. if [ -e "$V_USERS/$user/ssl/$domain.crt" ]; then
  52. crt=$(cat $V_USERS/$user/ssl/$domain.crt |sed -e ':a;N;$!ba;s/\n/\\n/g' )
  53. fi
  54. if [ -e "$V_USERS/$user/ssl/$domain.key" ]; then
  55. key=$(cat $V_USERS/$user/ssl/$domain.key |sed -e ':a;N;$!ba;s/\n/\\n/g' )
  56. fi
  57. if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
  58. ca=$(cat $V_USERS/$user/ssl/$domain.ca |sed -e ':a;N;$!ba;s/\n/\\n/g' )
  59. fi
  60. # Listing domains
  61. case $format in
  62. json) json_list_ssl ;;
  63. plain) nohead=1; shell_list_ssl ;;
  64. shell) shell_list_ssl ;;
  65. *) check_args '1' '0' '[format]'
  66. esac
  67. #----------------------------------------------------------#
  68. # Vesta #
  69. #----------------------------------------------------------#
  70. exit