v_list_web_domain 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. # info: list web domain
  3. # options: user domain [format]
  4. #
  5. # The function of obtaining the list of domain parameters. This call, just as
  6. # all v_list_* calls, supports 3 formats - json, shell and plain.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. domain=$2
  13. format=${3-shell}
  14. # Importing variables
  15. source $VESTA/conf/vars.conf
  16. source $V_FUNC/shared.func
  17. source $V_FUNC/domain.func
  18. # Json function
  19. json_list_domain() {
  20. i=1
  21. fileds_count=$(echo "$fields" | wc -w)
  22. line=$(grep "DOMAIN='$domain'" $conf)
  23. # Print top bracket
  24. echo '{'
  25. # Assing key=value
  26. eval $line
  27. # Starting output loop
  28. for field in $fields; do
  29. # Parsing key=value
  30. eval value=$field
  31. # Checking first field
  32. if [ "$i" -eq 1 ]; then
  33. echo -e "\t\"$value\": {"
  34. else
  35. if [ "$fileds_count" -eq "$i" ]; then
  36. echo -e "\t\t\"${field//$/}\": \"$value\","
  37. else
  38. echo -e "\t\t\"${field//$/}\": \"$value\""
  39. fi
  40. fi
  41. # Updating iterator
  42. (( ++i))
  43. done
  44. # If there was any output
  45. if [ -n "$value" ]; then
  46. echo -e ' }'
  47. fi
  48. # Printing bottom json bracket
  49. echo -e "}"
  50. }
  51. # Shell function
  52. shell_list_domain() {
  53. line=$(grep "DOMAIN='$domain'" $conf)
  54. # Parsing key=value
  55. eval $line
  56. # Print result line
  57. for field in $fields; do
  58. eval key="$field"
  59. echo "${field//$/}: $key "
  60. done
  61. }
  62. #----------------------------------------------------------#
  63. # Verifications #
  64. #----------------------------------------------------------#
  65. # Checking args
  66. check_args '2' "$#" 'user domain [format]'
  67. # Checking user
  68. is_user_valid
  69. # Checking domain exist
  70. is_web_domain_valid
  71. #----------------------------------------------------------#
  72. # Action #
  73. #----------------------------------------------------------#
  74. # Defining config
  75. conf=$V_USERS/$user/web.conf
  76. # Defining fileds to select
  77. fields='$DOMAIN $IP $U_DISK $U_BANDWIDTH $TPL $ALIAS $PHP $CGI $ELOG $STATS
  78. $STATS_AUTH $SSL $SSL_HOME $NGINX $NGINX_EXT $SUSPEND $DATE'
  79. # Listing domains
  80. case $format in
  81. json) json_list_domain ;;
  82. plain) nohead=1; shell_list_domain ;;
  83. shell) shell_list_domain |column -t ;;
  84. *) check_args '2' '0' 'user domain [format]'
  85. esac
  86. #----------------------------------------------------------#
  87. # Vesta #
  88. #----------------------------------------------------------#
  89. exit