v_list_user_ns 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_FUNC/shared.func
  15. # Json function
  16. json_list_ns() {
  17. ns=$(grep "^NS='" $V_USERS/$user/user.conf |cut -f 2 -d \')
  18. # Print top bracket
  19. echo '['
  20. i=1
  21. nslistc=$(echo -e "${ns//,/\n}"|wc -l)
  22. # Listing servers
  23. for nameserver in ${ns//,/ };do
  24. if [ "$i" -ne "$nslistc" ]; then
  25. echo -e "\t\"$nameserver\","
  26. else
  27. echo -e "\t\"$nameserver\""
  28. fi
  29. (( ++i))
  30. done
  31. echo "]"
  32. }
  33. # Shell function
  34. shell_list_ns() {
  35. ns=$(grep "^NS='" $V_USERS/$user/user.conf |cut -f 2 -d \')
  36. if [ -z "$nohead" ]; then
  37. # Print result
  38. echo "NAMESERVER"
  39. echo "----------"
  40. fi
  41. for nameserver in ${ns//,/ };do
  42. echo "$nameserver"
  43. done
  44. }
  45. #----------------------------------------------------------#
  46. # Verifications #
  47. #----------------------------------------------------------#
  48. # Checking args
  49. check_args '1' "$#" 'user [format]'
  50. # Checking argument format
  51. format_validation 'user'
  52. # Checking user
  53. is_user_valid
  54. #----------------------------------------------------------#
  55. # Action #
  56. #----------------------------------------------------------#
  57. # Listing nameservers
  58. case $format in
  59. json) json_list_ns ;;
  60. plain) nohead=1; shell_list_ns ;;
  61. shell) shell_list_ns ;;
  62. *) check_args '1' '0' 'user [format]'
  63. esac
  64. #----------------------------------------------------------#
  65. # Vesta #
  66. #----------------------------------------------------------#
  67. exit