v-add-web-domain-stats-user 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # info: add password protection to web domain statistics
  3. # options: USER DOMAIN STATS_USER STATS_PASSWORD
  4. #
  5. # The call is used for securing the web statistics page.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. stats_user=$3
  13. password=$4; HIDE=4
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/domain.sh
  17. source $VESTA/conf/vesta.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '4' "$#" 'USER DOMAIN STATS_USER STATS_PASS'
  22. is_format_valid 'user' 'domain' 'stats_user'
  23. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  24. is_object_valid 'user' 'USER' "$user"
  25. is_object_unsuspended 'user' 'USER' "$user"
  26. is_object_valid 'web' 'DOMAIN' "$domain"
  27. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  28. is_password_valid
  29. #----------------------------------------------------------#
  30. # Action #
  31. #----------------------------------------------------------#
  32. # Defining statistic dir
  33. stats_dir="$HOMEDIR/$user/web/$domain/stats"
  34. # Adding htaccess file
  35. echo "AuthUserFile $stats_dir/.htpasswd
  36. AuthName \"Web Statistics\"
  37. AuthType Basic
  38. Require valid-user" > $stats_dir/.htaccess
  39. # Generating htaccess user and password
  40. rm -f $stats_dir/.htpasswd
  41. htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$password" &>/dev/null
  42. stats_crypt=$(grep $stats_user: $stats_dir/.htpasswd |cut -f 2 -d :)
  43. #----------------------------------------------------------#
  44. # Vesta #
  45. #----------------------------------------------------------#
  46. # Adding stats user in config
  47. update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
  48. update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_crypt"
  49. # Logging
  50. log_history "added password protection for web stats on $domain"
  51. log_event "$OK" "$ARGUMENTS"
  52. exit