Subversion Repositories ALCASAR

Rev

Rev 2688 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2688 Rev 2708
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-dhcp.sh 2688 2019-01-18 23:15:49Z lucas.echard $
2
# $Id: alcasar-dhcp.sh 2708 2019-03-05 23:17:43Z 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 14... Line 14...
14
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
14
ALCASAR_CONF_FILE="/usr/local/etc/alcasar.conf"
15
 
15
 
16
# define DHCP parameters (LAN side)
16
# define DHCP parameters (LAN side)
17
PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2`
17
PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2`
18
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
18
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
19
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP_MASK |cut -d"=" -f2`				# network prefix (ie. 24)
-
 
20
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
19
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
21
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`
20
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2`
22
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`
21
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2`
23
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX					# ie.: 192.168.182.0/24
22
PRIVATE_NETWORK_MASK="$PRIVATE_NETWORK/$PRIVATE_PREFIX"							# ie.: 192.168.182.0/24
24
classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`; classe_sup_sup=`expr $classe + 2`		# ie.: 2=classe B, 3=classe C
-
 
25
PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2`		# private network broadcast (ie.: 192.168.182.255)
-
 
26
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup`		# last octet of LAN address
-
 
27
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup`		# last octet of LAN broadcast
-
 
28
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_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1`	# last network address (ex.: 192.168.182.254)
-
 
30
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX
-
 
31
EXT_DHCP_IP=`grep ^EXT_DHCP_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2`				# Adresse du serveur DHCP externe
23
EXT_DHCP_IP=`grep ^EXT_DHCP_IP= $ALCASAR_CONF_FILE|cut -d"=" -f2`					# Adresse du serveur DHCP externe
32
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
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
33
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
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
34
RELAY_DHCP_PORT=`grep ^RELAY_DHCP_PORT= $ALCASAR_CONF_FILE|cut -d"=" -f2`			# Port de redirection vers le relay DHCP :  67 par défaut
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
35
RELAY_DHCP_PORT=${RELAY_DHCP_PORT:=67}
27
RELAY_DHCP_PORT=${RELAY_DHCP_PORT:=67}
36
 
28
 
37
usage="Usage: alcasar-dhcp.sh {--on | -on} | {--off | -off} "
29
usage="Usage: alcasar-dhcp.sh {--on | -on} | {--off | -off} "
38
nb_args=$#
30
nb_args=$#
39
args=$1
31
args=$1
Line 46... Line 38...
46
	-\? | -h | --h)
38
	-\? | -h | --h)
47
		echo "$usage"
39
		echo "$usage"
48
		exit 0
40
		exit 0
49
		;;
41
		;;
50
	--off|-off) # disable DHCP service
42
	--off|-off) # disable DHCP service
-
 
43
		$SED "s?^DHCP=.*?DHCP=off?g" $ALCASAR_CONF_FILE
51
		$SED "s?.*statip.*?statip\t\t$PRIVATE_NETWORK_MASK?g" $CHILLI_CONF_FILE
44
		$SED "s?.*statip.*?statip\t\t$PRIVATE_NETWORK_MASK?g" $CHILLI_CONF_FILE
52
		$SED "s?^#nodynip.*?nodynip?g" $CHILLI_CONF_FILE
45
		$SED "s?^#nodynip.*?nodynip?g" $CHILLI_CONF_FILE
53
		$SED "s?^dynip.*?#dynip?g" $CHILLI_CONF_FILE
-
 
54
		$SED "s?^#dynip.*?#dynip?g" $CHILLI_CONF_FILE
46
		$SED "s@^#\?dynip.*@#dynip@g" $CHILLI_CONF_FILE
55
		$SED "s?^DHCP.*?DHCP=off?g" $ALCASAR_CONF_FILE
-
 
56
		if [ "$EXT_DHCP_IP" != "none" ]
47
		if [ -n "$EXT_DHCP_IP" ] && [ "$EXT_DHCP_IP" != "none" ]
57
		then
48
		then
58
			$SED "s?.*dhcpgateway\t.*?dhcpgateway\t\t $EXT_DHCP_IP?g" $CHILLI_CONF_FILE
