Subversion Repositories ALCASAR

Rev

Rev 1020 | Rev 1050 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
672 richard 1
#/bin/bash
64 franck 2
# $Id: alcasar-conf.sh 1024 2013-02-06 01:29:13Z franck $
672 richard 3
 
4
# alcasar-conf.sh
865 richard 5
# by REXY
672 richard 6
# This script is distributed under the Gnu General Public License (GPL)
7
 
8
# Ce script permet la mise à jour ALCASAR 
9
#	- création et chargement de l'archive des fichiers de configuration (/tmp/alcasar-conf.tar.gz)
10
#	- application des directives du fichier de conf central (/usr/local/etc/alcasar.conf)
11
# This script allows ALCASAR update 
12
#	- create and load the configuration files backup (/tmp/alcasar-conf.tar.gz)
13
#	- apply ALCASAR central configuration file (/usr/local/etc/alcasar.conf)
14
 
865 richard 15
new="$(date +%G%m%d-%Hh%M)"  			# date et heure des fichiers
806 richard 16
fichier="alcasar-conf-$new.tar.gz"		# nom du fichier de sauvegarde
8 franck 17
DIR_UPDATE="/tmp/conf"				# répertoire de stockage des fichier de conf pour une mise à jour
18
DIR_WEB="/var/www/html"				# répertoire du centre de gestion
478 richard 19
DIR_BIN="/usr/local/bin"			# répertoire des scripts d'admin
346 richard 20
DIR_SBIN="/usr/local/sbin"			# répertoire des scripts d'admin
21
DIR_ETC="/usr/local/etc"			# répertoire des fichiers de conf
811 richard 22
DIR_SAVE="/var/Save/system_backup"		# répertoire de sauvegarde
628 richard 23
CONF_FILE="$DIR_ETC/alcasar.conf"		# main alcasar conf file
510 richard 24
VERSION="/var/www/html/VERSION"			# contient la version en cours
628 richard 25
EXTIF="eth0"					# ETH0 est l'interface connectée à Internet (Box FAI)
26
INTIF="eth1"					# ETH1 est l'interface connectée au réseau local de consultation
27
HOSTNAME="alcasar"
369 richard 28
DB_USER="radius"
504 richard 29
radiuspwd=""
384 richard 30
SED="/bin/sed -i"
510 richard 31
RUNNING_VERSION=`cat $VERSION|cut -d" " -f1`
32
MAJ_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f1`
33
MIN_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f2|cut -c1`
34
UPD_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f3`
923 franck 35
DOMAIN=`grep DOMAIN $CONF_FILE|cut -d"=" -f2`
36
DOMAIN=${DOMAIN:=localdomain}
628 richard 37
DATE=`date '+%d %B %Y - %Hh%M'`
38
private_network_calc ()
39
{
40
	PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`		# prefixe du réseau (ex. 24)
41
	PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`		# @ réseau de consultation (ex.: 192.168.182.0)
42
	PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX					# @ + masque du réseau de consult (192.168.182.0/24)
43
	classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`; classe_sup_sup=`expr $classe + 2`		# classes de réseau (ex.: 2=classe B, 3=classe C)
