Subversion Repositories ALCASAR

Rev

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

Rev 1969 Rev 2099
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1969 2016-06-28 22:12:54Z richard $
3
# $Id: alcasar-bl.sh 2099 2016-12-17 03:42:24Z raphael.pion $
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 308... Line 308...
308
		do
308
		do
309
			rm -f $dir/ossi*
309
			rm -f $dir/ossi*
310
		done
310
		done
311
		find $DIR_DG_BL/ -type f -name domains | grep ossi- > $FILE_tmp # retrieve ossi directories name where a domain file exist
311
		find $DIR_DG_BL/ -type f -name domains | grep ossi- > $FILE_tmp # retrieve ossi directories name where a domain file exist
312
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
312
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
-
 
313
		
-
 
314
		#retrieve max Top Level Domain for domain name synthax
-
 
315
		MAX_TLD=$(curl http://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v '-' | grep -v '#' | wc -L)
-
 
316
		if [ $(echo $MAX_TLD | wc -c) -eq 0 ];then
-
 
317
			MAX_TLD=18
-
 
318
		fi
-
 
319
		
313
		for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
320
		for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
314
		do
321
		do
315
			ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
322
			ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
316
			short_categorie=`echo "$ossi_categorie" | cut -d"-" -f2`
323
			short_categorie=`echo "$ossi_categorie" | cut -d"-" -f2`
317
			if [ $short_categorie == "bl" ]
324
			if [ $short_categorie == "bl" ]
Line 323... Line 330...
323
			$SED "s/\.\{2,10\}/\./g" $ossi_custom_dir/domains $ossi_custom_dir/urls # correction 'coma" instead of 'dot'
330
			$SED "s/\.\{2,10\}/\./g" $ossi_custom_dir/domains $ossi_custom_dir/urls # correction 'coma" instead of 'dot'
324
			$SED "/^$/d" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove empty lines
331
			$SED "/^$/d" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove empty lines
325
			$SED "s/\r//" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove Windows <CR>
332
			$SED "s/\r//" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove Windows <CR>
326
			# extract ip addresses for iptables
333
			# extract ip addresses for iptables
327
			awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $ossi_custom_dir/domains > $FILE_ip_tmp
334
			awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $ossi_custom_dir/domains > $FILE_ip_tmp
-
 
335
			
328
			# for dnsmask, remove IP addesses, accented characters and commented lines.
336
			#Extract domain name for dnsmask and check synthax of domain names
329
			egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $ossi_custom_dir/domains > $FILE_tmp
337
			grep -Eo "([a-zA-Z0-9_-.]+\.){1,2}[a-zA-Z]{2,$MAX_TDL}" $ossi_custom_dir/domains > $FILE_tmp
330
			$SED "/[äâëêïîöôüû]/d" $FILE_tmp
-
 
331
			$SED "/^#.*/d" $FILE_tmp
338
			
332
			if [ $categorie_type == "white" ]
339
			if [ $categorie_type == "white" ]
333
			then
340
			then
334
			# adapt the file to the dnsmasq syntax and enable it if needed
341
			# adapt the file to the dnsmasq syntax and enable it if needed
335
			# for the WL
342
			# for the WL
336
				$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
343
				$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp