v_list_web_templates 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # info: list web templates
  3. # options: user [format]
  4. #
  5. # The function for obtaining the list of apache templates available to a user.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. format=${2-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. # Json function
  15. json_list_wtpl() {
  16. i=1
  17. echo '{'
  18. for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
  19. if [ -e "$WEBTPL/apache_$template.descr" ]; then
  20. descr=$(cat $WEBTPL/apache_$template.descr | grep '#'|\
  21. sed -e ':a;N;$!ba;s/\n/ /g')
  22. if [ $i -ne 1 ]; then
  23. echo -e "\t},"
  24. fi
  25. echo -e "\t\"$template\": {"
  26. echo -e "\t\t\"DESCR\": \"${descr//# /}\""
  27. (( ++i))
  28. fi
  29. done
  30. if [ -n "$template" ]; then
  31. echo -e "\t}"
  32. fi
  33. echo '}'
  34. }
  35. # Shell function
  36. shell_list_wtpl() {
  37. for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
  38. if [ -e "$WEBTPL/apache_$template.descr" ]; then
  39. tpl_descr=$(cat $WEBTPL/apache_$template.descr |grep '#')
  40. if [ -z "$nohead" ]; then
  41. echo "----------"
  42. fi
  43. echo "TEMPLATE: $template"
  44. echo "DESCRIPTION: ${tpl_descr//# /}"
  45. fi
  46. done
  47. }
  48. #----------------------------------------------------------#
  49. # Verifications #
  50. #----------------------------------------------------------#
  51. check_args '1' "$#" 'user'
  52. validate_format 'user'
  53. is_object_valid 'user' 'USER' "$user"
  54. #----------------------------------------------------------#
  55. # Action #
  56. #----------------------------------------------------------#
  57. # Get user package package
  58. templates=$(get_user_value '$WEB_TPL')
  59. # Listing domains
  60. case $format in
  61. json) json_list_wtpl ;;
  62. plain) nohead=1; shell_list_wtpl ;;
  63. shell) shell_list_wtpl ;;
  64. *) check_args '1' '0' '[format]'
  65. esac
  66. #----------------------------------------------------------#
  67. # Vesta #
  68. #----------------------------------------------------------#
  69. exit