Subversion Repositories ALCASAR

Rev

Rev 2994 | Go to most recent revision | Details | 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"
13
LOCAL_IPTABLE_FILE="/usr/local/etc/alcasar-iptables-local.sh"
14
saslPath="/etc/postfix/sasl"
15
smtpIP="0.0.0.0/0"
16
 
17
usage="Usage: alcasar-mail_install.sh 0|1|2|3"
18
nb_args=$#
19
if [ $nb_args -eq 0 ]
20
then
21
	echo "$usage"
22
	exit 0
23
fi
24
if [[ ${#} -ne 0 ]]
25
then
26
	while getopts ":s:p:r:m:o:a:w:0123" option
27
	do
28
		case $option in
29
			0)
30
				TYPE_MAIL=0
31
			;;
32
			1)
33
				TYPE_MAIL=1
34
			;;
35
			2)
36
				TYPE_MAIL=2
37
			;;
38
			3)
39
				TYPE_MAIL=3
40
			;;
41
			s)
42
				smtp=$OPTARG
43
			;;
44
			p)
45
				port=$OPTARG
46
			;;
47
			r)
48
				smtpIP=$OPTARG
49
			;;
50
			m)
51
				mailAddr=$OPTARG
52
			;;
53
			o)
54
				mailMdp=$OPTARG
55
			;;
56
			a)
57
				adminMail=$OPTARG
58
			;;
59
			w)
60
				whiteDomain=$OPTARG
61
			;;
62
			:)
63
				echo "L'option $OPTARG requiert un argument"
64
				exit 1
65
			;;
66
			\?)
67
				echo "$OPTARG : option invalide"
68
				exit 1
69
			;;
70
		esac
71
	done
72
fi
73
if  [[ $TYPE_MAIL -eq 0 ]]; then # idesable mail service
74
	$SED "s/^MAIL=.*/MAIL=off/" $CONF_FILE
75
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=/" $CONF_FILE
76
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
77
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
78
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=/" $CONF_FILE
79
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
80
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAINE=/" $CONF_FILE
81
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
82
	$SED "/^SMTP_IP/ s/^/#/" $LOCAL_IPTABLE_FILE
83
	$SED "/^\$IPTABLES -A OUTPUT -p tcp -d \$SMTP_IP/ s/^/#/" $LOCAL_IPTABLE_FILE
84
	$SED "/^SMTP_PORT/ s/^/#/g" $LOCAL_IPTABLE_FILE
85
	$SED "/^\$IPTABLES -A INPUT  -p tcp -s \$SMTP_IP/ s/^/#/g" $LOCAL_IPTABLE_FILE
86
elif [[ $TYPE_MAIL -eq 2 ]]; then
87
	echo "relayhost = [${smtp}]:${port}" >> /etc/postfix/main.cf
88
elif [[ $TYPE_MAIL -eq 3 ]]; then
89
	echo "relayhost = [${smtp}]:${port}" >> /etc/postfix/main.cf
90
	[ -d ${saslPath} ] || mkdir ${saslPath}
91
	echo "[${smtp}]:${port} ${mailAddr}:${mailMdp}" > ${saslPath}/sasl_passwd
92
	postmap ${saslPath}/sasl_passwd
93
	chmod -R 777 ${saslPath}
94
	#chown root:root ${saslPath}/sasl_passwd*
95
	#chmod 0600 ${saslPath}/sasl_passwd*
96
else
97
	echo "Erreur ! Aucun type de messagerie sélectionné !"
98
	exit 0
99
fi
100
/usr/local/bin/alcasar-iptables.sh
101
exit 0