v_add_web_domain_stat_auth 2.6 KB

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