v_list_web_domain_ssl 2.1 KB

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