Subversion Repositories ALCASAR

Rev

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

Rev 1341 Rev 1361
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1341 2014-05-06 08:07:32Z richard $
3
# $Id: alcasar-bl.sh 1361 2014-05-25 22:08:44Z 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
DNSMASQ_BL_CONF="/etc/dnsmasq-blackhole.conf"				# conf file of dnsmasq-blackhole
33
DNSMASQ_BL_CONF="/etc/dnsmasq-blackhole.conf"				# conf file of dnsmasq-blackhole
34
BL_SERVER="dsi.ut-capitole.fr"
34
BL_SERVER="dsi.ut-capitole.fr"
35
SED="/bin/sed -i"
35
SED="/bin/sed -i"
36
 
36
 
37
# enable/disable the BL & WL categories
37
# enable/disable the BL & WL categories
38
function cat_choice (){
38
function cat_choice (){
39
	# saving ip files and ossi category
39
	# saving ip files and ossi category
40
	mkdir $DIR_tmp
40
	mkdir $DIR_tmp
41
	cp $DIR_IP_BL_ENABLED/ossi-* $DIR_tmp
41
	cp $DIR_IP_BL_ENABLED/ossi-* $DIR_tmp
42
	cp $DIR_IP_BL/ossi $DIR_tmp
42
	cp $DIR_IP_BL/ossi $DIR_tmp
43
	rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED # cleaning for dnsmasq and iptables
43
	rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED # cleaning for dnsmasq and iptables
44
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
44
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
45
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
45
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
46
	mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED 
46
	mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED 
47
	chown apache $DIR_IP_BL_ENABLED
47
	chown apache $DIR_IP_BL_ENABLED
48
	# process the file $BL_CATEGORIES with the choice of categories 
48
	# process the file $BL_CATEGORIES with the choice of categories 
49
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
49
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
50
	do
50
	do
51
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
51
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
52
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
52
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
53
		ln -s $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
53
		ln -s $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
54
		ln -s $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
54
		ln -s $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
55
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
55
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
56
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
56
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
57
	done
57
	done
58
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
58
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
59
	mv $FILE_tmp $BL_CATEGORIES
59
	mv $FILE_tmp $BL_CATEGORIES
60
	# process the file $WL_CATEGORIES with the choice of categories 
60
	# process the file $WL_CATEGORIES with the choice of categories 
61
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
61
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
62
	do
62
	do
63
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
63
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
64
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
64
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
65
		ln -s $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
65
		ln -s $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
66
	done
66
	done
67
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
67
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
68
	mv $FILE_tmp $WL_CATEGORIES
68
	mv $FILE_tmp $WL_CATEGORIES
69
	# restoring ip files and ossi category
69
	# restoring ip files and ossi category
70
	mv $DIR_tmp/ossi $DIR_IP_BL
70
	mv $DIR_tmp/ossi $DIR_IP_BL
71
	chown apache $DIR_IP_BL/ossi
71
	chown apache $DIR_IP_BL/ossi
72
	mv $DIR_tmp/ossi-* $DIR_IP_BL_ENABLED
72
	mv $DIR_tmp/ossi-* $DIR_IP_BL_ENABLED
73
	rm -rf $DIR_tmp
73
	rm -rf $DIR_tmp
74
}
74
}
75
function bl_enable (){
75
function bl_enable (){
76
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
76
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
77
	if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
77
	if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
78
	then
78
	then
79
		service dansguardian restart
79
		service dansguardian restart
80
		service dnsmasq restart
80
		service dnsmasq restart
81
		/usr/local/bin/alcasar-iptables.sh
81
		/usr/local/bin/alcasar-iptables.sh
82
	fi
82
	fi
83
}
83
}
84
function bl_disable (){
84
function bl_disable (){
85
	rm -rf $DIR_DNS_BL_ENABLED/*
85
	rm -rf $DIR_DNS_BL_ENABLED/*
86
	$SED "s/^reportinglevel =.*/reportinglevel = -1/g" /etc/dansguardian/dansguardian.conf
86
	$SED "s/^reportinglevel =.*/reportinglevel = -1/g" /etc/dansguardian/dansguardian.conf
87
	$SED "/google/d" $DNSMASQ_BL_CONF # remove nosslsearch server
87
	$SED "/google/d" $DNSMASQ_BL_CONF # remove nosslsearch server
88
	$SED "s?^[^#]?#&?g" $DIR_DG/urlregexplist  # remove safe searching
88
	$SED "s?^[^#]?#&?g" $DIR_DG/urlregexplist  # remove safe searching
89
	$SED "s/^\*ip$/#*ip/g" $DIR_DG/bannedsitelist # remove pureip browsing
89
	$SED "s/^\*ip$/#*ip/g" $DIR_DG/bannedsitelist # remove pureip browsing
90
	if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
90
	if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
91
	then
91
	then
92
		service dansguardian restart
92
		service dansguardian restart
93
		service dnsmasq restart
93
		service dnsmasq restart
94
		/usr/local/bin/alcasar-iptables.sh
94
		/usr/local/bin/alcasar-iptables.sh
95
	fi
95
	fi
96
}
96
}
97
usage="Usage: alcasar-bl.sh { -on or --on } | { -off or --off } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
97
usage="Usage: alcasar-bl.sh { -on or --on } | { -off or --off } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
98
nb_args=$#
98
nb_args=$#
99
args=$1
99
args=$1
100
if [ $nb_args -eq 0 ]
100
if [ $nb_args -eq 0 ]
101
then
101
then
102
	DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
