v-change-web-domain-httpauth 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. # info: change password for http auth user
  3. # options: USER DOMAIN AUTH_USER AUTH_PASSWORD
  4. #
  5. # The call is used for changing http auth user password
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. auth_user=$3
  13. password=$4; HIDE=4
  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. htpasswd="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.htpasswd"
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '4' "$#" 'USER DOMAIN AUTH_USER AUTH_PASSWORD [RESTART]'
  24. is_format_valid 'user' 'domain'
  25. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  30. is_password_valid
  31. get_domain_values 'web'
  32. if [ -z "$(echo "$AUTH_USER" |tr : '\n' |grep ^$auth_user$)" ]; then
  33. echo "Error: auth user $auth_user doesn't exist"
  34. log_event "$E_NOTEXIST" "$ARGUMENTS"
  35. exit $E_NOTEXIST
  36. fi
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Adding httpasswd user
  41. auth_hash=$($BIN/v-generate-password-hash htpasswd htpasswd $password)
  42. touch $htpasswd
  43. sed -i "/^$auth_user:/d" $htpasswd
  44. echo "$auth_user:$auth_hash" >> $htpasswd
  45. #----------------------------------------------------------#
  46. # Vesta #
  47. #----------------------------------------------------------#
  48. # Rebuilding AUTH_HASH variable
  49. position=$(echo $AUTH_USER |tr ':' '\n' |grep -n '' |grep ":$auth_user$" |\
  50. cut -f 1 -d:)
  51. auth_hash=$(echo $AUTH_HASH |tr ':' '\n' |grep -n '' |\
  52. sed -e "s%^$position:.*%$position:$auth_hash%" |\
  53. cut -f 2 -d :| sed -e "/^$/d"| sed -e ':a;N;$!ba;s/\n/:/g')
  54. # Updating config
  55. update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_HASH' "$auth_hash"
  56. # Logging
  57. log_history "changed auth user $httpauth_user password on $domain"
  58. log_event "$OK" "$ARGUMENTS"
  59. exit