v_list_dns_domain 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/bash
  2. # info: listing dns domain
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. domain=$2
  9. format=${3-shell}
  10. # Importing variables
  11. source $VESTA/conf/vars.conf
  12. source $V_FUNC/shared.func
  13. source $V_FUNC/domain.func
  14. # Json func
  15. json_list_dns() {
  16. # Print top bracket
  17. echo '{'
  18. # Count fields
  19. fileds_count=$(echo $fields| wc -w )
  20. # Reading file line by line
  21. while read line; do
  22. # New delimeter
  23. IFS=$'\n'
  24. # Assing key=value pair
  25. for key in $line; do
  26. eval ${key%%=*}=${key#*=}
  27. done
  28. # Closing bracket if there already was output
  29. if [ -n "$data" ]; then
  30. echo -e ' },'
  31. fi
  32. i=1
  33. IFS=' '
  34. for field in $fields; do
  35. eval value=\"$field\"
  36. value=$(echo "$value" | sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
  37. if [ $i -eq 1 ]; then
  38. # Printing parrent
  39. (( ++i))
  40. echo -e "\t\"$value\": {"
  41. else
  42. # Printing child
  43. if [ $i -lt $fileds_count ]; then
  44. (( ++i))
  45. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  46. else
  47. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  48. data=1
  49. fi
  50. fi
  51. done
  52. done < $conf
  53. # Closing bracket if there was output
  54. if [ -n "$data" ]; then
  55. echo -e ' }'
  56. fi
  57. # Printing bottom bracket
  58. echo -e '}'
  59. }
  60. # Shell function
  61. shell_list_dns() {
  62. if [ -z "$nohead" ] ; then
  63. # Print brief info
  64. echo "${fields//$/}"
  65. for a in $fields; do
  66. echo -e "------ \c"
  67. done
  68. echo
  69. fi
  70. # Reading file line by line
  71. while read line ; do
  72. # New delimeter
  73. IFS=$'\n'
  74. # Assing key=value pair
  75. for key in $line; do
  76. eval ${key%%=*}=${key#*=}
  77. done
  78. # Print result
  79. eval echo "$fields" | sed -e "s/%quote%/'/g"
  80. done < $conf
  81. }
  82. #----------------------------------------------------------#
  83. # Verifications #
  84. #----------------------------------------------------------#
  85. # Checking args
  86. check_args '2' "$#" 'user domain [format]'
  87. # Checking argument format
  88. format_validation 'user' 'domain'
  89. # Checking user
  90. is_user_valid
  91. # Checking domain exist
  92. is_dns_domain_valid
  93. #----------------------------------------------------------#
  94. # Action #
  95. #----------------------------------------------------------#
  96. # Defining config
  97. conf=$V_USERS/$user/zones/$domain
  98. # Defining fileds to select
  99. fields='$ID $RECORD $TYPE $VALUE $SUSPEND $DATE'
  100. # Listing domains
  101. case $format in
  102. json) json_list_dns ;;
  103. plain) nohead=1; shell_list_dns ;;
  104. shell) fields='$ID $RECORD $TYPE $VALUE';
  105. shell_list_dns | column -t ;;
  106. *) check_args '2' '0' 'user domain [format]'
  107. esac
  108. #----------------------------------------------------------#
  109. # Vesta #
  110. #----------------------------------------------------------#
  111. # Logging
  112. log_event 'system' "$V_EVENT"
  113. exit