Subversion Repositories ALCASAR

Rev

Rev 2662 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2662 Rev 2688
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
3
# Id: $Id: alcasar-url_filter_wl.sh 2662 2018-11-18 12:55:55Z lucas.echard $
3
# Id: $Id: alcasar-url_filter_wl.sh 2688 2019-01-18 23:15:49Z lucas.echard $
4
 
4
 
5
# alcasar-url_filter.sh
5
# alcasar-url_filter.sh
6
# by REXY
6
# by REXY
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
# Active / désactive : safesearch des moteurs de recherche
9
# Active / désactive : safesearch des moteurs de recherche
10
# Enable / disable : search engines safesearch
10
# Enable / disable : search engines safesearch
11
# Active / désactive : le filtrage des url contenant une adresse ip à la place d'un nom de domaine
11
# Active / désactive : le filtrage des url contenant une adresse ip à la place d'un nom de domaine
12
# Enable / disable : filter of urls containing ip address instead of domain name
12
# Enable / disable : filter of urls containing ip address instead of domain name
13
 
13
 
14
TINY_CONF="/etc/tinyproxy/tinyproxy.conf"
-
 
15
DNSMASQ_WL_CONF="/etc/dnsmasq-whitelist.conf"
-
 
16
IP_WL="/usr/local/share/iptables-wl-enabled/ossi-ip-safesearch"
-
 
17
CONF_FILE="/usr/local/etc/alcasar.conf"
14
CONF_FILE="/usr/local/etc/alcasar.conf"
-
 
15
UNBOUND_WL_DOMAIN_FILTER_CONF="/etc/unbound/conf.d/whitelist/domainfilter.conf"
-
 
16
IP_WL="/usr/local/share/iptables-wl-enabled/ossi-ip-safesearch"
18
SED="/bin/sed -i"
17
SED="/bin/sed -i"
19
safesearch="Off"
18
safesearch="Off"
20
usage="Usage: alcasar-url_filter_wl.sh { -safesearch_on or -safesearch_off }"
19
usage="Usage: alcasar-url_filter_wl.sh { -safesearch_on or -safesearch_off }"
21
 
20
 
-
 
21
nb_args=$#
-
 
22
 
