Subversion Repositories ALCASAR

Rev

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

Rev 1366 Rev 1369
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1366 2014-05-29 09:21:47Z richard $
3
# $Id: alcasar-bl.sh 1369 2014-06-03 16:23:07Z 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 22... Line 22...
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
FILE_IP_WL="$DIR_SHARE/ossi_wl"
-
 
28
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
29
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl"					# all the WL	'	'	'
28
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 
29
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)
30
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	'	'	'
31
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled"			#	'	'	'	WL	'	'	'
Line 94... Line 93...
94
		service dansguardian restart
93
		service dansguardian restart
95
		service dnsmasq restart
94
		service dnsmasq restart
96
		/usr/local/bin/alcasar-iptables.sh
95
		/usr/local/bin/alcasar-iptables.sh
97
	fi
96
	fi
98
}
97
}
99
usage="Usage: alcasar-bl.sh { -on or --on } | { -off or --off } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
98
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
100
nb_args=$#
99
nb_args=$#
101
args=$1
100
args=$1
102
if [ $nb_args -eq 0 ]
101
if [ $nb_args -eq 0 ]
103
then
102
then
104
	echo "Set BlackList Filtering to ON"
-
 
105
	cat_choice
103
	  args="-h"
106
	bl_enable
-
 
107
	exit 0
-
 
108
fi
104
fi
109
case $args in
105
case $args in
110
	-\? | -h* | --h*)
106
	-\? | -h* | --h*)
111
		echo "$usage"
107
		echo "$usage"
112
		exit 0
108
		exit 0
113
		;;
109
		;;
114
	# enable the filtering
110
	# Retrieve Toulouse BL
115
	-on | --on)	
111
	-cat_choice | --cat_choice)
116
		cat_choice
112
		cat_choice
117
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=on?g" $CONF_FILE
-
 
118
		bl_enable
-
 
119
		;;
-
 
120
	# disable the filtering
-
 
121
	-off | --off)
-
 
122
		$SED "s?^DNS_FILTERING.*?DNS_FILTERING=off?g" $CONF_FILE
-
 
123
		bl_disable
-
 
124
		;;
113
		;;
125
	# Retrieve Toulouse BL
-
 
126
	-download | --download)
114
	-download | --download)
127
		rm -rf /tmp/con_ok.html
115
		rm -rf /tmp/con_ok.html
128
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
116
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
129
		if [ ! -e /tmp/con_ok.html ]
117
		if [ ! -e /tmp/con_ok.html ]
130
		then
118
		then
Line 138... Line 126...
138
		fi
126
		fi
139
		;;		
127
		;;		
140
	# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
128
	# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
141
	-adapt | --adapt)
129
	-adapt | --adapt)
142
		echo -n "Toulouse BlackList migration process. Please wait : "
130
		echo -n "Toulouse BlackList migration process. Please wait : "
143
		# Saving whitelist ip
131
		# Saving OSSI files (IP_WL, IP_BL, domain)
144
		if [ -e $FILE_IP_WL ]
132
		if [ -e $DIR_SHARE/ossi-ip-wl ]
145
		then
133
		then
146
			cp $FILE_IP_WL $DIR_tmp
134
			cp $DIR_SHARE/ossi-ip-wl $DIR_tmp/ossi-ip-wl
147
		else
135
		else
148
			touch $FILE_IP_WL
136
			touch $DIR_SHARE/ossi-ip-wl
149
			chown apache $FILE_IP_WL
137
			chown apache $DIR_SHARE/ossi-ip-wl
150
		fi
138
		fi
151
		# Saving ossi category
-
 
152
		if [ -f $DIR_tmp/blacklists.tar.gz ]
139
		if [ -f $DIR_tmp/blacklists.tar.gz ]
153
		then
140
		then
154
			[ -d $DIR_DG_BL/ossi ] && mv $DIR_DG_BL/ossi $DIR_tmp
141
			[ -d $DIR_DG_BL/ossi ] && mv $DIR_DG_BL/ossi $DIR_tmp
155
			[ -e $DIR_IP_BL/ossi ] && mv $DIR_IP_BL/ossi $DIR_tmp/ossi-ip
142
			[ -e $DIR_IP_BL/ossi ] && mv $DIR_IP_BL/ossi $DIR_tmp/ossi-ip-bl
156
			rm -rf $DIR_DG_BL
143
			rm -rf $DIR_DG_BL $DIR_IP_BL
157
			mkdir $DIR_DG_BL
144
			mkdir $DIR_DG_BL $DIR_IP_BL
158
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
145
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
159
			[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
146
			[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
160
		fi
147
		fi
161
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
148
		rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
162
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
149
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
Line 222... Line 209...
222
				fi
209
				fi
223
			done
210
			done
224
		done
211
		done
225
		rm -f $FILE_tmp $FILE_ip_tmp
212
		rm -f $FILE_tmp $FILE_ip_tmp
226
		# Restoring ossi files
213
		# Restoring ossi files
227
		[ -e $DIR_tmp/ossi-ip ] && mv $DIR_tmp/ossi-ip $DIR_IP_BL/ossi
214
		[ -e $DIR_tmp/ossi-ip-bl ] && mv $DIR_tmp/ossi-ip-bl $DIR_IP_BL/ossi
228
		[ -e $DIR_tmp/ossi_wl ] && mv $DIR_tmpi/ossi_wl $DIR_SHARE/ossi_wl
215
		[ -e $DIR_tmp/ossi-ip-wl ] && mv $DIR_tmp/ossi-ip-wl $DIR_SHARE/ossi-ip-wl
229
		fi
-
 
230
		rm -rf $DIR_tmp
216
		rm -rf $DIR_tmp
231
		echo
217
		echo
232
		;;
218
		;;
233
	# reload when categories are changed 
219
	# reload when categories are changed 
234
	-reload | --reload)
220
	-reload | --reload)