Subversion Repositories ALCASAR

Rev

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

Rev 1886 Rev 1898
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1886 2016-05-12 15:36:52Z raphael.pion $
3
# $Id: alcasar-bl.sh 1898 2016-05-18 16:33:55Z 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 256... Line 256...
256
		# Restoring ossi file of BL IP
256
		# Restoring ossi file of BL IP
257
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
257
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
258
		rm -rf $DIR_tmp
258
		rm -rf $DIR_tmp
259
		echo
259
		echo
260
		;;
260
		;;
261
		#mise a jour d'une categorie avec rsync
261
	# update the categories which are written in "/usr/local/etc/update_cat.conf" with rsync
262
		-update_cat | --update_cat)
262
	-update_cat | --update_cat)
263
		
-
 
264
		if [ $(cat /usr/local/etc/update_cat.conf | wc -l) -ne 0 ]
263
		if [ $(cat /usr/local/etc/update_cat.conf | wc -l) -ne 0 ]
265
		then
264
		then
266
		echo -n "Updating categories in /usr/local/etc/update_cat.conf ..."
265
			echo -n "Updating categories in /usr/local/etc/update_cat.conf ..."
267
 
-
 
268
		cat /usr/local/etc/update_cat.conf | while read LIGNE_RSYNC
266
			cat /usr/local/etc/update_cat.conf | while read LIGNE_RSYNC
269
		do
267
			do
270
		CATEGORIE=$(echo $LIGNE_RSYNC | cut -d' ' -f1)
268
				CATEGORIE=$(echo $LIGNE_RSYNC | cut -d' ' -f1)
271
		URL=$(echo $LIGNE_RSYNC | cut -d' ' -f2)
269
				URL=$(echo $LIGNE_RSYNC | cut -d' ' -f2)
272
			
-
 
273
		PATH_FILE=$(find $DIR_DG_BL/ -type d -name $CATEGORIE) # retrieve directory name of the category
270
				PATH_FILE=$(find $DIR_DG_BL/ -type d -name $CATEGORIE) # retrieve directory name of the category
274
		rsync -rv $URL $(dirname $PATH_FILE ) #rsync inside of the blacklist directory
271
				rsync -rv $URL $(dirname $PATH_FILE ) #rsync inside of the blacklist directory
275
		
-
 
276
		# Creation of DNSMASQ and Iptables BL and WL
272
				# Creation of DNSMASQ and Iptables BL and WL
277
		DOMAINE=$(basename $PATH_FILE)
273
				DOMAINE=$(basename $PATH_FILE)
278
 
-
 
279
		#correct some synthaxes
274
				# correct some synthaxes
280
		$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls
275
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls
281
		# extract ip addresses for iptables
276
				# extract ip addresses for iptables
282
		awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
277
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
283
		# for dnsmask, remove IP addesses, accented characters and commented lines.
278
				# for dnsmask, remove IP addresses, accentuated characters and commented lines.
284
		egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
279
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
285
		$SED "/[äâëêïîöôüû]/d" $FILE_tmp
280
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
286
		$SED "/^#.*/d" $FILE_tmp
281
				$SED "/^#.*/d" $FILE_tmp
287
		
-
 
288
		black=`grep black $PATH_FILE/usage |wc -l`
282
				black=`grep black $PATH_FILE/usage |wc -l`
289
		if [ $black == "1" ]
283
				if [ $black == "1" ]
290
		then
284
				then
291
			# adapt to the dnsmasq syntax for the blacklist
285
					# adapt to the dnsmasq syntax for the blacklist
292
			$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
286
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
293
			mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
287
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
294
			mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
288
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
295
		else
289
				else
296
			# adapt to the dnsmasq syntax for the whitelist
290
					# adapt to the dnsmasq syntax for the whitelist
297
			$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
291
					$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
298
			mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
292
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
299
		fi
293
				fi
300
		rm -f $FILE_tmp $FILE_ip_tmp
294
				rm -f $FILE_tmp $FILE_ip_tmp
301
 
-
 
302
		done
295
			done
303
		
-
 
304
		/usr/bin/systemctl restart dnsmasq-whitelist
296
			/usr/bin/systemctl restart dnsmasq-whitelist
305
		/usr/bin/systemctl restart dnsmasq-blacklist
297
			/usr/bin/systemctl restart dnsmasq-blacklist
306
		/usr/bin/systemctl restart dansguardian
298
			/usr/bin/systemctl restart dansguardian
307
		/usr/local/bin/alcasar-iptables.sh
299
			/usr/local/bin/alcasar-iptables.sh
308
		else
300
		else
309
		echo -n "/usr/local/etc/update_cat.conf is empty ..."
301
			  echo -n "/usr/local/etc/update_cat.conf is empty ..."
310
		fi
302
		fi
311
		
-
 
312
	
-
 
313
		echo 
303
		echo 
314
		;;
304
		;;
315
	# reload when categories are changed 
305
	# reload when categories are changed 
316
	-reload | --reload)
306
	-reload | --reload)
317
		# for DG
307
		# for DG