44
	PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`.			# @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
45
}
8 franck 46
 
933 franck 47
usage="Usage: alcasar-conf.sh {--create or -create} | {--load or -load} | {--apply or -apply}"
8 franck 48
nb_args=$#
49
args=$1
50
if [ $nb_args -eq 0 ]
51
then
52
	nb_args=1
53
	args="-h"
54
fi
55
case $args in
56
	-\? | -h* | --h*)
57
		echo "$usage"
58
		exit 0
59
		;;
389 franck 60
	--create|-create)	
8 franck 61
		[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
62
		mkdir $DIR_UPDATE
978 franck 63
# Sauvegarde du fichier général de DNSMASQ  ---- provisoire le temps que le bug de dnsmasq soit corrigé.
986 franck 64
		if  [ `grep -c "^OPTIONS=\"\$OPTIONS --server=" /etc/sysconfig/dnsmasq` -eq "1" ]
978 franck 65
		  then cp /etc/sysconfig/dnsmasq $DIR_UPDATE
66
		fi
8 franck 67
# Sauvegarde de la base des usagers
411 richard 68
		/usr/local/sbin/alcasar-mysql.sh -dump
8 franck 69
		cp /var/Save/base/`ls /var/Save/base|tail -1` $DIR_UPDATE
70
# Sauvegarde du logo
71
		cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
310 richard 72
# Sauvegarde des fichiers exploités par dansguardian 
73
		cp -f /etc/dansguardian/lists/exceptioniplist $DIR_UPDATE
879 richard 74
		cp -f /etc/dansguardian/lists/urlregexplist $DIR_UPDATE
310 richard 75
		cp -f /etc/dansguardian/lists/exceptionsitelist $DIR_UPDATE
76
		cp -f /etc/dansguardian/lists/bannedsitelist $DIR_UPDATE
77
		cp -f /etc/dansguardian/lists/exceptionurllist $DIR_UPDATE
78
		cp -f /etc/dansguardian/lists/bannedurllist $DIR_UPDATE
79
		cp -rf /etc/dansguardian/lists/blacklists/ossi $DIR_UPDATE
612 richard 80
# sauvegarde des fichiers : de conf, de filtrage, d'exception, digest, etc.
8 franck 81
		mkdir $DIR_UPDATE/etc/
346 richard 82
		cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
510 richard 83
# particularité des versions
636 richard 84
# si version <= 2.0
85
		if [ $MAJ_RUNNING_VERSION -lt 2 ] || ([ $MAJ_RUNNING_VERSION -eq 2 ] && [ $MIN_RUNNING_VERSION -eq 0 ])
510 richard 86
		then
87
			rm -f $DIR_UPDATE/etc/alcasar-dns-name		# changement de format
88
			rm -rf $DIR_UPDATE/etc/digest			# hostname=alcasar
638 richard 89
			if [ -e $DIR_UPDATE/etc/alcasar-uamallowed ]; then
90
				uamallowed=`cat $DIR_UPDATE/etc/alcasar-uamallowed`
91
				if [ $uamallowed == "uamallowed=\"\"" ]
92
					then rm -f $DIR_UPDATE/etc/alcasar-uamallowed		# un uamallowed 'vide' perturbe coova
93
				fi
618 richard 94
			fi
638 richard 95
			if [ -e $DIR_UPDATE/etc/alcasar-uamdomain ]; then
96
				uamdomain=`cat $DIR_UPDATE/etc/alcasar-uamdomain`
97
				if [ $uamdomain == "uamdomain=\"\"" ]
98
					then rm -f $DIR_UPDATE/etc/alcasar-uamdomain		# un uamdomain 'vide' perturbe coova
99
				fi
618 richard 100
			fi
510 richard 101
		else
605 richard 102
# si version >= 2.1 : sauvegarde des certificats (serveur et CA)
510 richard 103
			mkdir $DIR_UPDATE/pki/
104
			cert_date=`/usr/bin/openssl x509 -noout -in /etc/pki/tls/certs/alcasar.crt -dates|grep After|cut -d"=" -f2`
105
			cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE
106
			cp -f /etc/pki/tls/private/alcasar.key $DIR_UPDATE
107
			cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
108
			cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
675 richard 109
			if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
110
				cp -f /etc/pki/tls/certs/server-chain.crt $DIR_UPDATE
111
			else
112
				cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.crt
113
			fi
510 richard 114
		fi
605 richard 115
# si version < 2.2
636 richard 116
		if [ $MAJ_RUNNING_VERSION -lt 2 ] || ([ $MAJ_RUNNING_VERSION -eq 2 ] && [ $MIN_RUNNING_VERSION -lt 2 ])
605 richard 117
		then
636 richard 118
			ORGANISM=`cat $DIR_WEB/intercept.php|grep '$organisme =' | cut -d"=" -f2|tr -d ";\" "` # Sauvegarde du nom d'organisme
628 richard 119
			rm -f $DIR_UPDATE/etc/alcasar-ethers		# This file doesn't contain comments
688 richard 120
			rm -f $DIR_UPDATE/exceptionurllist		# This file was not empty (comments)
628 richard 121
			# Create the initial conf file (doesn't exist in earlier versions)
122
			cat <<EOF > $CONF_FILE
123
##########################################
124
##                                      ##
125
##          ALCASAR Parameters          ##
126
##                                      ##
127
##########################################
128
 
129
INSTALL_DATE=$DATE
130
VERSION=$RUNNING_VERSION
632 richard 131
ORGANISM=$ORGANISM
923 franck 132
DOMAIN=$DOMAIN
628 richard 133
EOF
636 richard 134
			PUBLIC_IP=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-$EXTIF|cut -d"=" -f2` 	# @ip du portail (côté Internet)
