Subversion Repositories ALCASAR

Rev

Rev 1056 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1056 Rev 1057
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1056 2013-03-26 21:46:36Z stephane $
3
# $Id: alcasar-bl.sh 1057 2013-03-27 22:05:36Z 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
 
9
# Gestion de la BL pour le filtrage de domaine (via dnsmasq) et d'URL (via Dansguardian)
9
# Gestion de la BL pour le filtrage de domaine (via dnsmasq) et d'URL (via Dansguardian)
10
# Manage the BL for DnsBlackHole (dnsmasq) and URL filtering (Dansguardian)
10
# Manage the BL for DnsBlackHole (dnsmasq) and URL filtering (Dansguardian)
11
 
11
 
12
DIR_CONF="/usr/local/etc"
12
DIR_CONF="/usr/local/etc"
13
CONF_FILE="$DIR_CONF/alcasar.conf"
13
CONF_FILE="$DIR_CONF/alcasar.conf"
14
private_ip_mask=`grep PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
14
private_ip_mask=`grep PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
15
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
15
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
16
PRIVATE_IP=`echo $private_ip_mask | cut -d"/" -f1`			# ALCASAR LAN IP address
16
PRIVATE_IP=`echo $private_ip_mask | cut -d"/" -f1`			# ALCASAR LAN IP address
17
DIR_tmp="/tmp/blacklists"
17
DIR_tmp="/tmp/blacklists"
18
FILE_tmp="/tmp/filesfilter.txt"
18
FILE_tmp="/tmp/filesfilter.txt"
19
FILE_ip_tmp="/tmp/filesipfilter.txt"
19
FILE_ip_tmp="/tmp/filesipfilter.txt"
20
DIR_DG="/etc/dansguardian/lists"
20
DIR_DG="/etc/dansguardian/lists"
21
DIR_DG_BL="$DIR_DG/blacklists"
21
DIR_DG_BL="$DIR_DG/blacklists"
22
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories"				# list of names of the 	BL categories
22
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories"				# list of names of the 	BL categories
23
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories"				#'	'		WL	'
23
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories"				#'	'		WL	'
24
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled"		#	'	'	BL enabled categories
24
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled"		#	'	'	BL enabled categories
25
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled"		#	'	'	WL enabled categories
25
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled"		#	'	'	WL enabled categories
26
DIR_SHARE="/usr/local/share"
26
DIR_SHARE="/usr/local/share"
27
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl"					# all the BL in the DNSMASQ format
27
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl"					# all the BL in the DNSMASQ format
28
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl"					# all the WL	'	'	'
28
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl"					# all the WL	'	'	'
29
DIR_IP_BL="$DIR_SHARE/iptables-bl"					# all the IP addresses of the BL 
29
DIR_IP_BL="$DIR_SHARE/iptables-bl"					# all the IP addresses of the BL 
30
DIR_DNS_BL_ENABLED="$DIR_SHARE/dnsmasq-bl-enabled"			# symbolic link to the dnsmasq	BL (only enabled categories)
30
DIR_DNS_BL_ENABLED="$DIR_SHARE/dnsmasq-bl-enabled"			# symbolic link to the dnsmasq	BL (only enabled categories)
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 & WL 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 $WL_CATEGORIES # cleaning BL & WL 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 
46
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
46
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
47
		ln -s $DIR_DNS_BL/$ENABLE_CATEGORIE $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
47
		ln -s $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
48
		ln -s $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
48
		ln -s $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
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 
54
	# process the file $WL_CATEGORIES with the choice of categories 
55
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
55
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
56
	do
56
	do
57
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
57
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
58
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $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
59
		ln -s $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
60
	done
60
	done
61
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
61
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
62
	mv $FILE_tmp $WL_CATEGORIES
62
	mv $FILE_tmp $WL_CATEGORIES
63
}
63
}
64
function bl_enable (){
64
function bl_enable (){
65
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
65
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
66
	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
67
	then
67
	then
68
		service dansguardian restart
68
		service dansguardian restart
69
		service dnsmasq restart
69
		service dnsmasq restart
70
		/usr/local/bin/alcasar-iptables.sh
70
		/usr/local/bin/alcasar-iptables.sh
71
	fi
71
	fi
72
}
72
}
73
function bl_disable (){
73
function bl_disable (){
74
	rm -rf $DIR_DNS_BL_ENABLED/*
74
	rm -rf $DIR_DNS_BL_ENABLED/*
75
	$SED "s/^reportinglevel =.*/reportinglevel = -1/g" /etc/dansguardian/dansguardian.conf
75
	$SED "s/^reportinglevel =.*/reportinglevel = -1/g" /etc/dansguardian/dansguardian.conf
76
	if [ "$PARENT_SCRIPT" != "/usr/local/bin/alcasar-conf.sh" ] # don't launch on install stage
76
	if [ "$PARENT_SCRIPT" != "/usr/local/bin/alcasar-conf.sh" ] # don't launch on install stage
77
	then
77
	then
78
		service dansguardian restart
78
		service dansguardian restart
79
		service dnsmasq restart
79
		service dnsmasq restart
80
		/usr/local/bin/alcasar-iptables.sh
80
		/usr/local/bin/alcasar-iptables.sh
81
	fi
81
	fi
82
}
82
}
83
usage="Usage: alcasar-bl.sh {-on or --on} | { -off or --off } | { -download or --download } | { -reload or --reload }"
83
usage="Usage: alcasar-bl.sh {-on or --on} | { -off or --off } | { -download or --download } | { -reload or --reload }"
84
nb_args=$#
84
nb_args=$#
85
args=$1
85
args=$1
86
if [ $nb_args -eq 0 ]
86
if [ $nb_args -eq 0 ]
87
then
87
then
88
	DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
