v-list-mail-domain 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. # Includes
  15. source $VESTA/func/main.sh
  16. # Json function
  17. json_list_domain() {
  18. i=1
  19. fileds_count=$(echo "$fields" | wc -w)
  20. line=$(grep "DOMAIN='$domain'" $conf)
  21. echo '{'
  22. eval $line
  23. for field in $fields; do
  24. eval value=$field
  25. if [ "$i" -eq 1 ]; then
  26. echo -e "\t\"$value\": {"
  27. else
  28. if [ "$fileds_count" -eq "$i" ]; then
  29. echo -e "\t\t\"${field//$/}\": \"$value\""
  30. else
  31. echo -e "\t\t\"${field//$/}\": \"$value\","
  32. fi
  33. fi
  34. (( ++i))
  35. done
  36. if [ -n "$value" ]; then
  37. echo -e ' }'
  38. fi
  39. echo -e "}"
  40. }
  41. # Shell function
  42. shell_list_domain() {
  43. line=$(grep "DOMAIN='$domain'" $conf)
  44. eval $line
  45. for field in $fields; do
  46. eval key="$field"
  47. echo "${field//$/}: $key "
  48. done
  49. }
  50. #----------------------------------------------------------#
  51. # Verifications #
  52. #----------------------------------------------------------#
  53. check_args '2' "$#" 'user domain [format]'
  54. is_object_valid 'user' 'USER' "$user"
  55. is_object_valid 'mail' 'DOMAIN' "$domain"
  56. #----------------------------------------------------------#
  57. # Action #
  58. #----------------------------------------------------------#
  59. # Defining fileds to select
  60. conf=$USER_DATA/mail.conf
  61. fields='$DOMAIN $ANTIVIRUS $ANTISPAM $DKIM $ACCOUNTS $U_DISK $CATCHALL
  62. $SUSPENDED $TIME $DATE'
  63. # Listing domains
  64. case $format in
  65. json) json_list_domain ;;
  66. plain) nohead=1; shell_list_domain ;;
  67. shell) shell_list_domain |column -t ;;
  68. *) check_args '2' '0' 'user domain [format]'
  69. esac
  70. #----------------------------------------------------------#
  71. # Vesta #
  72. #----------------------------------------------------------#
  73. exit