135
			PUBLIC_NETMASK=`grep NETMASK /etc/sysconfig/network-scripts/ifcfg-$EXTIF|cut -d"=" -f2`
136
			PUBLIC_PREFIX=`/bin/ipcalc -p $PUBLIC_IP $PUBLIC_NETMASK |cut -d"=" -f2`		# prefixe du réseau (ex. 24)
137
			PUBLIC_GATEWAY=`grep GATEWAY /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF|cut -d"=" -f2`
138
			DNS1=`grep DNS1 /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF|cut -d"=" -f2` 	# @ip 1er DNS
139
			DNS2=`grep DNS2 /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF|cut -d"=" -f2` 	# @ip 2ème DNS
140
			DNS1=${DNS1:=208.67.220.220}
141
			DNS2=${DNS2:=208.67.222.222}
142
			PRIVATE_IP=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-$INTIF|cut -d"=" -f2` 	# @ip du portail (côté LAN)
143
			PRIVATE_NETMASK=`grep NETMASK /etc/sysconfig/network-scripts/ifcfg-$INTIF|cut -d"=" -f2`
144
			private_network_calc
145
			echo "PUBLIC_IP=$PUBLIC_IP/$PUBLIC_PREFIX" >> $CONF_FILE 
146
			echo "GW=$PUBLIC_GATEWAY" >> $CONF_FILE
147
			echo "DNS1=$DNS1" >> $CONF_FILE
148
			echo "DNS2=$DNS2" >> $CONF_FILE 
149
			echo "PRIVATE_IP=$PRIVATE_IP/$PRIVATE_PREFIX" >> $CONF_FILE 
945 richard 150
			echo "DHCP=full" >> $CONF_FILE
923 franck 151
			echo "EXT_DHCP_IP=none" >> $CONF_FILE
152
			echo "RELAY_DHCP_IP=none" >> $CONF_FILE
153
			echo "RELAY_DHCP_PORT=none" >> $CONF_FILE
154
 
636 richard 155
			if [ -r /var/run/sshd.pid ]; then
156
				echo "SSH=on" >> $CONF_FILE
157
			else
158
				echo "SSH=off" >> $CONF_FILE
159
			fi
160
			echo "QOS=off" >> $CONF_FILE
637 richard 161
			echo "WEB_ANTIVIRUS=on" >> $CONF_FILE
636 richard 162
			if [ `grep ^ldap /etc/raddb/sites-available/alcasar | wc -l` -eq "0" ];	then
163
				echo "LDAP=off" >> $CONF_FILE
164
			else
165
				echo "LDAP=on" >> $CONF_FILE
166
			fi
681 richard 167
			PROTOCOLS_FILTERING=`grep ^PROTO_FILTERING /usr/local/bin/alcasar-iptables.sh | cut -d"=" -f2`
637 richard 168
			PROTOCOLS_FILTERING=${PROTOCOLS_FILTERING:="no"}
638 richard 169
			if [ $PROTOCOLS_FILTERING = "no" ]; then
637 richard 170
				echo "PROTOCOLS_FILTERING=off" >> $CONF_FILE
171
			else
172
				echo "PROTOCOLS_FILTERING=on" >> $CONF_FILE
173
			fi
638 richard 174
			DNS_FILTERING=`grep ^reportinglevel /etc/dansguardian/dansguardian.conf | cut -d"=" -f2 | tr -d " "`
637 richard 175
			DNS_FILTERING=${DNS_FILTERING:="-1"}
638 richard 176
			if [ $DNS_FILTERING -eq "-1" ]; then
637 richard 177
				echo "DNS_FILTERING=off" >> $CONF_FILE
178
			else
179
				echo "DNS_FILTERING=on" >> $CONF_FILE
180
			fi
605 richard 181
		fi
977 richard 182
# since V2.6
183
# macallowed is replaced with macauth since 
184
		rm -f $DIR_UPDATE/etc/alcasar-macallowed
185
# DHCP mode can be "off/half/full"
862 richard 186
		DHCP_mode=`cat $CONF_FILE|grep DHCP=|cut -d"=" -f2`
187
		if [ $DHCP_mode = "on" ]; then
945 richard 188
			$SED "s?^DHCP=on.*?DHCP=full?" $CONF_FILE	# DHCP option can be "off/half/full" since V2.6
862 richard 189
		fi
977 richard 190
# le paramêtre 'EXT_LAN_FILTERING' n'existe plus
885 richard 191
		$SED "/^EXT_LAN/d" $CONF_FILE
977 richard 192
# la catégorie de sites filtrés "ip" n'existe plus
878 richard 193
		$SED "/\/ip\/urls/d" $DIR_UPDATE/bannedurllist;	$SED "/\/ip\/domains/d" $DIR_UPDATE/bannedsitelist
885 richard 194
		$SED "/blacklists\/ip/d" $DIR_UPDATE/etc/alcasar-bl-categories; $SED "/^ip/d" $DIR_UPDATE/etc/alcasar-bl-categories-enabled
1015 richard 195
# les bl et wl de dnsmasq sont reconstruites dynamiquement dans /usr/local/share
196
		rm -rf $DIR_UPDATE/etc/alcasar-dnsfilter-enabled $DIR_UPDATE/etc/alcasar-dnsfilter-available
977 richard 197
# bing et Youtube sont ajoutés au safesearching
885 richard 198
		Bing=`grep bing $DIR_UPDATE/urlregexplist | wc -l`
199
		if [ $Bing -ne "1" ]; then
200
			SafeSearch=`grep ^\"\(\^http\:\/\/ $DIR_UPDATE/urlregexplist | wc -l`
