Subversion Repositories ALCASAR

Rev

Rev 2811 | Rev 2824 | 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 2813 2020-04-26 21:26:32Z 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
 
2744 rexy 8
# Ce script permet la mise à jour d'un ALCASAR
9
#	- (alcasar-conf.sh -create) : création de l'archive des fichiers de configuration (/var/tmp/alcasar-conf.tar.gz)
10
#	- (alcasar-conf.sh -load) : chargement de l'archive des fichiers de configuration. Le cas échéant, c'est ici qu'on met à jour les fichiers entre versions
11
#	- (alcasar-conf.sh -apply) : application des directives du fichier de conf central "/usr/local/etc/alcasar.conf". Peut aussi être exploité à chaud après avoir changé des valeurs du fichier de conf.
2570 rexy 12
# This script allows ALCASAR update
2744 rexy 13
#	- (alcasar-conf.sh -create) : create the configuration files backup (/var/tmp/alcasar-conf.tar.gz)
14
#	- (alcasar-conf.sh -load) : load the backup of configuration files. If needed, it's here we update files between versions
15
#	- (alcasar-conf.sh -load) : apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf". Can be use after changes of conf file values.
672 richard 16
 
2585 tom.houday 17
DIR_UPDATE="/var/tmp/conf"				# répertoire de stockage des fichier de conf pour une mise à jour
2247 tom.houday 18
DIR_WEB="/var/www/html"					# répertoire du centre de gestion
19
DIR_BIN="/usr/local/bin"				# scripts directory
20
DIR_ETC="/usr/local/etc"				# conf directory
2688 lucas.echa 21
DIR_E2G="/etc/e2guardian/lists"			# Toulouse BL directory
22
DIR_BLACKLIST="$DIR_E2G/blacklists"		# Toulouse BL directory
2247 tom.houday 23
CONF_FILE="$DIR_ETC/alcasar.conf"			# main alcasar conf file
24
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2`		# EXTernal InterFace
25
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`		# INTernal InterFace
26
MTU=`grep ^PUBLIC_MTU= $CONF_FILE|cut -d"=" -f2`
1890 franck 27
DHCP_mode=`grep ^DHCP= $CONF_FILE|cut -d"=" -f2`
28
INT_DNS_mode=`grep ^INT_DNS_ACTIVE= $CONF_FILE|cut -d"=" -f2`
29
LDAP_mode=`grep ^LDAP= $CONF_FILE|cut -d"=" -f2`
2247 tom.houday 30
HOSTNAME=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
31
DOMAIN=`grep ^DOMAIN= $CONF_FILE|cut -d"=" -f2`
384 richard 32
SED="/bin/sed -i"
2474 tom.houday 33
DNS1=`grep ^DNS1= $CONF_FILE | cut -d'=' -f2` 			# server DNS1 (for WL domain names)
923 franck 34
DOMAIN=${DOMAIN:=localdomain}
2247 tom.houday 35
 
628 richard 36
private_network_calc ()
37
{
1060 richard 38
	PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`				# prefixe du réseau (ex. 24)
2561 rexy 39
	PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`			# @ réseau de consultation (ex.: 192.168.182.0)
40
	PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX									# @ + masque du réseau de consult (192.168.182.0/24)
2688 lucas.echa 41
	classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`;							# classes de réseau (ex.: 2=classe B, 3=classe C)
1060 richard 42
	PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`.					# @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
43
	PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2`				# private network broadcast (ie.: 192.168.182.255)
2561 rexy 44
	private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup`			# last octet of LAN broadcast
45
	private_ip_ending=`echo $PRIVATE_IP | cut -d"." -f4`									# last octet of LAN address
46
	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 47
	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 48
	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 49
}
8 franck 50
 
933 franck 51
usage="Usage: alcasar-conf.sh {--create or -create} | {--load or -load} | {--apply or -apply}"
8 franck 52
nb_args=$#
53
args=$1
54
if [ $nb_args -eq 0 ]
55
then
2430 tom.houday 56
	nb_args=1
8 franck 57
	args="-h"
58
fi
59
case $args in
60
	-\? | -h* | --h*)
61
		echo "$usage"
62
		exit 0
63
		;;
2688 lucas.echa 64
	--create|-create)
