forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_add_mail_domain
More file actions
executable file
·123 lines (95 loc) · 3.65 KB
/
Copy pathv_add_mail_domain
File metadata and controls
executable file
·123 lines (95 loc) · 3.65 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# info: add mail domain
# options: user domain [antispam] [antivirus] [dkim] [dkim_size]
#
# The function adds MAIL domain.
#----------------------------------------------------------#
# 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")
antispam=${3-yes}
antivirus=${4-yes}
dkim=${5-yes}
dkim_size=${6-512}
# Importing variables
source $VESTA/conf/vars.conf
source $V_CONF/vesta.conf
source $V_FUNC/shared.func
source $V_FUNC/domain.func
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'user domain [antispam] [antivirus] [dkim] [dkim_size]'
# Checking argument format
format_validation 'user' 'domain' 'antispam' 'antivirus' 'dkim' 'dkim_size'
# Checking dns system is enabled
is_system_enabled 'MAIL_SYSTEM'
# Checking user
is_user_valid
# Checking user is active
is_user_suspended
# Checking domain
is_domain_new 'mail'
# Checking package
is_package_full 'MAIL_DOMAINS'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Adding domain directory
mkdir $V_HOME/$user/conf/mail/$domain
touch $V_HOME/$user/conf/mail/$domain/aliases
touch $V_HOME/$user/conf/mail/$domain/protection
touch $V_HOME/$user/conf/mail/$domain/passwd
chown -R root:mail $V_HOME/$user/conf/mail/$domain
chmod 770 $V_HOME/$user/conf/mail/$domain
chmod 660 $V_HOME/$user/conf/mail/$domain*
# Adding antispam protection
if [ "$antispam" = 'yes' ]; then
echo 'antispam' >> $V_HOME/$user/conf/mail/$domain/protection
fi
# Adding antivirus protection
if [ "$antivirus" = 'yes' ]; then
echo 'antivirus' >> $V_HOME/$user/conf/mail/$domain/protection
fi
# Adding dkim
if [ "$dkim" = 'yes' ]; then
openssl genrsa -out $V_USERS/$user/mail/$domain.pem $dkim_size 2>/dev/null
openssl rsa -pubout -in $V_USERS/$user/mail/$domain.pem \
-out $V_USERS/$user/mail/$domain.pub 2>/dev/null
chmod 660 $V_USERS/$user/mail/$domain.*
cp $V_USERS/$user/mail/$domain.pem $V_HOME/$user/conf/mail/$domain/dkim.pem
chown root:mail $V_HOME/$user/conf/mail/$domain/dkim.pem
chmod 660 $V_HOME/$user/conf/mail/$domain/dkim.pem
# Adding dkim dns records
check_dns_domain=$(is_domain_valid 'dns')
if [ "$?" -eq 0 ]; then
p=$(cat $V_USERS/$user/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
record='_domainkey'
policy="\"t=y; o=~;\""
$V_BIN/v_add_dns_domain_record $user $domain $record TXT "$policy"
record='mail._domainkey'
selector="\"k=rsa\; p=$p\""
$V_BIN/v_add_dns_domain_record $user $domain $record TXT "$selector"
fi
fi
# Adding domain to vesta db
s="DOMAIN='$domain' ANTIVIRUS='$antivirus' ANTISPAM='$antispam' DKIM='$dkim'"
s="$s ACCOUNTS='0' U_DISK='0' CATCHALL='' SUSPENDED='no' DATE='$V_DATE'"
echo $s >> $V_USERS/$user/mail.conf
touch $V_USERS/$user/mail/$domain
chmod 660 $V_USERS/$user/mail.conf
chmod 660 $V_USERS/$user/mail/$domain
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Increasing domain value
increase_user_value "$user" '$U_MAIL_DOMAINS'
# Logging
log_history "$V_EVENT" "v_delete_mail_domain $user $domain"
log_event 'system' "$V_EVENT"
exit