v_add_web_domain_stats_user 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 defenition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. stats_user=$3
  13. stats_pass=$4
  14. # Includes
  15. source $VESTA/conf/vesta.conf
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/domain.sh
  18. # Hiding password
  19. A4='******'
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '4' "$#" 'user domain stats_user stats_pass'
  24. validate_format 'user' 'domain' 'stats_user' 'stats_pass'
  25. is_system_enabled "$WEB_SYSTEM"
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  30. is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS'
  31. #----------------------------------------------------------#
  32. # Action #
  33. #----------------------------------------------------------#
  34. # Definining statistic dir
  35. stats_dir="$HOMEDIR/$user/web/$domain/stats"
  36. # Adding htaccess file
  37. echo "AuthUserFile $stats_dir/.htpasswd
  38. AuthName \"Web Statistics\"
  39. AuthType Basic
  40. Require valid-user" > $stats_dir/.htaccess
  41. # Generating htaccess user and password
  42. rm -f $stats_dir/.htpasswd
  43. htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$stats_pass" &>/dev/null
  44. stats_crypt=$(grep $stats_user: $stats_dir/.htpasswd |cut -f 2 -d :)
  45. #----------------------------------------------------------#
  46. # Vesta #
  47. #----------------------------------------------------------#
  48. # Adding stats user in config
  49. update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
  50. update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_crypt"
  51. # Logging
  52. log_history "$EVENT"
  53. log_event "$OK" "$EVENT"
  54. exit