Subversion Repositories ALCASAR

Rev

Rev 2262 | Rev 2688 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2223 tom.houday 1
#!/bin/bash
2
# $Id: alcasar-dns-local.sh 2559 2018-06-10 12:56:39Z rexy $
1607 franck 3
 
4
# alcasar-dns-interne.sh
5
# by Rexy - 3abtux
6
# This script is distributed under the Gnu General Public License (GPL)
7
 
8
# active ou desactive la redirection du service DNS sur le réseau de consultation
9
# enable or disable the redirector of internal DNS service on consultation LAN
10
 
11
SED="/bin/sed -i"
12
 
13
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
1614 franck 14
DNSMASQ_CONF_FILE="/etc/dnsmasq.conf /etc/dnsmasq-blackhole.conf /etc/dnsmasq-blacklist.conf /etc/dnsmasq-whitelist.conf"
2559 rexy 15
LOCAL_DOMAIN_CONF_FILE="/usr/local/etc/alcasar-dns-name"
16
LOCAL_HOSTNAME_FILE="/etc/hosts"
1607 franck 17
 
18
# define DNS parameters (LAN side)
19
 
20
INT_DNS_DOMAIN=`grep INT_DNS_DOMAIN $ALCASAR_CONF_FILE|cut -d"=" -f2`			# Nom du domaine DNS interne
21
INT_DNS_IP=`grep INT_DNS_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`				# Adresse du serveur DNS interne
22
INT_DNS_ACTIVE=`grep INT_DNS_ACTIVE $ALCASAR_CONF_FILE|cut -d"=" -f2`			# Activation de la redirection DNS interne
23
 
2559 rexy 24
usage="Usage: alcasar-dns-interne.sh {--on | -on} | {--off | -off} | {--add | -add}"
1607 franck 25
nb_args=$#
26
args=$1
27
if [ $nb_args -eq 0 ]
28
then
29
	echo "$usage"
30
	exit 1
31
fi
2559 rexy 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
 
1607 franck 39
case $args in
40
	-\? | -h | --h)
41
		echo "$usage"
42
		exit 0
43
		;;
2559 rexy 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
 
1607 franck 65
	--off|-off) # disable DNS redirector
66
		$SED "s?^#filterwin2k.*?filterwin2k?g" $DNSMASQ_CONF_FILE
2559 rexy 67
		$SED "s?^server.*?#&?g" $LOCAL_DOMAIN_CONF_FILE
1607 franck 68
		$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=off?g" $ALCASAR_CONF_FILE
2559 rexy 69
		restart_dns
1607 franck 70
		;;
71
	--on|-on) # enable DHCP service on all range of IP addresses
72
		$SED "s?^filterwin2k.*?#filterwin2k?g" $DNSMASQ_CONF_FILE
2559 rexy 73
		$SED "s?^server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $LOCAL_DOMAIN_CONF_FILE
74
		$SED "s?^#server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $LOCAL_DOMAIN_CONF_FILE
1607 franck 75
		$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=on?g" $ALCASAR_CONF_FILE
2559 rexy 76
		restart_dns
1607 franck 77
		;;
78
	*)
79
		echo "Argument inconnu :$1";
80
		echo "$usage"
81
		exit 1
82
		;;
83
esac