49
			$SED "s?.*dhcpgateway\s.*?dhcpgateway\t$EXT_DHCP_IP?g" $CHILLI_CONF_FILE
59
			$SED "s?.*dhcprelayagent.*?dhcprelayagent\t\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
50
			$SED "s?.*dhcprelayagent.*?dhcprelayagent\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
60
			$SED "s?.*dhcpgatewayport.*?dhcpgatewayport\t\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
51
			$SED "s?.*dhcpgatewayport.*?dhcpgatewayport\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
61
		else
52
		else
62
			$SED "s?.*dhcpgateway\t.*?#dhcpgateway\t\t$EXT_DHCP_IP?g" $CHILLI_CONF_FILE
53
			$SED "s?.*dhcpgateway\s.*?#dhcpgateway\t\t$EXT_DHCP_IP?g" $CHILLI_CONF_FILE
63
			$SED "s?.*dhcprelayagent.*?#dhcprelayagent\t\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
54
			$SED "s?.*dhcprelayagent.*?#dhcprelayagent\t\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
64
			$SED "s?.*dhcpgatewayport.*?#dhcpgatewayport\t\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
55
			$SED "s?.*dhcpgatewayport.*?#dhcpgatewayport\t\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
65
		fi
56
		fi
66
		/usr/bin/systemctl restart chilli
57
		/usr/bin/systemctl restart chilli
67
		;;
58
		;;
68
	--on|-on) # enable DHCP service on all range of IP addresses
59
	--on|-on) # enable DHCP service on all range of IP addresses
-
 
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
69
		$SED "s?^.*statip.*?#statip?g" $CHILLI_CONF_FILE
63
		$SED "s?^.*statip.*?#statip?g" $CHILLI_CONF_FILE
70
		$SED "s?^nodynip.*?#nodynip?g" $CHILLI_CONF_FILE
64
		$SED "s?^nodynip.*?#nodynip?g" $CHILLI_CONF_FILE
71
		$SED "s?^DHCP.*?DHCP=on?g" $ALCASAR_CONF_FILE
-
 
72
		$SED "s?^dynip.*?dynip\t\t$PRIVATE_NETWORK_MASK?g" $CHILLI_CONF_FILE
-
 
73
		$SED "s?^#dynip.*?dynip\t\t$PRIVATE_NETWORK_MASK?g" $CHILLI_CONF_FILE
65
		$SED "s@^#\?dynip.*@dynip\t\t$PRIVATE_NETWORK_MASK@g" $CHILLI_CONF_FILE
74
		$SED "s?^dhcpgateway\t.*?#dhcpgateway\t\t $EXT_DHCP_IP?g" $CHILLI_CONF_FILE
66
		$SED "s?^dhcpgateway\s.*?#dhcpgateway\t$EXT_DHCP_IP?g" $CHILLI_CONF_FILE
75
		$SED "s?^dhcprelayagent.*?#dhcprelayagent\t\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
67
		$SED "s?^dhcprelayagent.*?#dhcprelayagent\t$RELAY_DHCP_IP?g" $CHILLI_CONF_FILE
76
		$SED "s?^dhcpgatewayport.*?#dhcpgatewayport\t\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
68
		$SED "s?^dhcpgatewayport.*?#dhcpgatewayport\t$RELAY_DHCP_PORT?g" $CHILLI_CONF_FILE
77
		$SED "s?^EXT_DHCP_IP.*?EXT_DHCP_IP=$EXT_DHCP_IP?g" $ALCASAR_CONF_FILE
-
 
78
		$SED "s?^RELAY_DHCP_IP.*?RELAY_DHCP_IP=$RELAY_DHCP_IP?g" $ALCASAR_CONF_FILE
-
 
79
		$SED "s?^RELAY_DHCP_PORT.*?RELAY_DHCP_PORT=$RELAY_DHCP_PORT?g" $ALCASAR_CONF_FILE
-
 
80
		/usr/bin/systemctl restart chilli
69
		/usr/bin/systemctl restart chilli
81
		;;
70
		;;
82
	*)
71
	*)
83
		echo "Argument inconnu :$1";
72
		echo "Argument inconnu :$1";
84
		echo "$usage"
73
		echo "$usage"