Subversion Repositories ALCASAR

Rev

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