v_add_web_domain_stat_auth 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # info: add password protection to web domain statistics
  3. # options: user domain auth_user auth_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. auth_user=$3
  13. auth_pass=$4
  14. # Importing variables
  15. source $VESTA/conf/vars.conf
  16. source $V_CONF/vesta.conf
  17. source $V_FUNC/shared.func
  18. source $V_FUNC/domain.func
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Checking arg number
  23. check_args '4' "$#" 'user domain auth_user auth_password'
  24. # Checking argument format
  25. format_validation 'user' 'domain' 'auth_user' 'auth_pass'
  26. # Checking web system is enabled
  27. is_system_enabled 'web'
  28. # Checking user
  29. is_user_valid
  30. # Checking user is active
  31. is_user_suspended
  32. # Checking domain exist
  33. is_web_domain_valid
  34. # Checking domain is not suspened
  35. is_domain_suspended 'web'
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Definining statistic dir
  40. stat_dir="$V_HOME/$user/web/$domain/stats"
  41. # Adding htaccess file
  42. if [ ! -e "$stat_dir/.htaccess" ]; then
  43. echo "AuthUserFile $stat_dir/.htpasswd" > $stat_dir/.htaccess
  44. echo "AuthName \"Only for admins\"" >> $stat_dir/.htaccess
  45. echo "AuthType Basic" >> $stat_dir/.htaccess
  46. echo "Require valid-user" >> $stat_dir/.htaccess
  47. echo "" >> $stat_dir/.htaccess
  48. fi
  49. # Generating htaccess user and password
  50. if [ ! -e "$stat_dir/.htpasswd" ]; then
  51. htpasswd -bc $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
  52. else
  53. htpasswd -b $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
  54. fi
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Get current value
  59. curr_val=$(get_web_domain_value '$STATS_AUTH')
  60. check_uniq=$(echo "$curr_val" | grep -w "$auth_user")
  61. # Checking current users
  62. if [ -z "$curr_val" ] || [ "$curr_val" = 'no' ]; then
  63. a_users="$auth_user"
  64. else
  65. if [ -z "$check_uniq" ]; then
  66. a_users="$curr_val,$auth_user"
  67. else
  68. a_users="$curr_val"
  69. fi
  70. fi
  71. # Adding stats user in config
  72. update_web_domain_value '$STATS_AUTH' "$a_users"
  73. # Hiding password
  74. V_EVENT="$V_DATE $V_SCRIPT $user $domain $auth_user *****"
  75. # Logging
  76. log_history "$V_EVENT" "v_delete_web_domain_stat_auth $user $domain $auth_user"
  77. log_event 'system' "$V_EVENT"
  78. exit