88
	DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
89
	DNS_FILTERING=${DNS_FILTERING:=off}
89
	DNS_FILTERING=${DNS_FILTERING:=off}
90
	echo "Set BlackList Filtering to $DNS_FILTERING"
90
	echo "Set BlackList Filtering to $DNS_FILTERING"
91
	if [ $DNS_FILTERING = on ]; then
91
	if [ $DNS_FILTERING = on ]; then
92
		cat_choice
92
		cat_choice
93
		bl_enable
93
		bl_enable
94
	else
94
	else
95
		bl_disable
95
		bl_disable
96
	fi
96
	fi
97
	exit 0
97
	exit 0
98
fi
98
fi
99
case $args in
99
case $args in
100
	-\? | -h* | --h*)
100
	-\? | -h* | --h*)
101
		echo "$usage"
101
		echo "$usage"
102
		exit 0
102
		exit 0
103
		;;
103
		;;
104
	# enable the filtering
104
	# enable the filtering
105
	-on | --on)	
105
	-on | --on)	
106
		cat_choice
106
		cat_choice
107
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=on?g" $CONF_FILE
107
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=on?g" $CONF_FILE
108
		bl_enable
108
		bl_enable
109
		;;
109
		;;
110
	# disable the filtering
110
	# disable the filtering
111
	-off | --off)
111
	-off | --off)
112
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=off?g" $CONF_FILE
112
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=off?g" $CONF_FILE
113
		bl_disable
113
		bl_disable
114
		;;
114
		;;
115
	# Retrieve Toulouse BL
115
	# Retrieve Toulouse BL
116
	-download | --download)
116
	-download | --download)
117
		rm -rf /tmp/con_ok.html
117
		rm -rf /tmp/con_ok.html
118
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
118
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
119
		if [ ! -e /tmp/con_ok.html ]
119
		if [ ! -e /tmp/con_ok.html ]
120
		then
120
		then
121
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
121
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
122
		else 
122
		else 
123
			rm -rf /tmp/con_ok.html $DIR_tmp
123
			rm -rf /tmp/con_ok.html $DIR_tmp
124
			mkdir $DIR_tmp
124
			mkdir $DIR_tmp
125
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
125
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
126
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
126
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
127
			chown -R apache:apache $DIR_tmp
127
			chown -R apache:apache $DIR_tmp
128
		fi
128
		fi
129
		;;		
129
		;;		
130
	# Adapt Toulouse BL to our structure (dnsmasq + DG)
130
	# Adapt Toulouse BL to our structure (dnsmasq + DG)
131
	-adapt | --adapt)
131
	-adapt | --adapt)
132
		echo -n "Toulouse BlackList migration process. Please wait : "
132
		echo -n "Toulouse BlackList migration process. Please wait : "
133
		if [ -f $DIR_tmp/blacklists.tar.gz ]
133
		if [ -f $DIR_tmp/blacklists.tar.gz ]
134
		then
134
		then
