v-delete-web-domain-httpauth 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # info: delete http auth user
  3. # options: USER DOMAIN AUTH_USER [RESTART]
  4. #
  5. # The call is used for deleting http auth user
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. auth_user=$3
  13. restart=${4-yes}
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/domain.sh
  17. source $VESTA/conf/vesta.conf
  18. # Defining htpasswd file
  19. htaccess="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.conf_htaccess"
  20. htpasswd="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.htpasswd"
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '3' "$#" 'USER DOMAIN AUTH_USER [RESTART]'
  25. is_format_valid 'user' 'domain'
  26. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_unsuspended 'user' 'USER' "$user"
  29. is_object_valid 'web' 'DOMAIN' "$domain"
  30. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  31. is_password_valid
  32. get_domain_values 'web'
  33. if [ -z "$(echo "$AUTH_USER" |tr : '\n' |grep ^$auth_user$)" ]; then
  34. echo "Error: auth user $auth_user doesn't exist"
  35. log_event "$E_NOTEXIST" "$ARGUMENTS"
  36. exit $E_NOTEXIST
  37. fi
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. # Deleting auth user
  42. sed -i "/^$auth_user:/d" $htpasswd
  43. # Deleting password protection
  44. if [ "$(echo "$AUTH_USER" |tr : '\n' |wc -l)" -le 1 ]; then
  45. rm -f $htaccess $htpasswd
  46. restart_required='yes'
  47. fi
  48. # Restarting web server
  49. if [ "$restart" != 'no' ] && [ "$restart_required" = 'yes' ]; then
  50. $BIN/v-restart-web
  51. fi
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. # Rebuilding FTP variables
  56. position=$(echo $AUTH_USER |tr ':' '\n' |grep -n '' |grep ":$auth_user$" |\
  57. cut -f 1 -d:)
  58. auth_user=$(echo $AUTH_USER |tr ':' '\n' |grep -n '' |grep -v "^$position:" |\
  59. cut -f 2 -d :| sed -e "/^$/d"| sed -e ':a;N;$!ba;s/\n/:/g')
  60. auth_hash=$(echo $AUTH_HASH |tr ':' '\n' |grep -n '' |grep -v "^$position:" |\
  61. cut -f 2 -d :| sed -e ':a;N;$!ba;s/\n/:/g')
  62. # Update config
  63. update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_USER' "$auth_user"
  64. update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_HASH' "$auth_hash"
  65. # Logging
  66. log_history "changed auth user $httpauth_user password on $domain"
  67. log_event "$OK" "$ARGUMENTS"
  68. exit