Skip to content

Commit 1211690

Browse files
committed
mail api 50% completed
1 parent 4134cc3 commit 1211690

File tree

4 files changed

+304
-1
lines changed

4 files changed

+304
-1
lines changed

bin/v_change_mail_domain_cactchall

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
# info: change mail domain catchall email
3+
# options: user domain email
4+
#
5+
# The function changes mail domain cathcall.
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+
36+
# Checking dns system is enabled
37+
is_system_enabled 'MAIL_SYSTEM'
38+
39+
# Checking user
40+
is_user_valid
41+
42+
# Checking user is active
43+
is_user_suspended
44+
45+
# Checking domain
46+
is_domain_valid 'mail'
47+
48+
# Checking domain is not suspened
49+
is_domain_suspended 'mail'
50+
51+
52+
#----------------------------------------------------------#
53+
# Action #
54+
#----------------------------------------------------------#
55+
56+
# Get old catchall
57+
catchall=$(get_domain_value 'mail' '$CATCHALL')
58+
59+
# Change cathcall alias
60+
sed -i "/*@demo.vestacp.com:/d" $V_HOME/$user/conf/mail/$domain/aliases
61+
echo "*@demo.vestacp.com:$email" >> $V_HOME/$user/conf/mail/$domain/aliases
62+
63+
64+
#----------------------------------------------------------#
65+
# Vesta #
66+
#----------------------------------------------------------#
67+
68+
# Change catchall in config
69+
update_domain_value 'mail' '$CATCHALL' "$email"
70+
71+
# Logging
72+
log_history "$V_EVENT" "v_change_mail_domain_catchall $user $domain $catchall"
73+
log_event 'system' "$V_EVENT"
74+
75+
exit

bin/v_delete_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: delete mail domain catchall email
3+
# options: user domain
4+
#
5+
# The function disables mail domain cathcall.
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 current value
51+
is_domain_value_exist 'mail' '$CATCHALL'
52+
53+
54+
#----------------------------------------------------------#
55+
# Action #
56+
#----------------------------------------------------------#
57+
58+
# Get old catchall
59+
email=$(get_domain_value 'mail' '$CATCHALL')
60+
61+
# Delete cathcall alias
62+
sed -i "/*@demo.vestacp.com:/d" $V_HOME/$user/conf/mail/$domain/aliases
63+
64+
65+
#----------------------------------------------------------#
66+
# Vesta #
67+
#----------------------------------------------------------#
68+
69+
# Delete catchall in config
70+
update_domain_value 'mail' '$CATCHALL' ''
71+
72+
# Logging
73+
log_history "$V_EVENT" "v_add_mail_domain_catchall $user $domain $email"
74+
log_event 'system' "$V_EVENT"
75+
76+
exit

bin/v_list_mail_domain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ check_args '2' "$#" 'user domain [format]'
8585
is_user_valid
8686

8787
# Checking domain exist
88-
is_domain_valid 'web'
88+
is_domain_valid 'mail'
8989

9090

9191
#----------------------------------------------------------#

