Subversion Repositories ALCASAR

Rev

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

Rev 1811 Rev 1827
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1811 2016-04-05 19:32:37Z richard $
3
# $Id: alcasar-bl.sh 1827 2016-04-19 09:47:29Z raphael.pion $
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
OSSI_DOMAINS_WL="$DIR_DG/blacklists/ossi/domains_wl"			# Domain names for the ossi category
26
OSSI_DOMAINS_WL="$DIR_DG/blacklists/ossi/domains_wl"			# Domain names for the ossi category
27
DIR_SHARE="/usr/local/share"
27
DIR_SHARE="/usr/local/share"
28
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl"					# all the BL in the DNSMASQ format
28
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl"					# all the BL in the DNSMASQ format
29
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl"					# all the WL	'	'	'
29
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl"					# all the WL	'	'	'
30
DIR_IP_BL="$DIR_SHARE/iptables-bl"					# all the IP addresses of the BL 
30
DIR_IP_BL="$DIR_SHARE/iptables-bl"					# all the IP addresses of the BL 
31
DIR_DNS_BL_ENABLED="$DIR_SHARE/dnsmasq-bl-enabled"			# symbolic link to the domains BL (only enabled categories)
31
DIR_DNS_BL_ENABLED="$DIR_SHARE/dnsmasq-bl-enabled"			# symbolic link to the domains BL (only enabled categories)
32
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled"			#	'	'	'	WL	'	'	'
32
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled"			#	'	'	'	WL	'	'	'
33
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled"			#	'	'	ip BL (only enabled categories)
33
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled"			#	'	'	ip BL (only enabled categories)
34
DNSMASQ_BL_CONF="/etc/dnsmasq-blacklist.conf"				# conf file of dnsmasq-blacklist
34
DNSMASQ_BL_CONF="/etc/dnsmasq-blacklist.conf"				# conf file of dnsmasq-blacklist
35
DNS1=`grep "DNS1" $CONF_FILE | cut -d '=' -f 2` 			# server DNS1 (for WL domain names)
35
DNS1=`grep "DNS1" $CONF_FILE | cut -d '=' -f 2` 			# server DNS1 (for WL domain names)
36
BL_SERVER="dsi.ut-capitole.fr"
36
BL_SERVER="dsi.ut-capitole.fr"
37
SED="/bin/sed -i"
37
SED="/bin/sed -i"
38
 
38
 
