v_list_dns_templates 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. # Includes
  12. source $VESTA/func/main.sh
  13. # Json function
  14. json_list_dnstpl() {
  15. echo '{'
  16. for template in $(ls $DNSTPL/| grep '.descr'); do
  17. if [ -n "$data" ]; then
  18. echo -e ' },'
  19. fi
  20. tpl_descr=$(cat $DNSTPL/$template |grep '#'|tr -d '\n')
  21. tpl_name="${template//.descr/}"
  22. echo -e "\t\"$tpl_name\": {"
  23. echo -e "\t\t\"DESCR\": \"${tpl_descr//# /}\""
  24. data=1
  25. done
  26. if [ -n "$data" ]; then
  27. echo -e ' }'
  28. fi
  29. echo -e '}'
  30. }
  31. # Shell function
  32. shell_list_dnstpl() {
  33. for template in $(ls $DNSTPL/| grep '.descr'); do
  34. tpl_name="${template//.descr/}"
  35. tpl_descr=$(cat $DNSTPL/$template |grep '#')
  36. if [ -z "$nohead" ] ; then
  37. echo "----------"
  38. fi
  39. echo "TEMPLATE: $tpl_name"
  40. echo "DESCRIPTION: ${tpl_descr//# /}"
  41. if [ -z "$nohead" ] ; then
  42. echo
  43. fi
  44. done
  45. }
  46. #----------------------------------------------------------#
  47. # Action #
  48. #----------------------------------------------------------#
  49. # Listing domains
  50. case $format in
  51. json) json_list_dnstpl;;
  52. plain) nohead=1; shell_list_dnstpl ;;
  53. shell) shell_list_dnstpl ;;
  54. *) check_args '1' '0' '[format] [limit] [offset]';;
  55. esac
  56. #----------------------------------------------------------#
  57. # Vesta #
  58. #----------------------------------------------------------#
  59. exit