Subversion Repositories ALCASAR

Rev

Rev 2561 | Rev 2567 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2223 tom.houday 1
#!/bin/bash
64 franck 2
# $Id: alcasar-conf.sh 2566 2018-07-09 22:19:53Z rexy $
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 
2560 rexy 9
#	- création de l'archive des fichiers de configuration "/var/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
2327 richard 10
#	- chargement de l'archive de fichiers de configuration lors de la mise à jour d'un alcasar (alcasar-conf -load). Le cas échéant, c'est ici qu'on met à jour les fichiers entre versions 
1758 richard 11
#	- application des directives du fichier de conf central "/usr/local/etc/alcasar.conf" lors d'un changement de conf réseau à chaud (alcasar-conf -apply) 
672 richard 12
# This script allows ALCASAR update 
2560 rexy 13
#	- create the configuration files backup "/var/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
2327 richard 14
#	- load the backup of configuration files during the update process (alcasar-conf -load). If needed, it's here we update files between versions
1758 richard 15
#	- apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf" when hot modification is needed (alcasar-conf -apply)
672 richard 16
 
2247 tom.houday 17
new="$(date +%G%m%d-%Hh%M)"  				# date et heure des fichiers
18
fichier="alcasar-conf-$new.tar.gz"			# nom du fichier de sauvegarde
2560 rexy 19
DIR_UPDATE="/var/tmp/conf"					# répertoire de stockage des fichier de conf pour une mise à jour
2247 tom.houday 20
DIR_WEB="/var/www/html"					# répertoire du centre de gestion
21
DIR_BIN="/usr/local/bin"				# scripts directory
22
DIR_ETC="/usr/local/etc"				# conf directory
23
DIR_SHARE="/usr/local/share"				# data directory
2521 armand.ito 24
DIR_BLACKLIST="/etc/e2guardian/lists/blacklists"	# Toulouse BL directory
2247 tom.houday 25
CONF_FILE="$DIR_ETC/alcasar.conf"			# main alcasar conf file
26
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2`		# EXTernal InterFace
27
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`		# INTernal InterFace
28
MTU=`grep ^PUBLIC_MTU= $CONF_FILE|cut -d"=" -f2`
1890 franck 29
DHCP_mode=`grep ^DHCP= $CONF_FILE|cut -d"=" -f2`
30
INT_DNS_mode=`grep ^INT_DNS_ACTIVE= $CONF_FILE|cut -d"=" -f2`
31
LDAP_mode=`grep ^LDAP= $CONF_FILE|cut -d"=" -f2`
2247 tom.houday 32
HOSTNAME=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
33
DOMAIN=`grep ^DOMAIN= $CONF_FILE|cut -d"=" -f2`
2412 tom.houday 34
PASSWD_FILE="/root/ALCASAR-passwords.txt"
35
DB_USER=$(grep '^db_user=' $PASSWD_FILE | cut -d'=' -f 2-)
36
DB_PASS=$(grep '^db_password=' $PASSWD_FILE | cut -d'=' -f 2-)
384 richard 37
SED="/bin/sed -i"
2474 tom.houday 38
DNS1=`grep ^DNS1= $CONF_FILE | cut -d'=' -f2` 			# server DNS1 (for WL domain names)
923 franck 39
DOMAIN=${DOMAIN:=localdomain}
628 richard 40
DATE=`date '+%d %B %Y - %Hh%M'`
2247 tom.houday 41
 
