v_list_user 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. # info: list system user
  3. # options: user [format]
  4. #
  5. # The function for obtainig the list of all user's parameters.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. USER="$user"
  12. format=${2-shell}
  13. # Importing variables
  14. source $VESTA/conf/vars.conf
  15. source $V_FUNC/shared.func
  16. # Json function
  17. json_list_user() {
  18. i=1
  19. fileds_count=$(echo "$fields" | wc -w)
  20. line=$(cat $V_USERS/$USER/user.conf)
  21. # Print top bracket
  22. echo '{'
  23. # Assing key=value
  24. eval $line
  25. # Starting output loop
  26. for field in $fields; do
  27. # Parsing key=value
  28. eval value=$field
  29. # Checking first field
  30. if [ "$i" -eq 1 ]; then
  31. echo -e "\t\"$value\": {"
  32. else
  33. if [ "$fileds_count" -eq "$i" ]; then
  34. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  35. else
  36. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  37. fi
  38. fi
  39. # Updating iterator
  40. (( ++i))
  41. done
  42. # If there was any output
  43. if [ -n "$value" ]; then
  44. echo -e ' }'
  45. fi
  46. # Printing bottom json bracket
  47. echo -e "}"
  48. }
  49. # Shell function
  50. shell_list_user() {
  51. line=$(cat $V_USERS/$USER/user.conf)
  52. # Parsing key=value
  53. eval $line
  54. # Print result line
  55. for field in $fields; do
  56. eval key="$field"
  57. echo "${field//$/}: $key "
  58. done
  59. }
  60. #----------------------------------------------------------#
  61. # Verifications #
  62. #----------------------------------------------------------#
  63. # Checking args
  64. check_args '1' "$#" 'user [format]'
  65. # Checking argument format
  66. format_validation 'user'
  67. # Checking user
  68. is_user_valid
  69. #----------------------------------------------------------#
  70. # Action #
  71. #----------------------------------------------------------#
  72. # Defining config
  73. conf=$V_USERS/$user/user.conf
  74. # Defining fileds to select
  75. fields='$USER $FNAME $LNAME $PACKAGE $WEB_DOMAINS $WEB_SSL $WEB_ALIASES
  76. $DATABASES $MAIL_DOMAINS $MAIL_BOXES $MAIL_FORWARDERS $DNS_DOMAINS
  77. $DISK_QUOTA $BANDWIDTH $NS $SHELL $BACKUPS $WEB_TPL $SUSPENDED $CONTACT
  78. $RKEY $REPORTS $IP_OWNED $U_DIR_DISK $U_DISK $U_BANDWIDTH $U_WEB_DOMAINS
  79. $U_WEB_SSL $U_DNS_DOMAINS $U_DATABASES $U_MAIL_DOMAINS $U_CRON_JOBS $DATE'
  80. # Listing user
  81. case $format in
  82. json) json_list_user ;;
  83. plain) nohead=1; shell_list_user ;;
  84. shell) shell_list_user | column -t ;;
  85. *) check_args '1' '0' 'user [format]' ;;
  86. esac
  87. #----------------------------------------------------------#
  88. # Vesta #
  89. #----------------------------------------------------------#
  90. exit