Subversion Repositories ALCASAR

Rev

Rev 2993 | Rev 2997 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2993 rexy 1
#!/bin/bash
2
 
3
###########################################################################################
4
##				    ALCASAR SERVICE MAIL INSTALL
5
##
6
##	Script by joss_p & Rexy
7
##  This script configure the mail conf file and execute the configuration from the acc.
8
###########################################################################################
9
 
10
# ****** Paths - chemin des commandes *******
11
SED="/bin/sed -i"
12
CONF_FILE="/usr/local/etc/alcasar.conf"
2994 rexy 13
POSTFIX_CONF_FILE="/etc/postfix/main.cf"
2993 rexy 14
LOCAL_IPTABLE_FILE="/usr/local/etc/alcasar-iptables-local.sh"
15
saslPath="/etc/postfix/sasl"
16
smtpIP="0.0.0.0/0"
17
 
18
usage="Usage: alcasar-mail_install.sh 0|1|2|3"
19
nb_args=$#
20
if [ $nb_args -eq 0 ]
21
then
22
	echo "$usage"
23
	exit 0
24
fi
25
if [[ ${#} -ne 0 ]]
26
then
27
	while getopts ":s:p:r:m:o:a:w:0123" option
28
	do
29
		case $option in
30
			0)
31
				TYPE_MAIL=0
32
			;;
33
			1)
34
				TYPE_MAIL=1
35
			;;
36
			2)
37
				TYPE_MAIL=2
38
			;;
39
			3)
40
				TYPE_MAIL=3
41
			;;
42
			s)
43
				smtp=$OPTARG
44
			;;
45
			p)
46
				port=$OPTARG
47
			;;
48
			r)
49
				smtpIP=$OPTARG
50
			;;
51
			m)
52
				mailAddr=$OPTARG
53
			;;
54
			o)
55
				mailMdp=$OPTARG
56
			;;
57
			a)
58
				adminMail=$OPTARG
59
			;;
60
			w)
61
				whiteDomain=$OPTARG
62
			;;
63
			:)
64
				echo "L'option $OPTARG requiert un argument"
65
				exit 1
66
			;;
67
			\?)
68
				echo "$OPTARG : option invalide"
69
				exit 1
70
			;;
71
		esac
72
	done
73
fi
2994 rexy 74
if  [[ $TYPE_MAIL -eq 0 ]]; then # disable mail service
2993 rexy 75
	$SED "s/^MAIL=.*/MAIL=off/" $CONF_FILE
76
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=/" $CONF_FILE
77
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
78
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
79
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=/" $CONF_FILE
80
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
81
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAINE=/" $CONF_FILE
82
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
83
	$SED "/^SMTP_IP/ s/^/#/" $LOCAL_IPTABLE_FILE
2994 rexy 84
	$SED "/^SMTP_PORT/ s/^/#/g" $LOCAL_IPTABLE_FILE
2993 rexy 85
	$SED "/^\$IPTABLES -A OUTPUT -p tcp -d \$SMTP_IP/ s/^/#/" $LOCAL_IPTABLE_FILE
86
	$SED "/^\$IPTABLES -A INPUT  -p tcp -s \$SMTP_IP/ s/^/#/g" $LOCAL_IPTABLE_FILE
2994 rexy 87
	$SED "s/^relayhost =.*/relayhost =/g" $POSTFIX_CONF_FILE
88
elif [[ $TYPE_MAIL -eq 2 ]]; then # relay to an extern mail server
2993 rexy 89
	echo "relayhost = [${smtp}]:${port}" >> /etc/postfix/main.cf
2994 rexy 90
elif [[ $TYPE_MAIL -eq 3 ]]; then # use an email address
91
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
92
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
93
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
94
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtp/" $CONF_FILE
95
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
96
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
97
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAINE=$whiteDomain/" $CONF_FILE
98
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
99
	$SED "/^SMTP_IP/ s/^/SMTP_IP=$port/" $LOCAL_IPTABLE_FILE
100
	$SED "/^SMTP_PORT/ s/^/SMTP_PORT=$port/g" $LOCAL_IPTABLE_FILE
101
	$SED "/^\$IPTABLES -A OUTPUT -p tcp -d \$SMTP_IP/ s/^/#/" $LOCAL_IPTABLE_FILE
102
	$SED "/^\$IPTABLES -A INPUT  -p tcp -s \$SMTP_IP/ s/^/#/g" $LOCAL_IPTABLE_FILE
103
	$SED "s/^relayhost =.*/relayhost =/g" $POSTFIX_CONF_FILE
104
	$SED "s/^relayhost =.*/relayhost = $smtp:$port/g" $POSTFIX_CONF_FILE
2993 rexy 105
	[ -d ${saslPath} ] || mkdir ${saslPath}
106
	echo "[${smtp}]:${port} ${mailAddr}:${mailMdp}" > ${saslPath}/sasl_passwd
107
	postmap ${saslPath}/sasl_passwd
108
	chmod -R 777 ${saslPath}
109
	#chown root:root ${saslPath}/sasl_passwd*
110
	#chmod 0600 ${saslPath}/sasl_passwd*
111
else
112
	echo "Erreur ! Aucun type de messagerie sélectionné !"
113
	exit 0
114
fi
115
/usr/local/bin/alcasar-iptables.sh
116
exit 0