201
			if [ $SafeSearch -eq "0" ]; then
202
			cat <<EOF >> $DIR_UPDATE/urlregexplist
203
# Bing - add 'adlt=strict'
204
#"(^http://[0-9a-z]+\.bing\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&adlt=strict"
205
# Youtube - add 'edufilter=your_ID' 
206
#"(^http://[0-9a-z]+\.youtube\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&edufilter=ABCD1234567890abcdef"
207
EOF
208
			else
209
			cat <<EOF >> $DIR_UPDATE/urlregexplist
210
# Bing - add 'adlt=strict'
211
"(^http://[0-9a-z]+\.bing\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&adlt=strict"
212
# Youtube - add 'edufilter=your_ID' 
213
"(^http://[0-9a-z]+\.youtube\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&edufilter=ABCD1234567890abcdef"
214
EOF
215
			fi
216
		fi
977 richard 217
# la variable YOUTUBE_ID est déclarée dans le fichier de conf
885 richard 218
	YOUTUBE_ID=`grep ^YOUTUBE_ID $CONF_FILE | cut -d"=" -f2`
219
	YOUTUBE_ID=${YOUTUBE_ID:="-1"}
220
	if [ $YOUTUBE_ID = "-1" ]; then
221
		echo "YOUTUBE_ID=ABCD1234567890abcdef" >> $CONF_FILE
