Subversion Repositories ALCASAR

Rev

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

Rev 1015 Rev 1042
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1015 2013-01-27 22:43:29Z richard $
3
# $Id: alcasar-bl.sh 1042 2013-03-10 17:56:30Z 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 31... Line 31...
31
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled"			#	'	'	'	WL	'	'	'
31
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled"			#	'	'	'	WL	'	'	'
32
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled"			#	'	'	ip BL (only enabled categories)	
32
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled"			#	'	'	ip BL (only enabled categories)	
33
BL_SERVER="dsi.ut-capitole.fr"
33
BL_SERVER="dsi.ut-capitole.fr"
34
SED="/bin/sed -i"
34
SED="/bin/sed -i"
35
 
35
 
36
# enable/disable the BL categories
36
# enable/disable the BL & WL categories
37
function cat_choice (){
37
function cat_choice (){
38
	rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED # cleaning for dnsmasq and iptables
38
	rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED # cleaning for dnsmasq and iptables
39
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
39
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
40
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES # cleaning categories file (comment all lines)
40
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
41
	mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED 
41
	mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED 
42
	# process the file $BL_CATEGORIES with the choice of categories 
42
	# process the file $BL_CATEGORIES with the choice of categories 
43
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
43
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
44
	do
44
	do
45
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
45
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
Line 49... Line 49...
49
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # we let DG filters domain in order to prevent bypass by proxy http vpn ;-)
49
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # we let DG filters domain in order to prevent bypass by proxy http vpn ;-)
50
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
50
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
51
	done
51
	done
52
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
52
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
53
	mv $FILE_tmp $BL_CATEGORIES
53
	mv $FILE_tmp $BL_CATEGORIES
-
 
54
	# process the file $WL_CATEGORIES with the choice of categories 
-
 
55
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
-
 
56
	do
-
 
57
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
-
 
58
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
-
 
59
		ln -s $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
-
 
60
	done
-
 
61
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
-
 
62
	mv $FILE_tmp $WL_CATEGORIES
54
}
63
}
55
function bl_enable (){
64
function bl_enable (){
56
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
65
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
57
	if [ "$PARENT_SCRIPT" != "/usr/local/bin/alcasar-conf.sh" ] # don't launch on install stage
66
	if [ "$PARENT_SCRIPT" != "/usr/local/bin/alcasar-conf.sh" ] # don't launch on install stage
58
	then
67
	then
Line 127... Line 136...
127
			rm -rf $DIR_DG_BL
136
			rm -rf $DIR_DG_BL
128
			mkdir $DIR_DG_BL
137
			mkdir $DIR_DG_BL
129
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
138
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
130
			[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
139
			[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
131
			rm -rf $DIR_tmp
140
			rm -rf $DIR_tmp
132
			chown -R dansguardian:apache $DIR_DG
-
 
133
			chmod -R g+w $DIR_DG
-
 
134
		fi
141
		fi
135
		rm -f $BL_CATEGORIES $WL_CATEGORIES 
142
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
136
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
143
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
137
		touch $BL_CATEGORIES $WL_CATEGORIES
144
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
138
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
145
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
-
 
146
		chown -R dansguardian:apache $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
-
 
147
		chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
139
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
148
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
140
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
149
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
141
		for dir_categorie in `cat $FILE_tmp` # create the blackist and the whitelist files
150
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
142
		do
151
		do
143
			categorie=`echo $dir_categorie|cut -d "/" -f6`
152
			categorie=`echo $dir_categorie|cut -d "/" -f6`
144
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
153
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
145
			if [ "$categorie_type" == "white" ]
154
			if [ "$categorie_type" == "white" ]
146
			then
155
			then
147
				echo "$dir_categorie" >> $WL_CATEGORIES 
156
				echo "$dir_categorie" >> $WL_CATEGORIES 
148
				echo "$dir_categorie" >> $WL_CATEGORIES_ENABLED  # by default all WL are enabled 
157
				echo `basename $dir_categorie` >> $WL_CATEGORIES_ENABLED  # by default all WL are enabled 
149
			else
158
			else
150
				echo "$dir_categorie" >> $BL_CATEGORIES
159
				echo "$dir_categorie" >> $BL_CATEGORIES
151
			fi
160
			fi
152
		done
161
		done
153
		rm -f $FILE_tmp
162
		rm -f $FILE_tmp
Line 188... Line 197...
188
	-reload | --reload)
197
	-reload | --reload)
189
		# for DG
198
		# for DG
190
		chown -R dansguardian:apache $DIR_DG_BL/ossi
199
		chown -R dansguardian:apache $DIR_DG_BL/ossi
191
		chmod -R g+w $DIR_DG_BL/ossi
200
		chmod -R g+w $DIR_DG_BL/ossi
192
		cat_choice
201
		cat_choice
193
		#  for dnsmasq (noms de domaine réhabilités)
202
		#  for dnsmasq (rehabited domain names)
194
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
203
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
195
		then
204
		then
196
			for i in `cat $DIR_DG/exceptionsitelist`
205
			for i in `cat $DIR_DG/exceptionsitelist`
197
			do
206
			do
198
				$SED "/$i/d" $DIR_DNS_BL/*
207
				$SED "/$i/d" $DIR_DNS_BL/*
199
			done
208
			done
200
		fi
209
		fi
201
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
210
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
202
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
211
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
-
 
212
		cp -f $DIR_DG_BL/ossi/domains_wl $DIR_DNS_WL/ossi.conf
203
		DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
213
		DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
204
		DNS_FILTERING=${DNS_FILTERING:=off}
214
		DNS_FILTERING=${DNS_FILTERING:=off}
205
		if [ $DNS_FILTERING = on ]; then
215
		if [ $DNS_FILTERING = on ]; then
206
			bl_enable
216
			bl_enable
207
		else
217
		else