1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
|
2 |
|
3 |
###########################################################################################
|
3 |
###########################################################################################
|
4 |
## ALCASAR MAIL SERVICE CONFIGURATION
|
4 |
## ALCASAR MAIL SERVICE CONFIGURATION
|
5 |
##
|
5 |
##
|
6 |
## Script by K@M3L & T3RRY (LaPlateform), joss_p & Rexy
|
6 |
## Script by K@M3L & T3RRY (LaPlateform), joss_p & Rexy
|
7 |
## This script configure PostFix
|
7 |
## This script configure PostFix
|
8 |
## 0 : no email autoregistration
|
8 |
## 0 : no email autoregistration
|
9 |
## 1 : PostFix is the SMTP server
|
9 |
## 1 : PostFix is the SMTP server
|
10 |
## 2 : PostFix relay to an other SMTP server
|
10 |
## 2 : PostFix relay to an other SMTP server
|
11 |
## 2 : PostFix use an external email address (with SASL)
|
11 |
## 2 : PostFix use an external email address (with SASL)
|
12 |
###########################################################################################
|
12 |
###########################################################################################
|
13 |
|
13 |
|
14 |
# ****** Paths *******
|
14 |
# ****** Paths *******
|
15 |
SED="/bin/sed -i"
|
15 |
SED="/bin/sed -i"
|
16 |
CONF_FILE="/usr/local/etc/alcasar.conf"
|
16 |
CONF_FILE="/usr/local/etc/alcasar.conf"
|
17 |
POSTFIX_CONF_FILE="/etc/postfix/main.cf"
|
17 |
POSTFIX_CONF_FILE="/etc/postfix/main.cf"
|
18 |
LOCAL_IPTABLE_FILE="/usr/local/etc/alcasar-iptables-local.sh"
|
18 |
LOCAL_IPTABLE_FILE="/usr/local/etc/alcasar-iptables-local.sh"
|
19 |
SASLPATH="/etc/postfix/sasl"
|
19 |
SASLPATH="/etc/postfix/sasl"
|
20 |
smtpIP="0.0.0.0/0"
|
20 |
smtpIP="0.0.0.0/0"
|
21 |
hostName=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
|
21 |
hostName=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
|
22 |
domainName=`grep ^DOMAIN= $CONF_FILE|cut -d"=" -f2`
|
22 |
domainName=`grep ^DOMAIN= $CONF_FILE|cut -d"=" -f2`
|
23 |
usage="Usage: alcasar-mail_install.sh -h|-0|-1|-2|-3"
|
23 |
usage="Usage: alcasar-mail_install.sh -h|-0|-1|-2|-3"
|
24 |
|
24 |
|
25 |
nb_args=$#
|
25 |
nb_args=$#
|
26 |
if [ $nb_args -eq 0 ]; then # apply alcasar.conf
|
26 |
if [ $nb_args -eq 0 ]; then # apply alcasar.conf
|
27 |
mail=`grep ^MAIL= $CONF_FILE|cut -d"=" -f2`
|
27 |
mail=`grep ^MAIL= $CONF_FILE|cut -d"=" -f2`
|
28 |
if [ "$mail" = "off" ]; then
|
28 |
if [ "$mail" = "off" ]; then
|
29 |
TYPE_MAIL=0
|
29 |
TYPE_MAIL=0
|
30 |
else
|
30 |
else
|
31 |
TYPE_MAIL=`grep ^MAIL_TYPE= $CONF_FILE|cut -d"=" -f2`
|
31 |
TYPE_MAIL=`grep ^MAIL_TYPE= $CONF_FILE|cut -d"=" -f2`
|
32 |
smtpPort=`grep ^MAIL_SMTP_PORT= $CONF_FILE|cut -d"=" -f2`
|
32 |
smtpPort=`grep ^MAIL_SMTP_PORT= $CONF_FILE|cut -d"=" -f2`
|
33 |
smtpIP=`grep ^MAIL_SMTP_IP= $CONF_FILE|cut -d"=" -f2`
|
33 |
smtpIP=`grep ^MAIL_SMTP_IP= $CONF_FILE|cut -d"=" -f2`
|
34 |
mailAddr=`grep ^MAIL_ADDR= $CONF_FILE|cut -d"=" -f2`
|
34 |
mailAddr=`grep ^MAIL_ADDR= $CONF_FILE|cut -d"=" -f2`
|
35 |
[ -e ${SASLPATH}/sasl_passwd ] && mailMdp=`cat $SASLPATH/sasl_passwd|cut -d":" -f3`
|
35 |
[ -e ${SASLPATH}/sasl_passwd ] && mailMdp=`cat $SASLPATH/sasl_passwd|cut -d":" -f3`
|
36 |
adminMail=`grep ^MAIL_ADMIN= $CONF_FILE|cut -d"=" -f2`
|
36 |
adminMail=`grep ^MAIL_ADMIN= $CONF_FILE|cut -d"=" -f2`
|
37 |
whiteDomain=`grep ^MAIL_WHITEDOMAIN= $CONF_FILE|cut -d"=" -f2`
|
37 |
whiteDomain=`grep ^MAIL_WHITEDOMAIN= $CONF_FILE|cut -d"=" -f2`
|
38 |
fi
|
38 |
fi
|
39 |
else # apply args
|
39 |
else # apply args
|
40 |
if [ "$1" = "-h" ] || [ "$1" = "--h" ]; then
|
40 |
if [ "$1" = "-h" ] || [ "$1" = "--h" ]; then
|
41 |
echo $usage
|
41 |
echo $usage
|
42 |
exit 0
|
42 |
exit 0
|
43 |
fi
|
43 |
fi
|
44 |
while getopts ":h:s:p:m:o:a:w:0123" option
|
44 |
while getopts ":h:s:p:m:o:a:w:0123" option
|
45 |
do
|
45 |
do
|
46 |
case $option in
|
46 |
case $option in
|
47 |
0)
|
47 |
0)
|
48 |
TYPE_MAIL=0
|
48 |
TYPE_MAIL=0
|
49 |
;;
|
49 |
;;
|
50 |
1)
|
50 |
1)
|
51 |
TYPE_MAIL=1
|
51 |
TYPE_MAIL=1
|
52 |
;;
|
52 |
;;
|
53 |
2)
|
53 |
2)
|
54 |
TYPE_MAIL=2
|
54 |
TYPE_MAIL=2
|
55 |
;;
|
55 |
;;
|
56 |
3)
|
56 |
3)
|
57 |
TYPE_MAIL=3
|
57 |
TYPE_MAIL=3
|
58 |
;;
|
58 |
;;
|
59 |
p)
|
59 |
p)
|
60 |
smtpPort=$OPTARG
|
60 |
smtpPort=$OPTARG
|
61 |
;;
|
61 |
;;
|
62 |
s)
|
62 |
s)
|
63 |
smtpIP=$OPTARG
|
63 |
smtpIP=$OPTARG
|
64 |
;;
|
64 |
;;
|
65 |
m)
|
65 |
m)
|
66 |
mailAddr=$OPTARG
|
66 |
mailAddr=$OPTARG
|
67 |
;;
|
67 |
;;
|
68 |
o)
|
68 |
o)
|
69 |
mailMdp=$OPTARG
|
69 |
mailMdp=$OPTARG
|
70 |
;;
|
70 |
;;
|
71 |
a)
|
71 |
a)
|
72 |
adminMail=$OPTARG
|
72 |
adminMail=$OPTARG
|
73 |
;;
|
73 |
;;
|
74 |
w)
|
74 |
w)
|
75 |
whiteDomain=$OPTARG
|
75 |
whiteDomain=$OPTARG
|
76 |
;;
|
76 |
;;
|
77 |
:)
|
77 |
:)
|
78 |
echo "L'option $OPTARG requiert un argument"
|
78 |
echo "L'option $OPTARG requiert un argument"
|
79 |
exit 1
|
79 |
exit 1
|
80 |
;;
|
80 |
;;
|
81 |
\?)
|
81 |
\?)
|
82 |
echo "$OPTARG : option invalide"
|
82 |
echo "$OPTARG : option invalide"
|
83 |
exit 1
|
83 |
exit 1
|
84 |
;;
|
84 |
;;
|
85 |
esac
|
85 |
esac
|
86 |
done
|
86 |
done
|
87 |
fi
|
87 |
fi
|
88 |
if [[ $TYPE_MAIL -eq 0 ]]; then # disable mail service
|
88 |
if [[ $TYPE_MAIL -eq 0 ]]; then # disable mail service
|
89 |
$SED "s/^MAIL=.*/MAIL=off/" $CONF_FILE
|
89 |
$SED "s/^MAIL=.*/MAIL=off/" $CONF_FILE
|
90 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=/" $CONF_FILE
|
90 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=/" $CONF_FILE
|
91 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
|
91 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
|
92 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=/" $CONF_FILE
|
92 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=/" $CONF_FILE
|
93 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
|
93 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
|
94 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=/" $CONF_FILE
|
94 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=/" $CONF_FILE
|
95 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
|
95 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
|
96 |
$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
|
96 |
$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
|
97 |
$SED "/^SMTP_PORT=/ s/^/#/" $LOCAL_IPTABLE_FILE
|
97 |
$SED "/^SMTP_PORT=/ s/^/#/" $LOCAL_IPTABLE_FILE
|
98 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -d \$SMTP_IP -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
98 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -d \$SMTP_IP -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
99 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -s \$SMTP_IP -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
99 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -s \$SMTP_IP -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
100 |
$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
|
100 |
$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
|
101 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = may/g" $POSTFIX_CONF_FILE
|
101 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = may/g" $POSTFIX_CONF_FILE
|
102 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = no/g" $POSTFIX_CONF_FILE
|
102 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = no/g" $POSTFIX_CONF_FILE
|
103 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
103 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
104 |
[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/*
|
104 |
[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/*
|
105 |
elif [[ $TYPE_MAIL -eq 1 ]]; then # Enable mail service (act as smtp server)
|
105 |
elif [[ $TYPE_MAIL -eq 1 ]]; then # Enable mail service (act as smtp server)
|
106 |
$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
|
106 |
$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
|
107 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=1/" $CONF_FILE
|
107 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=1/" $CONF_FILE
|
108 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
|
108 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
|
109 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=$smtpPort/" $CONF_FILE
|
109 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=$smtpPort/" $CONF_FILE
|
110 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
|
110 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
|
111 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
|
111 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
|
112 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
|
112 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
|
113 |
$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
|
113 |
$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
|
114 |
$SED "s/^SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
114 |
$SED "s/^SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
115 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
115 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
116 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
116 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
117 |
$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
117 |
$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
118 |
$SED "s/^#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
118 |
$SED "s/^#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
119 |
$SED "s/^#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
119 |
$SED "s/^#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
120 |
$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
|
120 |
$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
|
121 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = may/g" $POSTFIX_CONF_FILE
|
121 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = may/g" $POSTFIX_CONF_FILE
|
122 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = no/g" $POSTFIX_CONF_FILE
|
122 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = no/g" $POSTFIX_CONF_FILE
|
123 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
123 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
124 |
[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/*
|
124 |
[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/*
|
125 |
elif [[ $TYPE_MAIL -eq 2 ]]; then # Enable mail service (relaying to an extern mail server)
|
125 |
elif [[ $TYPE_MAIL -eq 2 ]]; then # Enable mail service (relaying to an extern mail server)
|
126 |
$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
|
126 |
$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
|
127 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=2/" $CONF_FILE
|
127 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=2/" $CONF_FILE
|
128 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
|
128 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
|
129 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=$smtpPort/" $CONF_FILE
|
129 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=$smtpPort/" $CONF_FILE
|
130 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
|
130 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
|
131 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
|
131 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
|
132 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
|
132 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
|
133 |
$SED "s/^SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
133 |
$SED "s/^SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
134 |
$SED "s/^SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
134 |
$SED "s/^SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
135 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -d \$SMTP_IP -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
135 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -d \$SMTP_IP -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
136 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -s \$SMTP_IP -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
136 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -s \$SMTP_IP -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
137 |
$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
137 |
$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
138 |
$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
138 |
$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
139 |
$SED "s/^#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -d \$SMTP_IP -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
139 |
$SED "s/^#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -d \$SMTP_IP -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
140 |
$SED "s/^#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -s \$SMTP_IP -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
140 |
$SED "s/^#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -s \$SMTP_IP -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
141 |
$SED "s/^relayhost =.*/relayhost = $smtpIP:$smtpPort/g" $POSTFIX_CONF_FILE
|
141 |
$SED "s/^relayhost =.*/relayhost = [$smtpIP]:$smtpPort/g" $POSTFIX_CONF_FILE
|
142 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = may/g" $POSTFIX_CONF_FILE
|
142 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = may/g" $POSTFIX_CONF_FILE
|
143 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = no/g" $POSTFIX_CONF_FILE
|
143 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = no/g" $POSTFIX_CONF_FILE
|
144 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
144 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
145 |
[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/*
|
145 |
[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/*
|
146 |
elif [[ $TYPE_MAIL -eq 3 ]]; then # Enable mail service (using an email address)
|
146 |
elif [[ $TYPE_MAIL -eq 3 ]]; then # Enable mail service (using an email address)
|
147 |
$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
|
147 |
$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
|
148 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
|
148 |
$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
|
149 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
|
149 |
$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
|
150 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=$smtpPort/" $CONF_FILE
|
150 |
$SED "s/^MAIL_SMTP_PORT=.*/MAIL_SMTP_PORT=$smtpPort/" $CONF_FILE
|
151 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
|
151 |
$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
|
152 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
|
152 |
$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
|
153 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
|
153 |
$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
|
154 |
$SED "s/^SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
154 |
$SED "s/^SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
155 |
$SED "s/^SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
155 |
$SED "s/^SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
156 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
156 |
$SED "s/^\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
157 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
157 |
$SED "s/^\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
158 |
$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
158 |
$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
|
159 |
$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
159 |
$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$smtpPort/" $LOCAL_IPTABLE_FILE
|
160 |
$SED "s/^#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
160 |
$SED "s/^#\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT.*/\$IPTABLES -A OUTPUT -p tcp --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
161 |
$SED "s/^#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
161 |
$SED "s/^#\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT.*/\$IPTABLES -A INPUT -p tcp --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
|
162 |
$SED "s/^relayhost =.*/relayhost = $smtpIP:$smtpPort/g" $POSTFIX_CONF_FILE
|
162 |
$SED "s/^relayhost =.*/relayhost = [$smtpIP]:$smtpPort/g" $POSTFIX_CONF_FILE
|
163 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = encrypt/g" $POSTFIX_CONF_FILE
|
163 |
$SED "s/^smtp_tls_security_level =.*/smtp_tls_security_level = encrypt/g" $POSTFIX_CONF_FILE
|
164 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = yes/g" $POSTFIX_CONF_FILE
|
164 |
$SED "s/^smtp_tls_wrappermode =.*/smtp_tls_wrappermode = yes/g" $POSTFIX_CONF_FILE
|
165 |
if [ "$domainName" = "localdomain" ]; then # use a real domain name to avoid extern smtp server reject
|
165 |
if [ "$domainName" = "localdomain" ]; then # use a real domain name to avoid extern smtp server reject
|
166 |
$SED "s/^myhostname =.*/myhostname = alcasar.net/g" $POSTFIX_CONF_FILE
|
166 |
$SED "s/^myhostname =.*/myhostname = alcasar.net/g" $POSTFIX_CONF_FILE
|
167 |
else
|
167 |
else
|
168 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
168 |
$SED "s/^myhostname =.*/myhostname = $hostName.$domainName/g" $POSTFIX_CONF_FILE
|
169 |
fi
|
169 |
fi
|
170 |
[ -d ${SASLPATH} ] || mkdir ${SASLPATH}
|
170 |
[ -d ${SASLPATH} ] || mkdir ${SASLPATH}
|
171 |
echo "[${smtpIP}]:${smtpPort} ${mailAddr}:${mailMdp}" > ${SASLPATH}/sasl_passwd
|
171 |
echo "[${smtpIP}]:${smtpPort} ${mailAddr}:${mailMdp}" > ${SASLPATH}/sasl_passwd
|
172 |
postmap ${SASLPATH}/sasl_passwd
|
172 |
postmap ${SASLPATH}/sasl_passwd
|
173 |
chmod -R 644 ${SASLPATH}
|
173 |
chmod -R 644 ${SASLPATH}
|
174 |
chown root:root ${SASLPATH}/sasl_passwd*
|
174 |
chown root:root ${SASLPATH}/sasl_passwd*
|
175 |
chmod 0600 ${SASLPATH}/sasl_passwd*
|
175 |
chmod 0600 ${SASLPATH}/sasl_passwd*
|
176 |
else
|
176 |
else
|
177 |
echo "Erreur ! Aucun type de messagerie sélectionné !"
|
177 |
echo "Erreur ! Aucun type de messagerie sélectionné !"
|
178 |
exit 0
|
178 |
exit 0
|
179 |
fi
|
179 |
fi
|
180 |
/usr/local/bin/alcasar-iptables.sh
|
180 |
/usr/local/bin/alcasar-iptables.sh
|
181 |
systemctl restart postfix.service
|
181 |
systemctl restart postfix.service
|
182 |
exit 0
|
182 |
exit 0
|
183 |
|
183 |
|