forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_add_mail_account
More file actions
executable file
·85 lines (62 loc) · 2.37 KB
/
Copy pathv_add_mail_account
File metadata and controls
executable file
·85 lines (62 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# info: add mail domain account
# options: user domain account password [quota]
#
# The function add new email account.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
password=$4
quota=${5-0}
# Importing variables
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/domain.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '4' "$#" 'user domain account password quota'
# Checking argument format
validate_format 'user' 'domain' 'account' 'password' 'quota'
# Checking dns system is enabled
is_system_enabled 'MAIL_SYSTEM'
# Checking user
is_object_valid 'user' 'USER' "$user"
# Checking user is active
is_object_unsuspended 'user' 'USER' "$user"
# Checking domain
is_domain_valid 'mail'
# Checking domain is not suspened
is_domain_suspended 'mail'
# Checking package
is_package_full 'MAIL_ACCOUNTS'
# Checking account
is_mail_account_free
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
password=$(/usr/sbin/dovecotpw -s md5 -p "$password")
str="$account:$password:$user:mail::$HOMEDIR/$user:$quota"
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
str="$str U_DISK='0' SUSPENDED='no' DATE='$DATE'"
echo "$str" >> $USER_DATA/mail/$domain.conf
# Increase mail accounts counter
accounts=$(wc -l $USER_DATA/mail/$domain.conf|cut -f 1 -d ' ')
increase_user_value "$user" '$U_MAIL_ACCOUNTS'
update_domain_value 'mail' '$ACCOUNTS' "$accounts"
# Logging
EVENT="$DATE $SCRIPT $user $domain ***** $quota"
log_history "$EVENT" "v_delete_mail_account $user $domain $account"
log_event "$OK" "$EVENT"
exit