v_add_web_domain_stat_auth 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # info: adding web domain
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. domain=$(idn -t --quiet -u "$2" )
  9. auth_user="$3"
  10. auth_pass="$4"
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_FUNC/shared_func.sh
  14. source $V_FUNC/domain_func.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '4' "$#" 'user domain auth_user auth_password'
  20. # Checking argument format
  21. format_validation 'user' 'domain' 'auth_user' 'auth_pass'
  22. # Checking web system is enabled
  23. is_system_enabled 'web'
  24. # Checking user
  25. is_user_valid
  26. # Checking user is active
  27. is_user_suspended
  28. # Checking domain exist
  29. is_web_domain_valid
  30. # Checking domain is not suspened
  31. is_domain_suspended 'web'
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Definining statistic dir
  36. stat_dir="$V_HOME/$user/web/$domain/stats"
  37. # Adding htaccess file
  38. if [ ! -e "$stat_dir/.htaccess" ]; then
  39. echo "AuthUserFile $stat_dir/.htpasswd" > $stat_dir/.htaccess
  40. echo "AuthName \"Only for admins\"" >> $stat_dir/.htaccess
  41. echo "AuthType Basic" >> $stat_dir/.htaccess
  42. echo "Require valid-user" >> $stat_dir/.htaccess
  43. echo "" >> $stat_dir/.htaccess
  44. fi
  45. # Generating htaccess user and password
  46. if [ ! -e "$stat_dir/.htpasswd" ]; then
  47. htpasswd -bc $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
  48. else
  49. htpasswd -b $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
  50. fi
  51. #----------------------------------------------------------#
  52. # Vesta #
  53. #----------------------------------------------------------#
  54. # Get current value
  55. curr_val=$(get_web_domain_value '$STATS_AUTH')
  56. check_uniq=$(echo "$curr_val" | grep -w "$auth_user")
  57. # Checking current users
  58. if [ -z "$curr_val" ] || [ "$curr_val" = 'no' ]; then
  59. a_users="$auth_user"
  60. else
  61. if [ -z "$check_uniq" ]; then
  62. a_users="$curr_val,$auth_user"
  63. else
  64. a_users="$curr_val"
  65. fi
  66. fi
  67. # Adding stats user in config
  68. update_web_domain_value '$STATS_AUTH' "$a_users"
  69. # Hiding password
  70. V_EVENT="$(date +%m-%d-%y" "%H:%m:%S) $V_SCRIPT $user $domain $auth_user *****"
  71. # Logging
  72. log_history "$V_EVENT" "v_del_web_domain_stat_auth $user $domain $auth_user"
  73. log_event 'system' "$V_EVENT"
  74. exit $OK