v-list-web-templates-proxy 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. cut -f1 -d . |\
  57. grep -v proxy_ip |\
  58. sort -u )
  59. fi
  60. # Listing data
  61. case $format in
  62. json) json_list ;;
  63. plain) plain_list ;;
  64. csv) csv_list ;;
  65. shell) shell_list ;;
  66. esac
  67. #----------------------------------------------------------#
  68. # Vesta #
  69. #----------------------------------------------------------#
  70. exit