v_add_web_domain_stats 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # info: add log analyzer to generate domain statitics
  3. # options: user domain type
  4. #
  5. # The call is used for enabling log analyzer system to a domain. At this time
  6. # two types of these system is supported - awstats and webalizer. For viewing
  7. # the domain statistics use http://domain.tld/vstats/ link. Access this page
  8. # is not protected by default. If you want to secure it with passwords you
  9. # should use v_add_web_domain_stat_auth script.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument defenition
  14. user=$1
  15. domain=$(idn -t --quiet -u "$2" )
  16. domain_idn=$(idn -t --quiet -a "$domain")
  17. type=$3
  18. # Includes
  19. source $VESTA/conf/vesta.conf
  20. source $VESTA/func/main.sh
  21. source $VESTA/func/domain.sh
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '3' "$#" 'user domain type'
  26. validate_format 'user' 'domain'
  27. is_system_enabled "$WEB_SYSTEM"
  28. is_type_valid "$STATS_SYSTEM" "$type"
  29. is_object_valid 'user' 'USER' "$user" "$user"
  30. is_object_unsuspended 'user' 'USER' "$user"
  31. is_object_valid 'web' 'DOMAIN' "$domain"
  32. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  33. is_object_value_empty 'web' 'DOMAIN' "$domain" '$STATS'
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Parse aliases
  38. get_domain_values 'web'
  39. # Preparing domain values for the template substitution
  40. upd_web_domain_values
  41. # Adding statistic config
  42. cat $WEBTPL/$type.tpl |\
  43. sed -e "s/%ip%/$ip/g" \
  44. -e "s/%web_port%/$WEB_PORT/g" \
  45. -e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \
  46. -e "s/%proxy_port%/$PROXY_PORT/g" \
  47. -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
  48. -e "s/%domain_idn%/$domain_idn/g" \
  49. -e "s/%domain%/$domain/g" \
  50. -e "s/%user%/$user/g" \
  51. -e "s/%home%/${HOMEDIR////\/}/g" \
  52. -e "s/%alias%/${aliases//,/ }/g" \
  53. -e "s/%alias_idn%/${aliases_idn//,/ }/g" \
  54. > $HOMEDIR/$user/conf/web/$type.$domain.conf
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Schedule statistic processing
  59. echo "$BIN/v_update_web_domain_stat $user $domain" >> $V_QUEUE/stats.pipe
  60. # Update config
  61. update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"
  62. # Logging
  63. log_history "$EVENT"
  64. log_event "$OK" "$EVENT"
  65. exit