v_list_dns_template 3.1 KB

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