2223 |
tom.houday |
1 |
#!/bin/bash
|
958 |
franck |
2 |
# $Id: alcasar-dhcp.sh 2708 2019-03-05 23:17:43Z tom.houdayer $
|
838 |
richard |
3 |
|
|
|
4 |
# alcasar-dhcp.sh
|
1783 |
franck |
5 |
|
838 |
richard |
6 |
# by Rexy
|
|
|
7 |
# This script is distributed under the Gnu General Public License (GPL)
|
|
|
8 |
|
|
|
9 |
# active ou desactive le service DHCP sur le réseau de consultation
|
|
|
10 |
# enable or disable the DHCP service on consultation LAN
|
|
|
11 |
|
|
|
12 |
SED="/bin/sed -i"
|
841 |
richard |
13 |
CHILLI_CONF_FILE="/etc/chilli.conf"
|
838 |
richard |
14 |
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
|
|
|
15 |
|
861 |
richard |
16 |
# define DHCP parameters (LAN side)
|
2474 |
tom.houday |
17 |
PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2`
|
841 |
richard |
18 |
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
|
|
|
19 |
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
|
861 |
richard |
20 |
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`
|
841 |
richard |
21 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`
|
2708 |
tom.houday |
22 |
PRIVATE_NETWORK_MASK="$PRIVATE_NETWORK/$PRIVATE_PREFIX" # ie.: 192.168.182.0/24
|
|
|
23 |
EXT_DHCP_IP=`grep ^EXT_DHCP_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2` # Adresse du serveur DHCP externe
|
|
|
24 |
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
|
|
|
25 |
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
|
|
|
26 |
RELAY_DHCP_PORT=`grep ^RELAY_DHCP_PORT= $ALCASAR_CONF_FILE|cut -d"=" -f2` # Port de redirection vers le relay DHCP : 67 par défaut
|
916 |
franck |
27 |
RELAY_DHCP_PORT=${RELAY_DHCP_PORT:=67}
|
841 |
richard |
28 |
|
2013 |
raphael.pi |
29 |
usage="Usage: alcasar-dhcp.sh {--on | -on} | {--off | -off} "
|
838 |
richard |
30 |
nb_args=$#
|
|
|
31 |
args=$1
|
|
|
32 |
if [ $nb_args -eq 0 ]
|
|
|
33 |
then
|
|
|
34 |
echo "$usage"
|
|
|
35 |
exit 1
|
|
|
36 |
fi
|
|
|
37 |
case $args in
|
861 |
richard |
38 |
-\? | -h | --h)
|
838 |
richard |
39 |
echo "$usage"
|
|
|
40 |
exit 0
|
|
|
41 |
;;
|
|
|
42 |
--off|-off) # disable DHCP service
|
2708 |
tom.houday |
43 |
$SED "s?^DHCP=.*?DHCP=off?g" $ALCASAR_CONF_FILE
|
861 |
richard |
44 |
$SED "s?.*statip.*?statip\t\t$PRIVATE_NETWORK_MASK?g" $CHILLI_CONF_FILE
|
841 |
richard |
45 |
$SED "s?^#nodynip.*?nodynip?g" $CHILLI_CONF_FILE
|
2708 |
tom.houday |
46 |
$SED "s@^#\?dynip.*@#dynip@g" $CHILLI_CONF_FILE
|
|
|
47 |
if [ -n "$EXT_DHCP_IP" ] && [ "$EXT_DHCP_IP" != "none" ]
|
914 |
franck |
48 |
then
|
2708 |
tom.houday |
49 |
$SED "s?.*dhcpgateway\s.*?dhcpgateway\t$EXT_DHCP_IP?g" $CHILLI_CONF_FILE
|
|
|
50 |
$SED "s?.*dhcprelayagent.*?dhcprelayagent\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
|
|
|
51 |
$SED "s?.*dhcpgatewayport.*?dhcpgatewayport\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
|
1101 |
franck |
52 |
else
|
2708 |
tom.houday |
53 |
$SED "s?.*dhcpgateway\s.*?#dhcpgateway\t\t$EXT_DHCP_IP?g" $CHILLI_CONF_FILE
|
2454 |
tom.houday |
54 |
$SED "s?.*dhcprelayagent.*?#dhcprelayagent\t\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
|
|
|
55 |
$SED "s?.*dhcpgatewayport.*?#dhcpgatewayport\t\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
|
914 |
franck |
56 |
fi
|
1419 |
richard |
57 |
/usr/bin/systemctl restart chilli
|
838 |
richard |
58 |
;;
|
1484 |
richard |
59 |
--on|-on) # enable DHCP service on all range of IP addresses
|
2708 |
tom.houday |
60 |
$SED "s?^DHCP=.*?DHCP=on?g" $ALCASAR_CONF_FILE
|
|
|
61 |
$SED "s?^RELAY_DHCP_IP=.*?RELAY_DHCP_IP=$RELAY_DHCP_IP?g" $ALCASAR_CONF_FILE
|
|
|
62 |
$SED "s?^RELAY_DHCP_PORT=.*?RELAY_DHCP_PORT=$RELAY_DHCP_PORT?g" $ALCASAR_CONF_FILE
|
861 |
richard |
63 |
$SED "s?^.*statip.*?#statip?g" $CHILLI_CONF_FILE
|
841 |
richard |
64 |
$SED "s?^nodynip.*?#nodynip?g" $CHILLI_CONF_FILE
|
2708 |
tom.houday |
65 |
$SED "s@^#\?dynip.*@dynip\t\t$PRIVATE_NETWORK_MASK@g" $CHILLI_CONF_FILE
|
|
|
66 |
$SED "s?^dhcpgateway\s.*?#dhcpgateway\t$EXT_DHCP_IP?g" $CHILLI_CONF_FILE
|
|
|
67 |
$SED "s?^dhcprelayagent.*?#dhcprelayagent\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
|
|
|
68 |
$SED "s?^dhcpgatewayport.*?#dhcpgatewayport\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
|
1419 |
richard |
69 |
/usr/bin/systemctl restart chilli
|
841 |
richard |
70 |
;;
|
838 |
richard |
71 |
*)
|
|
|
72 |
echo "Argument inconnu :$1";
|
|
|
73 |
echo "$usage"
|
|
|
74 |
exit 1
|
|
|
75 |
;;
|
|
|
76 |
esac
|