v-list-dns-templates 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. templates=$(ls -t $DNSTPL |grep '\.tpl' |cut -f 1 -d '.')
  16. t_counter=$(echo "$templates" | wc -w)
  17. i=1
  18. echo '['
  19. for template in $templates; do
  20. if [ "$i" -lt "$t_counter" ]; then
  21. echo -e "\t\"$template\","
  22. else
  23. echo -e "\t\"$template\""
  24. fi
  25. (( ++i))
  26. done
  27. echo "]"
  28. }
  29. # Shell function
  30. shell_list_dnstpl() {
  31. templates=$(ls -t $DNSTPL |grep '\.tpl' |cut -f 1 -d '.')
  32. if [ -z "$nohead" ]; then
  33. echo "Templates"
  34. echo "----------"
  35. fi
  36. for template in $templates; do
  37. echo "$template"
  38. done
  39. }
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Listing domains
  44. case $format in
  45. json) json_list_dnstpl;;
  46. plain) nohead=1; shell_list_dnstpl ;;
  47. shell) shell_list_dnstpl ;;
  48. *) check_args '1' '0' '[format] [limit] [offset]';;
  49. esac
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. exit