Subversion Repositories ALCASAR

Rev

Rev 2569 | Rev 2678 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2223 tom.houday 1
#!/bin/bash
1015 richard 2
 
63 franck 3
# $Id: alcasar-bl.sh 2675 2018-12-14 09:56:50Z lucas.echard $
4
 
672 richard 5
# alcasar-bl.sh
6
# by Franck BOUIJOUX and Richard REY
7
# This script is distributed under the Gnu General Public License (GPL)
1 root 8
 
2521 armand.ito 9
# Gestion de la BL pour le filtrage de domaine (via dnsmasq) et d'URL (via E2guardian)
10
# Manage the BL for DnsBlackHole (dnsmasq) and URL filtering (E2guardian)
672 richard 11
 
878 richard 12
DIR_CONF="/usr/local/etc"
13
CONF_FILE="$DIR_CONF/alcasar.conf"
2474 tom.houday 14
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
854 richard 15
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
16
PRIVATE_IP=`echo $private_ip_mask | cut -d"/" -f1`			# ALCASAR LAN IP address
308 richard 17
DIR_tmp="/tmp/blacklists"
1852 raphael.pi 18
DIR_WL_tmp="/tmp/whitelists"
1015 richard 19
FILE_tmp="/tmp/filesfilter.txt"
20
FILE_ip_tmp="/tmp/filesipfilter.txt"
2521 armand.ito 21
DIR_DG="/etc/e2guardian/lists"
316 richard 22
DIR_DG_BL="$DIR_DG/blacklists"
2675 lucas.echa 23
GLOBAL_USAGE="$DIR_CONF/alcasar-global-usage"				# file containing the description of the lists
1015 richard 24
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories"				# list of names of the 	BL categories
1926 richard 25
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories"				#	'	'	WL categories
1015 richard 26
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled"		#	'	'	BL enabled categories
27
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled"		#	'	'	WL enabled categories
28
DIR_SHARE="/usr/local/share"
29
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl"					# all the BL in the DNSMASQ format
30
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl"					# all the WL	'	'	'
2454 tom.houday 31
DIR_IP_BL="$DIR_SHARE/iptables-bl"					# all the IP addresses of the BL
32
DIR_IP_WL="$DIR_SHARE/iptables-wl"					# IP ossi disabled WL
1366 richard 33
DIR_DNS_BL_ENABLED="$DIR_SHARE/dnsmasq-bl-enabled"			# symbolic link to the domains BL (only enabled categories)
1931 richard 34
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled"			#	'	'	'	WL	'	'
1377 richard 35
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled"			#	'	'	ip BL (only enabled categories)
1852 raphael.pi 36
DIR_IP_WL_ENABLED="$DIR_SHARE/iptables-wl-enabled"			#	'	'	ip WL (ossi and ossi-* imported from ACC)
2474 tom.houday 37
DNS1=`grep ^DNS1= $CONF_FILE | cut -d'=' -f2-` 			# server DNS1 (for WL domain names)
878 richard 38
BL_SERVER="dsi.ut-capitole.fr"
1 root 39
SED="/bin/sed -i"
637 richard 40
 
