v_delete_web_domain_stat_auth 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/vesta.conf
  18. source $VESTA/func/shared.sh
  19. source $VESTA/func/domain.sh
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. # Checking arg number
  24. check_args '2' "$#" 'user domain [auth_user]'
  25. # Checking argument format
  26. validate_format 'user' 'domain'
  27. # Checking web system is enabled
  28. is_system_enabled 'WEB_SYSTEM'
  29. # Checking user
  30. is_object_valid 'user' 'USER' "$user"
  31. # Checking user is active
  32. is_object_unsuspended 'user' 'USER' "$user"
  33. # Checking domain exist
  34. is_domain_valid 'web'
  35. # Checking domain is not suspened
  36. is_domain_suspended 'web'
  37. # Checking stats auth enabled
  38. is_domain_value_exist 'web' '$STATS_AUTH'
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Definining statistic dir
  43. stat_dir="$HOMEDIR/$user/web/$domain/stats"
  44. # Checking auth_user
  45. if [ ! -z "$auth_user" ]; then
  46. validate_format 'auth_user'
  47. htpasswd -D $stat_dir/.htpasswd "$auth_user" &>/dev/null
  48. fi
  49. # Checking htpasswd current users
  50. lines=$(wc -l $stat_dir/.htpasswd |cut -f 1 -d ' ')
  51. if [ -z "$auth_user" ] || [ "$lines" -eq '0' ]; then
  52. rm -f $stat_dir/.htpasswd
  53. rm -f $stat_dir/.htaccess
  54. fi
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Checking auth_user
  59. if [ ! -z "$auth_user" ]; then
  60. # Get current value
  61. curr_val=$(get_domain_value 'web' '$STATS_AUTH')
  62. # Deleteting auth_user
  63. new_val=$(echo "$curr_val" |\
  64. sed -e "s/,/\n/g"|\
  65. sed -e "s/^$auth_user$//g"|\
  66. sed -e "/^$/d"|\
  67. sed -e ':a;N;$!ba;s/\n/,/g')
  68. # Checking it was last user
  69. if [ -z "$new_val" ]; then
  70. new_val=''
  71. fi
  72. else
  73. # User empty, deleting all
  74. new_val=''
  75. fi
  76. # Deleting stats auth_user
  77. update_domain_value 'web' '$STATS_AUTH' "$new_val"
  78. # Logging
  79. log_history "$EVENT"
  80. log_event "$OK" "$EVENT"
  81. exit