102
	DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
103
	DNS_FILTERING=${DNS_FILTERING:=off}
103
	DNS_FILTERING=${DNS_FILTERING:=off}
104
	echo "Set BlackList Filtering to $DNS_FILTERING"
104
	echo "Set BlackList Filtering to $DNS_FILTERING"
105
	if [ $DNS_FILTERING = on ]; then
105
	if [ $DNS_FILTERING = on ]; then
106
		cat_choice
106
		cat_choice
107
		bl_enable
107
		bl_enable
108
	else
108
	else
109
		bl_disable
109
		bl_disable
110
	fi
110
	fi
111
	exit 0
111
	exit 0
112
fi
112
fi
113
case $args in
113
case $args in
114
	-\? | -h* | --h*)
114
	-\? | -h* | --h*)
115
		echo "$usage"
115
		echo "$usage"
116
		exit 0
116
		exit 0
117
		;;
117
		;;
118
	# enable the filtering
118
	# enable the filtering
119
	-on | --on)	
119
	-on | --on)	
120
		cat_choice
120
		cat_choice
121
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=on?g" $CONF_FILE
121
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=on?g" $CONF_FILE
122
		bl_enable
122
		bl_enable
123
		;;
123
		;;
124
	# disable the filtering
124
	# disable the filtering
125
	-off | --off)
125
	-off | --off)
126
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=off?g" $CONF_FILE
126
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=off?g" $CONF_FILE
127
		bl_disable
127
		bl_disable
128
		;;
128
		;;
129
	# Retrieve Toulouse BL
129
	# Retrieve Toulouse BL
130
	-download | --download)
130
	-download | --download)
131
		rm -rf /tmp/con_ok.html
131
		rm -rf /tmp/con_ok.html
132
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
132
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
133
		if [ ! -e /tmp/con_ok.html ]
133
		if [ ! -e /tmp/con_ok.html ]
134
		then
134
		then
135
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
135
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
136
		else 
136
		else 
137
			rm -rf /tmp/con_ok.html $DIR_tmp
137
			rm -rf /tmp/con_ok.html $DIR_tmp
138
			mkdir $DIR_tmp
138
			mkdir $DIR_tmp
139
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
139
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
140
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
140
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
141
			chown -R apache:apache $DIR_tmp
141
			chown -R apache:apache $DIR_tmp
142
		fi
142
		fi
143
		;;		
143
		;;		
144
	# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
144
	# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
145
	-adapt | --adapt)
145
	-adapt | --adapt)
146
		echo -n "Toulouse BlackList migration process. Please wait : "
146
		echo -n "Toulouse BlackList migration process. Please wait : "
-
 
147
		# Saving IP ossi category if exist else create it (ie : during the installaton process)
-
 
148
		if [ ! -f $DIR_IP_BL/ossi ]
-
 
149
		      then
147
		# Saving ossi category
150
		      touch $DIR_IP_BL/ossi
-
 
151
		      chown dansguardian:apache $DIR_IP_BL/ossi
-
 
152
		fi
148
		cp $DIR_IP_BL/ossi $DIR_tmp/ossi-ip
153
		mv -f $DIR_IP_BL/ossi $DIR_tmp/ossi-ip
149
		if [ -f $DIR_tmp/blacklists.tar.gz ]
154
		if [ -f $DIR_tmp/blacklists.tar.gz ]
150
		then
155
		then
