Subversion Repositories ALCASAR

Rev

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

Rev 2262 Rev 2559
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-dns-local.sh 2262 2017-05-29 20:19:03Z tom.houdayer $
2
# $Id: alcasar-dns-local.sh 2559 2018-06-10 12:56:39Z rexy $
3
 
3
 
4
# alcasar-dns-interne.sh
4
# alcasar-dns-interne.sh
5
# by Rexy - 3abtux
5
# by Rexy - 3abtux
6
# This script is distributed under the Gnu General Public License (GPL)
6
# This script is distributed under the Gnu General Public License (GPL)
7
 
7
 
Line 10... Line 10...
10
 
10
 
11
SED="/bin/sed -i"
11
SED="/bin/sed -i"
12
 
12
 
13
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
13
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
14
DNSMASQ_CONF_FILE="/etc/dnsmasq.conf /etc/dnsmasq-blackhole.conf /etc/dnsmasq-blacklist.conf /etc/dnsmasq-whitelist.conf"
14
DNSMASQ_CONF_FILE="/etc/dnsmasq.conf /etc/dnsmasq-blackhole.conf /etc/dnsmasq-blacklist.conf /etc/dnsmasq-whitelist.conf"
15
DNSMASQ_CONF_LOCAL_FILE="/usr/local/etc/alcasar-dns-name"
15
LOCAL_DOMAIN_CONF_FILE="/usr/local/etc/alcasar-dns-name"
-
 
16
LOCAL_HOSTNAME_FILE="/etc/hosts"
16
 
17
 
17
# define DNS parameters (LAN side)
18
# define DNS parameters (LAN side)
18
 
19
 
19
INT_DNS_DOMAIN=`grep INT_DNS_DOMAIN $ALCASAR_CONF_FILE|cut -d"=" -f2`			# Nom du domaine DNS interne
20
INT_DNS_DOMAIN=`grep INT_DNS_DOMAIN $ALCASAR_CONF_FILE|cut -d"=" -f2`			# Nom du domaine DNS interne
20
INT_DNS_IP=`grep INT_DNS_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`				# Adresse du serveur DNS interne
21
INT_DNS_IP=`grep INT_DNS_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`				# Adresse du serveur DNS interne
21
INT_DNS_ACTIVE=`grep INT_DNS_ACTIVE $ALCASAR_CONF_FILE|cut -d"=" -f2`			# Activation de la redirection DNS interne
22
INT_DNS_ACTIVE=`grep INT_DNS_ACTIVE $ALCASAR_CONF_FILE|cut -d"=" -f2`			# Activation de la redirection DNS interne
22
 
23
 
23
usage="Usage: alcasar-dns-interne.sh {--on | -on} | {--off | -off}"
24
usage="Usage: alcasar-dns-interne.sh {--on | -on} | {--off | -off} | {--add | -add}"
24
nb_args=$#
25
nb_args=$#
25
args=$1
26
args=$1
26
if [ $nb_args -eq 0 ]
27
if [ $nb_args -eq 0 ]
27
then
28
then
28
	echo "$usage"
29
	echo "$usage"
29
	exit 1
30
	exit 1
30
fi
31
fi
-
 
32
function restart_dns(){
-
 
33
	for dns in dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole
-
 
34
	do
-
 
35
		systemctl restart $dns
-
 
36
	done
-
 
37
}
-
 
38
 
31
case $args in
39
case $args in
32
	-\? | -h | --h)
40
	-\? | -h | --h)
33
		echo "$usage"
41
		echo "$usage"
34
		exit 0
42
		exit 0
35
		;;
43
		;;
-
 
44
	--add|-add) # add a local host resolution
-
 
45
		if [ $nb_args -ne 3 ]
-
 
46
		then
-
 
47
			echo "$usage"
-
 
48
			exit 1
-
 
49
		else
-
 
50
			echo -e "$2\t$3" >> $LOCAL_HOSTNAME_FILE
-
 
51
			restart_dns
-
 
52
		fi
-
 
53
		;;
-
 
54
	--del|-del) # remove a local host resolution
-
 
55
		if [ $nb_args -ne 3 ]
-
 
56
		then
-
 
57
			echo "$usage"
-
 
58
			exit 1
-
 
59
		else
-
 
60
			$SED "/^$2\t$3/d" SLOCAL_HOSTNAME_FILE
-
 
61
			restart_dns
-
 
62
		fi
-
 
63
		;;
-
 
64
 
36
	--off|-off) # disable DNS redirector
65
	--off|-off) # disable DNS redirector
37
		$SED "s?^#filterwin2k.*?filterwin2k?g" $DNSMASQ_CONF_FILE
66
		$SED "s?^#filterwin2k.*?filterwin2k?g" $DNSMASQ_CONF_FILE
38
		$SED "s?^server.*?#&?g" $DNSMASQ_CONF_LOCAL_FILE
67
		$SED "s?^server.*?#&?g" $LOCAL_DOMAIN_CONF_FILE
39
		$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=off?g" $ALCASAR_CONF_FILE
68
		$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=off?g" $ALCASAR_CONF_FILE
40
 
-
 
41
		/usr/bin/systemctl restart dnsmasq
69
		restart_dns
42
		/usr/bin/systemctl restart dnsmasq-blacklist
-
 
43
		/usr/bin/systemctl restart dnsmasq-blackhole
-
 
44
		/usr/bin/systemctl restart dnsmasq-whitelist
-
 
45
		;;
70
		;;
46
	--on|-on) # enable DHCP service on all range of IP addresses
71
	--on|-on) # enable DHCP service on all range of IP addresses
47
		$SED "s?^filterwin2k.*?#filterwin2k?g" $DNSMASQ_CONF_FILE
72
		$SED "s?^filterwin2k.*?#filterwin2k?g" $DNSMASQ_CONF_FILE
48
		$SED "s?^server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $DNSMASQ_CONF_LOCAL_FILE
73
		$SED "s?^server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $LOCAL_DOMAIN_CONF_FILE
49
		$SED "s?^#server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $DNSMASQ_CONF_LOCAL_FILE
74
		$SED "s?^#server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $LOCAL_DOMAIN_CONF_FILE
50
		$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=on?g" $ALCASAR_CONF_FILE
75
		$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=on?g" $ALCASAR_CONF_FILE
51
 
-
 
52
		/usr/bin/systemctl restart dnsmasq
76
		restart_dns
53
		/usr/bin/systemctl restart dnsmasq-blacklist
-
 
54
		/usr/bin/systemctl restart dnsmasq-blackhole
-
 
55
		/usr/bin/systemctl restart dnsmasq-whitelist
-
 
56
		;;
77
		;;
57
	*)
78
	*)
58
		echo "Argument inconnu :$1";
79
		echo "Argument inconnu :$1";
59
		echo "$usage"
80
		echo "$usage"
60
		exit 1
81
		exit 1