v_delete_web_domain_stat_auth 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_CONF/vesta.conf
  13. source $V_FUNC/shared.func
  14. source $V_FUNC/domain.func
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '2' "$#" 'user domain [auth_user]'
  20. # Checking argument format
  21. format_validation 'user' 'domain'
  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. # Checking stats auth enabled
  33. is_web_domain_value_exist '$STATS_AUTH'
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Definining statistic dir
  38. stat_dir="$V_HOME/$user/web/$domain/stats"
  39. # Checking auth_user
  40. if [ ! -z "$auth_user" ]; then
  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