v-list-web-templates-proxy 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # info: listing proxy templates
  3. # options: [FORMAT]
  4. #
  5. # The function for obtaining the list of proxy templates available to a user.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. source $VESTA/conf/vesta.conf
  14. # JSON list function
  15. json_list() {
  16. objects=$(echo "$templates" |wc -w)
  17. i=1
  18. echo '['
  19. for template in $templates; do
  20. if [ "$i" -lt "$objects" ]; then
  21. echo -e "\t\"$template\","
  22. else
  23. echo -e "\t\"$template\""
  24. fi
  25. (( ++i))
  26. done
  27. echo "]"
  28. }
  29. # SHELL list function
  30. shell_list() {
  31. echo "TEMPLATE"
  32. echo "--------"
  33. for template in $templates; do
  34. echo "$template"
  35. done
  36. }
  37. # PLAIN list function
  38. plain_list() {
  39. for template in $templates; do
  40. echo "$template"
  41. done
  42. }
  43. # CSV list function
  44. csv_list() {
  45. echo "TEMPLATE"
  46. for template in $templates; do
  47. echo "$template"
  48. done
  49. }
  50. #----------------------------------------------------------#
  51. # Action #
  52. #----------------------------------------------------------#
  53. # Parsing proxy templates
  54. if [ ! -z "$PROXY_SYSTEM" ]; then
  55. templates=$(ls -t $WEBTPL/$PROXY_SYSTEM |\
  56. grep ".tpl$" |\
  57. cut -f1 -d . |\
  58. grep -v proxy_ip |\
  59. sort -u )
  60. fi
  61. # Listing data
  62. case $format in
  63. json) json_list ;;
  64. plain) plain_list ;;
  65. csv) csv_list ;;
  66. shell) shell_list ;;
  67. esac
  68. #----------------------------------------------------------#
  69. # Vesta #
  70. #----------------------------------------------------------#
  71. exit