Subversion Repositories ALCASAR

Rev

Rev 2997 | Rev 3011 | 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"
2997 rexy 15
SASLPATH="/etc/postfix/sasl"
2993 rexy 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
2997 rexy 81
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=/" $CONF_FILE
2993 rexy 82
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
2997 rexy 83
	$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
84
	$SED "/^SMTP_PORT=/ s/^/#/" $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
2997 rexy 87
	$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
88
elif [[ $TYPE_MAIL -eq 2 ]]; then # Enable mail service (relaying to an extern mail server)
3001 rexy 89
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
90
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=2/" $CONF_FILE
91
	$SED "s/^#\$IPTABLES -A OUTPUT -p tcp -d \$SMTP_IP.*/\$IPTABLES -A OUTPUT -p tcp -d \$SMTP_IP --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
92
	$SED "s/^#\$IPTABLES -A INPUT  -p tcp -s \$SMTP_IP.*/\$IPTABLES -A INPUT  -p tcp -s \$SMTP_IP --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED     -j ACCEPT/" $LOCAL_IPTABLE_FILE
93
	$SED "s/^relayhost =.*/relayhost = $smtp:$port/g" $POSTFIX_CONF_FILE
2997 rexy 94
elif [[ $TYPE_MAIL -eq 3 ]]; then # Enable mail service (using an email address)
2994 rexy 95
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
96
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
97
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
98
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtp/" $CONF_FILE
99
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
100
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
2997 rexy 101
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
2994 rexy 102
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
2997 rexy 103
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$port/" $LOCAL_IPTABLE_FILE
104
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $LOCAL_IPTABLE_FILE
105
	$SED "s/^#\$IPTABLES -A OUTPUT -p tcp -d \$SMTP_IP.*/\$IPTABLES -A OUTPUT -p tcp -d \$SMTP_IP --dport \$SMTP_PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT/" $LOCAL_IPTABLE_FILE
106
	$SED "s/^#\$IPTABLES -A INPUT  -p tcp -s \$SMTP_IP.*/\$IPTABLES -A INPUT  -p tcp -s \$SMTP_IP --sport \$SMTP_PORT -m conntrack --ctstate ESTABLISHED     -j ACCEPT/" $LOCAL_IPTABLE_FILE
2994 rexy 107
	$SED "s/^relayhost =.*/relayhost = $smtp:$port/g" $POSTFIX_CONF_FILE
2997 rexy 108
	[ -d ${SASLPATH} ] || mkdir ${SASLPATH}
109
	echo "[${smtp}]:${port} ${mailAddr}:${mailMdp}" > ${SASLPATH}/sasl_passwd
110
	postmap ${SASLPATH}/sasl_passwd
3001 rexy 111
	chmod -R 644 ${SASLPATH}
112
	chown root:root ${SASLPATH}/sasl_passwd*
113
	chmod 0600 ${SASLPATH}/sasl_passwd*
2993 rexy 114
else
115
	echo "Erreur ! Aucun type de messagerie sélectionné !"
116
	exit 0
117
fi
118
/usr/local/bin/alcasar-iptables.sh
119
exit 0