Skip to content

Commit 8f6fbfc

Browse files
committed
completed about 20% of email api
1 parent af54a85 commit 8f6fbfc

12 files changed

+672
-63
lines changed

bin/v_add_dns_domain_record

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ echo "$dns_rec" >> $zone
8787
sort_dns_records
8888

8989
# Updating zone
90+
conf="$V_HOME/$user/conf/dns/$domain.db"
9091
update_domain_zone
9192

9293

bin/v_add_mail_domain

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add mail domain
3-
# options: user domain [antispam] [antivirus]
3+
# options: user domain [antispam] [antivirus] [dkim] [dkim_size]
44
#
55
# The function adds MAIL domain.
66

@@ -15,7 +15,9 @@ domain=$(idn -t --quiet -u "$2" )
1515
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
1616
domain_idn=$(idn -t --quiet -a "$domain")
1717
antispam=${3-yes}
18-
antivirus=${3-yes}
18+
antivirus=${4-yes}
19+
dkim=${5-yes}
20+
dkim_size=${6-512}
1921

2022
# Importing variables
2123
source $VESTA/conf/vars.conf
@@ -29,10 +31,10 @@ source $V_FUNC/domain.func
2931
#----------------------------------------------------------#
3032

3133
# Checking arg number
32-
check_args '2' "$#" 'user domain [antispam] [antivirus]'
34+
check_args '2' "$#" 'user domain [antispam] [antivirus] [dkim] [dkim_size]'
3335

3436
# Checking argument format
35-
format_validation 'user' 'domain' 'antispam' 'antivirus'
37+
format_validation 'user' 'domain' 'antispam' 'antivirus' 'dkim' 'dkim_size'
3638

3739
# Checking dns system is enabled
3840
is_system_enabled 'MAIL_SYSTEM'
@@ -50,70 +52,72 @@ is_domain_new 'mail'
5052
is_package_full 'MAIL_DOMAINS'
5153

5254

53-
exit
54-
5555
#----------------------------------------------------------#
5656
# Action #
5757
#----------------------------------------------------------#
5858

