Line 1... |
Line 1... |
1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
# $Id: alcasar-conf.sh 860 2012-04-20 17:51:24Z richard $
|
2 |
# $Id: alcasar-conf.sh 861 2012-04-21 20:18:48Z richard $
|
3 |
|
3 |
|
4 |
# alcasar-conf.sh
|
4 |
# alcasar-conf.sh
|
5 |
# by Richard REY
|
5 |
# by Richard REY
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
7 |
|
7 |
|
Line 41... |
Line 41... |
41 |
classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`; classe_sup_sup=`expr $classe + 2` # classes de réseau (ex.: 2=classe B, 3=classe C)
|
41 |
classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`; classe_sup_sup=`expr $classe + 2` # classes de réseau (ex.: 2=classe B, 3=classe C)
|
42 |
PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`. # @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
|
42 |
PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`. # @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
|
43 |
PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2` # @ broadcast réseau de consultation (ex.: 192.168.182.255)
|
43 |
PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2` # @ broadcast réseau de consultation (ex.: 192.168.182.255)
|
44 |
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup` # dernier octet de l'@ de réseau
|
44 |
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup` # dernier octet de l'@ de réseau
|
45 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # dernier octet de l'@ de broadcast
|
45 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # dernier octet de l'@ de broadcast
|
46 |
PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1` # 1ère adresse de la plage dynamique (ex.: 192.168.182.129)
|
46 |
PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1` # 1ère adresse de la plage de consultation (ex.: 192.168.182.1)
|
- |
|
47 |
PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # dernière adresse de la plage de consultation (ex.: 192.168.182.254)
|
- |
|
48 |
tmp_mask=`echo $PRIVATE_NETWORK_MASK|cut -d"/" -f2`; half_mask=`expr $tmp_mask + 1` # masque du 1/2 réseau de consultation (ex.: 25)
|
- |
|
49 |
PRIVATE_STAT_IP=$PRIVATE_NETWORK/$half_mask # plage des adresses statiques (ex.: 192.168.182.0/25)
|
- |
|
50 |
private_plage=`expr $private_broadcast_ending - $private_network_ending + 1`
|
- |
|
51 |
private_half_plage=`expr $private_plage / 2`
|
- |
|
52 |
private_dyn=`expr $private_half_plage + $private_network_ending`
|
- |
|
53 |
private_dyn_ip_network=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`"."$private_dyn"."`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup_sup-5`
|
- |
|
54 |
PRIVATE_DYN_IP=`echo $private_dyn_ip_network | cut -d"." -f1-4`/$half_mask # @ réseau (CIDR) de la plage des adresses dynamiques (ex.: 192.168.182.128/25)
|
- |
|
55 |
private_dyn_ip_ending=`echo $private_dyn_ip_network | cut -d"." -f4`
|
- |
|
56 |
PRIVATE_DYN_FIRST_IP=`echo $private_dyn_ip_network | cut -d"." -f1-3`"."`expr $private_dyn_ip_ending + 1` # 1ère adresse de la plage dynamique (ex.: 192.168.182.129)
|
47 |
PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # dernière adresse de la plage dynamique (ex.: 192.168.182.254)
|
57 |
PRIVATE_DYN_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # dernière adresse de la plage dynamique (ex.: 192.168.182.254)
|
48 |
}
|
58 |
}
|
49 |
|
59 |
|
50 |
usage="Usage: alcasar-conf.sh --create | --load | --apply"
|
60 |
usage="Usage: alcasar-conf.sh --create | --load | --apply"
|
51 |
nb_args=$#
|
61 |
nb_args=$#
|
52 |
args=$1
|
62 |
args=$1
|
Line 144... |
Line 154... |
144 |
echo "GW=$PUBLIC_GATEWAY" >> $CONF_FILE
|
154 |
echo "GW=$PUBLIC_GATEWAY" >> $CONF_FILE
|
145 |
echo "DNS1=$DNS1" >> $CONF_FILE
|
155 |
echo "DNS1=$DNS1" >> $CONF_FILE
|
146 |
echo "DNS2=$DNS2" >> $CONF_FILE
|
156 |
echo "DNS2=$DNS2" >> $CONF_FILE
|
147 |
echo "PRIVATE_IP=$PRIVATE_IP/$PRIVATE_PREFIX" >> $CONF_FILE
|
157 |
echo "PRIVATE_IP=$PRIVATE_IP/$PRIVATE_PREFIX" >> $CONF_FILE
|
148 |
echo "DHCP=on" >> $CONF_FILE
|
158 |
echo "DHCP=on" >> $CONF_FILE
|
- |
|
159 |
|
149 |
if [ -r /var/run/sshd.pid ]; then
|
160 |
if [ -r /var/run/sshd.pid ]; then
|
150 |
echo "SSH=on" >> $CONF_FILE
|
161 |
echo "SSH=on" >> $CONF_FILE
|
151 |
else
|
162 |
else
|
152 |
echo "SSH=off" >> $CONF_FILE
|
163 |
echo "SSH=off" >> $CONF_FILE
|
153 |
fi
|
164 |
fi
|
Line 327... |
Line 338... |
327 |
do
|
338 |
do
|
328 |
$SED "/^server=/d" $i
|
339 |
$SED "/^server=/d" $i
|
329 |
echo "server=$DNS1" >> $i
|
340 |
echo "server=$DNS1" >> $i
|
330 |
echo "server=$DNS2" >> $i
|
341 |
echo "server=$DNS2" >> $i
|
331 |
done
|
342 |
done
|
332 |
$SED "s?^dhcp-range=.*?dhcp-range=$PRIVATE_FIRST_IP,$PRIVATE_LAST_IP,$PRIVATE_NETMASK,12h?g" /etc/dnsmasq.conf
|
343 |
$SED "s?^dhcp-range=.*?dhcp-range=$PRIVATE_DYN_FIRST_IP,$PRIVATE_DYN_LAST_IP,$PRIVATE_NETMASK,12h?g" /etc/dnsmasq.conf
|
333 |
$SED "s?^dhcp-option=option:router.*?dhcp-option=option:router,$PRIVATE_IP?g" /etc/dnsmasq.conf
|
344 |
$SED "s?^dhcp-option=option:router.*?dhcp-option=option:router,$PRIVATE_IP?g" /etc/dnsmasq.conf
|
334 |
# DG + BL
|
345 |
# DG + BL
|
335 |
$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/dansguardian/dansguardian.conf
|
346 |
$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/dansguardian/dansguardian.conf
|
336 |
# Watchdog
|
347 |
# Watchdog
|
337 |
$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
|
348 |
$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
|