8 franck 65
		[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
66
		mkdir $DIR_UPDATE
1916 franck 67
# backup the users database  (test to delete in future version)
2664 tom.houday 68
		$DIR_BIN/alcasar-mysql.sh --dump
2688 lucas.echa 69
		cp /var/Save/base/"$(ls -1t /var/Save/base|head -1)" $DIR_UPDATE
1758 richard 70
# backup the logo
8 franck 71
		cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
1912 richard 72
# backup BL/WL custom files
1914 richard 73
		mkdir $DIR_UPDATE/custom_bl
2541 rexy 74
		for i in exceptioniplist urlregexplist exceptionsitelist bannedsitelist exceptionurllist bannedurllist
75
		do
2570 rexy 76
			if [ -d /etc/dansguardian ]; then
77
				cp /etc/dansguardian/lists/$i $DIR_UPDATE/custom_bl/ # before V3.3
2661 lucas.echa 78
				cp -rf /etc/dansguardian/lists/blacklists/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
2541 rexy 79
			else
2688 lucas.echa 80
				cp $DIR_E2G/$i $DIR_UPDATE/custom_bl/ # since V3.3
2661 lucas.echa 81
				cp -rf $DIR_BLACKLIST/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
2541 rexy 82
			fi
83
		done
2560 rexy 84
# backup of different conf files (main conf file, filtering, digest, /etc/hosts, etc.)
8 franck 85
		mkdir $DIR_UPDATE/etc/
346 richard 86
		cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
2560 rexy 87
		cp /etc/hosts $DIR_UPDATE/etc/
1758 richard 88
# backup of the security certificates (server & CA)
2561 rexy 89
		cp -f /etc/pki/tls/certs/alcasar.crt* $DIR_UPDATE
90
		cp -f /etc/pki/tls/private/alcasar.key* $DIR_UPDATE
2570 rexy 91
		[ -e /etc/pki/tls/private/alcasar.pem ] && cp -f /etc/pki/tls/private/alcasar.pem $DIR_UPDATE # since V3.3
1564 richard 92
		cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
93
		cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
2813 rexy 94
		if [ -e /etc/pki/tls/certs/server-chain.pem ]; then
95
			cp -f /etc/pki/tls/certs/server-chain.pem $DIR_UPDATE # autosigned and official if exist
510 richard 96
		else
2813 rexy 97
			cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.pem
510 richard 98
		fi
2688 lucas.echa 99
# pureip & safesearch status
100
		[ -d /etc/dansguardian ] && dg_path=/etc/dansguardian || dg_path=/etc/e2guardian
101
 
102
		if ! grep -Eq '^WL_SAFESEARCH=' $DIR_UPDATE/etc/alcasar.conf; then
103
			if [ -f /etc/dnsmasq-whitelist.conf ] && grep -iq "SafeSearch" /etc/dnsmasq-whitelist.conf; then
104
				echo 'WL_SAFESEARCH=on' >> $DIR_UPDATE/etc/alcasar.conf
105
			else
106
				echo 'WL_SAFESEARCH=off' >> $DIR_UPDATE/etc/alcasar.conf
107
			fi
108
		fi
109
 
110
		if ! grep -Eq '^BL_SAFESEARCH=' $DIR_UPDATE/etc/alcasar.conf; then
111
			if [ -f /etc/dnsmasq-blacklist.conf ] && grep -iq "SafeSearch" /etc/dnsmasq-blacklist.conf; then
112
				echo 'BL_SAFESEARCH=on' >> $DIR_UPDATE/etc/alcasar.conf
113
			else
114
				echo 'BL_SAFESEARCH=off' >> $DIR_UPDATE/etc/alcasar.conf
115
			fi
116
		fi
117
 
118
		if ! grep -Eq '^BL_PUREIP=' $DIR_UPDATE/etc/alcasar.conf; then
119
			if grep -Eq "^\*ip" $dg_path/lists/bannedsitelist; then
120
				echo 'BL_PUREIP=on' >> $DIR_UPDATE/etc/alcasar.conf
121
			else
122
				echo 'BL_PUREIP=off' >> $DIR_UPDATE/etc/alcasar.conf
123
			fi
124
		fi
125
 
1758 richard 126
# archive file creation
2688 lucas.echa 127
		cd /var/tmp || { echo "Unable to find /var/tmp directory"; }
8 franck 128
		tar -cf alcasar-conf.tar conf/
129
		gzip -f alcasar-conf.tar
130
		rm -rf $DIR_UPDATE
131
		;;
2560 rexy 132
 
389 franck 133
	--load|-load)
2688 lucas.echa 134
		cd /var/tmp || { echo "Unable to find /var/tmp directory"; }
2560 rexy 135
		tar -xf alcasar-conf*.tar.gz
2570 rexy 136
#########################   modifications between versions  #######################
137
# Retrieve the previous version
2561 rexy 138
		PREVIOUS_VERSION=`grep ^VERSION= $DIR_UPDATE/etc/alcasar.conf|cut -d"=" -f2`
139
		MAJ_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f1`
140
		MIN_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f2`
141
		UPD_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f3|cut -c1`
2570 rexy 142
##  From 3.2.0 & 3.2.1  ##
143
	## rewrite /etc/hosts file managing hostname resolution
2665 tom.houday 144
		PRIVATE_IP=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2|cut -d"/" -f1`
