Subversion Repositories ALCASAR

Rev

Rev 838 | Rev 861 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

#/bin/bash
# $Id: alcasar-nf.sh 791 2012-01-13 21:31:36Z richard $

# alcasar-dhcp.sh
# by Rexy
# This script is distributed under the Gnu General Public License (GPL)

# active ou desactive le service DHCP sur le réseau de consultation
# enable or disable the DHCP service on consultation LAN

SED="/bin/sed -i"
CHILLI_CONF_FILE="/etc/chilli.conf"
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
ETHERS_FILE="/usr/local/etc/alcasar-ethers"

PRIVATE_IP_MASK=`grep PRIVATE_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX

usage="Usage: alcasar-dhcp.sh {--on | -on} | {--off | -off}"
nb_args=$#
args=$1
if [ $nb_args -eq 0 ]
then
        echo "$usage"
        exit 1
fi
case $args in
        -\? | -h* | --h*)
                echo "$usage"
                exit 0
                ;;
        --off|-off) # disable DHCP service
                $SED "s?^#statip.*?statip\t\t$PRIVATE_NETWORK_MASK?g" $CHILLI_CONF_FILE
                $SED "s?^#nodynip.*?nodynip?g" $CHILLI_CONF_FILE
                $SED "s?^ethers.*?#ethers\t\t$ETHERS_FILE?g" $CHILLI_CONF_FILE
                $SED "s?^DHCP.*?DHCP=off?g" $ALCASAR_CONF_FILE
                /etc/init.d/chilli restart
                ;;
        --on|-on) # enable DHCP service
                $SED "s?^statip.*?#statip\t\t$PRIVATE_NETWORK_MASK?g" $CHILLI_CONF_FILE
                $SED "s?^nodynip.*?#nodynip?g" $CHILLI_CONF_FILE
                $SED "s?^#ethers.*?ethers\t\t$ETHERS_FILE?g" $CHILLI_CONF_FILE
                $SED "s?^DHCP.*?DHCP=on?g" $ALCASAR_CONF_FILE
                /etc/init.d/chilli restart
                ;;
        *)
                echo "Argument inconnu :$1";
                echo "$usage"
                exit 1
                ;;
esac