1042 richard 41
# enable/disable the BL & WL categories
308 richard 42
function cat_choice (){
1931 richard 43
	mkdir -p $DIR_tmp
44
	for LIST in $DIR_IP_BL_ENABLED $DIR_DNS_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_WL_ENABLED
1930 richard 45
	do
1938 richard 46
		if [ ! -e $LIST ] #  only on install stage
1933 richard 47
		then
48
			mkdir $LIST
49
		else
50
			rm -rf $LIST/*
51
		fi
52
		chown root:apache $LIST
53
		chmod 770 $LIST
1930 richard 54
	done
1870 raphael.pi 55
	# update categories with rsync
56
	if [ ! -e $DIR_CONF/update_cat.conf ]
57
	then
58
		touch $DIR_CONF/update_cat.conf
59
		chown root:apache $DIR_CONF/update_cat.conf
60
		chmod 660 $DIR_CONF/update_cat.conf
61
	fi
1015 richard 62
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
1042 richard 63
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
1912 richard 64
 
2454 tom.houday 65
	# process the file $BL_CATEGORIES with the choice of categories
66
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
313 richard 67
	do
2454 tom.houday 68
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
2521 armand.ito 69
		$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
1395 richard 70
		ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
71
		ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
1293 richard 72
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
648 richard 73
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
313 richard 74
	done
878 richard 75
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
313 richard 76
	mv $FILE_tmp $BL_CATEGORIES
2193 richard 77
	sort +0.0 -0.2 $BL_CATEGORIES_ENABLED -o $FILE_tmp
78
	mv $FILE_tmp $BL_CATEGORIES_ENABLED
79
	chown root:apache $BL_CATEGORIES $BL_CATEGORIES_ENABLED
80
	chmod 660 $BL_CATEGORIES $BL_CATEGORIES_ENABLED
1912 richard 81
 
2454 tom.houday 82
# process the file $WL_CATEGORIES with the choice of categories
83
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
1042 richard 84
	do
2454 tom.houday 85
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
2521 armand.ito 86
		$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
1395 richard 87
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
1042 richard 88
	done
89
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
90
	mv $FILE_tmp $WL_CATEGORIES
2193 richard 91
	sort +0.0 -0.2 $WL_CATEGORIES_ENABLED -o $FILE_tmp
92
	mv $FILE_tmp $WL_CATEGORIES_ENABLED
93
	chown root:apache $WL_CATEGORIES $WL_CATEGORIES_ENABLED
94
	chmod 660 $WL_CATEGORIES $WL_CATEGORIES_ENABLED
308 richard 95
}
1482 richard 96
 
2192 richard 97
# cleaning file and split it ("domains" in $FILE_tmp & "IP" in $FILE_ip_tmp)
98
function clean_split (){
99
	$SED '/^#.*/d' $FILE_tmp # remove commented lines
100
	$SED '/^\s*$/d' $FILE_tmp # remove empty lines
101
	$SED '/[äâëêïîöôüû@,]/d' $FILE_tmp # remove line with "chelou" characters
102
	# extract ip addresses for iptables.
103
	awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $FILE_tmp > $FILE_ip_tmp
104
	# extract domain names for dnsmasq.
105
	$SED -n '/^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/!p' $FILE_tmp
106
	# Retrieve max Top Level Domain for domain name synthax
107
	#MAX_TLD=$(curl http://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v '-' | grep -v '#' | wc -L)
108
	#if [ $(echo $MAX_TLD | wc -c) -eq 0 ];then
109
	#	MAX_TLD=18
110
	#fi
111
	# search for correction	egrep "([a-zA-Z0-9_-.]+\.){1,2}[a-zA-Z]{2,$MAX_TLD}" $ossi_custom_dir/domains > $FILE_tmp
112
}
113
 
1870 raphael.pi 114
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
1 root 115
nb_args=$#
116
args=$1
117
if [ $nb_args -eq 0 ]
118
then
2454 tom.houday 119
	args="-h"
1 root 120
fi
121
case $args in
122
	-\? | -h* | --h*)
123
		echo "$usage"
124
		exit 0
125
		;;
1873 richard 126
	# Retrieve Toulouse University BL
386 franck 127
	-download | --download)
1 root 128
		rm -rf /tmp/con_ok.html
129
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
130
		if [ ! -e /tmp/con_ok.html ]
131
		then
132
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
2454 tom.houday 133
		else
878 richard 134
			rm -rf /tmp/con_ok.html $DIR_tmp
135
			mkdir $DIR_tmp
885 richard 136
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
878 richard 137
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
885 richard 138
			chown -R apache:apache $DIR_tmp
878 richard 139
		fi
2675 lucas.echa 140
		;;
1488 richard 141
	# enable/disable categories (used only during the alcasar install process)
142
	-cat_choice | --cat_choice)
143
		cat_choice
144
		;;
1873 richard 145
	# Adapt Toulouse University BL to ALCASAR architecture (dnsmasq + DG + iptables)
878 richard 146
	-adapt | --adapt)
1873 richard 147
		echo -n "Adaptation process of Toulouse University blackList. Please wait : "
1371 richard 148
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
878 richard 149
		then
2454 tom.houday 150
			# keep custom files (ossi)
1930 richard 151
			for x in $(ls -1 $DIR_DG_BL | grep "^ossi-*")
152
			do
153
				mv $DIR_DG_BL/$x $DIR_tmp
154
			done
1369 richard 155
			rm -rf $DIR_DG_BL $DIR_IP_BL
156
			mkdir $DIR_DG_BL $DIR_IP_BL
878 richard 157
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
2521 armand.ito 158
			chown -R e2guardian:apache $DIR_DG
1940 richard 159
			chmod -R 770 $DIR_DG
1930 richard 160
			# Retrieve custom files (ossi)
161
			for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
162
			do
163
				mv $DIR_tmp/$x $DIR_DG_BL
164
			done
165
		fi
166
		rm -f $BL_CATEGORIES $WL_CATEGORIES
167
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
2675 lucas.echa 168
		rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
1930 richard 169
		touch $BL_CATEGORIES $WL_CATEGORIES
170
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
2675 lucas.echa 171
		mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
1930 richard 172
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
173
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
1042 richard 174
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
878 richard 175
		do
1015 richard 176
			categorie=`echo $dir_categorie|cut -d "/" -f6`
2675 lucas.echa 177
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie\$ $GLOBAL_USAGE | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
1015 richard 178
			if [ "$categorie_type" == "white" ]