135
			[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
135
			[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
136
			rm -rf $DIR_DG_BL
136
			rm -rf $DIR_DG_BL
137
			mkdir $DIR_DG_BL
137
			mkdir $DIR_DG_BL
138
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
138
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
139
			[ -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/
140
			rm -rf $DIR_tmp
140
			rm -rf $DIR_tmp
141
		fi
141
		fi
142
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
142
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
143
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
143
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
144
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
144
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
145
		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
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
147
		chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
148
		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
149
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
149
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
150
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
150
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
151
		do
151
		do
152
			categorie=`echo $dir_categorie|cut -d "/" -f6`
152
			categorie=`echo $dir_categorie|cut -d "/" -f6`
153
			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"`
154
			if [ "$categorie_type" == "white" ]
154
			if [ "$categorie_type" == "white" ]
155
			then
155
			then
156
				echo "$dir_categorie" >> $WL_CATEGORIES 
156
				echo "$dir_categorie" >> $WL_CATEGORIES 
157
				echo `basename $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 
158
			else
158
			else
159
				echo "$dir_categorie" >> $BL_CATEGORIES
159
				echo "$dir_categorie" >> $BL_CATEGORIES
160
			fi
160
			fi
161
		done
161
		done
162
		rm -f $FILE_tmp
162
		rm -f $FILE_tmp
-
 
163
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
-
 
164
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
-
 
165
		do
-
 
166
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
-
 
167
			if [ $ok != "1" ] 
-
 
168
			then
-
 
169
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
-
 
170
			fi
-
 
171
		done
163
		# Creation of DNSMASQ BL and WL
172
		# Creation of DNSMASQ BL and WL
164
		for LIST in $BL_CATEGORIES $WL_CATEGORIES	# for each list (bl and wl)
173
		for LIST in $BL_CATEGORIES $WL_CATEGORIES	# for each list (bl and wl)
165
		do
174
		do
166
			for PATH_FILE in `cat $LIST` # for each category
175
			for PATH_FILE in `cat $LIST` # for each category
167
			do
176
			do
168
				DOMAINE=`basename $PATH_FILE`
177
				DOMAINE=`basename $PATH_FILE`
169
				echo -n "$DOMAINE, "
178
				echo -n "$DOMAINE, "
170
		  		if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
179
		  		if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
171
				then
180
				then
172
					touch $PATH_FILE/urls
181
					touch $PATH_FILE/urls
173
					chown dansguardian:apache $PATH_FILE/urls
182
					chown dansguardian:apache $PATH_FILE/urls
174
				fi
183
				fi
175
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
184
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
176
				# retrieve the ip addresses for iptables
185
				# retrieve the ip addresses for iptables
177
				egrep  "([0-9]{1,3}\.){3}[0-9]{1,3}" $PATH_FILE/domains > $FILE_ip_tmp
186
				egrep  "([0-9]{1,3}\.){3}[0-9]{1,3}" $PATH_FILE/domains > $FILE_ip_tmp
178
				# for dnsmask, remove IP addesses, accented characters and commented lines.
187
				# for dnsmask, remove IP addesses, accented characters and commented lines.
179
				egrep  -v "([0-9]{1,3}\.){3}[0-9]{1,3}" $PATH_FILE/domains > $FILE_tmp
188
				egrep  -v "([0-9]{1,3}\.){3}[0-9]{1,3}" $PATH_FILE/domains > $FILE_tmp
180
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
189
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
181
				$SED "/^#.*/d" $FILE_tmp
190
				$SED "/^#.*/d" $FILE_tmp
182
				# adapt to the dnsmasq syntax
191
				# adapt to the dnsmasq syntax
183
				$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
192
				$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
184
				if [ "$LIST" == "$BL_CATEGORIES" ]
193
				if [ "$LIST" == "$BL_CATEGORIES" ]
185
				then
194
				then
186
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
195
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
187
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
196
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
188
				else
197
				else
189
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
198
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
190
				fi
199
				fi
191
			done
200
			done
192
		done
201
		done
193
		rm -f $FILE_tmp $FILE_ip_tmp
202
		rm -f $FILE_tmp $FILE_ip_tmp
194
		echo
203
		echo
195
		;;
204
		;;
196
	# reload when categories are changed 
205
	# reload when categories are changed 
197
	-reload | --reload)
206
	-reload | --reload)
198
		# for DG
207
		# for DG
199
		chown -R dansguardian:apache $DIR_DG_BL/ossi
208
		chown -R dansguardian:apache $DIR_DG_BL/ossi
200
		chmod -R g+w $DIR_DG_BL/ossi
209
		chmod -R g+w $DIR_DG_BL/ossi
201
		cat_choice
210
		cat_choice
202
		#  for dnsmasq (rehabited domain names)
211
		#  for dnsmasq (rehabited domain names)
203
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
212
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
204
		then
213
		then
205
			for i in `cat $DIR_DG/exceptionsitelist`
214
			for i in `cat $DIR_DG/exceptionsitelist`
206
			do
215
			do
207
				$SED "/$i/d" $DIR_DNS_BL/*
216
				$SED "/$i/d" $DIR_DNS_BL/*
208
			done
217
			done
209
		fi
218
		fi
210
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
219
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
211
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
220
		$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
221
		cp -f $DIR_DG_BL/ossi/domains_wl $DIR_DNS_WL/ossi.conf
213
		DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
222
		DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
214
		DNS_FILTERING=${DNS_FILTERING:=off}
223
		DNS_FILTERING=${DNS_FILTERING:=off}
215
		if [ $DNS_FILTERING = on ]; then
224
		if [ $DNS_FILTERING = on ]; then
216
			bl_enable
225
			bl_enable
217
		else
226
		else
218
			bl_disable
227
			bl_disable
219
		fi
228
		fi
220
		;;
229
		;;
221
	*)
230
	*)
222
		echo "Argument inconnu :$1";
231
		echo "Argument inconnu :$1";
223
		echo "$usage"
232
		echo "$usage"
224
		exit 1
233
		exit 1
225
		;;
234
		;;
226
esac
235
esac
227
 
236
 
228
 
237