Subversion Repositories ALCASAR

Rev

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

Rev 2223 Rev 2262
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
3
# Id: $Id: alcasar-url_filter_wl.sh 2223 2017-05-14 14:38:01Z tom.houdayer $
3
# Id: $Id: alcasar-url_filter_wl.sh 2262 2017-05-29 20:19:03Z tom.houdayer $
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"
14
TINY_CONF="/etc/tinyproxy/tinyproxy.conf"
15
DNSMASQ_WL_CONF="/etc/dnsmasq-whitelist.conf"
15
DNSMASQ_WL_CONF="/etc/dnsmasq-whitelist.conf"
16
IP_WL="/usr/local/share/iptables-wl-enabled/ossi-ip-safesearch"
16
IP_WL="/usr/local/share/iptables-wl-enabled/ossi-ip-safesearch"
17
CONF_FILE="/usr/local/etc/alcasar.conf"
17
CONF_FILE="/usr/local/etc/alcasar.conf"
18
SED="/bin/sed -i"
18
SED="/bin/sed -i"
19
safesearch="Off"
19
safesearch="Off"
20
usage="Usage: alcasar-url_filter_wl.sh { -safesearch_on or -safesearch_off }"
20
usage="Usage: alcasar-url_filter_wl.sh { -safesearch_on or -safesearch_off }"
21
nb_args=$#
21
nb_args=$#
22
if [ $nb_args -le 0 ]
22
if [ $nb_args -le 0 ]
23
then
23
then
24
	echo "$usage"
24
	echo "$usage"
25
	nb_args=0
25
	nb_args=0
26
else
26
else
27
	while [ $nb_args -ge 1 ]
27
	while [ $nb_args -ge 1 ]
28
	do
28
	do
29
		arg=${!nb_args}
29
		arg=${!nb_args}
30
		case $arg in
30
		case $arg in
31
		-\? | -h* | --h*)
31
		-\? | -h* | --h*)
32
			echo "$usage"
32
			echo "$usage"
33
			exit 0
33
			exit 0
34
			;;
34
			;;
35
		# Safe search activation
35
		# Safe search activation
36
		-safesearch_on | --safesearch_on)	
36
		-safesearch_on | --safesearch_on)	
37
			safesearch="On"
37
			safesearch="On"
38
			;;
38
			;;
39
		# Safe search desactivation
39
		# Safe search desactivation
40
		-safesearch_off | --safesearch_off)	
40
		-safesearch_off | --safesearch_off)	
41
			safesearch="Off"
41
			safesearch="Off"
42
			;;
42
			;;
43
		*)
43
		*)
44
			echo "Argument inconnu :$arg";
44
			echo "Argument inconnu :$arg";
45
			echo "$usage"
45
			echo "$usage"
46
			exit 1
46
			exit 1
47
			;;
47
			;;
48
		esac
48
		esac
49
	nb_args=$(expr $nb_args - 1)
49
	nb_args=$(expr $nb_args - 1)
50
	done
50
	done
51
	forcesafesearch_server=`host -ta forcesafesearch.google.com|cut -d" " -f4`	# retrieve google forcesafesearch ip
51
	forcesafesearch_server=`host -ta forcesafesearch.google.com|cut -d" " -f4`	# retrieve google forcesafesearch ip
52
	if [ $safesearch == "On" ]
52
	if [ $safesearch == "On" ]
53
	then
53
	then
54
# add 'SafeSearch' redirection for google searching
54
# add 'SafeSearch' redirection for google searching
55
		$SED "/google/d" $DNSMASQ_WL_CONF # remove old google declaration
55
		$SED "/google/d" $DNSMASQ_WL_CONF # remove old google declaration
56
		if [ -e $IP_WL ]
56
		if [ -e $IP_WL ]
57
		then
57
		then
58
			rm $IP_WL # remove old google declaration
58
			rm $IP_WL # remove old google declaration
59
		fi
59
		fi
60
		echo "# SafeSearch redirect server for google" >> $DNSMASQ_WL_CONF
60
		echo "# SafeSearch redirect server for google" >> $DNSMASQ_WL_CONF
61
		for gg_dnsname in .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 
61
		for gg_dnsname in .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 
62
		do
62
		do
63
			echo "address=/$gg_dnsname/$forcesafesearch_server" >> $DNSMASQ_WL_CONF
63
			echo "address=/$gg_dnsname/$forcesafesearch_server" >> $DNSMASQ_WL_CONF
64
		done
64
		done
65
		echo "add wl_ip_allowed $forcesafesearch_server" >> $IP_WL
65
		echo "add wl_ip_allowed $forcesafesearch_server" >> $IP_WL
66
	else
66
	else
67
		$SED "/google/d" $DNSMASQ_WL_CONF
67
		$SED "/google/d" $DNSMASQ_WL_CONF
68
		rm $IP_WL
68
		rm $IP_WL
69
	fi
69
	fi
70
systemctl restart dnsmasq-whitelist
70
systemctl restart dnsmasq-whitelist
71
fi
71
fi
72
 
72
 
73
 
73