222
	fi
933 franck 223
	 	cp /etc/sysconfig/dnsmasq $DIR_UPDATE
885 richard 224
# copie du fichier de conf modifié
225
	cp $CONF_FILE $DIR_UPDATE/etc/
806 richard 226
# le répertoire "ISO" est remplacé par "system_backup" suite à la suppression de "mondoarchive" (V2.5)
227
		rm -rf /var/Save/ISO
228
# création de l'archive et copie dans le répertoire WEB associé
8 franck 229
		cd /tmp
230
		tar -cf alcasar-conf.tar conf/
231
		gzip -f alcasar-conf.tar
811 richard 232
		[ -d $DIR_SAVE ] && cp alcasar-conf.tar.gz $DIR_SAVE/$fichier
8 franck 233
		rm -rf $DIR_UPDATE
234
		;;
389 franck 235
	--load|-load)
8 franck 236
		cd /tmp
30 richard 237
		tar -xf /tmp/alcasar-conf.tar.gz
978 franck 238
# récupération du fichier général de dnsmasq en attendant sa correction du bug pour les DNS externes
239
		[ -e $DIR_UPDATE/dnsmasq ] && cp -f $DIR_UPDATE/dnsmasq /etc/sysconfig/dnsmasq \
240
		&& chown root.root /etc/sysconfig/dnsmasq \
241
		&& chmod 644 /etc/sysconfig/dnsmasq
8 franck 242
# Récupération du logo
510 richard 243
		[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
8 franck 244
		chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
245
# Récupération des certificats (CA et serveur)
510 richard 246
		[ -e $DIR_UPDATE/alcasar-ca.crt ] && cp -f $DIR_UPDATE/alcasar-ca.crt /etc/pki/CA/
247
		[ -e $DIR_UPDATE/alcasar-ca.key ] && cp -f $DIR_UPDATE/alcasar-ca.key /etc/pki/CA/private/
248
		[ -e $DIR_UPDATE/alcasar.crt ] && cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
249
		[ -e $DIR_UPDATE/alcasar.key ] && cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
675 richard 250
		[ -e $DIR_UPDATE/server-chain.crt ] &&	cp -f $DIR_UPDATE/server-chain.crt /etc/pki/tls/certs/
8 franck 251
		chown -R root:apache /etc/pki
252
		chmod -R 750 /etc/pki
253
# Import de la dernière base usagers
254
		mysql -u$DB_USER -p$radiuspwd < `ls $DIR_UPDATE/radius*`
612 richard 255
# Récupération des paramêtres locaux (fichier de conf, règles de filtrage, fichiers d'exception, comptes de gestion, etc.)
256
		[ -d $DIR_UPDATE/etc ] && cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
310 richard 257
# Récupération des fichiers de Dansguardian
510 richard 258
		[ -e $DIR_UPDATE/exceptioniplist ] && cp -f $DIR_UPDATE/exceptioniplist /etc/dansguardian/lists/
259
		[ -e $DIR_UPDATE/exceptionsitelist ] && cp -f $DIR_UPDATE/exceptionsitelist /etc/dansguardian/lists/
879 richard 260
		[ -e $DIR_UPDATE/urlregexplist ] && cp -f $DIR_UPDATE/urlregexplist /etc/dansguardian/lists/
510 richard 261
		[ -e $DIR_UPDATE/bannedsitelist ] && cp -f $DIR_UPDATE/bannedsitelist /etc/dansguardian/lists/ 
262
		[ -e $DIR_UPDATE/exceptionurllist ] && cp -f $DIR_UPDATE/exceptionurllist /etc/dansguardian/lists/
263
		[ -e $DIR_UPDATE/bannedurllist ] && cp -f $DIR_UPDATE/bannedurllist /etc/dansguardian/lists/
264
		[ -d $DIR_UPDATE/ossi ] && cp -rf $DIR_UPDATE/ossi /etc/dansguardian/lists/blacklists/
8 franck 265
		chown -R dansguardian:apache /etc/dansguardian/lists
266
		chmod -R g+rw /etc/dansguardian/lists
634 richard 267
# Start / Stop DNS/URL filtering
637 richard 268
		PARENT_SCRIPT=$0
269
		export PARENT_SCRIPT
654 richard 270
		$DIR_SBIN/alcasar-bl.sh -reload
933 franck 271
		[ -e $DIR_UPDATE/dnsmasq ] && cp -f $DIR_UPDATE/dnsmasq /etc/sysconfig/dnsmasq
434 richard 272
# Prise en compte des comptes de gestion (admin + manager + backup)
395 franck 273
		$DIR_SBIN/alcasar-profil.sh --list
634 richard 274
# Start / Stop SSH Daemon
275
		ssh_active=`grep SSH $CONF_FILE|cut -d"=" -f2`
276
		if [ $ssh_active = "on" ]
277
		then
278
			/sbin/chkconfig --add sshd
279
		else
280
			/sbin/chkconfig --del sshd
281
		fi
226 franck 282
# Effacement du répertoire d'update
8 franck 283
		rm -rf $DIR_UPDATE
284
		;;
628 richard 285
	--apply|-apply)
