Subversion Repositories ALCASAR

Rev

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

Rev 3195 Rev 3263
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
3
# Id: $Id: alcasar-url_filter_bl.sh 3195 2024-04-23 22:39:48Z rexy $
3
# Id: $Id: alcasar-url_filter_bl.sh 3263 2025-03-25 23:14:18Z rexy $
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
 
Line 11... Line 11...
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
CONF_FILE="/usr/local/etc/alcasar.conf"
14
CONF_FILE="/usr/local/etc/alcasar.conf"
15
DIR_DG_GROUP1="/etc/e2guardian/lists/group1"
15
DIR_DG_GROUP1="/etc/e2guardian/lists/group1"
16
UNBOUND_BL_DOMAIN_FILTER_CONF="/etc/unbound/conf.d/blacklist/domainfilter.conf"
-
 
17
SED="/bin/sed -i"
16
SED="/bin/sed -i"
18
safesearch="Off"
17
safesearch="Off"
19
pureip="Off"
18
pureip="Off"
20
usage="Usage: alcasar-url_filter_bl.sh { -safesearch_on or -safesearch_off } & { -pureip_on or -pureip_off }"
19
usage="Usage: alcasar-url_filter_bl.sh { -safesearch_on or -safesearch_off } & { -pureip_on or -pureip_off }"
21
 
20
 
22
nb_args=$#
21
nb_args=$#
23
 
-
 
24
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."
-
 
25
 
-
 
26
youtubedomains="www.youtube.com m.youtube.com youtubei.googleapis.com youtube.googleapis.com www.youtube-nocookie.com"
-
 
27
 
-
 
28
safesearch=""
-
 
29
pureip=""
-
 
30
 
-
 
31
if [ $nb_args -lt 1 ]
22
if [ $nb_args -lt 1 ]
32
then
23
then
33
	echo "$usage"
24
	echo "$usage"
34
	exit 1
25
	exit 1
35
fi
26
fi
Line 67... Line 58...
67
nb_args=$(expr $nb_args - 1)
58
nb_args=$(expr $nb_args - 1)
68
done
59
done
69
 
60
 
70
if [ "$safesearch" == "On" ]
61
if [ "$safesearch" == "On" ]
71
then
62
then
72
	$SED "s?^#\"?\"?g" $DIR_DG_GROUP1/urlregexplist # on décommente les lignes de regles
63
	$SED "s?^#\"?\"?g" $DIR_DG_GROUP1/urlregexplist # uncomment rules lines
73
	# add 'SafeSearch' redirection for google searching
64
	# Before we wrote a special Unbound file with redirection. Ex. for google safesearching
74
	google_safe_server=`host -ta forcesafesearch.google.com | grep "address" | cut -d" " -f4`	# retrieve google forcesafesearch ip
65
	# google_safe_server=`host -ta forcesafesearch.google.com | grep "address" | cut -d" " -f4`	# retrieve google forcesafesearch ip
75
 
-
 
76
	# config file header
-
 
77
	echo "server:" > $UNBOUND_BL_DOMAIN_FILTER_CONF
66
	# echo "server:" > $UNBOUND_BL_DOMAIN_FILTER_CONF
78
 
-
 
79
	for domain in $googledomains
67
	# for domain in "google.com. google.ad. google.ae. google.com.af. google.com.ag. google.com etc."
80
	do
68
	# do
81
		echo -e "\tlocal-zone: \"$domain\" redirect" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
69
	#	echo -e "\tlocal-zone: \"$domain\" redirect" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
82
		echo -e "\tlocal-data: \"$domain A $google_safe_server\"" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
70
	#	echo -e "\tlocal-data: \"$domain A $google_safe_server\"" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
83
	done
71
	# done
84
 
-
 
85
	# add 'SafeSearch' redirection for youtube searching
-
 
86
	youtube_safe_server=`host -ta restrict.youtube.com | grep "address" | cut -d" " -f4`	# retrieve youtube restrict ip
-
 
87
	for domain in $youtubedomains
-
 
88
	do
72
	#
89
		echo -e "\tlocal-zone: \"$domain\" redirect" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
-
 
90
		echo -e "\tlocal-data: \"$domain A $youtube_safe_server\"" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
-
 
91
	done
-
 
92
 
-
 
93
	# add 'SafeSearch' redirection for bing searching
-
 
94
	bing_safe_server=`host -ta strict.bing.com | grep "address" | cut -d" " -f4`	# retrieve bing strict ip
-
 
95
	echo -e "\tlocal-zone: \"www.bing.com\" redirect" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
-
 
96
	echo -e "\tlocal-data: \"www.bing.com A $bing_safe_server\"" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
-
 
97
 
-
 
98
	# add 'SafeSearch' redirection for qwant searching
-
 
99
	qwant_safe_server=`host -ta safeapi.qwant.com | grep "address" | cut -d" " -f4`	# retrieve qwant strict ip
73
	# If enable again, add/remove "safe-searching" file in /etc/unbound/conf.d/blacklist (in this file, CNAME is used instead of REDIRECT)
100
	echo -e "\tlocal-zone: \"api.qwant.com\" redirect" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
-
 
101
	echo -e "\tlocal-data: \"api.qwant.com A $qwant_safe_server\"" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
-
 
102
 
-
 
103
	$SED 's/^BL_SAFESEARCH=.*/BL_SAFESEARCH=on/g' $CONF_FILE
74
	$SED 's/^BL_SAFESEARCH=.*/BL_SAFESEARCH=on/g' $CONF_FILE
104
elif [ "$safesearch" == "Off" ]
75
elif [ "$safesearch" == "Off" ]
105
then
76
then
106
	$SED "s?^[^#]?#&?g" $DIR_DG_GROUP1/urlregexplist
77
	$SED "s?^[^#]?#&?g" $DIR_DG_GROUP1/urlregexplist # comment rules lines
107
	[ -e $UNBOUND_BL_DOMAIN_FILTER_CONF ] && rm -f $UNBOUND_BL_DOMAIN_FILTER_CONF
-
 
108
 
78
 
109
	$SED 's/^BL_SAFESEARCH=.*/BL_SAFESEARCH=off/g' $CONF_FILE
79
	$SED 's/^BL_SAFESEARCH=.*/BL_SAFESEARCH=off/g' $CONF_FILE
110
fi
80
fi
111
 
81
 
112
if [ "$pureip" == "On" ]
82
if [ "$pureip" == "On" ]