v-add-mail-account 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # info: add mail domain account
  3. # options: USER DOMAIN ACCOUNT PASSWORD [QUOTA]
  4. #
  5. # The function add new email account.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  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=$(echo $3 | tr '[:upper:]' '[:lower:]')
  15. password=$4
  16. quota=${5-0}
  17. # Includes
  18. source $VESTA/func/main.sh
  19. source $VESTA/func/domain.sh
  20. source $VESTA/conf/vesta.conf
  21. # Hiding password
  22. A4='******'
  23. EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
  24. #----------------------------------------------------------#
  25. # Verifications #
  26. #----------------------------------------------------------#
  27. check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD [QUOTA]'
  28. validate_format 'user' 'domain' 'account' 'password' 'quota'
  29. is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
  30. is_object_valid 'user' 'USER' "$user"
  31. is_object_unsuspended 'user' 'USER' "$user"
  32. is_object_valid 'mail' 'DOMAIN' "$domain"
  33. is_object_unsuspended 'mail' 'DOMAIN' "$domain"
  34. is_package_full 'MAIL_ACCOUNTS'
  35. is_mail_new "$account"
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. if [ -x '/usr/bin/doveadm' ]; then
  40. md5=$(/usr/bin/doveadm pw -s md5 -p "$password")
  41. else
  42. md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
  43. fi
  44. if [[ "$MAIL_SYSTEM" =~ exim ]]; then
  45. str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
  46. echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
  47. fi
  48. #----------------------------------------------------------#
  49. # Vesta #
  50. #----------------------------------------------------------#
  51. str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
  52. str="$str FWD_ONLY='' MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
  53. str="$str DATE='$DATE'"
  54. echo "$str" >> $USER_DATA/mail/$domain.conf
  55. chmod 660 $USER_DATA/mail/$domain.conf
  56. # Increase mail accounts counter
  57. accounts=$(wc -l $USER_DATA/mail/$domain.conf | cut -f 1 -d ' ')
  58. increase_user_value "$user" '$U_MAIL_ACCOUNTS'
  59. update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accounts"
  60. # Logging
  61. log_history "added mail account $account@$domain"
  62. log_event "$OK" "$EVENT"
  63. exit