-
-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy path19-postfix
More file actions
executable file
·143 lines (117 loc) · 5.44 KB
/
Copy path19-postfix
File metadata and controls
executable file
·143 lines (117 loc) · 5.44 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
#
# Copyright (c) 2024 YunoHost Contributors
#
# This file is part of YunoHost (see https://yunohost.org)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Exit hook on subcommand error or unset variable
set -e
# Source YNH helpers
# shellcheck source=../../helpers/helpers
source /usr/share/yunohost/helpers
do_pre_regen() {
pending_dir=$1
cd /usr/share/yunohost/conf/postfix
postfix_dir="${pending_dir}/etc/postfix"
mkdir -p "$postfix_dir"
default_dir="${pending_dir}/etc/default/"
mkdir -p "$default_dir"
# install plain conf files
cp plain/* "$postfix_dir"
# prepare main.cf conf file
main_domain=$(cat /etc/yunohost/current_host)
# Support different strategy for security configurations
export compatibility="$(jq -r '.postfix_compatibility' <<< "$YNH_SETTINGS")"
# Add possibility to specify a relay
# Could be useful with some isp with no 25 port open or more complex setup
export relay_port=""
export relay_user=""
export relay_host=""
export relay_enabled="$(jq -r '.smtp_relay_enabled' <<< "$YNH_SETTINGS" | int_to_bool)"
if [ "${relay_enabled}" == "True" ]; then
relay_host="$(jq -r '.smtp_relay_host' <<< "$YNH_SETTINGS")"
relay_port="$(jq -r '.smtp_relay_port' <<< "$YNH_SETTINGS")"
relay_user="$(jq -r '.smtp_relay_user' <<< "$YNH_SETTINGS")"
relay_password="$(jq -r '.smtp_relay_password' <<< "$YNH_SETTINGS")"
# Avoid to display "Relay account paswword" to other users
touch "${postfix_dir}/sasl_passwd"
chmod 750 "${postfix_dir}/sasl_passwd"
# Avoid "postmap: warning: removing zero-length database file"
chown postfix "${pending_dir}/etc/postfix"
chown postfix "${pending_dir}/etc/postfix/sasl_passwd"
cat <<< "[${relay_host}]:${relay_port} ${relay_user}:${relay_password}" > "${postfix_dir}/sasl_passwd"
fi
export enable_blocklists="$(jq -r '.enable_blocklists' <<< "$YNH_SETTINGS" | int_to_bool)"
# Use this postfix server as a backup MX
export backup_mx_domains="$(jq -r '.smtp_backup_mx_domains' <<< "$YNH_SETTINGS" | sed 's/^null$//g' | sed "s/,/ /g")"
export backup_mx_emails="$(jq -r '.smtp_backup_mx_emails_whitelisted' <<< "$YNH_SETTINGS" | sed "s/,/ /g")"
rm -f "${postfix_dir}/relay_recipients"
touch "${postfix_dir}/relay_recipients"
rm -f "${postfix_dir}/relay_recipients.db"
touch "${postfix_dir}/relay_recipients.db"
if [ -n "${backup_mx_domains}" ] && [ -n "${backup_mx_emails}" ]; then
for mail in ${backup_mx_emails}; do
echo "$mail OK" >> "${postfix_dir}/relay_recipients"
done
postmap "${postfix_dir}/relay_recipients"
fi
export main_domain
export domain_list="$YNH_DOMAINS_WITH_MAIL_IN_AND_OUT"
ynh_render_template "main.cf" "${postfix_dir}/main.cf"
ynh_render_template "sni" "${postfix_dir}/sni"
# Activate mailbox only on domains with mail_in features
# If mail_in is disabled for a domain, this allows to send
# mails on external mailbox using this domain
# See: https://forum.yunohost.org/t/how-to-keep-your-mailbox-outside-yunohost/4860
echo "# This file is regenerated automatically" > "${postfix_dir}/virtual-mailbox-domains"
echo "# Please DO NOT edit manually ... changes will be overwritten!" >> "${postfix_dir}/virtual-mailbox-domains"
tr ' ' '\n' <<< "$YNH_DOMAINS_WITH_MAIL_IN" >> "${postfix_dir}/virtual-mailbox-domains"
cat postsrsd \
| sed "s/{{ main_domain }}/${main_domain}/g" \
| sed "s/{{ domain_list }}/${domain_list}/g" \
> "${default_dir}/postsrsd"
# adapt it for IPv4-only hosts
ipv6="$(jq -r '.smtp_allow_ipv6' <<< "$YNH_SETTINGS" | int_to_bool)"
if [ "$ipv6" == "False" ] || [ ! -f /proc/net/if_inet6 ]; then
sed -i \
's/ \[::ffff:127.0.0.0\]\/104 \[::1\]\/128//g' \
"${postfix_dir}/main.cf"
sed -i \
's/inet_interfaces = all/&\ninet_protocols = ipv4/' \
"${postfix_dir}/main.cf"
sed -i \
's/smtp_address_preference = ipv6/smtp_address_preference = ipv4/' \
"${postfix_dir}/main.cf"
fi
}
do_post_regen() {
regen_conf_files=$1
chown postfix /etc/postfix
if [ -e /etc/postfix/sasl_passwd ]; then
chmod 750 /etc/postfix/sasl_passwd*
chown postfix:root /etc/postfix/sasl_passwd*
postmap /etc/postfix/sasl_passwd
fi
if [ -e /etc/postfix/relay_recipients ]; then
chmod 750 /etc/postfix/relay_recipients*
chown postfix:root /etc/postfix/relay_recipients*
fi
postmap -F hash:/etc/postfix/sni
python3 -c 'from yunohost.app import regen_mail_app_user_config_for_dovecot_and_postfix as r; r(only="postfix")'
[[ -z "$regen_conf_files" ]] \
|| { systemctl restart postfix && systemctl restart postsrsd; }
}
"do_$1_regen" "$(echo "${*:2}" | xargs)"