v_list_sys_user 2.7 KB

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