994 franck 286
		PTN="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/([012]?[0-9]|3[0-2])\b"
628 richard 287
		PRIVATE_IP_MASK=`grep PRIVATE_IP $CONF_FILE|cut -d"=" -f2`
288
		check=$(echo $PRIVATE_IP_MASK | egrep $PTN)
289
		if [[ "$?" -ne 0 ]]
290
		then 
291
			echo "Syntax error for PRIVATE_IP_MASK ($PRIVATE_IP_MASK)"
292
			exit 0
293
		fi
294
		PUBLIC_IP_MASK=`grep PUBLIC_IP $CONF_FILE|cut -d"=" -f2`
295
		check=$(echo $PUBLIC_IP_MASK | egrep $PTN)
296
		if [[ "$?" -ne 0 ]]
297
		then 
298
			echo "Syntax error for PUBLIC_IP_MASK ($PUBLIC_IP_MASK)"
299
			exit 0
300
		fi
301
		PTN="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
302
		PUBLIC_GATEWAY=`grep GW $CONF_FILE|cut -d"=" -f2`
303
		check=$(echo $PUBLIC_GATEWAY | egrep $PTN)
304
		if [[ "$?" -ne 0 ]]
305
			then 
306
			echo "Syntax error for the Gateway IP ($PUBLIC_GATEWAY)"
307
			exit 0
308
		fi
309
		DNS1=`grep DNS1 $CONF_FILE|cut -d"=" -f2`
673 richard 310
		check=$(echo $DNS1 | egrep $PTN)
628 richard 311
		if [[ "$?" -ne 0 ]]
312
		then 
313
			echo "Syntax error for the IP address of the first DNS server ($DNS1)"
314
			exit 0
315
		fi
316
		DNS2=`grep DNS2 $CONF_FILE|cut -d"=" -f2`
673 richard 317
		check=$(echo $DNS2 | egrep $PTN)
628 richard 318
		if [[ "$?" -ne 0 ]]
319
		then 
320
			echo "Syntax error for the IP address of the second DNS server ($DNS2)"
321
			exit 0
322
		fi
632 richard 323
		PUBLIC_IP=`echo $PUBLIC_IP_MASK | cut -d"/" -f1`
324
		PUBLIC_NETMASK=`/bin/ipcalc -m $PUBLIC_IP_MASK | cut -d"=" -f2`
