Subversion Repositories ALCASAR

Rev

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