Subversion Repositories ALCASAR

Rev

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

Rev 2099 Rev 2187
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 2099 2016-12-17 03:42:24Z raphael.pion $
3
# $Id: alcasar-bl.sh 2187 2017-04-27 22:18:45Z 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 217... Line 217...
217
		  		if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
217
		  		if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
218
				then
218
				then
219
					touch $PATH_FILE/urls
219
					touch $PATH_FILE/urls
220
					chown dansguardian:apache $PATH_FILE/urls
220
					chown dansguardian:apache $PATH_FILE/urls
221
				fi
221
				fi
-
 
222
				$SED "/[äâëêïîöôüû@]/d" $FILE_tmp
-
 
223
				$SED "/^#.*/d" $FILE_tmp
222
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
224
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
223
				# extract ip addresses for iptables
225
				# extract ip addresses for iptables
224
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
226
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
225
				# for dnsmask, remove IP addesses, accented characters and commented lines.
227
				# for dnsmask, remove IP addesses, accented characters and commented lines.
226
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
228
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
227
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
-
 
228
				$SED "/^#.*/d" $FILE_tmp
-
 
229
				if [ "$LIST" == "$BL_CATEGORIES" ]
229
				if [ "$LIST" == "$BL_CATEGORIES" ]
230
				then
230
				then
231
					# adapt to the dnsmasq syntax for the blacklist
231
					# adapt to the dnsmasq syntax for the blacklist
232
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
232
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
233
					mv $FILE_tmp $DIR_DNS_BL/$DOMAIN.conf
233
					mv $FILE_tmp $DIR_DNS_BL/$DOMAIN.conf
Line 263... Line 263...
263
				$SED "/^$/d" $PATH_FILE/domains $PATH_FILE/urls # remove empty lines
263
				$SED "/^$/d" $PATH_FILE/domains $PATH_FILE/urls # remove empty lines
264
				# extract ip addresses for iptables
264
				# extract ip addresses for iptables
265
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
265
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
266
				# for dnsmask, remove IP addresses, accentuated characters and commented lines.
266
				# for dnsmask, remove IP addresses, accentuated characters and commented lines.
267
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
267
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
268
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
268
				$SED "/[äâëêïîöôüû@]/d" $FILE_tmp
269
				$SED "/^#.*/d" $FILE_tmp
269
				$SED "/^#.*/d" $FILE_tmp
270
				black=`grep black $PATH_FILE/usage |wc -l`
270
				black=`grep black $PATH_FILE/usage |wc -l`
271
				if [ $black == "1" ]
271
				if [ $black == "1" ]
272
				then
272
				then
273
					# adapt to the dnsmasq syntax for the blacklist
273
					# adapt to the dnsmasq syntax for the blacklist
Line 325... Line 325...
325
			then
325
			then
326
				categorie_type="black"
326
				categorie_type="black"
327
			else
327
			else
328
				categorie_type="white"
328
				categorie_type="white"
329
			fi
329
			fi
330
			$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'
331
			$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
332
			$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>
333
			# extract ip addresses for iptables
333
			# extract ip addresses for iptables
334
			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
			
-
 
336
			#Extract domain name for dnsmask and check synthax of domain names
335
 			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
336
# search for correction	egrep "([a-zA-Z0-9_-.]+\.){1,2}[a-zA-Z]{2,$MAX_TLD}" $ossi_custom_dir/domains > $FILE_tmp
338
			
-
 
339
			if [ $categorie_type == "white" ]
337
			if [ $categorie_type == "white" ]
340
			then
338
			then
341
			# adapt the file to the dnsmasq syntax and enable it if needed
339
			# adapt the file to the dnsmasq syntax and enable it if needed
342
			# for the WL
340
			# for the WL
343
				$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
341
				$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp