v_delete_web_domain_stat_auth 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # info: disable webdomain stats authentication support
  3. # options: user domain [auth_user]
  4. #
  5. # The function removes authentication of statistics system. If the script is
  6. # called without naming a certain user, all users will be removed. After
  7. # deleting all of them statistics will be accessible for view without an
  8. # authentication.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument defenition
  13. user=$1
  14. domain=$(idn -t --quiet -u "$2" )
  15. auth_user=$3
  16. # Importing variables
  17. source $VESTA/conf/vars.conf
  18. source $V_CONF/vesta.conf
  19. source $V_FUNC/shared.func
  20. source $V_FUNC/domain.func
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. # Checking arg number
  25. check_args '2' "$#" 'user domain [auth_user]'
  26. # Checking argument format
  27. format_validation 'user' 'domain'
  28. # Checking web system is enabled
  29. is_system_enabled 'web'
  30. # Checking user
  31. is_user_valid
  32. # Checking user is active
  33. is_user_suspended
  34. # Checking domain exist
  35. is_web_domain_valid
  36. # Checking domain is not suspened
  37. is_domain_suspended 'web'
  38. # Checking stats auth enabled
  39. is_web_domain_value_exist '$STATS_AUTH'
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Definining statistic dir
  44. stat_dir="$V_HOME/$user/web/$domain/stats"
  45. # Checking auth_user
  46. if [ ! -z "$auth_user" ]; then
  47. format_validation 'auth_user'
  48. htpasswd -D $stat_dir/.htpasswd "$auth_user" >/dev/null 2>&1
  49. fi
  50. # Checking htpasswd current users
  51. lines=$(wc -l $stat_dir/.htpasswd |cut -f 1 -d ' ')
  52. if [ -z "$auth_user" ] || [ "$lines" -eq '0' ]; then
  53. rm -f $stat_dir/.htpasswd
  54. rm -f $stat_dir/.htaccess
  55. fi
  56. #----------------------------------------------------------#
  57. # Vesta #
  58. #----------------------------------------------------------#
  59. # Checking auth_user
  60. if [ ! -z "$auth_user" ]; then
  61. # Get current value
  62. curr_val=$(get_web_domain_value '$STATS_AUTH')
  63. # Deleteting auth_user
  64. new_val=$(echo "$curr_val" |\
  65. sed -e "s/,/\n/g"|\
  66. sed -e "s/^$auth_user$//g"|\
  67. sed -e "/^$/d"|\
  68. sed -e ':a;N;$!ba;s/\n/,/g')
  69. # Checking it was last user
  70. if [ -z "$new_val" ]; then
  71. new_val=''
  72. fi
  73. else
  74. # User empty, deleting all
  75. new_val=''
  76. fi
  77. # Deleting stats auth_user
  78. update_web_domain_value '$STATS_AUTH' "$new_val"
  79. # Logging
  80. log_history "$V_EVENT"
  81. log_event 'system' "$V_EVENT"
  82. exit