v_list_dns_templates 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # info: list dns templates
  3. # options: [format]
  4. #
  5. # The function for obtaining the list of all DNS templates available.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. format=${1-shell}
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_FUNC/shared.func
  14. # Json function
  15. json_list_dnstpl() {
  16. # Print top bracket
  17. echo '{'
  18. # Count fields
  19. for template in $(ls $V_DNSTPL/| grep '.descr'); do
  20. # Closing bracket if there already was output
  21. if [ -n "$data" ]; then
  22. echo -e ' },'
  23. fi
  24. tpl_descr=$(cat $V_DNSTPL/$template |grep '#'|tr -d '\n')
  25. tpl_name="${template//.descr/}"
  26. echo -e "\t\"$tpl_name\": {"
  27. echo -e "\t\t\"DESCR\": \"${tpl_descr//# /}\""
  28. data=1
  29. done
  30. # Closing bracket if there was output
  31. if [ -n "$data" ]; then
  32. echo -e ' }'
  33. fi
  34. # Printing bottom bracket
  35. echo -e '}'
  36. }
  37. # Shell function
  38. shell_list_dnstpl() {
  39. for template in $(ls $V_DNSTPL/| grep '.descr'); do
  40. tpl_name="${template//.descr/}"
  41. tpl_descr=$(cat $V_DNSTPL/$template |grep '#')
  42. # Print result
  43. if [ -z "$nohead" ] ; then
  44. echo "----------"
  45. fi
  46. echo "TEMPLATE: $tpl_name"
  47. echo "DESCRIPTION: ${tpl_descr//# /}"
  48. if [ -z "$nohead" ] ; then
  49. echo
  50. fi
  51. done
  52. }
  53. #----------------------------------------------------------#
  54. # Action #
  55. #----------------------------------------------------------#
  56. # Listing domains
  57. case $format in
  58. json) json_list_dnstpl;;
  59. plain) nohead=1; shell_list_dnstpl ;;
  60. shell) shell_list_dnstpl ;;
  61. *) check_args '1' '0' '[format] [limit] [offset]';;
  62. esac
  63. #----------------------------------------------------------#
  64. # Vesta #
  65. #----------------------------------------------------------#
  66. exit