Subversion Repositories ALCASAR

Rev

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

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