v_list_web_domain 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # info: listing web domain
  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_domain() {
  16. i=1
  17. fileds_count=$(echo "$fields" | wc -w)
  18. line=$(grep "DOMAIN='$domain'" $conf)
  19. # Print top bracket
  20. echo '{'
  21. # Assing key=value
  22. eval $line
  23. # Starting output loop
  24. for field in $fields; do
  25. # Parsing key=value
  26. eval value=$field
  27. # Checking first field
  28. if [ "$i" -eq 1 ]; then
  29. echo -e "\t\"$value\": {"
  30. else
  31. if [ "$fileds_count" -eq "$i" ]; then
  32. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  33. else
  34. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  35. fi
  36. fi
  37. # Updating iterator
  38. (( ++i))
  39. done
  40. # If there was any output
  41. if [ -n "$value" ]; then
  42. echo -e ' }'
  43. fi
  44. # Printing bottom json bracket
  45. echo -e "}"
  46. }
  47. # Shell function
  48. shell_list_domain() {
  49. line=$(grep "DOMAIN='$domain'" $conf)
  50. # Parsing key=value
  51. eval $line
  52. # Print result line
  53. for field in $fields; do
  54. eval key="$field"
  55. echo "${field//$/}: $key "
  56. done
  57. }
  58. #----------------------------------------------------------#
  59. # Verifications #
  60. #----------------------------------------------------------#
  61. # Checking args
  62. check_args '2' "$#" 'user domain [format]'
  63. # Checking user
  64. is_user_valid
  65. # Checking domain exist
  66. is_web_domain_valid
  67. #----------------------------------------------------------#
  68. # Action #
  69. #----------------------------------------------------------#
  70. # Defining config
  71. conf=$V_USERS/$user/web.conf
  72. # Defining fileds to select
  73. fields='$DOMAIN $IP $U_DISK $U_BANDWIDTH $TPL $ALIAS $PHP $CGI $ELOG $STATS
  74. $STATS_AUTH $SSL $SSL_HOME $NGINX $NGINX_EXT $SUSPEND $DATE'
  75. # Listing domains
  76. case $format in
  77. json) json_list_domain ;;
  78. plain) nohead=1; shell_list_domain ;;
  79. shell) shell_list_domain |column -t ;;
  80. *) check_args '2' '0' 'user domain [format]'
  81. esac
  82. #----------------------------------------------------------#
  83. # Vesta #
  84. #----------------------------------------------------------#
  85. exit