Subversion Repositories ALCASAR

Rev

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

Rev 1864 Rev 1867
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1864 2016-05-03 12:45:00Z raphael.pion $
3
# $Id: alcasar-bl.sh 1867 2016-05-04 12:22:08Z 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 135... Line 135...
135
	chown apache $DIR_IP_BL/ossi
135
	chown apache $DIR_IP_BL/ossi
136
	rm -rf $DIR_tmp
136
	rm -rf $DIR_tmp
137
	
137
	
138
}
138
}
139
 
139
 
140
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
140
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat } & categorie & url_rsync"
141
nb_args=$#
141
nb_args=$#
142
args=$1
142
args=$1
143
if [ $nb_args -eq 0 ]
143
if [ $nb_args -eq 0 ]
144
then
144
then
145
	  args="-h"
145
	  args="-h"
Line 223... Line 223...
223
					touch $PATH_FILE/urls
223
					touch $PATH_FILE/urls
224
					chown dansguardian:apache $PATH_FILE/urls
224
					chown dansguardian:apache $PATH_FILE/urls
225
				fi
225
				fi
226
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
226
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
227
				# extract ip addresses for iptables
227
				# extract ip addresses for iptables
228
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
228
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
229
				# for dnsmask, remove IP addesses, accented characters and commented lines.
229
				# for dnsmask, remove IP addesses, accented characters and commented lines.
230
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
230
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
231
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
231
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
232
				$SED "/^#.*/d" $FILE_tmp
232
				$SED "/^#.*/d" $FILE_tmp
233
				if [ "$LIST" == "$BL_CATEGORIES" ]
233
				if [ "$LIST" == "$BL_CATEGORIES" ]
Line 247... Line 247...
247
		# Restoring ossi file of BL IP
247
		# Restoring ossi file of BL IP
248
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
248
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
249
		rm -rf $DIR_tmp
249
		rm -rf $DIR_tmp
250
		echo
250
		echo
251
		;;
251
		;;
-
 
252
		#mise a jour d'une categorie avec rsync
-
 
253
		-update_cat | --update_cat)
-
 
254
		
-
 
255
		if [ $# -ge 3 ]
-
 
256
		then
-
 
257
		echo -n "Updating $2 category ..."
-
 
258
 
-
 
259
		PATH_FILE=$(find $DIR_DG_BL/ -type d -name $2) # retrieve directory name of the category
-
 
260
		rsync -rv $3 $(dirname $PATH_FILE ) #rsync inside of the blacklist directory
-
 
261
		
-
 
262
		# Creation of DNSMASQ and Iptables BL and WL
-
 
263
		DOMAINE=$(basename $PATH_FILE)
-
 
264
		
-
 
265
		$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
-
 
266
		# extract ip addresses for iptables
-
 
267
		awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
-
 
268
		# for dnsmask, remove IP addesses, accented characters and commented lines.
-
 
269
		egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
-
 
270
		$SED "/[äâëêïîöôüû]/d" $FILE_tmp
-
 
271
		$SED "/^#.*/d" $FILE_tmp
-
 
272
		
-
 
273
		black=`grep black $PATH_FILE/usage |wc -l`
-
 
274
		if [ $black == "1" ]
-
 
275
		then
-
 
276
			# adapt to the dnsmasq syntax for the blacklist
-
 
277
			$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
-
 
278
			mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
-
 
279
			mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
-
 
280
			/usr/bin/systemctl restart dnsmasq-blacklist
-
 
281
		else
-
 
282
			# adapt to the dnsmasq syntax for the whitelist
-
 
283
			$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
-
 
284
			mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
-
 
285
			/usr/bin/systemctl restart dnsmasq-whitelist
-
 
286
		fi
-
 
287
 
-
 
288
		rm -f $FILE_tmp $FILE_ip_tmp
-
 
289
		/usr/bin/systemctl restart dansguardian
-
 
290
		/usr/local/bin/alcasar-iptables.sh
-
 
291
		
-
 
292
		echo "MAJ RSYNC réussie"
-
 
293
	
-
 
294
		else
-
 
295
			echo "$usage"
-
 
296
		fi
-
 
297
		;;
252
	# reload when categories are changed 
298
	# reload when categories are changed 
253
	-reload | --reload)
299
	-reload | --reload)
254
		# for DG
300
		# for DG
255
		chown -R dansguardian:apache $DIR_DG_BL/ossi
301
		chown -R dansguardian:apache $DIR_DG_BL/ossi
256
		chmod -R g+w $DIR_DG_BL/ossi
302
		chmod -R g+w $DIR_DG_BL/ossi
Line 277... Line 323...
277
		exit 1
323
		exit 1
278
		;;
324
		;;
279
esac
325
esac
280
 
326
 
281
 
327
 
-
 
328