628 richard 42
private_network_calc ()
43
{
1060 richard 44
	PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`				# prefixe du réseau (ex. 24)
2561 rexy 45
	PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`			# @ réseau de consultation (ex.: 192.168.182.0)
46
	PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX									# @ + masque du réseau de consult (192.168.182.0/24)
628 richard 47
	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 48
	PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`.					# @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
49
	PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2`				# private network broadcast (ie.: 192.168.182.255)
50
	private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup`				# last octet of LAN address
2561 rexy 51
	private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup`			# last octet of LAN broadcast
52
	private_ip_ending=`echo $PRIVATE_IP | cut -d"." -f4`									# last octet of LAN address
53
	PRIVATE_FIRST_IP=$PRIVATE_IP															# First network address (ex.: 192.168.182.1)
54
	PRIVATE_SECOND_IP=`echo $PRIVATE_IP | cut -d"." -f1-3`"."`expr $private_ip_ending + 1`	# second network address (ex.: 192.168.182.2)
1060 richard 55
	PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1`	# last network address (ex.: 192.168.182.254)
1581 richard 56
	PRIVATE_MAC=`/sbin/ip link show $INTIF | grep ether | cut -d" " -f6| sed 's/:/-/g'| awk '{print toupper($0)}'`	# MAC address of INTIF
628 richard 57
}
8 franck 58
 
933 franck 59
usage="Usage: alcasar-conf.sh {--create or -create} | {--load or -load} | {--apply or -apply}"
8 franck 60
nb_args=$#
61
args=$1
62
if [ $nb_args -eq 0 ]
63
then
2430 tom.houday 64
	nb_args=1
8 franck 65
	args="-h"
66
fi
67
case $args in
68
	-\? | -h* | --h*)
69
		echo "$usage"
70
		exit 0
71
		;;
389 franck 72
	--create|-create)	
8 franck 73
		[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
74
		mkdir $DIR_UPDATE
1916 franck 75
# backup the users database  (test to delete in future version)
1918 franck 76
		if [ -e $DIR_BIN/alcasar-mysql.sh ]; then
77
			$DIR_BIN/alcasar-mysql.sh --dump
1916 franck 78
		else
79
			/usr/local/sbin/alcasar-mysql.sh --dump
80
		fi
1777 richard 81
		cp /var/Save/base/`ls -1t /var/Save/base|head -1` $DIR_UPDATE
1758 richard 82
# backup the logo
8 franck 83
		cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
1912 richard 84
# backup BL/WL custom files
1914 richard 85
		mkdir $DIR_UPDATE/custom_bl
2541 rexy 86
		for i in exceptioniplist urlregexplist exceptionsitelist bannedsitelist exceptionurllist bannedurllist
87
		do
2561 rexy 88
			if [ -d /etc/dansguardian ]; then  # before V3.3
2541 rexy 89
				cp /etc/dansguardian/lists/$i $DIR_UPDATE/custom_bl/
90
			else
2561 rexy 91
				cp /etc/e2guardian/lists/$i $DIR_UPDATE/custom_bl/ # since V3.3
2541 rexy 92
			fi
93
		done
1961 richard 94
		cp -rf $DIR_BLACKLIST/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
2560 rexy 95
# backup of different conf files (main conf file, filtering, digest, /etc/hosts, etc.)
8 franck 96
		mkdir $DIR_UPDATE/etc/
346 richard 97
		cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
2560 rexy 98
		cp /etc/hosts $DIR_UPDATE/etc/
1758 richard 99
# backup of the security certificates (server & CA)
2561 rexy 100
		cp -f /etc/pki/tls/certs/alcasar.crt* $DIR_UPDATE
101
		cp -f /etc/pki/tls/private/alcasar.key* $DIR_UPDATE
2566 rexy 102
		cp -f /etc/pki/tls/private/alcasar.pem $DIR_UPDATE
1564 richard 103
		cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
104
		cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
105
		if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
2244 tom.houday 106
			cp -f /etc/pki/tls/certs/server-chain.crt* $DIR_UPDATE # autosigned and official if exist
510 richard 107
		else
1564 richard 108
			cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.crt
510 richard 109
		fi
1758 richard 110
# archive file creation
2560 rexy 111
		cd /var/tmp
8 franck 112
		tar -cf alcasar-conf.tar conf/
113
		gzip -f alcasar-conf.tar
114
		rm -rf $DIR_UPDATE
115
		;;
2560 rexy 116
 
389 franck 117
	--load|-load)
2560 rexy 118
		cd /var/tmp
119
		tar -xf alcasar-conf*.tar.gz
2561 rexy 120
# Extract the previous version
121
		PREVIOUS_VERSION=`grep ^VERSION= $DIR_UPDATE/etc/alcasar.conf|cut -d"=" -f2`
122
		MAJ_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f1`
123
		MIN_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f2`
124
		UPD_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f3|cut -c1`
1060 richard 125
# Retrieve the logo
510 richard 126
		[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
8 franck 127
		chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
1060 richard 128
# Retrieve the security certificates (CA and server)
2561 rexy 129
		cp -f $DIR_UPDATE/alcasar-ca.crt* /etc/pki/CA/
130
		cp -f $DIR_UPDATE/alcasar-ca.key* /etc/pki/CA/private/
1758 richard 131
		cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
132
		cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
2566 rexy 133
		cp -f $DIR_UPDATE/alcasar.pem /etc/pki/tls/private/	
2554 lucas.echa 134
		(cat /etc/pki/tls/private/alcasar.key; echo; cat /etc/pki/tls/certs/alcasar.crt) > /etc/pki/tls/private/alcasar.pem
2244 tom.houday 135
		[ -e $DIR_UPDATE/server-chain.crt ] && cp -f $DIR_UPDATE/server-chain.crt* /etc/pki/tls/certs/ # autosigned and official if exist
8 franck 136
		chown -R root:apache /etc/pki
137
		chmod -R 750 /etc/pki
1060 richard 138
# Import of the users database
2412 tom.houday 139
		gzip -dc < `ls $DIR_UPDATE/alcasar-users-database*` | mysql -u$DB_USER -p$DB_PASS
1914 richard 140
# Retrieve local parameters
2561 rexy 141
		cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
2560 rexy 142
		mv -f $DIR_ETC/hosts /etc/hosts
1914 richard 143
# Retrieve BL/WL custom files
2521 armand.ito 144
		cp -f $DIR_UPDATE/custom_bl/exceptioniplist /etc/e2guardian/lists/
145
		cp -f $DIR_UPDATE/custom_bl/exceptionsitelist /etc/e2guardian/lists/
146
		cp -f $DIR_UPDATE/custom_bl/urlregexplist /etc/e2guardian/lists/
147
		cp -f $DIR_UPDATE/custom_bl/bannedsitelist /etc/e2guardian/lists/ 
148
		cp -f $DIR_UPDATE/custom_bl/exceptionurllist /etc/e2guardian/lists/
149
		cp -f $DIR_UPDATE/custom_bl/bannedurllist /etc/e2guardian/lists/
1961 richard 150
		cp -rf $DIR_UPDATE/custom_bl/ossi-* $DIR_BLACKLIST/ 2>/dev/null
2521 armand.ito 151
		chown -R e2guardian:apache /etc/e2guardian/lists
152
		chmod -R g+rw /etc/e2guardian/lists
1060 richard 153
# Adapt DNS/URL filtering
154
		PARENT_SCRIPT=`basename $0`
637 richard 155
		export PARENT_SCRIPT
1946 richard 156
		$DIR_BIN/alcasar-bl.sh -cat_choice
1827 raphael.pi 157
		$DIR_BIN/alcasar-bl.sh -reload
1060 richard 158
# admin profile update (admin + manager + backup)
1827 raphael.pi 159
		$DIR_BIN/alcasar-profil.sh --list
634 richard 160
# Start / Stop SSH Daemon
2327 richard 161
		ssh_active=`grep "^SSH=" $CONF_FILE|cut -d"=" -f2`
634 richard 162
		if [ $ssh_active = "on" ]
163
		then
1574 richard 164
			/usr/bin/systemctl -q enable sshd.service
634 richard 165
		else
1574 richard 166
			/usr/bin/systemctl -q disable sshd.service
634 richard 167
		fi
1060 richard 168
# Remove the update folder
8 franck 169
		rm -rf $DIR_UPDATE
2560 rexy 170
#########################   modifications between versions  #######################
171
##  From 3.2.0 & 3.2.1  ##
2561 rexy 172
		if [ $MAJ_PREVIOUS_VERSION == "3" ] && [ $MIN_PREVIOUS_VERSION == "2" ]
2327 richard 173
		then
2560 rexy 174
			## rewrite the file managing domain name resolution (local & remote). Hostnames resolutions are now in /etc/hosts
175
			cat << EOF > $DIR_ETC/alcasar-dns-name
176
# Vous pouvez définir ici votre nom de domain local ('localdomain' par défaut)
177
# Here you can define your local domain name ('localdomain' by default)
178
local=/$DOMAIN/
179
domain=$DOMAIN
180
 
181
## Ajouter une ligne pour chaque nom de domaine géré par un autre seveur DNS
182
## Add one line for each domain name managed by an other DNS server
183
## server=/<your_domain>/<@IP_domain_server>
184
## Exemple for an A.D. domain :  server=/Your.Domain.AD/110.120.100.100
185
## Exemple for an other domain : server=/an_other_domain/10.20.30.40
186
 
187
## INFO : local hostnames are resolved in /etc/hosts file
188
EOF
189
			## rewrite /etc/hosts file managing hostname resolution
190
			PRIVATE_IP=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2|cut -d"/" -f1`
191
			HOSTNAME=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
192
			cat << EOF > /etc/hosts
193
127.0.0.1	localhost
194
$PRIVATE_IP	$HOSTNAME
195
EOF
2561 rexy 196
			# apache & dansguardian are replaced with lighttpd & E²guardian
197
			rm_rpm="apache apache-mod_php apache-mod_ssl dansguardian"
198
			/usr/sbin/urpme --auto -a $rm_rpm
199
			/usr/sbin/urpme --auto --auto-orphans
200
			rm -rf /etc/httpd/ /var/log/httpd/ /var/dansguardian/ /etc/dansguardian/
2566 rexy 201
			# lighttpd need a .pem certificate (aggregation with server crt & private key)
202
			(cat /etc/pki/tls/private/alcasar.key; echo; cat /etc/pki/tls/certs/alcasar.crt) > /etc/pki/tls/private/alcasar.pem
2327 richard 203
		fi
8 franck 204
		;;
2560 rexy 205
 
628 richard 206
	--apply|-apply)
994 franck 207
		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"
2474 tom.houday 208
		PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
628 richard 209
		check=$(echo $PRIVATE_IP_MASK | egrep $PTN)
210
		if [[ "$?" -ne 0 ]]
211
		then 
212
			echo "Syntax error for PRIVATE_IP_MASK ($PRIVATE_IP_MASK)"
213
			exit 0
214
		fi
2474 tom.houday 215
		PUBLIC_IP_MASK=`grep ^PUBLIC_IP= $CONF_FILE|cut -d"=" -f2`
1590 richard 216
		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"
1585 richard 217
		if [[ "$PUBLIC_IP_MASK" == "dhcp" ]]
218
		then
219
			PUBLIC_GATEWAY="dhcp"
1590 richard 220
 
1585 richard 221
		else
222
			check=$(echo $PUBLIC_IP_MASK | egrep $PTN)
223
			if [[ "$?" -ne 0 ]]
628 richard 224
			then 
1585 richard 225
				echo "Syntax error for PUBLIC_IP_MASK ($PUBLIC_IP_MASK)"
226
				exit 0
227
			fi
1590 richard 228
			PUBLIC_IP=`echo $PUBLIC_IP_MASK | cut -d"/" -f1`
229
			PUBLIC_NETMASK=`/bin/ipcalc -m $PUBLIC_IP_MASK | cut -d"=" -f2`
2474 tom.houday 230
			PUBLIC_GATEWAY=`grep ^GW= $CONF_FILE|cut -d"=" -f2`
1585 richard 231
			check=$(echo $PUBLIC_GATEWAY | egrep $PTN)
232
			if [[ "$?" -ne 0 ]]
233
			then 
234
				echo "Syntax error for the Gateway IP ($PUBLIC_GATEWAY)"
235
				exit 0
236
			fi
628 richard 237
		fi
2474 tom.houday 238
		DNS1=`grep ^DNS1= $CONF_FILE|cut -d"=" -f2`
1590 richard 239
		check=$(echo $DNS1 | egrep $PTN)
240
		if [[ "$?" -ne 0 ]]
241
		then 
242
			echo "Syntax error for the IP address of the first DNS server ($DNS1)"
243
			exit 0
244
		fi
2474 tom.houday 245
		DNS2=`grep ^DNS2= $CONF_FILE|cut -d"=" -f2`
1590 richard 246
		check=$(echo $DNS2 | egrep $PTN)
247
		if [[ "$?" -ne 0 ]]
248
		then 
249
			echo "Syntax error for the IP address of the second DNS server ($DNS2)"
250
			exit 0
251
		fi
631 richard 252
		PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
632 richard 253
		PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
628 richard 254
		private_network_calc
2474 tom.houday 255
		INSTALL_DATE=`grep ^INSTALL_DATE= $CONF_FILE|cut -d"=" -f2`
256
		ORGANISME=`grep ^ORGANISM= $CONF_FILE|cut -d"=" -f2-`
257
		DHCP_mode=`grep ^DHCP= $CONF_FILE|cut -d"=" -f2`
1060 richard 258
		if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
933 franck 259
		then
1890 franck 260
			if [ $DHCP_mode = "off" ] || [ $DHCP_mode = "Off" ] || [ $DHCP_mode = "OFF" ]
1060 richard 261
			then
1827 raphael.pi 262
				$DIR_BIN/alcasar-dhcp.sh --off
1890 franck 263
			else
264
			        $DIR_BIN/alcasar-dhcp.sh --on
1060 richard 265
			fi
1806 franck 266
 
267
# Implementation of the local DNS
1890 franck 268
			if [ $INT_DNS_mode = "on" ] || [ $INT_DNS_mode = "On" ] || [ $INT_DNS_mode = "ON" ]
269
			then
270
				$DIR_BIN/alcasar-dns-local.sh --on
271
			else
272
				$DIR_BIN/alcasar-dns-local.sh --off
273
			fi
1806 franck 274
 
1694 franck 275
# Implementation of the authentification LDAP
1890 franck 276
#			if [ LDAP_mode = "on" ] || [ $LDAP_mode = "On" ] || [ $LDAP_mode = "ON" ]
277
#			then
278
#				$DIR_BIN/alcasar-ldap.sh
279
#			fi
1611 franck 280
 
1585 richard 281
# Logout everybody
1827 raphael.pi 282
			$DIR_BIN/alcasar-logout.sh all		
1585 richard 283
# Services stop
1521 richard 284
			echo -n "Stop services : "
2488 lucas.echa 285
			for i in ntpd tinyproxy dnsmasq dnsmasq-whitelist dnsmasq-blacklist dnsmasq-blackhole chilli network lighttpd
1060 richard 286
			do
1574 richard 287
				/usr/bin/systemctl stop $i && echo -n "$i, "
1060 richard 288
			done
1521 richard 289
			echo
1060 richard 290
		fi
1518 richard 291
# EXTIF config
1585 richard 292
		if [ $PUBLIC_IP_MASK == "dhcp" ]
293
		then
294
			cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
295
DEVICE=$EXTIF
296
BOOTPROTO=dhcp
297
DNS1=127.0.0.1
298
PEERDNS=no
299
RESOLV_MODS=yes
300
ONBOOT=yes
301
METRIC=10
302
MII_NOT_SUPPORTED=yes
303
IPV6INIT=no
304
IPV6TO4INIT=no
305
ACCOUNTING=no
306
USERCTL=no
307
MTU=$MTU
1850 franck 308
NOZEROCONF=yes
1585 richard 309
EOF
310
		else	
311
			cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
312
DEVICE=$EXTIF
313
BOOTPROTO=static
314
IPADDR=$PUBLIC_IP
315
NETMASK=$PUBLIC_NETMASK
316
GATEWAY=$PUBLIC_GATEWAY
317
DNS1=127.0.0.1
318
RESOLV_MODS=yes
319
ONBOOT=yes
320
METRIC=10
321
MII_NOT_SUPPORTED=yes
322
IPV6INIT=no
323
IPV6TO4INIT=no
324
ACCOUNTING=no
325
USERCTL=no
326
MTU=$MTU
1850 franck 327
NOZEROCONF=yes
1585 richard 328
EOF
329
		fi
1518 richard 330
# INTIF config (for bypass mode only)
1554 richard 331
		$SED "s?^IPADDR=.*?IPADDR=$PRIVATE_IP?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
332
		$SED "s?^NETMASK=.*?NETMASK=$PRIVATE_NETMASK?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
628 richard 333
# NTP server
632 richard 334
		$SED "/127.0.0.1/!s?^restrict.*?restrict $PRIVATE_NETWORK mask $PRIVATE_NETMASK nomodify notrap?g" /etc/ntp.conf
628 richard 335
# host.allow 
336
		cat <<EOF > /etc/hosts.allow
337
ALL: LOCAL, 127.0.0.1, localhost, $PRIVATE_IP
338
sshd: ALL
339
ntpd: $PRIVATE_NETWORK_SHORT
340
EOF
2309 tom.houday 341
# Set hostname
342
		hostnamectl set-hostname $HOSTNAME.$DOMAIN
343
# /etc/hosts
344
		cat <<EOF > /etc/hosts
345
127.0.0.1	localhost
2560 rexy 346
$PRIVATE_IP	$HOSTNAME
2309 tom.houday 347
EOF
348
# Set hostname in CoovaChilli
349
		$SED "s/^uamallowed.*/uamallowed\t${domainNames// /,}/g" /etc/chilli.conf
350
		$SED "s/^locationname.*/locationname\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
2324 tom.houday 351
		[ `grep ^HTTPS_LOGIN= $CONF_FILE | cut -d'=' -f2` == "on" ] && chilli_login_protocol="https" || chilli_login_protocol="http"
352
		$SED "s/^uamserver.*/uamserver\t$chilli_login_protocol:\/\/$HOSTNAME.$DOMAIN\/intercept.php/" /etc/chilli.conf
2309 tom.houday 353
		$SED "s/^radiusnasid.*/radiusnasid\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
2488 lucas.echa 354
# Set hostname in Lighttpd
355
		$SED "s?^server\.bind.*?server\.bind = \"$HOSTNAME.$DOMAIN\"?g" /etc/lighttpd/lighttpd.conf
356
		$SED 's/^$SERVER\["socket"\] == ".*:443.*/$SERVER\["socket"\] == "'"$HOSTNAME.$DOMAIN"':443" {/g' /etc/lighttpd/vhosts.d/alcasar.conf
357
		$SED "s/^\([\t ]*\)var.server_name.*/\1var.server_name = \"$HOSTNAME.$DOMAIN\"/g" /etc/lighttpd/vhosts.d/alcasar.conf
2309 tom.houday 358
# FreeRADIUS Web
634 richard 359
		$SED "s?^nas1_name:.*?nas1_name: alcasar-$ORGANISME?g" /etc/freeradius-web/naslist.conf
360
		$SED "s?^nas1_ip:.*?nas1_ip: $PRIVATE_IP?g" /etc/freeradius-web/naslist.conf
632 richard 361
# coova
634 richard 362
		$SED "s?^net.*?net\t\t$PRIVATE_NETWORK_MASK?g" /etc/chilli.conf
363
		$SED "s?^dns1.*?dns1\t\t$PRIVATE_IP?g" /etc/chilli.conf
364
		$SED "s?^dns2.*?dns2\t\t$PRIVATE_IP?g" /etc/chilli.conf
365
		$SED "s?^uamlisten.*?uamlisten\t$PRIVATE_IP?g" /etc/chilli.conf
1581 richard 366
		# modify the DHCP static ip file. Reserve the second IP address for INTIF (the first one is for tun0). Keep previous entries
2274 richard 367
		$SED "s?^$PRIVATE_MAC.*?$PRIVATE_MAC $PRIVATE_SECOND_IP?" $DIR_ETC/alcasar-ethers $DIR_ETC/alcasar-ethers-info
632 richard 368
# dnsmasq
1795 franck 369
		$SED "/127.0.0.1/!s?^listen-address=.*?listen-address=$PRIVATE_IP?g" /etc/dnsmasq.conf /etc/dnsmasq-blacklist.conf /etc/dnsmasq-whitelist.conf /etc/dnsmasq-blackhole.conf
1377 richard 370
		for i in /etc/dnsmasq.conf /etc/dnsmasq-blacklist.conf
673 richard 371
		do
372
			$SED "/^server=/d" $i
373
			echo "server=$DNS1" >> $i
374
			echo "server=$DNS2" >> $i
375
		done
1969 richard 376
		$SED "s?^address=.*?address=/#/$PRIVATE_IP?g" /etc/dnsmasq-blackhole.conf
377
		for i in `ls $DIR_SHARE/dnsmasq-wl`
378
		do
379
			cat $DIR_SHARE/dnsmasq-wl/$i|cut -d"/" -f1,2 > /tmp/tmp_file
380
			$SED "s/$/\/$DNS1/" /tmp/tmp_file
381
			mv -f /tmp/tmp_file $DIR_SHARE/dnsmasq-wl/$i
382
		done
383
		chown root:apache $DIR_SHARE/dnsmasq-wl/*
384
		chmod 660 $DIR_SHARE/dnsmasq-wl/*
2546 tom.houday 385
		$SED "s@^\([#]\?\)dhcp-range=.*@\1dhcp-range=$PRIVATE_SECOND_IP,$PRIVATE_LAST_IP,$PRIVATE_NETMASK,12h@" /etc/dnsmasq.conf
386
		$SED "s@^\([#]\?\)dhcp-option=option:router.*@\1dhcp-option=option:router,$PRIVATE_IP@" /etc/dnsmasq.conf
387
		$SED "s@^\([#]\?\)dhcp-option=option:ntp-server.*@\1dhcp-option=option:ntp-server,$PRIVATE_IP@" /etc/dnsmasq.conf
1518 richard 388
# tinyproxy			
389
		$SED "s?^Listen.*?Listen $PRIVATE_IP?g" /etc/tinyproxy/tinyproxy.conf
634 richard 390
# DG + BL
2521 armand.ito 391
		$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/e2guardian/e2guardian.conf
634 richard 392
# Watchdog
393
		$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
394
# Prompts
395
		$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
396
# sudoers
397
		$SED "s?^Host_Alias.*?Host_Alias	LAN_ORG=$PRIVATE_NETWORK/$PRIVATE_NETMASK,localhost		#réseau de l'organisme?g" /etc/sudoers
1060 richard 398
		if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
399
		then
634 richard 400
# Services start
1574 richard 401
			/usr/bin/systemctl start network && echo -n "Start service : network" && sleep 1
2309 tom.houday 402
			$DIR_BIN/alcasar-dhcp.sh -$DHCP_mode && echo -n ", chilli" # apply DHCP mode and start CoovaChilli
403
			for i in dnsmasq dnsmasq-blackhole tinyproxy ntpd
404
			do
405
				sleep 1
406
				/usr/bin/systemctl start $i && echo -n ", $i"
407
			done
2247 tom.houday 408
			$DIR_BIN/alcasar-bl.sh -reload && echo -n ", dnsmasq-blacklist, dnsmasq-whitelist, iptables"
2488 lucas.echa 409
			/usr/bin/systemctl restart lighttpd && echo -n ", lighttpd"
1060 richard 410
		fi
628 richard 411
# Start / Stop SSH Daemon
2474 tom.houday 412
		ssh_active=`grep ^SSH= $CONF_FILE|cut -d"=" -f2`
634 richard 413
		if [ $ssh_active = "on" ]
414
		then
1574 richard 415
			/usr/bin/systemctl enable sshd.service
1060 richard 416
			if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
417
			then
1574 richard 418
				/usr/bin/systemctl start sshd.service
1060 richard 419
			fi
634 richard 420
		else
1574 richard 421
			/usr/bin/systemctl disable sshd.service
1060 richard 422
			if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
423
			then
1574 richard 424
				/usr/bin/systemctl stop sshd.service
1060 richard 425
			fi
634 richard 426
		fi
2561 rexy 427
echo
628 richard 428
		;;
8 franck 429
	*)
430
		echo "Argument inconnu :$1";
431
		echo "$usage"
432
		exit 1
433
		;;
434
esac