Subversion Repositories ALCASAR

Rev

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

Rev 1903 Rev 1912
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1903 2016-05-19 12:14:00Z raphael.pion $
3
# $Id: alcasar-bl.sh 1912 2016-05-29 13:18:17Z 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 46... Line 46...
46
# enable/disable the BL & WL categories
46
# enable/disable the BL & WL categories
47
function cat_choice (){
47
function cat_choice (){
48
	# saving ossi category
48
	# saving ossi category
49
	mkdir $DIR_tmp
49
	mkdir $DIR_tmp
50
	cp $DIR_IP_BL/ossi $DIR_tmp
50
	cp $DIR_IP_BL/ossi $DIR_tmp
51
 
-
 
52
	#ip BL ENABLE
51
	#ip BL ENABLE
53
	if [ -d $DIR_IP_BL_ENABLED ]
52
	if [ -d $DIR_IP_BL_ENABLED ]
54
	then
53
	then
55
		for file in `ls -1 $DIR_IP_BL_ENABLED | grep -v "^ossi-*"`
54
		for file in `ls -1 $DIR_IP_BL_ENABLED | grep -v "^ossi-*"`
56
		do
55
		do
Line 135... Line 134...
135
	then
134
	then
136
		touch $DIR_CONF/update_cat.conf
135
		touch $DIR_CONF/update_cat.conf
137
		chown root:apache $DIR_CONF/update_cat.conf
136
		chown root:apache $DIR_CONF/update_cat.conf
138
		chmod 660 $DIR_CONF/update_cat.conf
137
		chmod 660 $DIR_CONF/update_cat.conf
139
	fi
138
	fi
140
	
-
 
141
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
139
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
142
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
140
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
-
 
141
 
143
	# process the file $BL_CATEGORIES with the choice of categories 
142
	# process the file $BL_CATEGORIES with the choice of categories 
144
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
143
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
145
	do
144
	do
146
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
145
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
147
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
146
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
Line 150... Line 149...
150
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
149
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
151
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
150
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
152
	done
151
	done
153
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
152
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
154
	mv $FILE_tmp $BL_CATEGORIES
153
	mv $FILE_tmp $BL_CATEGORIES
-
 
154
 
155
	# process the file $WL_CATEGORIES with the choice of categories 
155
	# process the file $WL_CATEGORIES with the choice of categories 
156
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
156
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
157
	do
157
	do
158
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
158
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
159
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
159
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
160
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
160
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
161
	done
161
	done
162
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
162
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
163
	mv $FILE_tmp $WL_CATEGORIES
163
	mv $FILE_tmp $WL_CATEGORIES
164
	
164
 
165
	# restoring ip files and ossi category BL/WL
165
	# restoring ip files and ossi category BL/WL
166
	mv $DIR_tmp/ossi $DIR_IP_BL
166
	mv $DIR_tmp/ossi $DIR_IP_BL
167
	chown apache $DIR_IP_BL/ossi
167
	chown apache $DIR_IP_BL/ossi
168
	rm -rf $DIR_tmp
168
	rm -rf $DIR_tmp
169
	
-
 
170
}
169
}
171
 
170
 
172
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
171
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
173
nb_args=$#
172
nb_args=$#
174
args=$1
173
args=$1
Line 201... Line 200...
201
		cat_choice
200
		cat_choice
202
		;;
201
		;;
203
	# Adapt Toulouse University BL to ALCASAR architecture (dnsmasq + DG + iptables)
202
	# Adapt Toulouse University BL to ALCASAR architecture (dnsmasq + DG + iptables)
204
	-adapt | --adapt)
203
	-adapt | --adapt)
205
		echo -n "Adaptation process of Toulouse University blackList. Please wait : "
204
		echo -n "Adaptation process of Toulouse University blackList. Please wait : "
206
	
-
 
207
		#to keep ossi files
205
		# keep custom files (ossi)
208
		if [ -d $DIR_IP_BL -a -d $DIR_IP_WL -a -d $DIR_DNS_BL -a -d $DIR_DNS_WL ]
-
 
209
		then
-
 
210
			mkdir $tmp_DIR_IP_BL $tmp_DIR_IP_WL $tmp_DIR_DNS_BL $tmp_DIR_DNS_WL
-
 
211
			for x in $(ls -1 $DIR_IP_BL | grep "^ossi*")
206
		for x in $(ls -1 $DIR_IP_BL | grep "^ossi*")
212
			do
207
		do
213
				mv $DIR_IP_BL/$x $tmp_DIR_IP_BL
208
			mv $DIR_IP_BL/$x $tmp_DIR_IP_BL
214
			done
209
		done
