v_list_sys_user_ns 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # info: listing user nameservers
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. format=${2-shell}
  9. # Importing variables
  10. source $VESTA/conf/vars.conf
  11. source $V_FUNC/shared.func
  12. # Json function
  13. json_list_ns() {
  14. ns=$(grep "^NS='" $V_USERS/$user/user.conf |cut -f 2 -d \')
  15. # Print top bracket
  16. echo '['
  17. i=1
  18. nslistc=$(echo -e "${ns//,/\n}"|wc -l)
  19. # Listing servers
  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='" $V_USERS/$user/user.conf |cut -f 2 -d \')
  33. if [ -z "$nohead" ]; then
  34. # Print result
  35. echo "NAMESERVER"
  36. echo "----------"
  37. fi
  38. for nameserver in ${ns//,/ };do
  39. echo "$nameserver"
  40. done
  41. }
  42. #----------------------------------------------------------#
  43. # Verifications #
  44. #----------------------------------------------------------#
  45. # Checking args
  46. check_args '1' "$#" 'user [format]'
  47. # Checking argument format
  48. format_validation 'user'
  49. # Checking user
  50. is_user_valid
  51. #----------------------------------------------------------#
  52. # Action #
  53. #----------------------------------------------------------#
  54. # Listing nameservers
  55. case $format in
  56. json) json_list_ns ;;
  57. plain) nohead=1; shell_list_ns ;;
  58. shell) shell_list_ns ;;
  59. *) check_args '1' '0' 'user [format]'
  60. esac
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. exit