Subversion Repositories ALCASAR

Rev

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

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