Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
597 richard 1
#!/bin/sh
2
 
3
# alcasar-network.sh
4
# by Richard REY
5
# This script is distributed under the Gnu General Public License (GPL)
6
 
7
# Install network parameters for ALCASAR 
8
# Installation des paramètres réseau d'ALCASAR
9
 
10
# ******* Global *******
11
DIR_DEST_ETC="/usr/local/etc"			# répertoire des fichiers de conf
12
FIC_PARAM="/root/ALCASAR-parameters.txt"
13
HOSTNAME="alcasar"
14
DOMAIN="localdomain"				# domaine local
15
EXTIF="eth0"					# ETH0 est l'interface connectée à Internet (Box FAI)
16
INTIF="eth1"					# ETH1 est l'interface connectée au réseau local de consultation
17
SED="/bin/sed -i"
18
 
19
PTN="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[012]?[0-9]\b"
20
PRIVATE_IP_MASK=`cat $DIR_DEST_ETC/alcasar-network|grep PRIVATE_IP|cut -d"=" -f2`
21
check=$(echo $PRIVATE_IP_MASK | egrep $PTN)
22
if [[ "$?" -ne 0 ]]
23
then 
24
	echo "Syntax error for PRIVATE_IP ($PRIVATE_IP)"
25
	exit 0
26
fi
27
PUBLIC_IP_MASK=`cat $DIR_DEST_ETC/alcasar-network|grep PUBLIC_IP|cut -d"=" -f2`
28
check=$(echo $PUBLIC_IP_MASK | egrep $PTN)
29
if [[ "$?" -ne 0 ]]
30
then 
31
	echo "Syntax error for PUBLIC_IP ($PUBLIC_IP)"
32
	exit 0
33
fi
34
PTN="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
35
PUBLIC_GATEWAY=`cat $DIR_DEST_ETC/alcasar-network|grep GW|cut -d"=" -f2`
36
check=$(echo $PUBLIC_GATEWAY | egrep $PTN)
37
if [[ "$?" -ne 0 ]]
38
then 
39
	echo "Syntax error for the Gateway IP ($PUBLIC_GATEWAY)"
40
	exit 0
41
fi
42
DNS1=`cat $DIR_DEST_ETC/alcasar-network|grep DNS1|cut -d"=" -f2`
43
check=$(echo $PUBLIC_GATEWAY | egrep $PTN)
44
if [[ "$?" -ne 0 ]]
45
then 
46
	echo "Syntax error for the IP address of the first DNS server ($EXT_GATEWAY)"
47
	exit 0
48
fi
49
DNS2=`cat $DIR_DEST_ETC/alcasar-network|grep DNS2|cut -d"=" -f2`
50
check=$(echo $PUBLIC_GATEWAY | egrep $PTN)
51
if [[ "$?" -ne 0 ]]
52
then 
53
	echo "Syntax error for the IP address of the second DNS server ($EXT_GATEWAY)"
54
	exit 0
55
fi
56
	PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP_MASK | cut -d"=" -f2`	# @ réseau de consultation (ex.: 192.168.182.0)
57
	private_prefix=`/bin/ipcalc -p $PRIVATE_IP_MASK |cut -d"=" -f2`		# prefixe du réseau (ex. 24)
58
	PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$private_prefix			# @ + masque du réseau de consult (192.168.182.0/24)
59
	classe=$((private_prefix/8));						# classe de réseau (ex.: 2=classe B, 3=classe C)
60
	classe_sup=`expr $classe + 1`
61
	private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup`	# dernier octet de l'@ de réseau
62
	PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`.		# @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
63
	PRIVATE_MASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`		# masque réseau de consultation (ex.: 255.255.255.0)
64
	PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_IP_MASK | cut -d"=" -f2`	# @ broadcast réseau de consultation (ex.: 192.168.182.255)
65
	private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup`	# dernier octet de l'@ de broadcast
66
	PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`			# @ip du portail (côté réseau de consultation)
67
	PRIVATE_DYN_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 2`	# @ip du portail (côté réseau de consultation)
68
	PRIVATE_DYN_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1`	# @ip du portail (côté réseau de consultation)
69
 
70
# Change in ALCASAR-parameters
71
$SED "s?^- WAN IP.*?- WAN IP address ($EXTIF) :\t$PUBLIC_IP_MASK?g" $FIC_PARAM
72
$SED "s?^- Gateway.*?- Gateway IP addess :\t$PUBLIC_GATEWAY?g" $FIC_PARAM
73
$SED "s?^- DNS servers.*?- DNS servers :\t$DNS1 and $DNS2?g" $FIC_PARAM
74
$SED "s?^- LAN IP.*?- LAN IP address ($INTIF) :\t$PRIVATE_IP_MASK?g" $FIC_PARAM
75
$SED "s?^- Dynamic.*?- Dynamic IP addresses (DHCP) :\tfrom $PRIVATE_DYN_FIRST_IP to $PRIVATE_DYN_LAST_IP?g" $FIC_PARAM
76
# Change in ...