v_list_sys_user_ssl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # info: listing ssl certificates
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. format=${2-shell}
  9. # Importing variables
  10. source $VESTA/conf/vars.conf
  11. source $V_FUNC/shared.func
  12. # Json function
  13. json_list_cert() {
  14. # Print top bracket
  15. echo '['
  16. # Checking certificates number
  17. certificates=$(ls $V_USERS/$user/ssl/ |grep '.crt' )
  18. certificates_count=$(echo "$certificates" | wc -l)
  19. i=1
  20. # Listing files by mask
  21. for cert in $certificates; do
  22. if [ $i -eq $certificates_count ]; then
  23. echo -e "\t\"${cert//.crt/}\""
  24. else
  25. echo -e "\t\"${cert//.crt/}\","
  26. fi
  27. (( ++i))
  28. done
  29. # Printing bottom bracket
  30. echo -e "]"
  31. }
  32. # Shell function
  33. shell_list_cert() {
  34. if [ -z "$nohead" ] ; then
  35. # Print brief info
  36. echo "Certificate"
  37. echo "----------"
  38. fi
  39. # Listing files by mask
  40. for cert in $(ls $V_USERS/$user/ssl/ | grep '.crt'); do
  41. # Print result
  42. echo "${cert//.crt/}"
  43. done
  44. }
  45. #----------------------------------------------------------#
  46. # Verifications #
  47. #----------------------------------------------------------#
  48. # Checking args
  49. check_args '1' "$#" 'user [format] [limit] [offset]'
  50. # Checking argument format
  51. format_validation 'user'
  52. # Checking user
  53. is_user_valid
  54. #----------------------------------------------------------#
  55. # Action #
  56. #----------------------------------------------------------#
  57. # Listing domains
  58. case $format in
  59. json) json_list_cert ;;
  60. plain) nohead=1; shell_list_cert ;;
  61. shell) shell_list_cert | column -t ;;
  62. *) check_args '1' '0' 'user [format]' ;;
  63. esac
  64. #----------------------------------------------------------#
  65. # Vesta #
  66. #----------------------------------------------------------#
  67. exit