Line 1... |
Line 1... |
1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
# $Id: alcasar-dhcp.sh 2454 2017-12-09 18:59:31Z tom.houdayer $
|
2 |
# $Id: alcasar-dhcp.sh 2474 2017-12-30 02:00:04Z tom.houdayer $
|
3 |
|
3 |
|
4 |
# alcasar-dhcp.sh
|
4 |
# alcasar-dhcp.sh
|
5 |
|
5 |
|
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)
|
Line 13... |
Line 13... |
13 |
CHILLI_CONF_FILE="/etc/chilli.conf"
|
13 |
CHILLI_CONF_FILE="/etc/chilli.conf"
|
14 |
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
|
14 |
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
|
15 |
DNSMASQ_CONF_FILE="/etc/dnsmasq.conf"
|
15 |
DNSMASQ_CONF_FILE="/etc/dnsmasq.conf"
|
16 |
|
16 |
|
17 |
# define DHCP parameters (LAN side)
|
17 |
# define DHCP parameters (LAN side)
|
18 |
PRIVATE_IP_MASK=`grep PRIVATE_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`
|
18 |
PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2`
|
19 |
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
|
19 |
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
|
20 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP_MASK |cut -d"=" -f2` # network prefix (ie. 24)
|
20 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP_MASK |cut -d"=" -f2` # network prefix (ie. 24)
|
21 |
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
|
21 |
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
|
22 |
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`
|
22 |
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`
|
23 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`
|
23 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`
|
Line 27... |
Line 27... |
27 |
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup` # last octet of LAN address
|
27 |
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup` # last octet of LAN address
|
28 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # last octet of LAN broadcast
|
28 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # last octet of LAN broadcast
|
29 |
PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1` # First network address (ex.: 192.168.182.1)
|
29 |
PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1` # First network address (ex.: 192.168.182.1)
|
30 |
PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # last network address (ex.: 192.168.182.254)
|
30 |
PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # last network address (ex.: 192.168.182.254)
|
31 |
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX
|
31 |
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX
|
32 |
EXT_DHCP_IP=`grep EXT_DHCP_IP $ALCASAR_CONF_FILE|cut -d"=" -f2` # Adresse du serveur DHCP externe
|
32 |
EXT_DHCP_IP=`grep ^EXT_DHCP_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2` # Adresse du serveur DHCP externe
|
33 |
RELAY_DHCP_IP=`grep RELAY_DHCP_IP $ALCASAR_CONF_FILE|cut -d"=" -f2` # Adresse de l'agent Relay : IP interne (défaut 192.168.182.1) dans le cas de DHCP dans le LAN de consultation
|
33 |
RELAY_DHCP_IP=`grep ^RELAY_DHCP_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2` # Adresse de l'agent Relay : IP interne (défaut 192.168.182.1) dans le cas de DHCP dans le LAN de consultation
|
34 |
RELAY_DHCP_IP=${RELAY_DHCP_IP:=$PRIVATE_IP} # IP externe (défaut x.y.z.t) dans le cas de DHCP du côté WAN
|
34 |
RELAY_DHCP_IP=${RELAY_DHCP_IP:=$PRIVATE_IP} # IP externe (défaut x.y.z.t) dans le cas de DHCP du côté WAN
|
35 |
RELAY_DHCP_PORT=`grep RELAY_DHCP_PORT $ALCASAR_CONF_FILE|cut -d"=" -f2` # Port de redirection vers le relay DHCP : 67 par défaut
|
35 |
RELAY_DHCP_PORT=`grep ^RELAY_DHCP_PORT= $ALCASAR_CONF_FILE|cut -d"=" -f2` # Port de redirection vers le relay DHCP : 67 par défaut
|
36 |
RELAY_DHCP_PORT=${RELAY_DHCP_PORT:=67}
|
36 |
RELAY_DHCP_PORT=${RELAY_DHCP_PORT:=67}
|
37 |
|
37 |
|
38 |
usage="Usage: alcasar-dhcp.sh {--on | -on} | {--off | -off} "
|
38 |
usage="Usage: alcasar-dhcp.sh {--on | -on} | {--off | -off} "
|
39 |
nb_args=$#
|
39 |
nb_args=$#
|
40 |
args=$1
|
40 |
args=$1
|