Rev 2262 | Rev 2825 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log
#!/bin/bash
# $Id: alcasar-dns-local.sh 2559 2018-06-10 12:56:39Z rexy $
# alcasar-dns-interne.sh
# by Rexy - 3abtux
# This script is distributed under the Gnu General Public License (GPL)
# active ou desactive la redirection du service DNS sur le réseau de consultation
# enable or disable the redirector of internal DNS service on consultation LAN
SED="/bin/sed -i"
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
DNSMASQ_CONF_FILE="/etc/dnsmasq.conf /etc/dnsmasq-blackhole.conf /etc/dnsmasq-blacklist.conf /etc/dnsmasq-whitelist.conf"
LOCAL_DOMAIN_CONF_FILE="/usr/local/etc/alcasar-dns-name"
LOCAL_HOSTNAME_FILE="/etc/hosts"
# define DNS parameters (LAN side)
INT_DNS_DOMAIN=`grep INT_DNS_DOMAIN $ALCASAR_CONF_FILE|cut -d"=" -f2` # Nom du domaine DNS interne
INT_DNS_IP=`grep INT_DNS_IP $ALCASAR_CONF_FILE|cut -d"=" -f2` # Adresse du serveur DNS interne
INT_DNS_ACTIVE=`grep INT_DNS_ACTIVE $ALCASAR_CONF_FILE|cut -d"=" -f2` # Activation de la redirection DNS interne
usage="Usage: alcasar-dns-interne.sh {--on | -on} | {--off | -off} | {--add | -add}"
nb_args=$#
args=$1
if [ $nb_args -eq 0 ]
then
echo "$usage"
exit 1
fi
function restart_dns(){
for dns in dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole
do
systemctl restart $dns
done
}
case $args in
-\? | -h | --h)
echo "$usage"
exit 0
;;
--add|-add) # add a local host resolution
if [ $nb_args -ne 3 ]
then
echo "$usage"
exit 1
else
echo -e "$2\t$3" >> $LOCAL_HOSTNAME_FILE
restart_dns
fi
;;
--del|-del) # remove a local host resolution
if [ $nb_args -ne 3 ]
then
echo "$usage"
exit 1
else
$SED "/^$2\t$3/d" SLOCAL_HOSTNAME_FILE
restart_dns
fi
;;
--off|-off) # disable DNS redirector
$SED "s?^#filterwin2k.*?filterwin2k?g" $DNSMASQ_CONF_FILE
$SED "s?^server.*?#&?g" $LOCAL_DOMAIN_CONF_FILE
$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=off?g" $ALCASAR_CONF_FILE
restart_dns
;;
--on|-on) # enable DHCP service on all range of IP addresses
$SED "s?^filterwin2k.*?#filterwin2k?g" $DNSMASQ_CONF_FILE
$SED "s?^server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $LOCAL_DOMAIN_CONF_FILE
$SED "s?^#server=/.*?server=/$INT_DNS_DOMAIN/$INT_DNS_IP?g" $LOCAL_DOMAIN_CONF_FILE
$SED "s?^INT_DNS_ACTIVE.*?INT_DNS_ACTIVE=on?g" $ALCASAR_CONF_FILE
restart_dns
;;
*)
echo "Argument inconnu :$1";
echo "$usage"
exit 1
;;
esac