Subversion Repositories ALCASAR

Rev

Rev 3016 | Rev 3020 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3016 Rev 3018
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
3
###########################################################################################
3
###########################################################################################
4
##				    ALCASAR SERVICE MAIL INSTALL
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
-
 
8
##		0 : no email autoregistration
-
 
9
##		1 : PostFix is the SMTP server
-
 
10
##		2 : PostFix relay to an other SMTP server
7
##  This script configure the mail conf file and execute the configuration from the acc.
11
##		2 : PostFix use an external email address (with SASL)
8
###########################################################################################
12
###########################################################################################
9
 
13
 
10
# ****** Paths - chemin des commandes *******
14
# ****** Paths *******
11
SED="/bin/sed -i"
15
SED="/bin/sed -i"
12
CONF_FILE="/usr/local/etc/alcasar.conf"
16
CONF_FILE="/usr/local/etc/alcasar.conf"
13
POSTFIX_CONF_FILE="/etc/postfix/main.cf"
17
POSTFIX_CONF_FILE="/etc/postfix/main.cf"
14
LOCAL_IPTABLE_FILE="/usr/local/etc/alcasar-iptables-local.sh"
18
LOCAL_IPTABLE_FILE="/usr/local/etc/alcasar-iptables-local.sh"
15
SASLPATH="/etc/postfix/sasl"
19
SASLPATH="/etc/postfix/sasl"
16
smtpIP="0.0.0.0/0"
20
smtpIP="0.0.0.0/0"
-
 
21
usage="Usage: alcasar-mail_install.sh -h|-0|-1|-2|-3"
17
 
22
 
18
usage="Usage: alcasar-mail_install.sh 0|1|2|3"
-
 
19
nb_args=$#
23
nb_args=$#
20
if [ $nb_args -eq 0 ]
24
if [ $nb_args -eq 0 ] # apply alcasar.conf
21
then
25
then
-
 
26
	mail=`grep ^MAIL= $CONF_FILE|cut -d"=" -f2`
-
 
27
	if [ "$mail" = "off" ]; then
22
	echo "$usage"
28
		TYPE_MAIL=0
23
	exit 0
29
	else
-
 
30
		TYPE_MAIL=`grep ^MAIL_TYPE= $CONF_FILE|cut -d"=" -f2`
-
 
31
		smtp=`grep ^MAIL_SMTP= $CONF_FILE|cut -d"=" -f2`
-
 
32
		port=`grep ^MAIL_PORT= $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`
-
 
35
		mailMdp=`grep ^MAIL_PASSWORD= $CONF_FILE|cut -d"=" -f2`
-
 
36
		adminMail=`grep ^MAIL_ADMIN= $CONF_FILE|cut -d"=" -f2`
-
 
37
		whiteDomain=`grep ^MAIL_WHTEDOMAIN= $CONF_FILE|cut -d"=" -f2`
24
fi
38
	fi
25
if [[ ${#} -ne 0 ]]
39
else # apply args
-
 
40
	if [ "$1" = "-h" ] || [ "$1" = "--h" ]; then
-
 
41
		echo $usage
-
 
42
		exit 0
26
then
43
	fi
27
	while getopts ":s:p:r:m:o:a:w:0123" option
44
	while getopts ":h:s:p:r:m:o:a:w:0123" option
28
	do
45
	do
29
		case $option in
46
		case $option in
30
			0)
47
			0)
31
				TYPE_MAIL=0
48
				TYPE_MAIL=0
32
			;;
49
			;;
Line 69... Line 86...
69
				exit 1
86
				exit 1
70
			;;
87
			;;
71
		esac
88
		esac
72
	done
89
	done
73
fi
90
fi
-
 
91
echo "Type=$TYPE_MAIL - smtp=$smtp - port=$port - smtpIP=$smtpIP - mailAddr=$mailAddr - mailMdp=$mailMdp - adminMail=$adminMail - whitedomain=$whiteDomain"
74
if  [[ $TYPE_MAIL -eq 0 ]]; then # disable mail service
92
if  [[ $TYPE_MAIL -eq 0 ]]; then # disable mail service
75
	$SED "s/^MAIL=.*/MAIL=off/" $CONF_FILE
93
	$SED "s/^MAIL=.*/MAIL=off/" $CONF_FILE
76
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=/" $CONF_FILE
94
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=/" $CONF_FILE
77
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
95
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
78
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
96
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
79
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=/" $CONF_FILE
97
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=/" $CONF_FILE
80
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
98
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
-
 
99
	$SED "s/^MAIL_PASSWORD=.*/MAIL_PASSWORD=/" $CONF_FILE
81
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=/" $CONF_FILE
100
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=/" $CONF_FILE
82
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
101
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
83
	$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
102
	$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
84
	$SED "/^SMTP_PORT=/ s/^/#/" $LOCAL_IPTABLE_FILE
103
	$SED "/^SMTP_PORT=/ s/^/#/" $LOCAL_IPTABLE_FILE
85
	$SED "/^\$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
104
	$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
86
	$SED "/^\$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
105
	$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
87
	$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
106
	$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
88
	[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/sasl_passwd
107
	[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/sasl_passwd
89
elif [[ $TYPE_MAIL -eq 2 ]]; then # Enable mail service (relaying to an extern mail server)
108
elif [[ $TYPE_MAIL -eq 2 ]]; then # Enable mail service (relaying to an extern mail server)
90
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
109
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
91
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=2/" $CONF_FILE
110
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=2/" $CONF_FILE
92
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
111
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
93
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
112
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
94
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
113
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
95
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
114
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
-
 
115
	$SED "s/^MAIL_PASSWORD=.*/MAIL_PASSWORD=/" $CONF_FILE
96
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
116
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
97
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
117
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
98
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
118
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
99
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $LOCAL_IPTABLE_FILE
119
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $LOCAL_IPTABLE_FILE
100
	$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
120
	$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
Line 106... Line 126...
106
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
126
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
107
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
127
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
108
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
128
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
109
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
129
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
110
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
130
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
-
 
131
	$SED "s/^MAIL_PASSWORD=.*/MAIL_PASSWORD=$mailMdp/" $CONF_FILE
111
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
132
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
112
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
133
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
113
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
134
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
114
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $LOCAL_IPTABLE_FILE
135
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $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
136
	$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