Subversion Repositories ALCASAR

Rev

Rev 3013 | Rev 3018 | 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
##
3011 rexy 6
##	Script by K@M3L & T3RRY (LaPlateform), joss_p & Rexy
2993 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
3016 rexy 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
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
2997 rexy 87
	$SED "s/^relayhost =.*/relayhost =/" $POSTFIX_CONF_FILE
3016 rexy 88
	[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/sasl_passwd
2997 rexy 89
elif [[ $TYPE_MAIL -eq 2 ]]; then # Enable mail service (relaying to an extern mail server)
3001 rexy 90
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
91
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=2/" $CONF_FILE
3016 rexy 92
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
93
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
94
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
95
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=/" $CONF_FILE
96
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
97
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
98
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
99
	$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
101
	$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 102
	$SED "s/^relayhost =.*/relayhost = $smtp:$port/g" $POSTFIX_CONF_FILE
3016 rexy 103
	[ -e ${SASLPATH}/sasl_passwd ] && rm -f ${SASLPATH}/sasl_passwd
2997 rexy 104
elif [[ $TYPE_MAIL -eq 3 ]]; then # Enable mail service (using an email address)
2994 rexy 105
	$SED "s/^MAIL=.*/MAIL=on/" $CONF_FILE
106
	$SED "s/^MAIL_TYPE=.*/MAIL_TYPE=3/" $CONF_FILE
107
	$SED "s/^MAIL_SMTP=.*/MAIL_SMTP=/" $CONF_FILE
3016 rexy 108
	$SED "s/^MAIL_SMTP_IP=.*/MAIL_SMTP_IP=$smtpIP/" $CONF_FILE
2994 rexy 109
	$SED "s/^MAIL_PORT=.*/MAIL_PORT=$port/" $CONF_FILE
110
	$SED "s/^MAIL_ADDR=.*/MAIL_ADDR=$mailAddr/" $CONF_FILE
2997 rexy 111
	$SED "s/^MAIL_WHITEDOMAIN=.*/MAIL_WHITEDOMAIN=$whiteDomain/" $CONF_FILE
2994 rexy 112
	$SED "s/^MAIL_ADMIN=.*/MAIL_ADMIN=$adminMail/" $CONF_FILE
3013 rexy 113
	$SED "s/^#SMTP_IP=.*/SMTP_IP=$smtpIP/" $LOCAL_IPTABLE_FILE
2997 rexy 114
	$SED "s/^#SMTP_PORT=.*/SMTP_PORT=$port/" $LOCAL_IPTABLE_FILE
3016 rexy 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
116
	$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 117
	$SED "s/^relayhost =.*/relayhost = $smtpIP:$port/g" $POSTFIX_CONF_FILE
2997 rexy 118
	[ -d ${SASLPATH} ] || mkdir ${SASLPATH}
3013 rexy 119
	echo "[${smtpIP}]:${port} ${mailAddr}:${mailMdp}" > ${SASLPATH}/sasl_passwd
2997 rexy 120
	postmap ${SASLPATH}/sasl_passwd
3001 rexy 121
	chmod -R 644 ${SASLPATH}
122
	chown root:root ${SASLPATH}/sasl_passwd*
123
	chmod 0600 ${SASLPATH}/sasl_passwd*
2993 rexy 124
else
125
	echo "Erreur ! Aucun type de messagerie sélectionné !"
126
	exit 0
127
fi
128
/usr/local/bin/alcasar-iptables.sh
3016 rexy 129
systemctl restart postfix.service
2993 rexy 130
exit 0