878 richard 179
			then
2454 tom.houday 180
				echo "$dir_categorie" >> $WL_CATEGORIES
1930 richard 181
			else
182
				echo "$dir_categorie" >> $BL_CATEGORIES
878 richard 183
			fi
184
		done
185
		rm -f $FILE_tmp
1057 richard 186
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
2454 tom.houday 187
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
1057 richard 188
		do
189
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
2454 tom.houday 190
			if [ $ok != "1" ]
1057 richard 191
			then
192
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
193
			fi
194
		done
1926 richard 195
		# Verify that the enabled categories are effectively in the WL (need after an update of the WL)
2454 tom.houday 196
		for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
1926 richard 197
		do
198
			ok=`grep /$ENABLE_CATEGORIE$ $WL_CATEGORIES|wc -l`
2454 tom.houday 199
			if [ $ok != "1" ]
1926 richard 200
			then
201
				$SED "/^$ENABLE_CATEGORIE$/d" $WL_CATEGORIES_ENABLED
202
			fi
203
		done
1293 richard 204
		# Creation of DNSMASQ and Iptables BL and WL
1015 richard 205
		for LIST in $BL_CATEGORIES $WL_CATEGORIES	# for each list (bl and wl)
854 richard 206
		do
1015 richard 207
			for PATH_FILE in `cat $LIST` # for each category
208
			do
1938 richard 209
				DOMAIN=`basename $PATH_FILE`
210
				echo -n "$DOMAIN, "
2454 tom.houday 211
				if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
1015 richard 212
				then
213
					touch $PATH_FILE/urls
2521 armand.ito 214
					chown e2guardian:apache $PATH_FILE/urls
1015 richard 215
				fi
2454 tom.houday 216
				cp $PATH_FILE/domains $FILE_tmp
2192 richard 217
				clean_split # clean ossi custom files & split them for dnsmasq and for iptables
1015 richard 218
				if [ "$LIST" == "$BL_CATEGORIES" ]
219
				then
1365 richard 220
					# adapt to the dnsmasq syntax for the blacklist
2454 tom.houday 221
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp
1938 richard 222
					mv $FILE_tmp $DIR_DNS_BL/$DOMAIN.conf
223
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAIN
1015 richard 224
				else
1365 richard 225
					# adapt to the dnsmasq syntax for the whitelist
2454 tom.houday 226
					$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp
1938 richard 227
					mv $FILE_tmp $DIR_DNS_WL/$DOMAIN.conf
1015 richard 228
				fi
229
			done
854 richard 230
		done
1940 richard 231
		echo
1953 richard 232
		chown -R root:apache $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
2454 tom.houday 233
		chmod 770 $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
1940 richard 234
		chmod -f 660 $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
1015 richard 235
		rm -f $FILE_tmp $FILE_ip_tmp
1339 richard 236
		rm -rf $DIR_tmp
654 richard 237
		;;
2192 richard 238
	# Rsync the categories which are listed in "/usr/local/etc/update_cat.conf". Cron run this function every 12h
1898 richard 239
	-update_cat | --update_cat)
1874 raphael.pi 240
		if [ $(cat /usr/local/etc/update_cat.conf | wc -l) -ne 0 ]
241
		then
1898 richard 242
			echo -n "Updating categories in /usr/local/etc/update_cat.conf ..."
243
			cat /usr/local/etc/update_cat.conf | while read LIGNE_RSYNC
244
			do
245
				CATEGORIE=$(echo $LIGNE_RSYNC | cut -d' ' -f1)
246
				URL=$(echo $LIGNE_RSYNC | cut -d' ' -f2)
247
				PATH_FILE=$(find $DIR_DG_BL/ -type d -name $CATEGORIE) # retrieve directory name of the category
248
				rsync -rv $URL $(dirname $PATH_FILE ) #rsync inside of the blacklist directory
249
				# Creation of DNSMASQ and Iptables BL and WL
1938 richard 250
				DOMAIN=$(basename $PATH_FILE)
2192 richard 251
				cp $PATH_FILE/domains $FILE_tmp
252
				clean_split  # clean ossi custom files & split them for dnsmasq and for iptables
1898 richard 253
				black=`grep black $PATH_FILE/usage |wc -l`
254
				if [ $black == "1" ]
255
				then
256
					# adapt to the dnsmasq syntax for the blacklist
2454 tom.houday 257
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp
1938 richard 258
					mv $FILE_tmp $DIR_DNS_BL/$DOMAIN.conf
259
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAIN
1898 richard 260
				else
261
					# adapt to the dnsmasq syntax for the whitelist
2454 tom.houday 262
					$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp
1938 richard 263
					mv $FILE_tmp $DIR_DNS_WL/$DOMAIN.conf
264
					mv $FILE_ip_tmp $DIR_IP_WL/$DOMAIN
