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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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=$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. if [ "$WEB_SYSTEM" = 'nginx' ]; then
  36. echo "auth_basic \"Web Statistics\";" > $stats_dir/auth.conf
  37. echo "auth_basic_user_file $stats_dir/.htpasswd;" >> $stats_dir/auth.conf
  38. else
  39. echo "AuthUserFile $stats_dir/.htpasswd" > $stats_dir/.htaccess
  40. echo "AuthName \"Web Statistics\"" >> $stats_dir/.htaccess
  41. echo "AuthType Basic" >> $stats_dir/.htaccess
  42. echo "Require valid-user" >> $stats_dir/.htaccess
  43. fi
  44. # Generating htaccess user and password
  45. salt=$(generate_password "$PW_MATRIX" "8")
  46. stats_pass=$($BIN/v-generate-password-hash md5 $salt $password)
  47. echo "$stats_user:$stats_pass" > $stats_dir/.htpasswd
  48. #----------------------------------------------------------#
  49. # Vesta #
  50. #----------------------------------------------------------#
  51. # Adding stats user in config
  52. update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
  53. update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_pass"
  54. # Logging
  55. log_history "added password protection for web stats on $domain"
  56. log_event "$OK" "$ARGUMENTS"
  57. exit