v_list_mail_account 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # info: list mail domain account
  3. # options: user domain account [format]
  4. #
  5. # The function of obtaining the list of account parameters.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. domain=$2
  12. account=$3
  13. format=${4-shell}
  14. # Includes
  15. source $VESTA/func/main.sh
  16. # Json function
  17. json_list_account() {
  18. i=1
  19. fileds_count=$(echo "$fields" | wc -w)
  20. line=$(grep "ACCOUNT='$account'" $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_account() {
  43. line=$(grep "ACCOUNT='$account'" $conf)
  44. eval $line
  45. for field in $fields; do
  46. eval key="$field"
  47. if [ -z "$key" ]; then
  48. key=NULL
  49. fi
  50. echo "${field//$/}: $key "
  51. done
  52. }
  53. #----------------------------------------------------------#
  54. # Verifications #
  55. #----------------------------------------------------------#
  56. check_args '3' "$#" 'user domain account [format]'
  57. is_object_valid 'user' 'USER' "$user"
  58. is_object_valid 'mail' 'DOMAIN' "$domain"
  59. is_object_valid "mail/$domain" 'ACCOUNT' "$account"
  60. #----------------------------------------------------------#
  61. # Action #
  62. #----------------------------------------------------------#
  63. # Defining config and fields to select
  64. conf=$USER_DATA/mail/$domain.conf
  65. fields="\$ACCOUNT \$ALIAS \$FWD \$QUOTA \$AUTOREPLY \$U_DISK \$SUSPENDED"
  66. fields="$fields \$TIME \$DATE"
  67. # Listing domains
  68. case $format in
  69. json) json_list_account ;;
  70. plain) nohead=1; shell_list_account ;;
  71. shell) shell_list_account |column -t ;;
  72. *) check_args '2' '0' 'user domain account [format]'
  73. esac
  74. #----------------------------------------------------------#
  75. # Vesta #
  76. #----------------------------------------------------------#
  77. exit