bin/v_rebuild_mail_domains

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/bash
2+
# info: rebuild mail domains
3+
# options: user
4+
#
5+
# The function rebuilds EXIM configuration files for all mail domains.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
15+
# Importing variables
16+
source $VESTA/conf/vars.conf
17+
source $V_CONF/vesta.conf
18+
source $V_FUNC/shared.func
19+
source $V_FUNC/domain.func
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
# Checking arg number
27+
check_args '1' "$#" 'user'
28+
29+
# Checking argument format
30+
format_validation 'user'
31+
32+
# Checking mail system is enabled
33+
is_system_enabled 'MAIL_SYSTEM'
34+
35+
# Checking user
36+
is_user_valid
37+
38+
# Checking user is active
39+
is_user_suspended
40+
41+
42+
#----------------------------------------------------------#
43+
# Action #
44+
#----------------------------------------------------------#
45+
46+
# Reset counters
47+
U_MAIL_DOMAINS='0'
48+
U_MAIL_ACCOUNTS='0'
49+
SUSPENDED_MAIL='0'
50+
U_DISK_MAIL='0'
51+
52+
# Checking mail folder
53+
if [ ! -d "$V_USERS/$user/mail" ]; then
54+
rm -f $V_USERS/$user/mail
55+
mkdir $V_USERS/$user/mail
56+
fi
57+
58+
# Defining config
59+
conf="$V_USERS/$user/mail.conf"
60+
search_string="DOMAIN"
61+
field='$DOMAIN'
62+
domains=$(dom_clear_search)
63+
64+
# Starting loop
65+
for domain in $domains; do
66+
67+
# Defining variables
68+
get_domain_values 'mail'
69+
70+
# Rebuilding config structure
71+
mkdir -p $V_HOME/$user/conf/mail/$domain
72+
rm -f $V_HOME/$user/conf/mail/$domain/aliases
73+
rm -f $V_HOME/$user/conf/mail/$domain/protection
74+
rm -f $V_HOME/$user/conf/mail/$domain/passwd
75+
touch $V_HOME/$user/conf/mail/$domain/aliases
76+
touch $V_HOME/$user/conf/mail/$domain/protection
77+
touch $V_HOME/$user/conf/mail/$domain/passwd
78+
chown -R root:mail $V_HOME/$user/conf/mail/$domain
79+
chmod 770 $V_HOME/$user/conf/mail/$domain
80+
chmod 660 $V_HOME/$user/conf/mail/$domain*
81+
82+
# Adding antispam protection
83+
if [ "$ANTISPAM" = 'yes' ]; then
84+
echo 'antispam' >> $V_HOME/$user/conf/mail/$domain/protection
85+
fi
86+
87+
# Adding antivirus protection
88+
if [ "$ANTIVIRUS" = 'yes' ]; then
89+
echo 'antivirus' >> $V_HOME/$user/conf/mail/$domain/protection
90+
fi
91+
92+
# Adding dkim
93+
if [ "$DKIM" = 'yes' ]; then
94+
pem="$V_USERS/$user/mail/$domain.pem"
95+
pub="$V_USERS/$user/mail/$domain.pub"
96+
openssl genrsa -out $pem 512 2>/dev/null
97+
openssl rsa -pubout -in $pem -out $pub 2>/dev/null
98+
chmod 660 $V_USERS/$user/mail/$domain.*
99+
100+
cp $pem $V_HOME/$user/conf/mail/$domain/dkim.pem
101+
chown root:mail $V_HOME/$user/conf/mail/$domain/dkim.pem
102+
chmod 660 $V_HOME/$user/conf/mail/$domain/dkim.pem
103+
104+
# Deleting old dkim records
105+
records=$($V_BIN/v_list_dns_domain_records $user $domain plain)
106+
dkim_records=$(echo "$records" |grep -w '_domainkey'|cut -f 1 -d ' ')
107+
for id in $dkim_records; do
108+
$V_BIN/v_delete_dns_domain_record $user $domain $id
109+
done
110+
111+
# Adding dkim dns records
112+
check_dns_domain=$(is_domain_valid 'dns')
113+
if [ "$?" -eq 0 ]; then
114+
p=$(cat $pub|grep -v ' KEY---'|tr -d '\n')
115+
record='_domainkey'
116+
policy="\"t=y; o=~;\""
117+
$V_BIN/v_add_dns_domain_record $user $domain $record TXT "$policy"
118+
119+
record='mail._domainkey'
120+
slct="\"k=rsa\; p=$p\""
121+
$V_BIN/v_add_dns_domain_record $user $domain $record TXT "$slct"
122+
fi
123+
fi
124+
125+
# Rebuild counters
126+
U_MAIL_DOMAINS=$((U_MAIL_DOMAINS + 1))
127+
U_DISK_MAIL=$((U_DISK_MAIL + U_DISK))
128+
done
129+
130+
131+
#----------------------------------------------------------#
132+
# Vesta #
133+
#----------------------------------------------------------#
134+
135+
# Updating counters
136+
U_MAIL_DOMAINS='0'
137+
U_MAIL_ACCOUNTS='0'
138+
SUSPENDED_MAIL='0'
139+
U_DISK_MAIL='0'
140+
141+
update_user_value "$user" '$U_MAIL_DOMAINS' "$U_MAIL_DOMAINS"
142+
update_user_value "$user" '$U_MAIL_ACCOUNTS' "$U_MAIL_ACCOUNTS"
143+
update_user_value "$user" '$SUSPENDED_MAIL' "$SUSPENDED_MAIL"
144+
update_user_value "$user" '$U_DISK_MAIL' "$U_DISK_MAIL"
145+
146+
# Adding task to the vesta pipe
147+
restart_schedule 'mail'
148+
149+
# Logging
150+
log_event 'system' "$V_EVENT"
151+
152+
exit

0 commit comments

Comments
 (0)