Subversion Repositories ALCASAR

Rev

Rev 3016 | Rev 3020 | 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
###########################################################################################
3018 rexy 4
##				    ALCASAR MAIL SERVICE CONFIGURATION
2993 rexy 5
##
3011 rexy 6
##	Script by K@M3L & T3RRY (LaPlateform), joss_p & Rexy
3018 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
11
##		2 : PostFix use an external email address (with SASL)
2993 rexy 12
###########################################################################################
13
 
3018 rexy 14
# ****** Paths *******
2993 rexy 15
SED="/bin/sed -i"
16
CONF_FILE="/usr/local/etc/alcasar.conf"
2994 rexy 17
POSTFIX_CONF_FILE="/etc/postfix/main.cf"
2993 rexy 18
LOCAL_IPTABLE_FILE="/usr/local/etc/alcasar-iptables-local.sh"
2997 rexy 19
SASLPATH="/etc/postfix/sasl"
2993 rexy 20
smtpIP="0.0.0.0/0"
3018 rexy 21
usage="Usage: alcasar-mail_install.sh -h|-0|-1|-2|-3"
2993 rexy 22
 
23
nb_args=$#
3018 rexy 24
if [ $nb_args -eq 0 ] # apply alcasar.conf
2993 rexy 25
then
3018 rexy 26
	mail=`grep ^MAIL= $CONF_FILE|cut -d"=" -f2`
27
	if [ "$mail" = "off" ]; then
28
		TYPE_MAIL=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`
38
	fi
39
else # apply args
40
	if [ "$1" = "-h" ] || [ "$1" = "--h" ]; then
41
		echo $usage
42
		exit 0
43
	fi
44
	while getopts ":h:s:p:r:m:o:a:w:0123" option
2993 rexy 45
	do
46
		case $option in
47
			0)
48
				TYPE_MAIL=0
49
			;;
50
			1)
51
				TYPE_MAIL=1
52
			;;
53
			2)
54
				TYPE_MAIL=2
55
			;;
56
			3)
57
				TYPE_MAIL=3
58
			;;
59
			s)
60
				smtp=$OPTARG
61
			;;
62
			p)
63
				port=$OPTARG
64
			;;
65
			r)
66
				smtpIP=$OPTARG
67
			;;
68
			m)
69
				mailAddr=$OPTARG
70
			;;
71
			o)
72
				mailMdp=$OPTARG
73
			;;
74
			a)
75
				adminMail=$OPTARG
76
			;;
77
			w)
78
				whiteDomain=$OPTARG
79
			;;
80
			:)
81
				echo "L'option $OPTARG requiert un argument"
82
				exit 1
83
			;;
84
			\?)
85
				echo "$OPTARG : option invalide"
86
				exit 1
87
			;;
88
		esac
89
	done
90
fi
3018 rexy 91
echo "Type=$TYPE_MAIL - smtp=$smtp - port=$port - smtpIP=$smtpIP - mailAddr=$mailAddr - mailMdp=$mailMdp - adminMail=$adminMail - whitedomain=$whiteDomain"
2994 rexy 92
if  [[ $TYPE_MAIL -eq 0 ]]; then # disable mail service
2993 rexy 93
	$SED "s/^MAIL=.*/MAIL=off/" $CONF_FILE
94
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=/" $CONF_FILE
95
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
96
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=/" $CONF_FILE
97
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=/" $CONF_FILE
98
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
3018 rexy 99
	$SED "s/^MAIL_PASSWORD=.*/MAIL_PASSWORD=/" $CONF_FILE
2997 rexy 100
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=/" $CONF_FILE
2993 rexy 101
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=/" $CONF_FILE
2997 rexy 102
	$SED "/^SMTP_IP=/ s/^/#/" $LOCAL_IPTABLE_FILE
103
	$SED "/^SMTP_PORT=/ s/^/#/" $LOCAL_IPTABLE_FILE
3018 rexy 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
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
2997 rexy 106
	$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
3016 rexy 107
	[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/sasl_passwd
2997 rexy 108
elif [[ $TYPE_MAIL -eq 2 ]]; then # Enable mail service (relaying to an extern mail server)
3001 rexy 109
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
110
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=2/" $CONF_FILE
3016 rexy 111
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
112
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
113
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
114
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
3018 rexy 115
	$SED "s/^MAIL_PASSWORD=.*/MAIL_PASSWORD=/" $CONF_FILE
3016 rexy 116
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
117
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
118
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
119
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $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
121
	$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
3001 rexy 122
	$SED "s/^relayhost =.*/relayhost = $smtp:$port/g" $POSTFIX_CONF_FILE
3016 rexy 123
	[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/sasl_passwd
2997 rexy 124
elif [[ $TYPE_MAIL -eq 3 ]]; then # Enable mail service (using an email address)
2994 rexy 125
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
126
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
127
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
3016 rexy 128
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
2994 rexy 129
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
130
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
3018 rexy 131
	$SED "s/^MAIL_PASSWORD=.*/MAIL_PASSWORD=$mailMdp/" $CONF_FILE
2997 rexy 132
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
2994 rexy 133
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
3013 rexy 134
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
2997 rexy 135
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $LOCAL_IPTABLE_FILE
3016 rexy 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
137
	$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
3013 rexy 138
	$SED "s/^relayhost =.*/relayhost = $smtpIP:$port/g" $POSTFIX_CONF_FILE
2997 rexy 139
	[ -d ${SASLPATH} ] || mkdir ${SASLPATH}
3013 rexy 140
	echo "[${smtpIP}]:${port} ${mailAddr}:${mailMdp}" > ${SASLPATH}/sasl_passwd
2997 rexy 141
	postmap ${SASLPATH}/sasl_passwd
3001 rexy 142
	chmod -R 644 ${SASLPATH}
143
	chown root:root ${SASLPATH}/sasl_passwd*
144
	chmod 0600 ${SASLPATH}/sasl_passwd*
2993 rexy 145
else
146
	echo "Erreur ! Aucun type de messagerie sélectionné !"
147
	exit 0
148
fi
149
/usr/local/bin/alcasar-iptables.sh
3016 rexy 150
systemctl restart postfix.service
2993 rexy 151
exit 0