59-
# Defining variables
60-
i=1
61-
ns=$(get_user_value '$NS')
62-
for nameserver in ${ns//,/ };do
63-
eval ns$i=$nameserver
64-
i=$((i + 1))
65-
done
59+
# Adding domain directory
60+
mkdir $V_HOME/$user/conf/mail/$domain
61+
touch $V_HOME/$user/conf/mail/$domain/aliases
62+
touch $V_HOME/$user/conf/mail/$domain/protection
63+
touch $V_HOME/$user/conf/mail/$domain/passwd
64+
chown -R root:mail $V_HOME/$user/conf/mail/$domain
65+
chmod 770 $V_HOME/$user/conf/mail/$domain
66+
chmod 660 $V_HOME/$user/conf/mail/$domain*
67+
68+
# Adding antispam protection
69+
if [ "$antispam" = 'yes' ]; then
70+
echo 'antispam' >> $V_HOME/$user/conf/mail/$domain/protection
71+
fi
72+
73+
# Adding antivirus protection
74+
if [ "$antivirus" = 'yes' ]; then
75+
echo 'antivirus' >> $V_HOME/$user/conf/mail/$domain/protection
76+
fi
6677

67-
if [ -z "$soa" ]; then
68-
soa="$ns1"
78+
# Adding dkim
79+
if [ "$dkim" = 'yes' ]; then
80+
openssl genrsa -out $V_USERS/$user/mail/$domain.pem $dkim_size 2>/dev/null
81+
openssl rsa -pubout -in $V_USERS/$user/mail/$domain.pem \
82+
-out $V_USERS/$user/mail/$domain.pub 2>/dev/null
83+
chmod 660 $V_USERS/$user/mail/$domain.*
84+
85+
cp $V_USERS/$user/mail/$domain.pem $V_HOME/$user/conf/mail/$domain/dkim.pem
86+
chown root:mail $V_HOME/$user/conf/mail/$domain/dkim.pem
87+
chmod 660 $V_HOME/$user/conf/mail/$domain/dkim.pem
88+
89+
# Adding dkim dns records
90+
check_dns_domain=$(is_domain_valid 'dns')
91+
if [ "$?" -eq 0 ]; then
92+
p=$(cat $V_USERS/$user/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
93+
record='_domainkey'
94+
policy="\"t=y; o=~;\""
95+
$V_BIN/v_add_dns_domain_record $user $domain $record TXT "$policy"
96+
97+
record='mail._domainkey'
98+
selector="\"k=rsa\; p=$p\""
99+
$V_BIN/v_add_dns_domain_record $user $domain $record TXT "$selector"
100+
fi
69101
fi
70102

71-
# Adding zone to dns dir
72-
cat $V_DNSTPL/$template.tpl |\
73-
sed -e "s/%ip%/$ip/g" \
74-
-e "s/%domain_idn%/$domain_idn/g" \
75-
-e "s/%domain%/$domain/g" \
76-
-e "s/%ns1%/$ns1/g" \
77-
-e "s/%ns2%/$ns2/g" \
78-
-e "s/%ns3%/$ns3/g" \
79-
-e "s/%ns4%/$ns4/g" \
80-
-e "s/%ns5%/$ns5/g" \
81-
-e "s/%ns6%/$ns6/g" \
82-
-e "s/%ns7%/$ns7/g" \
83-
-e "s/%ns8%/$ns8/g" \
84-
-e "s/%date%/$V_DATE/g" > $V_USERS/$user/dns/$domain
85-
86-
# Adding dns.conf record
87-
dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
88-
dns_rec="$dns_rec SOA='$soa' SUSPENDED='no' DATE='$V_DATE'"
89-
echo "$dns_rec" >> $V_USERS/$user/dns.conf
90-
chmod 660 $V_USERS/$user/dns.conf
91-
92-
# Adding zone in named.conf
93-
named="zone \"$domain_idn\" {type master; file"
94-
named="$named \"$V_HOME/$user/conf/dns/$domain.db\";};"
95-
echo "$named" >> /etc/named.conf
96-
97-
# Updating domain dns zone
98-
conf="$V_HOME/$user/conf/dns/$domain.db"
99-
update_domain_zone
100-
101-
chmod 640 $conf
102-
chown root:named $conf
103+
# Adding domain to vesta db
104+
s="DOMAIN='$domain' ANTIVIRUS='$antivirus' ANTISPAM='$antispam' DKIM='$dkim'"
105+
s="$s ACCOUNTS='0' U_DISK='0' CATCHALL='' SUSPENDED='no' DATE='$V_DATE'"
106+
echo $s >> $V_USERS/$user/mail.conf
107+
touch $V_USERS/$user/mail/$domain
108+
chmod 660 $V_USERS/$user/mail.conf
109+
chmod 660 $V_USERS/$user/mail/$domain
103110

104111

105112
#----------------------------------------------------------#
106113
# Vesta #
107114
#----------------------------------------------------------#
108115

109116
# Increasing domain value
110-
increase_user_value "$user" '$U_DNS_DOMAINS'
111-
112-
# Adding task to the vesta pipe
113-
restart_schedule 'dns'
117+
increase_user_value "$user" '$U_MAIL_DOMAINS'
114118

115119
# Logging
116-
log_history "$V_EVENT" "v_delete_dns_domain $user $domain"
120+
log_history "$V_EVENT" "v_delete_mail_domain $user $domain"
117121
log_event 'system' "$V_EVENT"
118122

119123
exit

bin/v_add_mail_domain_antispam

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# info: add mail domain antispam support
3+
# options: user domain
4+
#
5+
# The function enables spamassasin for incomming emails.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
18+
# Importing variables
19+
source $VESTA/conf/vars.conf
20+
source $V_CONF/vesta.conf
21+
source $V_FUNC/shared.func
22+
source $V_FUNC/domain.func
23+
24+
25+
#----------------------------------------------------------#
26+
# Verifications #
27+
#----------------------------------------------------------#
28+
29+
# Checking arg number
30+
check_args '2' "$#" 'user domain'
31+
32+
# Checking argument format
33+
format_validation 'user' 'domain'
34+
35+
# Checking dns system is enabled
36+
is_system_enabled 'MAIL_SYSTEM'
37+
38+
# Checking user
39+
is_user_valid
40+
41+
# Checking user is active
42+
is_user_suspended
43+
44+
# Checking domain
45+
is_domain_valid 'mail'
46+
47+
# Checking domain is not suspened
48+
is_domain_suspended 'mail'
49+
50+
# Checking errorlog is not added
51+
is_domain_key_empty 'mail' '$ANTISPAM'
52+
53+
54+
#----------------------------------------------------------#
55+
# Action #
56+
#----------------------------------------------------------#
57+
58+
# Adding antispam key to config
59+
if [ -z "$(grep 'antispam' $V_HOME/$user/conf/mail/$domain/protection)" ]; then
60+
echo 'antispam' >> $V_HOME/$user/conf/mail/$domain/protection
61+
fi
62+
63+
#----------------------------------------------------------#
64+
# Vesta #
65+
#----------------------------------------------------------#
66+
67+
# Adding antispam in config
68+
update_domain_value 'mail' '$ANTISPAM' 'yes'
69+
70+
# Logging
71+
log_history "$V_EVENT" "v_delete_mail_domain_antispam $user $domain"
72+
log_event 'system' "$V_EVENT"
73+
74+
exit

bin/v_add_mail_domain_antivirus

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# info: add mail domain antivirus support
3+
# options: user domain
4+
#
5+
# The function enables clamav for incomming emails.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
18+
# Importing variables
19+
source $VESTA/conf/vars.conf
20+
source $V_CONF/vesta.conf
21+
source $V_FUNC/shared.func
22+
source $V_FUNC/domain.func
23+
24+
25+
#----------------------------------------------------------#
26+
# Verifications #
27+
#----------------------------------------------------------#
28+
29+
# Checking arg number
30+
check_args '2' "$#" 'user domain'
31+
32+
# Checking argument format
33+
format_validation 'user' 'domain'
34+
35+
# Checking dns system is enabled
36+
is_system_enabled 'MAIL_SYSTEM'
37+
38+
# Checking user
39+
is_user_valid
40+
41+
# Checking user is active
42+
is_user_suspended
43+
44+
# Checking domain
45+
is_domain_valid 'mail'
46+
47+
# Checking domain is not suspened
48+
is_domain_suspended 'mail'
49+
50+
# Checking errorlog is not added
51+
is_domain_key_empty 'mail' '$ANTIVIRUS'
52+
53+
54+
#----------------------------------------------------------#
55+
# Action #
56+
#----------------------------------------------------------#
57+
58+
# Adding antispam key to config
59+
if [ -z "$(grep 'virus' $V_HOME/$user/conf/mail/$domain/protection)" ]; then
60+
echo 'antivirus' >> $V_HOME/$user/conf/mail/$domain/protection
61+
fi
62+
63+
#----------------------------------------------------------#
64+
# Vesta #
65+
#----------------------------------------------------------#
66+
67+
# Adding antispam in config
68+
update_domain_value 'mail' '$ANTIVIRUS' 'yes'
69+
70+
# Logging
71+
log_history "$V_EVENT" "v_delete_mail_domain_antivirus $user $domain"
72+
log_event 'system' "$V_EVENT"
73+
74+
exit

bin/v_add_mail_domain_cactchall

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# info: add mail domain catchall account
3+
# options: user domain email
4+
#
5+
# The function enables catchall account for incomming emails.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
email="$3"
18+
19+
# Importing variables
20+
source $VESTA/conf/vars.conf
21+
source $V_CONF/vesta.conf
22+
source $V_FUNC/shared.func
23+
source $V_FUNC/domain.func
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
# Checking arg number
31+
check_args '3' "$#" 'user domain email'
32+
33+
# Checking argument format
34+
format_validation 'user' 'domain' 'email'
35+
exit
36+
37+
# Checking dns system is enabled
38+
is_system_enabled 'MAIL_SYSTEM'
39+
40+
# Checking user
41+
is_user_valid
42+
43+
# Checking user is active
44+
is_user_suspended
45+
46+
# Checking domain
47+
is_domain_valid 'mail'
48+
49+
# Checking domain is not suspened
50+
is_domain_suspended 'mail'
51+
52+
# Checking errorlog is not added
53+
is_domain_key_empty 'mail' '$ANTIVIRUS'
54+
55+
56+
#----------------------------------------------------------#
57+
# Action #
58+
#----------------------------------------------------------#
59+
60+
# Adding antispam key to config
61+
if [ -z "$(grep 'virus' $V_HOME/$user/conf/mail/$domain/protection)" ]; then
62+
echo 'antivirus' >> $V_HOME/$user/conf/mail/$domain/protection
63+
fi
64+
65+
#----------------------------------------------------------#
66+
# Vesta #
67+
#----------------------------------------------------------#
68+
69+
# Adding antispam in config
70+
update_domain_value 'mail' '$ANTIVIRUS' 'yes'
71+
72+
# Logging
73+
log_history "$V_EVENT" "v_delete_mail_domain_antivirus $user $domain"
74+
log_event 'system' "$V_EVENT"
75+
76+
exit

0 commit comments

Comments
 (0)