22
googledomains="google.com. google.ad. google.ae. google.com.af. google.com.ag. google.com.ai. google.al. google.am. google.co.ao. google.com.ar. google.as. google.at. google.com.au. google.az. google.ba. google.com.bd. google.be. google.bf. google.bg. google.com.bh. google.bi. google.bj. google.com.bn. google.com.bo. google.com.br. google.bs. google.bt. google.co.bw. google.by. google.com.bz. google.ca. google.cd. google.cf. google.cg. google.ch. google.ci. google.co.ck. google.cl. google.cm. google.cn. google.com.co. google.co.cr. google.com.cu. google.cv. google.com.cy. google.cz. google.de. google.dj. google.dk. google.dm. google.com.do. google.dz. google.com.ec. google.ee. google.com.eg. google.es. google.com.et. google.fi. google.com.fj. google.fm. google.fr. google.ga. google.ge. google.gg. google.com.gh. google.com.gi. google.gl. google.gm. google.gp. google.gr. google.com.gt. google.gy. google.com.hk. google.hn. google.hr. google.ht. google.hu. google.co.id. google.ie. google.co.il. google.im. google.co.in. google.iq. google.is. google.it. google.je. google.com.jm. google.jo. google.co.jp. google.co.ke. google.com.kh. google.ki. google.kg. google.co.kr. google.com.kw. google.kz. google.la. google.com.lb. google.li. google.lk. google.co.ls. google.lt. google.lu. google.lv. google.com.ly. google.co.ma. google.md. google.me. google.mg. google.mk. google.ml. google.com.mm. google.mn. google.ms. google.com.mt. google.mu. google.mv. google.mw. google.com.mx. google.com.my. google.co.mz. google.com.na. google.com.nf. google.com.ng. google.com.ni. google.ne. google.nl. google.no. google.com.np. google.nr. google.nu. google.co.nz. google.com.om. google.com.pa. google.com.pe. google.com.pg. google.com.ph. google.com.pk. google.pl. google.pn. google.com.pr. google.ps. google.pt. google.com.py. google.com.qa. google.ro. google.ru. google.rw. google.com.sa. google.com.sb. google.sc. google.se. google.com.sg. google.sh. google.si. google.sk. google.com.sl. google.sn. google.so. google.sm. google.sr. google.st. google.com.sv. google.td. google.tg. google.co.th. google.com.tj. google.tk. google.tl. google.tm. google.tn. google.to. google.com.tr. google.tt. google.com.tw. google.co.tz. google.com.ua. google.co.ug. google.co.uk. google.com.uy. google.co.uz. google.com.vc. google.co.ve. google.vg. google.co.vi. google.com.vn. google.vu. google.ws. google.rs. google.co.za. google.co.zm. google.co.zw. google.cat."
23
googledomains="google.com. google.ad. google.ae. google.com.af. google.com.ag. google.com.ai. google.al. google.am. google.co.ao. google.com.ar. google.as. google.at. google.com.au. google.az. google.ba. google.com.bd. google.be. google.bf. google.bg. google.com.bh. google.bi. google.bj. google.com.bn. google.com.bo. google.com.br. google.bs. google.bt. google.co.bw. google.by. google.com.bz. google.ca. google.cd. google.cf. google.cg. google.ch. google.ci. google.co.ck. google.cl. google.cm. google.cn. google.com.co. google.co.cr. google.com.cu. google.cv. google.com.cy. google.cz. google.de. google.dj. google.dk. google.dm. google.com.do. google.dz. google.com.ec. google.ee. google.com.eg. google.es. google.com.et. google.fi. google.com.fj. google.fm. google.fr. google.ga. google.ge. google.gg. google.com.gh. google.com.gi. google.gl. google.gm. google.gp. google.gr. google.com.gt. google.gy. google.com.hk. google.hn. google.hr. google.ht. google.hu. google.co.id. google.ie. google.co.il. google.im. google.co.in. google.iq. google.is. google.it. google.je. google.com.jm. google.jo. google.co.jp. google.co.ke. google.com.kh. google.ki. google.kg. google.co.kr. google.com.kw. google.kz. google.la. google.com.lb. google.li. google.lk. google.co.ls. google.lt. google.lu. google.lv. google.com.ly. google.co.ma. google.md. google.me. google.mg. google.mk. google.ml. google.com.mm. google.mn. google.ms. google.com.mt. google.mu. google.mv. google.mw. google.com.mx. google.com.my. google.co.mz. google.com.na. google.com.nf. google.com.ng. google.com.ni. google.ne. google.nl. google.no. google.com.np. google.nr. google.nu. google.co.nz. google.com.om. google.com.pa. google.com.pe. google.com.pg. google.com.ph. google.com.pk. google.pl. google.pn. google.com.pr. google.ps. google.pt. google.com.py. google.com.qa. google.ro. google.ru. google.rw. google.com.sa. google.com.sb. google.sc. google.se. google.com.sg. google.sh. google.si. google.sk. google.com.sl. google.sn. google.so. google.sm. google.sr. google.st. google.com.sv. google.td. google.tg. google.co.th. google.com.tj. google.tk. google.tl. google.tm. google.tn. google.to. google.com.tr. google.tt. google.com.tw. google.co.tz. google.com.ua. google.co.ug. google.co.uk. google.com.uy. google.co.uz. google.com.vc. google.co.ve. google.vg. google.co.vi. google.com.vn. google.vu. google.ws. google.rs. google.co.za. google.co.zm. google.co.zw. google.cat."
23
 
24
 
24
youtubedomains="www.youtube.com m.youtube.com youtubei.googleapis.com youtube.googleapis.com www.youtube-nocookie.com"
25
youtubedomains="www.youtube.com m.youtube.com youtubei.googleapis.com youtube.googleapis.com www.youtube-nocookie.com"
25
 
26
 
26
nb_args=$#
-
 
27
if [ $nb_args -le 0 ]
27
if [ $nb_args -le 0 ]
28
then
28
then
29
	echo "$usage"
29
	echo "$usage"
30
	nb_args=0
30
	exit 1