39
# enable/disable the BL & WL categories
39
# enable/disable the BL & WL categories
40
function cat_choice (){
40
function cat_choice (){
41
	# saving ossi category
41
	# saving ossi category
42
	mkdir $DIR_tmp
42
	mkdir $DIR_tmp
43
	cp $DIR_IP_BL/ossi $DIR_tmp
43
	cp $DIR_IP_BL/ossi $DIR_tmp
44
	if [ -d $DIR_IP_BL_ENABLED ]
44
	if [ -d $DIR_IP_BL_ENABLED ]
45
	then
45
	then
46
		for file in `ls -1 $DIR_IP_BL_ENABLED | grep -v "^ossi-*"`
46
		for file in `ls -1 $DIR_IP_BL_ENABLED | grep -v "^ossi-*"`
47
		do
47
		do
48
			rm -f $DIR_IP_BL_ENABLED/$file
48
			rm -f $DIR_IP_BL_ENABLED/$file
49
		done
49
		done
50
	else
50
	else
51
		mkdir $DIR_IP_BL_ENABLED
51
		mkdir $DIR_IP_BL_ENABLED
52
		chown apache $DIR_IP_BL_ENABLED
52
		chown apache $DIR_IP_BL_ENABLED
53
	fi
53
	fi
54
	if [ -d $DIR_DNS_BL_ENABLED ]
54
	if [ -d $DIR_DNS_BL_ENABLED ]
55
	then
55
	then
56
		for file in `ls -1 $DIR_DNS_BL_ENABLED | grep -v "^ossi-*"`
56
		for file in `ls -1 $DIR_DNS_BL_ENABLED | grep -v "^ossi-*"`
57
		do
57
		do
58
			rm -f $DIR_DNS_BL_ENABLED/$file
58
			rm -f $DIR_DNS_BL_ENABLED/$file
59
		done
59
		done
60
	else
60
	else
61
		mkdir $DIR_DNS_BL_ENABLED
61
		mkdir $DIR_DNS_BL_ENABLED
62
		chown apache $DIR_DNS_BL_ENABLED
62
		chown apache $DIR_DNS_BL_ENABLED
63
	fi
63
	fi
64
	rm -rf $DIR_DNS_WL_ENABLED # cleaning for dnsmasq and iptables
64
	rm -rf $DIR_DNS_WL_ENABLED # cleaning for dnsmasq and iptables
65
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
65
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
66
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
66
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
67
	mkdir $DIR_DNS_WL_ENABLED
67
	mkdir $DIR_DNS_WL_ENABLED
68
	# process the file $BL_CATEGORIES with the choice of categories 
68
	# process the file $BL_CATEGORIES with the choice of categories 
69
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
69
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
70
	do
70
	do
71
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
71
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES 
72
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
72
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
73
		ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
73
		ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
74
		ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
74
		ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
75
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
75
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by dnsmasq
76
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
76
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
77
	done
77
	done
78
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
78
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
79
	mv $FILE_tmp $BL_CATEGORIES
79
	mv $FILE_tmp $BL_CATEGORIES
80
	# process the file $WL_CATEGORIES with the choice of categories 
80
	# process the file $WL_CATEGORIES with the choice of categories 
81
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
81
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED` 
82
	do
82
	do
83
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
83
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES 
84
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
84
		$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
85
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
85
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
86
	done
86
	done
87
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
87
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
88
	mv $FILE_tmp $WL_CATEGORIES
88
	mv $FILE_tmp $WL_CATEGORIES
89
	# restoring ip files and ossi category
89
	# restoring ip files and ossi category
90
	mv $DIR_tmp/ossi $DIR_IP_BL
90
	mv $DIR_tmp/ossi $DIR_IP_BL
91
	chown apache $DIR_IP_BL/ossi
91
	chown apache $DIR_IP_BL/ossi
92
	rm -rf $DIR_tmp
92
	rm -rf $DIR_tmp
93
}
93
}
94
 
94
 
95
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
95
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
96
nb_args=$#
96
nb_args=$#
97
args=$1
97
args=$1
98
if [ $nb_args -eq 0 ]
98
if [ $nb_args -eq 0 ]
99
then
99
then
100
	  args="-h"
100
	  args="-h"
101
fi
101
fi
102
case $args in
102
case $args in
103
	-\? | -h* | --h*)
103
	-\? | -h* | --h*)
104
		echo "$usage"
104
		echo "$usage"
105
		exit 0
105
		exit 0
106
		;;
106
		;;
107
	# Retrieve Toulouse BL
107
	# Retrieve Toulouse BL
108
	-download | --download)
108
	-download | --download)
109
		rm -rf /tmp/con_ok.html
109
		rm -rf /tmp/con_ok.html
110
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
110
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
111
		if [ ! -e /tmp/con_ok.html ]
111
		if [ ! -e /tmp/con_ok.html ]
112
		then
112
		then
113
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
113
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
114
		else 
114
		else 
115
			rm -rf /tmp/con_ok.html $DIR_tmp
115
			rm -rf /tmp/con_ok.html $DIR_tmp
116
			mkdir $DIR_tmp
116
			mkdir $DIR_tmp
117
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
117
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
118
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
118
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
119
			chown -R apache:apache $DIR_tmp
119
			chown -R apache:apache $DIR_tmp
120
		fi
120
		fi
121
		;;		
121
		;;		
122
	# enable/disable categories (used only during the alcasar install process)
122
	# enable/disable categories (used only during the alcasar install process)
123
	-cat_choice | --cat_choice)
123
	-cat_choice | --cat_choice)
124
		cat_choice
124
		cat_choice
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
		if [ ! -e $DIR_SHARE/ossi-ip-wl ]
129
		if [ ! -e $DIR_SHARE/ossi-ip-wl ]
130
		then
130
		then
131
			touch $DIR_SHARE/ossi-ip-wl
131
			touch $DIR_SHARE/ossi-ip-wl
132
			chown apache $DIR_SHARE/ossi-ip-wl
132
			chown apache $DIR_SHARE/ossi-ip-wl
133
		fi
133
		fi
134
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
134
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
135
		then
135
		then
136
			[ -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
137
			[ -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
138
			rm -rf $DIR_DG_BL $DIR_IP_BL
138
			rm -rf $DIR_DG_BL $DIR_IP_BL
139
			mkdir $DIR_DG_BL $DIR_IP_BL
139
			mkdir $DIR_DG_BL $DIR_IP_BL
140
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
140
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
141
			[ -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/
142
		fi
142
		fi
143
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
143
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
144
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
144
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
145
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
145
		touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
146
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
146
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
147
		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
148
		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
149
		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
150
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
150
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
151
		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
152
		do
152
		do
153
			categorie=`echo $dir_categorie|cut -d "/" -f6`
153
			categorie=`echo $dir_categorie|cut -d "/" -f6`
154
			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"`
155
			if [ "$categorie_type" == "white" ]
155
			if [ "$categorie_type" == "white" ]
156
			then
156
			then
157
				echo "$dir_categorie" >> $WL_CATEGORIES 
157
				echo "$dir_categorie" >> $WL_CATEGORIES 
158
				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 
159
			fi
159
			fi
160
			echo "$dir_categorie" >> $BL_CATEGORIES # By default all categories are in BL
160
			echo "$dir_categorie" >> $BL_CATEGORIES # By default all categories are in BL
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)
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` 
164
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
165
		do
165
		do
166
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
166
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
167
			if [ $ok != "1" ] 
167
			if [ $ok != "1" ] 
168
			then
168
			then
169
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
169
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
170
			fi
170
			fi
171
		done
171
		done
172
		# Creation of DNSMASQ and Iptables BL and WL
172
		# Creation of DNSMASQ and Iptables BL and WL
173
		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)
174
		do
174
		do
175
			for PATH_FILE in `cat $LIST` # for each category
175
			for PATH_FILE in `cat $LIST` # for each category
176
			do
176
			do
177
				DOMAINE=`basename $PATH_FILE`
177
				DOMAINE=`basename $PATH_FILE`
178
				echo -n "$DOMAINE, "
178
				echo -n "$DOMAINE, "
179
		  		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
180
				then
180
				then
181
					touch $PATH_FILE/urls
181
					touch $PATH_FILE/urls
182
					chown dansguardian:apache $PATH_FILE/urls
182
					chown dansguardian:apache $PATH_FILE/urls
183
				fi
183
				fi
184
				$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
185
				# extract ip addresses for iptables
185
				# extract ip addresses for iptables
186
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
186
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
187
				# for dnsmask, remove IP addesses, accented characters and commented lines.
187
				# for dnsmask, remove IP addesses, accented characters and commented lines.
188
				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
189
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
189
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
190
				$SED "/^#.*/d" $FILE_tmp
190
				$SED "/^#.*/d" $FILE_tmp
191
				if [ "$LIST" == "$BL_CATEGORIES" ]
191
				if [ "$LIST" == "$BL_CATEGORIES" ]
192
				then
192
				then
193
					# adapt to the dnsmasq syntax for the blacklist
193
					# adapt to the dnsmasq syntax for the blacklist
194
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
194
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
195
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
195
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
196
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
196
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
197
				else
197
				else
198
					# adapt to the dnsmasq syntax for the whitelist
198
					# adapt to the dnsmasq syntax for the whitelist
199
					$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
199
					$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
200
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
200
					mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
201
				fi
201
				fi
202
			done
202
			done
203
		done
203
		done
204
		rm -f $FILE_tmp $FILE_ip_tmp
204
		rm -f $FILE_tmp $FILE_ip_tmp
205
		# Restoring ossi file of BL IP
205
		# Restoring ossi file of BL IP
206
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
206
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
207
		rm -rf $DIR_tmp
207
		rm -rf $DIR_tmp
208
		echo
208
		echo
209
		;;
209
		;;
210
	# reload when categories are changed 
210
	# reload when categories are changed 
211
	-reload | --reload)
211
	-reload | --reload)
212
		# for DG
212
		# for DG
213
		chown -R dansguardian:apache $DIR_DG_BL/ossi
213
		chown -R dansguardian:apache $DIR_DG_BL/ossi
214
		chmod -R g+w $DIR_DG_BL/ossi
214
		chmod -R g+w $DIR_DG_BL/ossi
215
		cat_choice
215
		cat_choice
216
		#  for dnsmasq (rehabited domain names)
216
		#  for dnsmasq (rehabited domain names)
217
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
217
		if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
218
		then
218
		then
219
			for i in `cat $DIR_DG/exceptionsitelist`
219
			for i in `cat $DIR_DG/exceptionsitelist`
220
			do
220
			do
221
				$SED "/$i/d" $DIR_DNS_BL/*
221
				$SED "/$i/d" $DIR_DNS_BL/*
222
			done
222
			done
223
		fi
223
		fi
224
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
224
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
225
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
225
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
226
		cp -f $OSSI_DOMAINS_WL $DIR_DNS_WL/ossi.conf
226
		cp -f $OSSI_DOMAINS_WL $DIR_DNS_WL/ossi.conf
227
		$SED "s?.*?server=/&/$DNS1?g" $DIR_DNS_WL/ossi.conf
227
		$SED "s?.*?server=/&/$DNS1?g" $DIR_DNS_WL/ossi.conf
228
		ln -s $DIR_DNS_WL/ossi.conf $DIR_DNS_WL_ENABLED/ossi
228
		ln -s $DIR_DNS_WL/ossi.conf $DIR_DNS_WL_ENABLED/ossi
229
		
229
		
230
		/usr/bin/systemctl restart dnsmasq-blacklist
230
		/usr/bin/systemctl restart dnsmasq-blacklist
231
		/usr/bin/systemctl restart dnsmasq-whitelist
231
		/usr/bin/systemctl restart dnsmasq-whitelist
232
		/usr/local/bin/alcasar-iptables.sh
232
		/usr/local/bin/alcasar-iptables.sh
233
		;;
233
		;;
234
	*)
234
	*)
235
		echo "Argument inconnu :$1";
235
		echo "Argument inconnu :$1";
236
		echo "$usage"
236
		echo "$usage"
237
		exit 1
237
		exit 1
238
		;;
238
		;;
239
esac
239
esac
240
 
240
 
241
 
241