v-list-user-ns 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # info: list user nameservers
  3. # options: user [format]
  4. #
  5. # Function for obtainig the list of user's DNS servers.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. format=${2-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. # Json function
  15. json_list_ns() {
  16. ns=$(grep "^NS='" $USER_DATA/user.conf |cut -f 2 -d \')
  17. echo '['
  18. i=1
  19. nslistc=$(echo -e "${ns//,/\n}"|wc -l)
  20. for nameserver in ${ns//,/ };do
  21. if [ "$i" -ne "$nslistc" ]; then
  22. echo -e "\t\"$nameserver\","
  23. else
  24. echo -e "\t\"$nameserver\""
  25. fi
  26. (( ++i))
  27. done
  28. echo "]"
  29. }
  30. # Shell function
  31. shell_list_ns() {
  32. ns=$(grep "^NS='" $USER_DATA/user.conf |cut -f 2 -d \')
  33. if [ -z "$nohead" ]; then
  34. echo "NAMESERVER"
  35. echo "----------"
  36. fi
  37. for nameserver in ${ns//,/ };do
  38. echo "$nameserver"
  39. done
  40. }
  41. #----------------------------------------------------------#
  42. # Verifications #
  43. #----------------------------------------------------------#
  44. check_args '1' "$#" 'user [format]'
  45. validate_format 'user'
  46. is_object_valid 'user' 'USER' "$user"
  47. #----------------------------------------------------------#
  48. # Action #
  49. #----------------------------------------------------------#
  50. # Listing nameservers
  51. case $format in
  52. json) json_list_ns ;;
  53. plain) nohead=1; shell_list_ns ;;
  54. shell) shell_list_ns ;;
  55. *) check_args '1' '0' 'user [format]'
  56. esac
  57. #----------------------------------------------------------#
  58. # Vesta #
  59. #----------------------------------------------------------#
  60. exit