31
else
31
fi
-
 
32
 
32
	while [ $nb_args -ge 1 ]
33
while [ $nb_args -ge 1 ]
-
 
34
do
-
 
35
	arg=${!nb_args}
-
 
36
	case $arg in
-
 
37
	-\? | -h* | --h*)
-
 
38
		echo "$usage"
-
 
39
		exit 0
-
 
40
		;;
-
 
41
	# Safe search activation
-
 
42
	-safesearch_on | --safesearch_on)
-
 
43
		safesearch="On"
-
 
44
		;;
-
 
45
	# Safe search desactivation
-
 
46
	-safesearch_off | --safesearch_off)
-
 
47
		safesearch="Off"
-
 
48
		;;
-
 
49
	*)
-
 
50
		echo "Argument inconnu : $arg";
-
 
51
		echo "$usage"
-
 
52
		exit 1
-
 
53
		;;
-
 
54
	esac
-
 
55
nb_args=$(expr $nb_args - 1)
-
 
56
done
-
 
57
 
-
 
58
if [ $safesearch == "On" ]
-
 
59
then
-
 
60
	[ -e $IP_WL ] && rm -f $IP_WL
-
 
61
 
-
 
62
	# add 'SafeSearch' redirection for google searching
-
 
63
	google_safe_server=`host -ta forcesafesearch.google.com | grep "address" | cut -d" " -f4`	# retrieve google forcesafesearch ip
-
 
64
 
-
 
65
	# config file header
-
 
66
	echo "server:" > $UNBOUND_WL_DOMAIN_FILTER_CONF
-
 
67
 
-
 
68
	for domain in $googledomains
-
 
69
	do
-
 
70
		echo -e "\tlocal-zone: \"$domain\" redirect" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
-
 
71
		echo -e "\tlocal-data: \"$domain A $google_safe_server\"" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
-
 
72
	done
-
 
73
	echo "add wl_ip_allowed $google_safe_server" >> $IP_WL
-
 
74
 
-
 
75
	# add 'SafeSearch' redirection for youtube searching
-
 
76
	youtube_safe_server=`host -ta restrict.youtube.com | grep "address" | cut -d" " -f4`	# retrieve youtube restrict ip
-
 
77
	for domain in $youtubedomains
33
	do
78
	do
34
		arg=${!nb_args}
-
 
35
		case $arg in
-
 
36
		-\? | -h* | --h*)
-
 
37
			echo "$usage"
-
 
38
			exit 0
-
 
39
			;;
-
 
40
		# Safe search activation
-
 
41
		-safesearch_on | --safesearch_on)
79
		echo -e "\tlocal-zone: \"$domain\" redirect" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
42
			safesearch="On"
-
 
43
			;;
-
 
44
		# Safe search desactivation
-
 
45
		-safesearch_off | --safesearch_off)
80
		echo -e "\tlocal-data: \"$domain A $youtube_safe_server\"" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
46
			safesearch="Off"
-
 
47
			;;
-
 
48
		*)
-
 
49
			echo "Argument inconnu :$arg";
-
 
50
			echo "$usage"
-
 
51
			exit 1
-
 
52
			;;
-
 
53
		esac
-
 
54
	nb_args=$(expr $nb_args - 1)
-
 
55
	done
81
	done
56
	if [ $safesearch == "On" ]
-
 
57
	then
-
 
58
		if [ -e $IP_WL ]
-
 
59
		then
-
 
60
			rm $IP_WL # remove old google declaration
-
 
61
		fi
-
 
62
 
-
 
63
		# add 'SafeSearch' redirection for google searching
-
 
64
		google_safe_server=`host -ta forcesafesearch.google.com | grep "address" | cut -d" " -f4`	# retrieve google forcesafesearch ip
-
 
65
		$SED "/google/d" $DNSMASQ_WL_CONF # remove old google declaration
-
 
66
		echo "# SafeSearch redirect server for google" >> $DNSMASQ_WL_CONF
-
 
67
		for bing_dnsname in $googledomains
-
 
68
		do
-
 
69
			echo "address=/$bing_dnsname/$google_safe_server" >> $DNSMASQ_WL_CONF
-
 