151
			[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
156
			[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
152
			rm -rf $DIR_DG_BL
157
			rm -rf $DIR_DG_BL
153
			mkdir $DIR_DG_BL
158
			mkdir $DIR_DG_BL
154
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
159
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
155
			[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
160
			[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
156
		fi
161
		fi
157
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
162
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
158
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
163
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
159
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
164
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
160
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
165
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
161
		chown -R dansguardian:apache $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
166
		chown -R dansguardian:apache $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
162
		chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
167
		chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
163
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
168
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
164
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
169
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
165
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
170
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
166
		do
171
		do
167
			categorie=`echo $dir_categorie|cut -d "/" -f6`
172
			categorie=`echo $dir_categorie|cut -d "/" -f6`
168
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
173
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
169
			if [ "$categorie_type" == "white" ]
174
			if [ "$categorie_type" == "white" ]
170
			then
175
			then
171
				echo "$dir_categorie" >> $WL_CATEGORIES 
176
				echo "$dir_categorie" >> $WL_CATEGORIES 
172
				echo `basename $dir_categorie` >> $WL_CATEGORIES_ENABLED  # by default all WL are enabled 
177
				echo `basename $dir_categorie` >> $WL_CATEGORIES_ENABLED  # by default all WL are enabled 
173
			else
178
			else
174
				echo "$dir_categorie" >> $BL_CATEGORIES
179
				echo "$dir_categorie" >> $BL_CATEGORIES
175
			fi
180
			fi
176
		done
181
		done
177
		rm -f $FILE_tmp
182
		rm -f $FILE_tmp
178
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
183
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
179
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
184
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
180
		do
185
		do
181
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
186
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
182
			if [ $ok != "1" ] 
187
			if [ $ok != "1" ] 
183
			then
188
			then
184
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
189
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
185
			fi
190
			fi
186
		done
191
		done
187
		# Creation of DNSMASQ and Iptables BL and WL
192
		# Creation of DNSMASQ and Iptables BL and WL
188
		for LIST in $BL_CATEGORIES $WL_CATEGORIES	# for each list (bl and wl)
193
		for LIST in $BL_CATEGORIES $WL_CATEGORIES	# for each list (bl and wl)
189
		do
194
		do
190
			for PATH_FILE in `cat $LIST` # for each category
195
			for PATH_FILE in `cat $LIST` # for each category
191
			do
196
			do
192
				DOMAINE=`basename $PATH_FILE`
197
				DOMAINE=`basename $PATH_FILE`
193
				echo -n "$DOMAINE, "
198
				echo -n "$DOMAINE, "
194
		  		if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
199
		  		if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
195
				then
200
				then
196
					touch $PATH_FILE/urls
201
					touch $PATH_FILE/urls
197
					chown dansguardian:apache $PATH_FILE/urls
202
					chown dansguardian:apache $PATH_FILE/urls
198
				fi
203
				fi
199
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
204
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
200
				
205
				
201
				# retrieve the ip addresses for iptables
206
				# retrieve the ip addresses for iptables
202
				# create an set save for the selected category
207
				# create an set save for the selected category
203
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
208
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
204
 
209
 
205
				# for dnsmask, remove IP addesses, accented characters and commented lines.
210
				# for dnsmask, remove IP addesses, accented characters and commented lines.
206
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
211
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
207
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
212
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
208
				$SED "/^#.*/d" $FILE_tmp
213
				$SED "/^#.*/d" $FILE_tmp
209
				# adapt to the dnsmasq syntax
214
				# adapt to the dnsmasq syntax
210
				$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
215
				$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
211
				if [ "$LIST" == "$BL_CATEGORIES" ]
216
				if [ "$LIST" == "$BL_CATEGORIES" ]
212
				then
217
				then
213
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
218
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
214
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
219
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
215
				else
220
				else
216
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
221
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
217
				fi
222
				fi
218
			done
223
			done
219
		done
224
		done
220
		rm -f $FILE_tmp $FILE_ip_tmp
225
		rm -f $FILE_tmp $FILE_ip_tmp
221
		# Restoring ossi category
226
		# Restoring ossi-IP category
222
		mv $DIR_tmp/ossi-ip $DIR_IP_BL/ossi
227
		mv $DIR_tmp/ossi-ip $DIR_IP_BL/ossi
223
		rm -rf $DIR_tmp
228
		rm -rf $DIR_tmp
224
		echo
229
		echo
225
		;;
230
		;;
226
	# reload when categories are changed 
231
	# reload when categories are changed 
227
	-reload | --reload)
232
	-reload | --reload)
228
		# for DG
233
		# for DG
229
		chown -R dansguardian:apache $DIR_DG_BL/ossi
234
		chown -R dansguardian:apache $DIR_DG_BL/ossi
230
		chmod -R g+w $DIR_DG_BL/ossi
235
		chmod -R g+w $DIR_DG_BL/ossi
231
		cat_choice
236
		cat_choice
232
		#  for dnsmasq (rehabited domain names)
237
		#  for dnsmasq (rehabited domain names)
233
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
238
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
234
		then
239
		then
235
			for i in `cat $DIR_DG/exceptionsitelist`
240
			for i in `cat $DIR_DG/exceptionsitelist`
236
			do
241
			do
237
				$SED "/$i/d" $DIR_DNS_BL/*
242
				$SED "/$i/d" $DIR_DNS_BL/*
238
			done
243
			done
239
		fi
244
		fi
240
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
245
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
241
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
246
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
242
		cp -f $DIR_DG_BL/ossi/domains_wl $DIR_DNS_WL/ossi.conf
247
		cp -f $DIR_DG_BL/ossi/domains_wl $DIR_DNS_WL/ossi.conf
243
		DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
248
		DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
244
		DNS_FILTERING=${DNS_FILTERING:=off}
249
		DNS_FILTERING=${DNS_FILTERING:=off}
245
		if [ $DNS_FILTERING = on ]; then
250
		if [ $DNS_FILTERING = on ]; then
246
			bl_enable
251
			bl_enable
247
		else
252
		else
248
			bl_disable
253
			bl_disable
249
		fi
254
		fi
250
		;;
255
		;;
251
	*)
256
	*)
252
		echo "Argument inconnu :$1";
257
		echo "Argument inconnu :$1";
253
		echo "$usage"
258
		echo "$usage"
254
		exit 1
259
		exit 1
255
		;;
260
		;;
256
esac
261
esac
257
 
262
 
258
 
263