631 richard 325
		PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
632 richard 326
		PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
628 richard 327
		private_network_calc
632 richard 328
		VERSION=`grep VERSION $CONF_FILE|cut -d"=" -f2`
329
		INSTALL_DATE=`grep INSTALL_DATE $CONF_FILE|cut -d"=" -f2`
330
		ORGANISME=`grep ORGANISM $CONF_FILE|cut -d"=" -f2`
923 franck 331
 		DOMAIN=`grep DOMAIN $CONF_FILE|cut -d"=" -f2`
862 richard 332
		DHCP_mode=`grep DHCP= $CONF_FILE|cut -d"=" -f2`
933 franck 333
		if [ $DHCP_mode = "off" ]
334
		then
335
		    $DIR_SBIN/alcasar-dhcp.sh --off
336
		fi
634 richard 337
# Logout everybody
338
		$DIR_SBIN/alcasar-logout.sh all		
339
# Services stop
923 franck 340
		for i in squid ntpd chilli httpd network
634 richard 341
		do
342
			[ -e /etc/init.d/$i ] && /etc/init.d/$i stop && killall $i 2>/dev/null
343
		done
628 richard 344
 
345
# /etc/hosts
346
		cat <<EOF > /etc/hosts
347
127.0.0.1	localhost
923 franck 348
$PRIVATE_IP	$HOSTNAME $HOSTNAME.$DOMAIN
628 richard 349
EOF
350
 
811 richard 351
# Ext Network Card config
628 richard 352
		$SED "s?^IPADDR=.*?IPADDR=$PUBLIC_IP?" /etc/sysconfig/network-scripts/ifcfg-$EXTIF
353
		$SED "s?^NETMASK=.*?NETMASK=$PUBLIC_NETMASK?" /etc/sysconfig/network-scripts/ifcfg-$EXTIF
354
		$SED "s?^GATEWAY=.*?GATEWAY=$PUBLIC_GATEWAY?" /etc/sysconfig/network-scripts/ifcfg-$EXTIF
355
# NTP server
632 richard 356
		$SED "/127.0.0.1/!s?^restrict.*?restrict $PRIVATE_NETWORK mask $PRIVATE_NETMASK nomodify notrap?g" /etc/ntp.conf
628 richard 357
# host.allow 
358
		cat <<EOF > /etc/hosts.allow
359
ALL: LOCAL, 127.0.0.1, localhost, $PRIVATE_IP
360
sshd: ALL
361
ntpd: $PRIVATE_NETWORK_SHORT
362
EOF
632 richard 363
# Alcasar Control Center
634 richard 364
		echo "$VERSION du $INSTALL_DATE" > /var/www/html/VERSION; chown apache:apache /var/www/html/VERSION
365
		$SED "s?^Listen.*?Listen $PRIVATE_IP:80?g" /etc/httpd/conf/httpd.conf
366
		FIC_MOD_SSL=`find /etc/httpd/modules.d/ -type f -name *mod_ssl.conf`
367
		$SED "s?^Listen.*?Listen $PRIVATE_IP:443?g" $FIC_MOD_SSL
368
		$SED "/127.0.0.1/!s?Allow from .*?Allow from $PRIVATE_NETWORK_MASK?g" /etc/httpd/conf/webapps.d/alcasar.conf
632 richard 369
# Dialup_Admin
634 richard 370
		$SED "s?^nas1_name:.*?nas1_name: alcasar-$ORGANISME?g" /etc/freeradius-web/naslist.conf
371
		$SED "s?^nas1_ip:.*?nas1_ip: $PRIVATE_IP?g" /etc/freeradius-web/naslist.conf
632 richard 372
# coova
634 richard 373
		$SED "s?ifconfig.*?ifconfig \$HS_LANIF $PRIVATE_IP?g" /etc/init.d/chilli
374
		$SED "s?^net.*?net\t\t$PRIVATE_NETWORK_MASK?g" /etc/chilli.conf
