v_list_web_templates_nginx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # info: listing nginx templates
  3. # options: user [format]
  4. #
  5. # The function for obtaining the list of nginx templates available to a user.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. format=${2-shell}
  12. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_FUNC/shared.func
  15. # Json function
  16. json_list_wtpl() {
  17. i='1' # iterator
  18. echo '{'
  19. # Listing files by mask
  20. for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
  21. if [ -e "$V_WEBTPL/ngingx_vhost_$template.descr" ]; then
  22. descr=$(cat $V_WEBTPL/ngingx_vhost_$template.descr | grep '#'|\
  23. sed -e ':a;N;$!ba;s/\n/ /g')
  24. # Checking !first line to print bracket
  25. if [ $i -ne 1 ]; then
  26. echo -e "\t},"
  27. fi
  28. # Print result
  29. echo -e "\t\"$template\": {"
  30. echo -e "\t\t\"DESCR\": \"${descr//# /}\""
  31. (( ++i))
  32. fi
  33. done
  34. # If there was any output
  35. if [ -n "$template" ]; then
  36. echo -e "\t}"
  37. fi
  38. echo '}'
  39. }
  40. # Shell function
  41. shell_list_wtpl() {
  42. for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
  43. if [ -e "$V_WEBTPL/ngingx_vhost_$template.descr" ]; then
  44. tpl_descr=$(cat $V_WEBTPL/ngingx_vhost_$template.descr |grep '#')
  45. if [ -z "$nohead" ]; then
  46. echo "----------"
  47. fi
  48. echo "TEMPLATE: $template"
  49. echo "DESCRIPTION: ${tpl_descr//# /}"
  50. fi
  51. done
  52. }
  53. #----------------------------------------------------------#
  54. # Verifications #
  55. #----------------------------------------------------------#
  56. # Checking arg number
  57. check_args '1' "$#" 'user'
  58. # Checking argument format
  59. format_validation 'user'
  60. # Checking user
  61. is_user_valid
  62. #----------------------------------------------------------#
  63. # Action #
  64. #----------------------------------------------------------#
  65. # Get user package package
  66. templates=$(get_user_value '$WEB_TPL')
  67. # Listing domains
  68. case $format in
  69. json) json_list_wtpl ;;
  70. plain) nohead=1; shell_list_wtpl ;;
  71. shell) shell_list_wtpl ;;
  72. *) check_args '1' '0' '[format]'
  73. esac
  74. #----------------------------------------------------------#
  75. # Vesta #
  76. #----------------------------------------------------------#
  77. exit