v-list-dns-template 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 definition
  10. template=$1
  11. format=${2-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. source $VESTA/func/domain.sh
  15. # JSON list function
  16. json_list() {
  17. IFS=$'\n'
  18. i=1
  19. objects=$(grep ID $DNSTPL/$template.tpl |wc -l)
  20. echo "{"
  21. while read str; do
  22. eval $str
  23. VALUE=$(echo "$VALUE" |sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
  24. echo -n ' "'$ID'": {
  25. "RECORD": "'$RECORD'",
  26. "TYPE": "'$TYPE'",
  27. "PRIORITY": "'$PRIORITY'",
  28. "VALUE": "'$VALUE'",
  29. "ID": "'$ID'"
  30. }'
  31. if [ "$i" -lt "$objects" ]; then
  32. echo ','
  33. else
  34. echo
  35. fi
  36. ((i++))
  37. done < <(cat $DNSTPL/$template.tpl)
  38. echo '}'
  39. }
  40. # SHELL list function
  41. shell_list() {
  42. IFS=$'\n'
  43. echo "ID^RECORD^TYPE^VALUE"
  44. echo "--^------^----^-----"
  45. while read str; do
  46. eval $str
  47. echo "$ID^$RECORD^$TYPE^$VALUE"
  48. done < <(cat $DNSTPL/$template.tpl)
  49. }
  50. # PLAIN list function
  51. plain_list() {
  52. IFS=$'\n'
  53. while read str; do
  54. eval $str
  55. VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
  56. echo -e "$ID\t$RECORD\t$TYPE\t$PRIORITY\t$VALUE"
  57. done < <(cat $DNSTPL/$template.tpl)
  58. }
  59. # CSV list function
  60. csv_list() {
  61. IFS=$'\n'
  62. echo "ID,RECORD,TYPE,PRIORITY,VALUE"
  63. while read str; do
  64. eval $str
  65. VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
  66. echo "$ID,$RECORD,$TYPE,$PRIORITY,\"$VALUE\""
  67. done < <(cat $DNSTPL/$template.tpl)
  68. }
  69. #----------------------------------------------------------#
  70. # Verifications #
  71. #----------------------------------------------------------#
  72. check_args '1' "$#" 'TEMPLATE [FORMAT]'
  73. is_format_valid 'template'
  74. is_dns_template_valid "$template"
  75. #----------------------------------------------------------#
  76. # Action #
  77. #----------------------------------------------------------#
  78. # Listing data
  79. case $format in
  80. json) json_list ;;
  81. plain) plain_list ;;
  82. csv) csv_list ;;
  83. shell) shell_list |column -t -s '^';;
  84. esac
  85. #----------------------------------------------------------#
  86. # Vesta #
  87. #----------------------------------------------------------#
  88. exit