v-change-mail-account-password 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # info: change mail account password
  3. # options: USER DOMAIN ACCOUNT PASSWORD
  4. #
  5. # The function changes email account password.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. account=$3
  15. password=$4; HIDE=4
  16. # Includes
  17. source $VESTA/func/main.sh
  18. source $VESTA/func/domain.sh
  19. source $VESTA/conf/vesta.conf
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD'
  24. is_format_valid 'user' 'domain' 'account'
  25. is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'mail' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'mail' 'DOMAIN' "$domain"
  30. is_object_valid "mail/$domain" 'ACCOUNT' "$account"
  31. is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
  32. is_password_valid
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Generating hashed password
  37. salt=$(generate_password "$PW_MATRIX" "8")
  38. md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
  39. if [[ "$MAIL_SYSTEM" =~ exim ]]; then
  40. sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
  41. str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
  42. echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
  43. fi
  44. #----------------------------------------------------------#
  45. # Vesta #
  46. #----------------------------------------------------------#
  47. # Update md5
  48. update_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5' "$md5"
  49. # Logging
  50. log_history "changed password for $account@$domain"
  51. log_event "$OK" "$ARGUMENTS"
  52. exit