v_del_web_domain_stat_auth 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # Importing variables
  11. source $VESTA/conf/vars.conf
  12. source $V_FUNC/shared_func.sh
  13. source $V_FUNC/domain_func.sh
  14. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. # Checking arg number
  18. check_args '2' "$#" 'user domain [auth_user]'
  19. # Checking argument format
  20. format_validation 'user' 'domain'
  21. # Checking web system is enabled
  22. is_system_enabled 'web'
  23. # Checking user
  24. is_user_valid
  25. # Checking user is active
  26. is_user_suspended
  27. # Checking domain exist
  28. is_web_domain_valid
  29. # Checking domain is not suspened
  30. is_domain_suspended 'web_domains'
  31. # Checking stats auth enabled
  32. is_web_domain_value_exist '$STATS_AUTH'
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Definining statistic dir
  37. stat_dir="$V_HOME/$user/domains/$domain/stats"
  38. # Checking auth_user
  39. if [ ! -z "$auth_user" ]; then
  40. # Checking argument format
  41. format_validation 'auth_user'
  42. htpasswd -D $stat_dir/.htpasswd "$auth_user" >/dev/null 2>&1
  43. fi
  44. # Checking htpasswd current users
  45. lines=$(wc -l $stat_dir/.htpasswd |cut -f 1 -d ' ')
  46. if [ -z "$auth_user" ] || [ "$lines" -eq '0' ]; then
  47. rm -f $stat_dir/.htpasswd
  48. rm -f $stat_dir/.htaccess
  49. fi
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. # Checking auth_user
  54. if [ ! -z "$auth_user" ]; then
  55. # Get current value
  56. curr_val=$(get_web_domain_value '$STATS_AUTH')
  57. # Deleteting auth_user
  58. new_val=$(echo "$curr_val" |\
  59. sed -e "s/,/\n/g"|\
  60. sed -e "s/^$auth_user$//g"|\
  61. sed -e "/^$/d"|\
  62. sed -e ':a;N;$!ba;s/\n/,/g')
  63. # Checking it was last user
  64. if [ -z "$new_val" ]; then
  65. new_val=''
  66. fi
  67. else
  68. # User empty, deleting all
  69. new_val=''
  70. fi
  71. # Deleting stats auth_user
  72. update_web_domain_value '$STATS_AUTH' "$new_val"
  73. # Logging
  74. log_history "$V_EVENT"
  75. log_event 'system' "$V_EVENT"
  76. exit $OK