Subversion Repositories ALCASAR

Rev

Rev 1953 | Rev 1955 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1953 Rev 1954
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1953 2016-06-18 06:18:11Z richard $
3
# $Id: alcasar-bl.sh 1954 2016-06-18 19:46:53Z richard $
4
 
4
 
5
# alcasar-bl.sh
5
# alcasar-bl.sh
6
# by Franck BOUIJOUX and Richard REY
6
# by Franck BOUIJOUX and Richard REY
7
# This script is distributed under the Gnu General Public License (GPL)
7
# This script is distributed under the Gnu General Public License (GPL)
8
 
8
 
Line 71... Line 71...
71
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
71
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
72
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
72
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
73
	done
73
	done
74
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
74
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
75
	mv $FILE_tmp $BL_CATEGORIES
75
	mv $FILE_tmp $BL_CATEGORIES
-
 
76
	chown root:apache $BL_CATEGORIES
76
 
77
 
77
# process the file $WL_CATEGORIES with the choice of categories 
78
# process the file $WL_CATEGORIES with the choice of categories 
78
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
79
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
79
	do
80
	do
80
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
81
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
81
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
82
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
82
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
83
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
83
	done
84
	done
84
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
85
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
85
	mv $FILE_tmp $WL_CATEGORIES
86
	mv $FILE_tmp $WL_CATEGORIES
-
 
87
	chown root:apache $WL_CATEGORIES
86
}
88
}
87
 
89
 
88
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
90
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
89
nb_args=$#
91
nb_args=$#
90
args=$1
92
args=$1
Line 302... Line 304...
302
		# adapt OSSI BL & WL custom files
304
		# adapt OSSI BL & WL custom files
303
		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
305
		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
304
		do
306
		do
305
			rm -f $dir/ossi*
307
			rm -f $dir/ossi*
306
		done
308
		done
307
		find $DIR_DG_BL/ -type f -name domains | grep ossi > $FILE_tmp # retrieve ossi directories name where a domain file exist
309
		find $DIR_DG_BL/ -type f -name domains | grep ossi- > $FILE_tmp # retrieve ossi directories name where a domain file exist
308
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
310
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
309
		for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
311
		for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
310
		do
312
		do
311
			ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
313
			ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
312
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$ossi_categorie$ $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
314
			short_categorie=`echo "$ossi_categorie" | cut -d"-" -f2`
-
 
315
			if [ $short_categorie == "bl" ]
-
 
316
			then
-
 
317
				categorie_type="black"
-
 
318
			else
-
 
319
				categorie_type="white"
-
 
320
			fi
313
			$SED "s/\.\{2,10\}/\./g" $ossi_custom_dir/domains $ossi_custom_dir/urls # correction 'coma" instead of 'dot'
321
			$SED "s/\.\{2,10\}/\./g" $ossi_custom_dir/domains $ossi_custom_dir/urls # correction 'coma" instead of 'dot'
314
			$SED "/^$/d" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove empty lines
322
			$SED "/^$/d" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove empty lines
315
			# extract ip addresses for iptables
323
			# extract ip addresses for iptables
316
			awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $ossi_custom_dir/domains > $FILE_ip_tmp
324
			awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $ossi_custom_dir/domains > $FILE_ip_tmp
317
			# for dnsmask, remove IP addesses, accented characters and commented lines.
325
			# for dnsmask, remove IP addesses, accented characters and commented lines.
Line 326... Line 334...
326
				mv $FILE_tmp $DIR_DNS_WL/$ossi_categorie.conf
334
				mv $FILE_tmp $DIR_DNS_WL/$ossi_categorie.conf
327
				mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
335
				mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
328
				enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
336
				enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
329
				if [ $enabled == "1" ]
337
				if [ $enabled == "1" ]
330
				then
338
				then
331
					echo "wl - $ossi_categorie - $categorie_type"
-
 
332
					$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES 
339
					$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES 
333
					$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
340
					$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
334
					ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
341
					ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
335
					ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
342
					ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
336
				fi
343
				fi
Line 340... Line 347...
340
				mv $FILE_tmp $DIR_DNS_BL/$ossi_categorie.conf
347
				mv $FILE_tmp $DIR_DNS_BL/$ossi_categorie.conf
341
				mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
348
				mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
342
				enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
349
				enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
343
				if [ $enabled == "1" ]
350
				if [ $enabled == "1" ]
344
				then
351
				then
345
					echo "bl - $ossi_categorie - $categorie_type"
-
 
346
					$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES 
352
					$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES 
347
					$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
353
					$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
348
					ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
354
					ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
349
					ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
355
					ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
350
				fi
356
				fi
351
			fi
357
			fi
352
		done
358
		done
353
		sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
359
		sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
354
		mv $FILE_tmp $BL_CATEGORIES
360
		mv $FILE_tmp $BL_CATEGORIES
-
 
361
		chown root:apache $BL_CATEGORIES
355
		sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
362
		sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
356
		mv $FILE_tmp $WL_CATEGORIES
363
		mv $FILE_tmp $WL_CATEGORIES
-
 
364
		chown root:apache $WL_CATEGORIES
357
		/usr/bin/systemctl restart dnsmasq-blacklist
365
		/usr/bin/systemctl restart dnsmasq-blacklist
358
		/usr/bin/systemctl restart dnsmasq-whitelist
366
		/usr/bin/systemctl restart dnsmasq-whitelist
359
		/usr/local/bin/alcasar-iptables.sh
367
		/usr/local/bin/alcasar-iptables.sh
360
		;;
368
		;;
361
	*)
369
	*)