70
		done
-
 
71
		echo "add wl_ip_allowed $google_safe_server" >> $IP_WL
82
	echo "add wl_ip_allowed $youtube_safe_server" >> $IP_WL
72
 
83
 
73
		# add 'SafeSearch' redirection for bing searching
84
	# add 'SafeSearch' redirection for bing searching
74
		bing_safe_server=`host -ta strict.bing.com | grep "address" | cut -d" " -f4`	# retrieve bing strict ip
85
	bing_safe_server=`host -ta strict.bing.com | grep "address" | cut -d" " -f4`	# retrieve bing strict ip
75
		$SED "/bing/d" $DNSMASQ_WL_CONF # remove old bing declaration
-
 
76
		echo "# SafeSearch redirect server for bing" >> $DNSMASQ_WL_CONF
86
	echo -e "\tlocal-zone: \"www.bing.com\" redirect" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
77
		echo "address=/www.bing.com/$bing_safe_server" >> $DNSMASQ_WL_CONF
87
	echo -e "\tlocal-data: \"www.bing.com A $bing_safe_server\"" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
78
		echo "add wl_ip_allowed $bing_safe_server" >> $IP_WL
88
	echo "add wl_ip_allowed $bing_safe_server" >> $IP_WL
79
 
89
 
80
		# add 'SafeSearch' redirection for youtube searching
90
	# add 'SafeSearch' redirection for qwant searching
81
		youtube_safe_server=`host -ta restrict.youtube.com | grep "address" | cut -d" " -f4`	# retrieve youtube restrict ip
91
	qwant_safe_server=`host -ta safeapi.qwant.com | grep "address" | cut -d" " -f4` # retrieve qwant strict ip
82
		$SED "/youtube/d" $DNSMASQ_WL_CONF # remove old youtube declaration
-
 
83
		echo "# SafeSearch redirect server for youtube" >> $DNSMASQ_WL_CONF
92
	echo -e "\tlocal-zone: \"api.qwant.com\" redirect" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
84
		for yt_dnsname in $youtubedomains
-
 
85
		do
-
 
86
			echo "address=/$yt_dnsname/$youtube_safe_server" >> $DNSMASQ_WL_CONF
93
	echo -e "\tlocal-data: \"api.qwant.com A $qwant_safe_server\"" >> $UNBOUND_WL_DOMAIN_FILTER_CONF
87
		done
-
 
88
		echo "add wl_ip_allowed $youtube_safe_server" >> $IP_WL
94
	echo "add wl_ip_allowed $qwant_safe_server" >> $IP_WL
89
 
95
 
90
		# add 'SafeSearch' redirection for qwant searching
-
 
91
		$SED "/qwant/d" $DNSMASQ_WL_CONF # remove old qwant declaration
96
	$SED 's/^WL_SAFESEARCH=.*/WL_SAFESEARCH=on/g' $CONF_FILE
92
		qwant_safe_server=`host -ta safeapi.qwant.com | grep "address" | cut -d" " -f4`	# retrieve qwant strict ip
-
 
93
		echo "# SafeSearch redirect server for qwant" >> $DNSMASQ_WL_CONF
-
 
94
		echo "address=/api.qwant.com/$qwant_safe_server" >> $DNSMASQ_WL_CONF
-
 
95
	else
97
else
96
		$SED "/google/d" $DNSMASQ_WL_CONF
-
 
97
		$SED "/bing/d" $DNSMASQ_WL_CONF
-
 
98
		$SED "/youtube/d" $DNSMASQ_WL_CONF
98
	[ -e $UNBOUND_WL_DOMAIN_FILTER_CONF ] && rm -f $UNBOUND_WL_DOMAIN_FILTER_CONF
99
		$SED "/qwant/d" $DNSMASQ_WL_CONF
99
	[ -e $IP_WL ] && rm -f $IP_WL
100
		rm $IP_WL
-
 
101
	fi
100
 
102
	systemctl restart dnsmasq-whitelist
101
	$SED 's/^WL_SAFESEARCH=.*/WL_SAFESEARCH=off/g' $CONF_FILE
103
fi
102
fi
-
 
103
systemctl restart unbound-whitelist