Subversion Repositories ALCASAR

Rev

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