215
			for x in $(ls -1 $DIR_IP_WL | grep "^ossi*")
210
		for x in $(ls -1 $DIR_IP_WL | grep "^ossi*")
216
			do
211
		do
217
				mv $DIR_IP_WL/$x $tmp_DIR_IP_WL
212
			mv $DIR_IP_WL/$x $tmp_DIR_IP_WL
218
			done
213
		done
219
			for x in $(ls -1 $DIR_DNS_BL | grep "^ossi*")
214
		for x in $(ls -1 $DIR_DNS_BL | grep "^ossi*")
220
			do
215
		do
221
				mv $DIR_DNS_BL/$x $tmp_DIR_DNS_BL
216
			mv $DIR_DNS_BL/$x $tmp_DIR_DNS_BL
222
			done
217
		done
223
			for x in $(ls -1 $DIR_DNS_WL | grep "^ossi*")
218
		for x in $(ls -1 $DIR_DNS_WL | grep "^ossi*")
224
			do
219
		do
225
				mv $DIR_DNS_WL/$x $tmp_DIR_DNS_WL
220
			mv $DIR_DNS_WL/$x $tmp_DIR_DNS_WL
226
			done
221
		done
227
		fi
-
 
228
			
-
 
229
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
222
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
230
		then
223
		then
231
			[ -d $DIR_DG_BL/ossi ] && mv $DIR_DG_BL/ossi $DIR_tmp
-
 
232
			[ -e $DIR_IP_BL/ossi ] && mv $DIR_IP_BL/ossi $DIR_tmp/ossi-ip-bl
-
 
233
			rm -rf $DIR_DG_BL $DIR_IP_BL
224
			rm -rf $DIR_DG_BL $DIR_IP_BL
234
			mkdir $DIR_DG_BL $DIR_IP_BL
225
			mkdir $DIR_DG_BL $DIR_IP_BL
235
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
226
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
236
			[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
-
 
237
		fi
227
		fi
238
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
228
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
239
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
229
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
240
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
230
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
241
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
231
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
Line 295... Line 285...
295
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
285
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
296
				fi
286
				fi
297
			done
287
			done
298
		done
288
		done
299
		rm -f $FILE_tmp $FILE_ip_tmp
289
		rm -f $FILE_tmp $FILE_ip_tmp
300
		# Restoring ossi file of BL IP
290
		# Restoring custom files (ossi)
301
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
-
 
302
		rm -rf $DIR_tmp
291
		rm -rf $DIR_tmp
303
		
-
 
304
		if [ -d $tmp_DIR_IP_BL -a -d $tmp_DIR_IP_WL -a -d $tmp_DIR_DNS_BL -a -d $tmp_DIR_DNS_WL ]
292
		if [ -d $tmp_DIR_IP_BL -a -d $tmp_DIR_IP_WL -a -d $tmp_DIR_DNS_BL -a -d $tmp_DIR_DNS_WL ]
305
		then
293
		then
306
			for x in $(ls -1 $tmp_DIR_IP_BL | grep "^ossi*")
294
			for x in $(ls -1 $tmp_DIR_IP_BL | grep "^ossi*")
307
			do
295
			do
308
				mv $tmp_DIR_IP_BL/$x $DIR_IP_BL
296
				mv $tmp_DIR_IP_BL/$x $DIR_IP_BL
Line 317... Line 305...
317
			done
305
			done
318
			for x in $(ls -1 $tmp_DIR_DNS_WL | grep "^ossi*")
306
			for x in $(ls -1 $tmp_DIR_DNS_WL | grep "^ossi*")
319
			do
307
			do
320
				mv $tmp_DIR_DNS_WL/$x $DIR_DNS_WL
308
				mv $tmp_DIR_DNS_WL/$x $DIR_DNS_WL
321
			done
309
			done
322
		
-
 
323
			rm -rf $tmp_DIR_IP_BL $tmp_DIR_IP_WL $tmp_DIR_DNS_BL $tmp_DIR_DNS_WL
310
			rm -rf $tmp_DIR_IP_BL $tmp_DIR_IP_WL $tmp_DIR_DNS_BL $tmp_DIR_DNS_WL
324
		fi
311
		fi
325
		
-
 
326
		echo
312
		echo
327
		;;
313
		;;
328
	# update the categories which are written in "/usr/local/etc/update_cat.conf" with rsync
314
	# update the categories which are written in "/usr/local/etc/update_cat.conf" with rsync
329
	-update_cat | --update_cat)
315
	-update_cat | --update_cat)
330
		if [ $(cat /usr/local/etc/update_cat.conf | wc -l) -ne 0 ]
316
		if [ $(cat /usr/local/etc/update_cat.conf | wc -l) -ne 0 ]