375
		$SED "s?^dns1.*?dns1\t\t$PRIVATE_IP?g" /etc/chilli.conf
376
		$SED "s?^dns2.*?dns2\t\t$PRIVATE_IP?g" /etc/chilli.conf
377
		$SED "s?^uamlisten.*?uamlisten\t$PRIVATE_IP?g" /etc/chilli.conf
378
		$SED "s?^\$organisme = .*?\$organisme = \"$ORGANISME\";?g" /var/www/html/intercept.php /var/www/html/status.php
862 richard 379
# dhcp (coova + dnsmasq)
380
		$DIR_SBIN/alcasar-dhcp.sh -$DHCP_mode
632 richard 381
# awstat
634 richard 382
		$SED "s?^HostAliases=.*?HostAliases=\"$PRIVATE_IP\"?g" /etc/awstats/awstats.conf
632 richard 383
# dnsmasq
634 richard 384
		$SED "/127.0.0.1/!s?^listen-address=.*?listen-address=$PRIVATE_IP?g" /etc/dnsmasq.conf /etc/dnsmasq-blackhole.conf
673 richard 385
		for i in /etc/dnsmasq.conf /etc/dnsmasq-blackhole.conf
386
		do
387
			$SED "/^server=/d" $i
388
			echo "server=$DNS1" >> $i
389
			echo "server=$DNS2" >> $i
390
		done
1020 franck 391
		$SED "s?^dhcp-range=.*?dhcp-range=$PRIVATE_IP,192.168.180.254,$PRIVATE_NETMASK,12h?g" /etc/dnsmasq.conf
634 richard 392
		$SED "s?^dhcp-option=option:router.*?dhcp-option=option:router,$PRIVATE_IP?g" /etc/dnsmasq.conf
393
# DG + BL
394
		$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/dansguardian/dansguardian.conf
395
# Watchdog
396
		$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
397
# SSHD
1024 franck 398
		$SED "/^ListenAddress/d" /etc/ssh/sshd_config
1020 franck 399
#		$SED "s?^#ListenAddress 0\.0\.0\.0?ListenAddress $PRIVATE_IP?g" /etc/ssh/sshd_config
1024 franck 400
		$SED "/ListenAddress 0.0.0.0.*/a\ListenAddress $PUBLIC_IP" /etc/ssh/sshd_config
1020 franck 401
		$SED "/ListenAddress $PUBLIC_IP/a\ListenAddress $PRIVATE_IP" /etc/ssh/sshd_config
634 richard 402
# Prompts
403
		$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
404
# sudoers
405
		$SED "s?^Host_Alias.*?Host_Alias	LAN_ORG=$PRIVATE_NETWORK/$PRIVATE_NETMASK,localhost		#réseau de l'organisme?g" /etc/sudoers
406
# Services start
407
		for i in network squid ntpd chilli httpd 
408
		do
409
			[ -e /etc/init.d/$i ] && /etc/init.d/$i start 2>/dev/null
410
		done
628 richard 411
# Start / Stop SSH Daemon
634 richard 412
		ssh_active=`grep SSH $CONF_FILE|cut -d"=" -f2`
413
		if [ $ssh_active = "on" ]
414
		then
415
			/sbin/chkconfig --add sshd
416
			/etc/init.d/sshd start
417
		else
418
			/sbin/chkconfig --del sshd
923 franck 419
			echo "Au redémarrage du serveur, le service SSH sera désactivé !!! ; au besoin l'activer dans l'interface de gestion."
420
			sleep 2
634 richard 421
		fi
422
# Reload BL (restart DG, dnsmasq & iptables)
423
		$DIR_SBIN/alcasar-bl.sh -reload
628 richard 424
		;;
8 franck 425
	*)
426
		echo "Argument inconnu :$1";
427
		echo "$usage"
428
		exit 1
429
		;;
430
esac
431