145
		HOSTNAME=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2-`
146
		domainNames="$HOSTNAME $HOSTNAME.$DOMAIN"
147
		[ "$HOSTNAME" != 'alcasar' ] && domainNames="alcasar $domainNames"
2688 lucas.echa 148
		if [ "$(grep -c "$PRIVATE_IP\s$domainNames" $DIR_UPDATE/etc/hosts )" -eq 0 ]; then
2570 rexy 149
			cat << EOF > $DIR_UPDATE/etc/hosts
150
127.0.0.1	localhost
2585 tom.houday 151
$PRIVATE_IP	$domainNames
2570 rexy 152
EOF
2665 tom.houday 153
		fi
2570 rexy 154
	## apache & dansguardian are replaced with lighttpd & E²guardian
2688 lucas.echa 155
		if [ "$(rpm -qa | grep '^\(apache\|apache-mod_php\|apache-mod_ssl\|dansguardian\)-' | wc -l)" -ne 0 ]; then
2570 rexy 156
			rm_rpm="apache apache-mod_php apache-mod_ssl dansguardian"
2571 rexy 157
			/usr/sbin/urpme --auto -a $rm_rpm 2>/dev/null
2570 rexy 158
			/usr/sbin/urpme --auto --auto-orphans
159
			rm -rf /etc/httpd/ /var/log/httpd/ /var/dansguardian/ /etc/dansguardian/
2665 tom.houday 160
		fi
2570 rexy 161
	## lighttpd need a .pem certificate (aggregation with private key & server crt)
2665 tom.houday 162
		[ ! -f $DIR_UPDATE/alcasar.pem ] && (cat $DIR_UPDATE/alcasar.key; echo; cat $DIR_UPDATE/alcasar.crt) > $DIR_UPDATE/alcasar.pem
2630 rexy 163
##  From 3.3.0  ##
2600 tom.houday 164
	# add "SMS=off" in conf file
2688 lucas.echa 165
		if [ "$(grep -c '^SMS=' $DIR_UPDATE/etc/alcasar.conf)" -eq 0 ]; then
2665 tom.houday 166
				echo "SMS=off" >> $DIR_UPDATE/etc/alcasar.conf
2600 tom.houday 167
		fi
2688 lucas.echa 168
		if [ "$(grep -c '^SMS_NUM=' $DIR_UPDATE/etc/alcasar.conf)" -eq 0 ]; then
2665 tom.houday 169
				echo "SMS_NUM=" >> $DIR_UPDATE/etc/alcasar.conf
170
		fi
2688 lucas.echa 171
##  From 3.4.0  ##
172
	# Fix subdomain dot position (.domain.org to domain.org.) for Unbound
2705 tom.houday 173
		for file in $DIR_E2G/exceptionsitelist $DIR_BLACKLIST/ossi-bl*/domains $DIR_BLACKLIST/ossi-wl*/domains; do
174
			[ -f $file ] && $SED "s/^\.\(.*\)$/\1./g" $file
175
		done
176
	# Add LDAPS parameters to config file
177
		if [ "$(grep -c '^LDAP_SSL=' $DIR_UPDATE/etc/alcasar.conf)" -eq 0 ]; then
178
				echo "LDAP_SSL=on" >> $DIR_UPDATE/etc/alcasar.conf
179
		fi
180
		if [ "$(grep -c '^LDAP_CERT_REQUIRED=' $DIR_UPDATE/etc/alcasar.conf)" -eq 0 ]; then
181
				echo "LDAP_CERT_REQUIRED=" >> $DIR_UPDATE/etc/alcasar.conf
182
		fi
2745 rexy 183
    # remove DNSMASQ primary service (keep only one instance for whitelist on port 55)
184
        [ -e /etc/dnsmasq.conf.default ] && mv /etc/dnsmasq.conf.default /etc/dnsmasq.conf
185
		[ -e /lib/systemd/system/dnsmasq.service.default ] && rm /lib/systemd/system/dnsmasq.service.default
186
		[ -e /lib/systemd/system/dnsmasq.service ] && rm /lib/systemd/system/dnsmasq.service
2570 rexy 187
######################   End of modifications between versions  #######################
1060 richard 188
# Retrieve the logo
510 richard 189
		[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
8 franck 190
		chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
1060 richard 191
# Retrieve the security certificates (CA and server)
2571 rexy 192
		cp -f $DIR_UPDATE/alcasar-ca.crt /etc/pki/CA/
193
		cp -f $DIR_UPDATE/alcasar-ca.key /etc/pki/CA/private/
1758 richard 194
		cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
195
		cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
2688 lucas.echa 196
		cp -f $DIR_UPDATE/alcasar.pem /etc/pki/tls/private/
2813 rexy 197
		[ -e $DIR_UPDATE/server-chain.pem ] && cp -f $DIR_UPDATE/server-chain.pem /etc/pki/tls/certs/ # autosigned and official if exist
2811 rexy 198
		chown root:apache /etc/pki/CA; chmod 750 /etc/pki/CA
199
		chmod 640 /etc/pki/CA/*
200
		chown root:root /etc/pki/CA/private; chmod 700 /etc/pki/CA/private
201
		chmod 600 /etc/pki/CA/private/*
202
		chown -R root:apache /etc/pki/tls/private; chmod 750 /etc/pki/tls/private
203
		chmod 640 /etc/pki/tls/private/*
1060 richard 204
# Import of the users database
2688 lucas.echa 205
		$DIR_BIN/alcasar-mysql.sh --import "$(ls $DIR_UPDATE/alcasar-users-database*)"
1914 richard 206
# Retrieve local parameters
2561 rexy 207
		cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
2570 rexy 208
		mv -f $DIR_UPDATE/etc/hosts /etc/hosts
2580 rexy 209
		chmod 755 /etc/hosts
1914 richard 210
# Retrieve BL/WL custom files
2688 lucas.echa 211
		cp -f $DIR_UPDATE/custom_bl/exceptioniplist $DIR_E2G/
212
		cp -f $DIR_UPDATE/custom_bl/exceptionsitelist $DIR_E2G/
213
		cp -f $DIR_UPDATE/custom_bl/urlregexplist $DIR_E2G/
214
		cp -f $DIR_UPDATE/custom_bl/bannedsitelist $DIR_E2G/
215
		cp -f $DIR_UPDATE/custom_bl/exceptionurllist $DIR_E2G/
216
		cp -f $DIR_UPDATE/custom_bl/bannedurllist $DIR_E2G/
1961 richard 217
		cp -rf $DIR_UPDATE/custom_bl/ossi-* $DIR_BLACKLIST/ 2>/dev/null
2688 lucas.echa 218
		chown -R e2guardian:apache $DIR_E2G
219
		chmod -R g+rw $DIR_E2G
1060 richard 220
# Adapt DNS/URL filtering
221
		PARENT_SCRIPT=`basename $0`
637 richard 222
		export PARENT_SCRIPT
1946 richard 223
		$DIR_BIN/alcasar-bl.sh -cat_choice
1827 raphael.pi 224
		$DIR_BIN/alcasar-bl.sh -reload
1060 richard 225
# admin profile update (admin + manager + backup)
1827 raphael.pi 226
		$DIR_BIN/alcasar-profil.sh --list
634 richard 227
# Start / Stop SSH Daemon
2327 richard 228
		ssh_active=`grep "^SSH=" $CONF_FILE|cut -d"=" -f2`
634 richard 229
		if [ $ssh_active = "on" ]
230
		then
1574 richard 231
			/usr/bin/systemctl -q enable sshd.service
634 richard 232
		else
1574 richard 233
			/usr/bin/systemctl -q disable sshd.service
634 richard 234
		fi
1060 richard 235
# Remove the update folder
8 franck 236
		rm -rf $DIR_UPDATE
237
		;;
2560 rexy 238
 
628 richard 239
	--apply|-apply)
994 franck 240
		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 241
		PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
2688 lucas.echa 242
		if ! echo $PRIVATE_IP_MASK | egrep -q $PTN
243
		then
628 richard 244
			echo "Syntax error for PRIVATE_IP_MASK ($PRIVATE_IP_MASK)"
245
			exit 0
246
		fi
2474 tom.houday 247
		PUBLIC_IP_MASK=`grep ^PUBLIC_IP= $CONF_FILE|cut -d"=" -f2`
1590 richard 248
		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 249
		if [[ "$PUBLIC_IP_MASK" == "dhcp" ]]
250
		then
251
			PUBLIC_GATEWAY="dhcp"
252
		else
2688 lucas.echa 253
			if ! echo $PUBLIC_IP_MASK | egrep -q $PTN
254
			then
1585 richard 255
				echo "Syntax error for PUBLIC_IP_MASK ($PUBLIC_IP_MASK)"
256
				exit 0
257
			fi
1590 richard 258
			PUBLIC_IP=`echo $PUBLIC_IP_MASK | cut -d"/" -f1`
259
			PUBLIC_NETMASK=`/bin/ipcalc -m $PUBLIC_IP_MASK | cut -d"=" -f2`
2474 tom.houday 260
			PUBLIC_GATEWAY=`grep ^GW= $CONF_FILE|cut -d"=" -f2`
2688 lucas.echa 261
			if ! echo $PUBLIC_GATEWAY | egrep -q $PTN
262
			then
1585 richard 263
				echo "Syntax error for the Gateway IP ($PUBLIC_GATEWAY)"
264
				exit 0
265
			fi
628 richard 266
		fi
2474 tom.houday 267
		DNS1=`grep ^DNS1= $CONF_FILE|cut -d"=" -f2`
2688 lucas.echa 268
		if ! echo $DNS1 | egrep -q $PTN
269
		then
1590 richard 270
			echo "Syntax error for the IP address of the first DNS server ($DNS1)"
271
			exit 0
272
		fi
2474 tom.houday 273
		DNS2=`grep ^DNS2= $CONF_FILE|cut -d"=" -f2`
2688 lucas.echa 274
		if ! echo $DNS2 | egrep -q $PTN
275
		then
1590 richard 276
			echo "Syntax error for the IP address of the second DNS server ($DNS2)"
277
			exit 0
278
		fi
631 richard 279
		PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
632 richard 280
		PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
628 richard 281
		private_network_calc
2474 tom.houday 282
		INSTALL_DATE=`grep ^INSTALL_DATE= $CONF_FILE|cut -d"=" -f2`
283
		ORGANISME=`grep ^ORGANISM= $CONF_FILE|cut -d"=" -f2-`
2688 lucas.echa 284
		BL_SAFESEARCH=`grep ^BL_SAFESEARCH= $CONF_FILE|cut -d"=" -f2`
285
		WL_SAFESEARCH=`grep ^WL_SAFESEARCH= $CONF_FILE|cut -d"=" -f2`
286
		BL_PUREIP=`grep ^BL_PUREIP= $CONF_FILE|cut -d"=" -f2`
2474 tom.houday 287
		DHCP_mode=`grep ^DHCP= $CONF_FILE|cut -d"=" -f2`
1060 richard 288
		if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
933 franck 289
		then
2688 lucas.echa 290
			if [ "$DHCP_mode" = "off" ] || [ "$DHCP_mode" = "Off" ] || [ "$DHCP_mode" = "OFF" ]
1060 richard 291
			then
1827 raphael.pi 292
				$DIR_BIN/alcasar-dhcp.sh --off
1890 franck 293
			else
2569 lucas.echa 294
				$DIR_BIN/alcasar-dhcp.sh --on
1060 richard 295
			fi
2568 rexy 296
# Set the local DNS (or not)
2688 lucas.echa 297
			if [ "$INT_DNS_mode" = "on" ] || [ "$INT_DNS_mode" = "On" ] || [ "$INT_DNS_mode" = "ON" ]
1890 franck 298
			then
299
				$DIR_BIN/alcasar-dns-local.sh --on
300
			else
301
				$DIR_BIN/alcasar-dns-local.sh --off
302
			fi
2688 lucas.echa 303
# Set the pure ip option (or not)
304
			if [ "$BL_PUREIP" = "off" ] || [ "$BL_PUREIP" = "Off" ] || [ "$BL_PUREIP" = "OFF" ]
305
			then
306
				bl_filter_param+="--pureip_off"
307
			else
308
				bl_filter_param+="--pureip_on"
309
			fi
310
# Set the safesearch options (or not)
311
			bl_filter_param=""
312
			if [ "$BL_SAFESEARCH" = "on" ] || [ "$BL_SAFESEARCH" = "On" ] || [ "$BL_SAFESEARCH" = "ON" ]
313
			then
314
				bl_filter_param+="--safesearch_on "
315
			else
316
				bl_filter_param+="--safesearch_off "
317
			fi
318
			$DIR_BIN/alcasar-url_filter_bl.sh $bl_filter_param
319
			if [ "$WL_SAFESEARCH" = "on" ] || [ "$WL_SAFESEARCH" = "On" ] || [ "$WL_SAFESEARCH" = "ON" ]
320
			then
321
				$DIR_BIN/alcasar-url_filter_wl.sh --safesearch_on
322
			else
323
				$DIR_BIN/alcasar-url_filter_wl.sh --safesearch_off
324
			fi
325
# Reload the local dns configuration
326
			$DIR_BIN/alcasar-dns-local.sh --reload
1585 richard 327
# Logout everybody
2688 lucas.echa 328
			$DIR_BIN/alcasar-logout.sh all
1585 richard 329
# Services stop
1521 richard 330
			echo -n "Stop services : "
2688 lucas.echa 331
			for i in ntpd tinyproxy e2guardian unbound unbound-whitelist dnsmasq-whitelist unbound-blacklist unbound-blackhole chilli network lighttpd
1060 richard 332
			do
1574 richard 333
				/usr/bin/systemctl stop $i && echo -n "$i, "
1060 richard 334
			done
1521 richard 335
			echo
1060 richard 336
		fi
1518 richard 337
# EXTIF config
1585 richard 338
		if [ $PUBLIC_IP_MASK == "dhcp" ]
339
		then
340
			cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
341
DEVICE=$EXTIF
342
BOOTPROTO=dhcp
343
DNS1=127.0.0.1
344
PEERDNS=no
345
RESOLV_MODS=yes
346
ONBOOT=yes
347
METRIC=10
348
MII_NOT_SUPPORTED=yes
349
IPV6INIT=no
350
IPV6TO4INIT=no
351
ACCOUNTING=no
352
USERCTL=no
353
MTU=$MTU
1850 franck 354
NOZEROCONF=yes
1585 richard 355
EOF
2688 lucas.echa 356
		else
1585 richard 357
			cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
358
DEVICE=$EXTIF
359
BOOTPROTO=static
360
IPADDR=$PUBLIC_IP
361
NETMASK=$PUBLIC_NETMASK
362
GATEWAY=$PUBLIC_GATEWAY
363
DNS1=127.0.0.1
364
RESOLV_MODS=yes
365
ONBOOT=yes
366
METRIC=10
367
MII_NOT_SUPPORTED=yes
368
IPV6INIT=no
369
IPV6TO4INIT=no
370
ACCOUNTING=no
371
USERCTL=no
372
MTU=$MTU
1850 franck 373
NOZEROCONF=yes
1585 richard 374
EOF
375
		fi
1518 richard 376
# INTIF config (for bypass mode only)
1554 richard 377
		$SED "s?^IPADDR=.*?IPADDR=$PRIVATE_IP?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
378
		$SED "s?^NETMASK=.*?NETMASK=$PRIVATE_NETMASK?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
628 richard 379
# NTP server
632 richard 380
		$SED "/127.0.0.1/!s?^restrict.*?restrict $PRIVATE_NETWORK mask $PRIVATE_NETMASK nomodify notrap?g" /etc/ntp.conf
2688 lucas.echa 381
# host.allow
628 richard 382
		cat <<EOF > /etc/hosts.allow
383
ALL: LOCAL, 127.0.0.1, localhost, $PRIVATE_IP
384
sshd: ALL
385
ntpd: $PRIVATE_NETWORK_SHORT
386
EOF
2309 tom.houday 387
# Set hostname
388
		hostnamectl set-hostname $HOSTNAME.$DOMAIN
389
# /etc/hosts
2585 tom.houday 390
		domainNames="$HOSTNAME $HOSTNAME.$DOMAIN"
391
		[ "$HOSTNAME" != 'alcasar' ] && domainNames="alcasar $domainNames"
392
		$SED "/^$PRIVATE_IP\t/d"  /etc/hosts
393
		$SED "/\s$HOSTNAME\s\$/d" /etc/hosts
394
		[ "$HOSTNAME" != 'alcasar' ] && $SED "/\salcasar\s\$/d" /etc/hosts
395
		echo "$PRIVATE_IP	$domainNames" >> /etc/hosts
2603 tom.houday 396
# MOTD
397
		$SED "s@'https://\(.\+\)/acc'@'https://$HOSTNAME.$DOMAIN/acc'@" /etc/mageia-release
2568 rexy 398
# Lighttpd
2688 lucas.echa 399
		$SED "s?^server\.bind.*?server\.bind = \"$PRIVATE_IP\"?g" /etc/lighttpd/lighttpd.conf
400
		$SED 's/^$SERVER\["socket"\] == ".*:443.*/$SERVER\["socket"\] == "'"$PRIVATE_IP"':443" {/g' /etc/lighttpd/vhosts.d/alcasar.conf
401
		$SED "s/^\([\t ]*\)var.server_name.*/\1var.server_name = \"$PRIVATE_IP\"/g" /etc/lighttpd/vhosts.d/alcasar.conf
2744 rexy 402
# FreeRADIUS
634 richard 403
		$SED "s?^nas1_name:.*?nas1_name: alcasar-$ORGANISME?g" /etc/freeradius-web/naslist.conf
404
		$SED "s?^nas1_ip:.*?nas1_ip: $PRIVATE_IP?g" /etc/freeradius-web/naslist.conf
2707 tom.houday 405
# CoovaChilli
2568 rexy 406
		$SED "s/^uamallowed.*/uamallowed\t$HOSTNAME,$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
407
		$SED "s/^locationname.*/locationname\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
2707 tom.houday 408
		$SED "s/^domain.*/domain\t\t$DOMAIN/g" /etc/chilli.conf
2688 lucas.echa 409
		[ "`grep ^HTTPS_LOGIN= $CONF_FILE | cut -d'=' -f2`" == "on" ] && chilli_login_protocol="https" || chilli_login_protocol="http"
2568 rexy 410
		$SED "s/^uamserver.*/uamserver\t$chilli_login_protocol:\/\/$HOSTNAME.$DOMAIN\/intercept.php/" /etc/chilli.conf
411
		$SED "s/^radiusnasid.*/radiusnasid\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
634 richard 412
		$SED "s?^net.*?net\t\t$PRIVATE_NETWORK_MASK?g" /etc/chilli.conf
413
		$SED "s?^dns1.*?dns1\t\t$PRIVATE_IP?g" /etc/chilli.conf
414
		$SED "s?^dns2.*?dns2\t\t$PRIVATE_IP?g" /etc/chilli.conf
415
		$SED "s?^uamlisten.*?uamlisten\t$PRIVATE_IP?g" /etc/chilli.conf
1581 richard 416
		# modify the DHCP static ip file. Reserve the second IP address for INTIF (the first one is for tun0). Keep previous entries
2274 richard 417
		$SED "s?^$PRIVATE_MAC.*?$PRIVATE_MAC $PRIVATE_SECOND_IP?" $DIR_ETC/alcasar-ethers $DIR_ETC/alcasar-ethers-info
2688 lucas.echa 418
# dnsmasq-whitelist
419
		$SED "/^server=/d" /etc/dnsmasq-whitelist.conf
420
		echo "server=$DNS1" >> /etc/dnsmasq-whitelist.conf
421
		echo "server=$DNS2" >> /etc/dnsmasq-whitelist.conf
422
# unbound
423
		# removing unbound configuration files
424
		rm -f /etc/unbound/conf.d/{forward,blacklist,whitelist,blackhole}/iface.*
425
		rm -f /etc/unbound/conf.d/common/forward-zone.conf
426
		find /etc/unbound/conf.d/common/local-dns/ ! -name "global.conf" -type f -delete
427
		# Configuration file for the dns servers forward-zone
428
		cat << EOF > /etc/unbound/conf.d/common/forward-zone.conf
429
forward-zone:
430
	name: "."
431
	forward-addr: $DNS1
432
	forward-addr: $DNS2
433
EOF
434
		# Configuration file of ALCASAR main domains for $INTIF
435
		cat << EOF > /etc/unbound/conf.d/common/local-dns/${INTIF}.conf
436
server:
437
	local-zone: "$HOSTNAME.$DOMAIN" static
438
	local-data: "$HOSTNAME.$DOMAIN A $PRIVATE_IP"
439
	local-zone: "$HOSTNAME" static
440
	local-data: "$HOSTNAME A $PRIVATE_IP"
441
EOF
2813 rexy 442
		if [ "$HOSTNAME" != 'alcasar' ]
443
		then
444
			echo -e "\tlocal-zone: \"alcasar\" static" >> /etc/unbound/conf.d/common/local-dns/${INTIF}.conf
445
			echo -e "\tlocal-zone: \"alcasar A $PRIVATE_IP\"" >> /etc/unbound/conf.d/common/local-dns/${INTIF}.conf
446
			echo -e "\tlocal-zone: \"alcasar\" static" >> /etc/unbound/conf.d/forward/iface.lo.conf
447
			echo -e "\tlocal-zone: \"alcasar A 127.0.0.1\"" >> /etc/unbound/conf.d/forward/iface.lo.conf
448
		fi
449
		# Configuration file for lo of forward
2688 lucas.echa 450
		cat << EOF > /etc/unbound/conf.d/forward/iface.lo.conf
451
server:
452
	interface: 127.0.0.1@53
453
	access-control-view: 127.0.0.1/8 lo
454
view:
455
	name: "lo"
456
	view-first: yes
457
	local-zone: "$HOSTNAME.$DOMAIN" static
458
	local-data: "$HOSTNAME.$DOMAIN A 127.0.0.1"
459
	local-zone: "$HOSTNAME" static
460
	local-data: "$HOSTNAME A 127.0.0.1"
461
	local-zone: "$DOMAIN." static
462
	local-data: "$DOMAIN. A"
463
EOF
2813 rexy 464
		# Configuration file for $INTIF of forward
2688 lucas.echa 465
		cat << EOF > /etc/unbound/conf.d/forward/iface.${INTIF}.conf
466
server:
467
	interface: ${PRIVATE_IP}@53
468
	access-control-view: $PRIVATE_NETWORK_MASK $INTIF
469
 
470
view:
471
	name: "$INTIF"
472
	view-first: yes
473
EOF
2813 rexy 474
		# Configuration file for $INTIF of blacklist
2688 lucas.echa 475
		cat << EOF > /etc/unbound/conf.d/blacklist/iface.${INTIF}.conf
476
server:
477
	interface: ${PRIVATE_IP}@54
478
	access-control: $PRIVATE_IP_MASK allow
479
	access-control-tag: $PRIVATE_IP_MASK "blacklist"
480
	access-control-tag-action: $PRIVATE_IP_MASK "blacklist" redirect
481
	access-control-tag-data: $PRIVATE_IP_MASK "blacklist" "A $PRIVATE_IP"
482
EOF
2813 rexy 483
		# Configuration file for $INTIF of whitelist
2688 lucas.echa 484
		cat << EOF > /etc/unbound/conf.d/whitelist/iface.${INTIF}.conf
485
server:
486
	interface: ${PRIVATE_IP}@55
487
	access-control: $PRIVATE_IP_MASK allow
488
	access-control-tag: $PRIVATE_IP_MASK "whitelist"
489
	access-control-tag-action: $PRIVATE_IP_MASK "whitelist" redirect
490
	access-control-tag-data: $PRIVATE_IP_MASK "whitelist" "A $PRIVATE_IP"
491
EOF
2813 rexy 492
		# Configuration file for $INTIF of blackhole
2688 lucas.echa 493
		cat << EOF > /etc/unbound/conf.d/blackhole/iface.${INTIF}.conf
494
server:
495
	interface: ${PRIVATE_IP}@56
496
	access-control-view: $PRIVATE_NETWORK_MASK $INTIF
497
view:
498
	name: "$INTIF"
499
	local-zone: "." redirect
500
	local-data: ". A $PRIVATE_IP"
501
EOF
502
# dhcpd
503
		cat <<EOF > /etc/dhcpd.conf
504
ddns-update-style none;
505
subnet $PRIVATE_NETWORK netmask $PRIVATE_NETMASK {
506
	option routers $PRIVATE_IP;
507
	option subnet-mask $PRIVATE_NETMASK;
508
	option domain-name-servers $PRIVATE_IP;
509
	range dynamic-bootp $PRIVATE_SECOND_IP $PRIVATE_LAST_IP;
510
	default-lease-time 21600;
511
	max-lease-time 43200;
512
}
513
EOF
514
# tinyproxy
1518 richard 515
		$SED "s?^Listen.*?Listen $PRIVATE_IP?g" /etc/tinyproxy/tinyproxy.conf
634 richard 516
# DG + BL
2521 armand.ito 517
		$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/e2guardian/e2guardian.conf
634 richard 518
# Watchdog
519
		$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
520
# Prompts
521
		$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
522
# sudoers
523
		$SED "s?^Host_Alias.*?Host_Alias	LAN_ORG=$PRIVATE_NETWORK/$PRIVATE_NETMASK,localhost		#réseau de l'organisme?g" /etc/sudoers
1060 richard 524
		if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
525
		then
634 richard 526
# Services start
1574 richard 527
			/usr/bin/systemctl start network && echo -n "Start service : network" && sleep 1
2309 tom.houday 528
			$DIR_BIN/alcasar-dhcp.sh -$DHCP_mode && echo -n ", chilli" # apply DHCP mode and start CoovaChilli
2688 lucas.echa 529
			for i in unbound unbound-blackhole tinyproxy ntpd
2309 tom.houday 530
			do
531
				sleep 1
532
				/usr/bin/systemctl start $i && echo -n ", $i"
533
			done
2688 lucas.echa 534
			$DIR_BIN/alcasar-bl.sh -reload && echo -n ", unbound-blacklist, unbound-whitelist, dnsmasq-whitelist, e2guardian, iptables"
2488 lucas.echa 535
			/usr/bin/systemctl restart lighttpd && echo -n ", lighttpd"
1060 richard 536
		fi
628 richard 537
# Start / Stop SSH Daemon
2474 tom.houday 538
		ssh_active=`grep ^SSH= $CONF_FILE|cut -d"=" -f2`
634 richard 539
		if [ $ssh_active = "on" ]
540
		then
1574 richard 541
			/usr/bin/systemctl enable sshd.service
1060 richard 542
			if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
543
			then
1574 richard 544
				/usr/bin/systemctl start sshd.service
1060 richard 545
			fi
634 richard 546
		else
1574 richard 547
			/usr/bin/systemctl disable sshd.service
1060 richard 548
			if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
549
			then
1574 richard 550
				/usr/bin/systemctl stop sshd.service
1060 richard 551
			fi
634 richard 552
		fi
2568 rexy 553
# Start / Stop LDAP authentification
2688 lucas.echa 554
		if [ $LDAP_mode = "on" ] || [ $LDAP_mode = "On" ] || [ $LDAP_mode = "ON" ]
2568 rexy 555
		then
2707 tom.houday 556
			$DIR_BIN/alcasar-ldap.sh --on
557
		else
558
			$DIR_BIN/alcasar-ldap.sh --off
2568 rexy 559
		fi
560
		echo
628 richard 561
		;;
8 franck 562
	*)
2688 lucas.echa 563
		echo "Argument inconnu : $1";
8 franck 564
		echo "$usage"
565
		exit 1
566
		;;
567
esac