1898 richard 265
				fi
266
				rm -f $FILE_tmp $FILE_ip_tmp
267
			done
268
			/usr/bin/systemctl restart dnsmasq-whitelist
269
			/usr/bin/systemctl restart dnsmasq-blacklist
2521 armand.ito 270
			/usr/bin/systemctl restart e2guardian
1898 richard 271
			/usr/local/bin/alcasar-iptables.sh
1867 raphael.pi 272
		else
2454 tom.houday 273
			echo -n "/usr/local/etc/update_cat.conf is empty ..."
1867 raphael.pi 274
		fi
2454 tom.houday 275
		echo
1867 raphael.pi 276
		;;
1938 richard 277
	# reload when selected categories are changed or when ossi change his custom files
386 franck 278
	-reload | --reload)
1015 richard 279
		# for DG
311 richard 280
		cat_choice
1042 richard 281
		#  for dnsmasq (rehabited domain names)
316 richard 282
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
311 richard 283
		then
2434 franck 284
			rm -f $DIR_DNS_BL_ENABLED/authorized-ossi-bl $DIR_DNS_BL/authorized-ossi-bl.conf
285
			touch $DIR_DNS_BL/authorized-ossi-bl.conf
316 richard 286
			for i in `cat $DIR_DG/exceptionsitelist`
311 richard 287
			do
1015 richard 288
				$SED "/$i/d" $DIR_DNS_BL/*
2434 franck 289
				echo "server=/$i/#" >> $DIR_DNS_BL/authorized-ossi-bl.conf
311 richard 290
			done
2434 franck 291
			ln -s $DIR_DNS_BL/authorized-ossi-bl.conf $DIR_DNS_BL_ENABLED/authorized-ossi-bl
311 richard 292
		fi
1938 richard 293
		# adapt OSSI BL & WL custom files
2675 lucas.echa 294
		for dir in $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
1938 richard 295
		do
296
			rm -f $dir/ossi*
297
		done
1954 richard 298
		find $DIR_DG_BL/ -type f -name domains | grep ossi- > $FILE_tmp # retrieve ossi directories name where a domain file exist
1938 richard 299
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
300
		for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
301
		do
2192 richard 302
			chown -R root:apache $ossi_custom_dir
303
			chmod 770 $ossi_custom_dir
1938 richard 304
			ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
1954 richard 305
			short_categorie=`echo "$ossi_categorie" | cut -d"-" -f2`
306
			if [ $short_categorie == "bl" ]
307
			then
308
				categorie_type="black"
309
			else
310
				categorie_type="white"
311
			fi
2192 richard 312
			$SED "s/\r//" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove Windows <CR> from custom file
313
			cp $ossi_custom_dir/domains $FILE_tmp
314
			clean_split # clean ossi custom files & split them for dnsmasq and for iptables
1951 richard 315
			if [ $categorie_type == "white" ]
1938 richard 316
			then
1951 richard 317
			# adapt the file to the dnsmasq syntax and enable it if needed
318
			# for the WL
2454 tom.houday 319
				$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp
1938 richard 320
				mv $FILE_tmp $DIR_DNS_WL/$ossi_categorie.conf
321
				mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
1951 richard 322
				enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
323
				if [ $enabled == "1" ]
324
				then
2454 tom.houday 325
					$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES
2521 armand.ito 326
					$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
1951 richard 327
					ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
328
					ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
329
				fi
1938 richard 330
			else
1951 richard 331
			# for the BL
2454 tom.houday 332
				$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp
1938 richard 333
				mv $FILE_tmp $DIR_DNS_BL/$ossi_categorie.conf
334
				mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
1951 richard 335
				enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
336
				if [ $enabled == "1" ]
337
				then
2454 tom.houday 338
					$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES
2521 armand.ito 339
					$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
1951 richard 340
					ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
341
					ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
342
				fi
1938 richard 343
			fi
344
		done
1958 richard 345
		for file in $BL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES $WL_CATEGORIES_ENABLED
346
		do
347
			sort +0.0 -0.2 $file -o $FILE_tmp
348
			mv $FILE_tmp $file
349
			chown root:apache $file
350
			chmod 660 $file
351
		done
1969 richard 352
		chown -R root:apache $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
353
		chmod 660 $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
1957 richard 354
		if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
355
		then
356
			/usr/bin/systemctl restart dnsmasq-blacklist
357
			/usr/bin/systemctl restart dnsmasq-whitelist
2569 lucas.echa 358
			/usr/bin/systemctl restart e2guardian
1957 richard 359
			/usr/local/bin/alcasar-iptables.sh
360
		fi
503 richard 361
		;;
1 root 362
	*)
363
		echo "Argument inconnu :$1";
364
		echo "$usage"
365
		exit 1
366
		;;
367
esac