Subversion Repositories ALCASAR

Rev

Rev 1363 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1363 Rev 1365
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1363 2014-05-26 22:07:44Z richard $
3
# $Id: alcasar-bl.sh 1365 2014-05-28 14:38:29Z 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
 
Line 15... Line 15...
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
FILE_IP_WL="/usr/local/share/ossi_wl"
20
DIR_DG="/etc/dansguardian/lists"
21
DIR_DG="/etc/dansguardian/lists"
21
DIR_DG_BL="$DIR_DG/blacklists"
22
DIR_DG_BL="$DIR_DG/blacklists"
22
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories"				# list of names of the 	BL categories
23
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories"				# list of names of the 	BL categories
23
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories"				#'	'		WL	'
24
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories"				#'	'		WL	'
24
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled"		#	'	'	BL enabled categories
25
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled"		#	'	'	BL enabled categories
Line 28... Line 29...
28
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl"					# all the WL	'	'	'
29
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 
30
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)
31
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	'	'	'
32
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)	
33
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
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)
34
BL_SERVER="dsi.ut-capitole.fr"
36
BL_SERVER="dsi.ut-capitole.fr"
35
SED="/bin/sed -i"
37
SED="/bin/sed -i"
36
 
38
 
37
# enable/disable the BL & WL categories
39
# enable/disable the BL & WL categories
38
function cat_choice (){
40
function cat_choice (){
Line 97... Line 99...
97
usage="Usage: alcasar-bl.sh { -on or --on } | { -off or --off } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
99
usage="Usage: alcasar-bl.sh { -on or --on } | { -off or --off } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
98
nb_args=$#
100
nb_args=$#
99
args=$1
101
args=$1
100
if [ $nb_args -eq 0 ]
102
if [ $nb_args -eq 0 ]
101
then
103
then
102
	DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2`		# DNS and URLs filter (on/off)
-
 
103
	DNS_FILTERING=${DNS_FILTERING:=off}
-
 
104
	echo "Set BlackList Filtering to $DNS_FILTERING"
104
	echo "Set BlackList Filtering to ON"
105
	if [ $DNS_FILTERING = on ]; then
-
 
106
		cat_choice
105
	cat_choice
107
		bl_enable
106
	bl_enable
108
	else
-
 
109
		bl_disable
-
 
110
	fi
-
 
111
	exit 0
107
	exit 0
112
fi
108
fi
113
case $args in
109
case $args in
114
	-\? | -h* | --h*)
110
	-\? | -h* | --h*)
115
		echo "$usage"
111
		echo "$usage"
Line 141... Line 137...
141
			chown -R apache:apache $DIR_tmp
137
			chown -R apache:apache $DIR_tmp
142
		fi
138
		fi
143
		;;		
139
		;;		
144
	# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
140
	# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
145
	-adapt | --adapt)
141
	-adapt | --adapt)
146
		echo -n "Migration process of Toulouse BlackList. Please wait : "
142
		echo -n "Toulouse BlackList migration process. Please wait : "
-
 
143
		# Saving whitelist ip
-
 
144
		if [ -e $FILE_IP_WL ]
-
 
145
		then
-
 
146
			cp $FILE_IP_WL $DIR_tmp
-
 
147
		else
-
 
148
			touch $FILE_IP_WL
-
 
149
			chown apache $FILE_IP_WL
-
 
150
		fi
147
		# Saving IP ossi category if exist else create it (ie : during the installaton process)
151
		# Saving ossi category
148
		[ -e $DIR_IP_BL/ossi ]	&& mv -f $DIR_IP_BL/ossi $DIR_tmp/ossi-ip
152
		cp $DIR_IP_BL/ossi $DIR_tmp/ossi-ip
149
		if [ -f $DIR_tmp/blacklists.tar.gz ]
153
		if [ -f $DIR_tmp/blacklists.tar.gz ]
150
		then
154
		then
151
			[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
155
			[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
152
			rm -rf $DIR_DG_BL
156
			rm -rf $DIR_DG_BL
153
			mkdir $DIR_DG_BL
157
			mkdir $DIR_DG_BL
Line 199... Line 203...
199
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
203
				$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
200
				
204
				
201
				# retrieve the ip addresses for iptables
205
				# retrieve the ip addresses for iptables
202
				# create an set save for the selected category
206
				# 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
207
				awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
204
 
-
 
205
				# for dnsmask, remove IP addesses, accented characters and commented lines.
208
				# 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
209
				egrep  -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
207
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
210
				$SED "/[äâëêïîöôüû]/d" $FILE_tmp
208
				$SED "/^#.*/d" $FILE_tmp
211
				$SED "/^#.*/d" $FILE_tmp
209
				# adapt to the dnsmasq syntax
-
 
210
				$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
-
 
211
				if [ "$LIST" == "$BL_CATEGORIES" ]
212
				if [ "$LIST" == "$BL_CATEGORIES" ]
212
				then
213
				then
-
 
214
					# adapt to the dnsmasq syntax for the blacklist
-
 
215
					$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
213
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
216
					mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
214
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
217
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
215
				else
218
				else
-
 
219
					# adapt to the dnsmasq syntax for the whitelist
-
 
220
					$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
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-IP category
226
		# Restoring ossi category
222
		[ -e $DIR_tmp/ossi-ip ] && mv $DIR_tmp/ossi-ip $DIR_IP_BL/ossi
227
		mv $DIR_tmp/ossi-ip $DIR_IP_BL/ossi
-
 
228
		# Restoring whitelist ip
-
 
229
		if [ -e $DIR_tmp/ossi_wl ]
-
 
230
		then
-
 
231
			mv $DIR_tmpi/ossi_wl /usr/local/share/
-
 
232
		fi
223
		rm -rf $DIR_tmp
233
		rm -rf $DIR_tmp
224
		echo
234
		echo
225
		;;
235
		;;
226
	# reload when categories are changed 
236
	# reload when categories are changed 
227
	-reload | --reload)
237
	-reload | --reload)
Line 238... Line 248...
238
			done
248
			done
239
		fi
249
		fi
240
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
250
		cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
241
		$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
251
		$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
252
		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)
-
 
244
		DNS_FILTERING=${DNS_FILTERING:=off}
-
 
245
		if [ $DNS_FILTERING = on ]; then
-
 
246
			bl_enable
253
		bl_enable
247
		else
-
 
248
			bl_disable
-
 
249
		fi
-
 
250
		;;
254
		;;
251
	*)
255
	*)
252
		echo "Argument inconnu :$1";
256
		echo "Argument inconnu :$1";
253
		echo "$usage"
257
		echo "$usage"
254
		exit 1
258
		exit 1