
il sera dans le PATH le jour de l'install party : usage : configure_borne --macs => dite le fichier de macs configure_borne --firewall => relance le firewall configure_borne --services => relance les services (aprs un reboot) darcs-hash:20041111044201-4ec08-ed6a23529023dc67dd07373bbe4eed9479b565cf.gz
122 lines
3 KiB
Bash
Executable file
122 lines
3 KiB
Bash
Executable file
#! /bin/sh
|
|
|
|
###################################
|
|
## Reconfigure une borne wifi ##
|
|
## du CR@NS en temps que routeur ##
|
|
###################################
|
|
|
|
BORNE="install-party.crans.org"
|
|
DIR="/home/chove/bornes"
|
|
MACS="$DIR/MACS-$BORNE"
|
|
|
|
#########################################################################
|
|
|
|
CLEF="/usr/scripts/gestion/clef-wifi"
|
|
SSH="ssh -i $CLEF -o StrictHostKeyChecking=no $BORNE"
|
|
SCP="scp -i $CLEF -o StrictHostKeyChecking=no"
|
|
|
|
usage () {
|
|
echo "Usage : "
|
|
echo " $0 --services <borne>"
|
|
echo " $0 --firewall <borne>"
|
|
}
|
|
|
|
error=1
|
|
|
|
#########################################################################
|
|
|
|
# Reconfiguration des services
|
|
|
|
if [[ "$1" == "--services" ]]
|
|
then
|
|
# génération du script
|
|
echo "Création du script de reconfiguration"
|
|
cat > $DIR/boot.sh <<EOF
|
|
# résolution de noms
|
|
echo "search crans.org" > /tmp/resolv.conf
|
|
echo "nameserver 138.231.136.6" >> /tmp/resolv.conf
|
|
echo "nameserver 138.231.136.10" >> /tmp/resolv.conf
|
|
|
|
# alias pour le dns
|
|
echo "127.0.0.1 localhost" > /etc/hosts
|
|
echo "138.231.136.9 debian.ens-cachan.fr" >> /etc/hosts
|
|
echo "138.231.136.9 ftp.crihan.fr" >> /etc/hosts
|
|
|
|
# dns
|
|
killall dnsmasq 2> /dev/null
|
|
/usr/sbin/dnsmasq
|
|
|
|
# dhcp
|
|
echo "start 192.168.0.10" > /tmp/udhcpd.
|
|
echo "end 192.168.0.254" >> /tmp/udhcpd.conf
|
|
echo "interface vlan1" >> /tmp/udhcpd.conf
|
|
killall udhcpd 2> /dev/null
|
|
/usr/sbin/udhcpd /tmp/udhcpd.conf
|
|
|
|
EOF
|
|
|
|
# envoi du fichier et execution
|
|
chmod 744 $DIR/boot.sh
|
|
echo "Envoi du script"
|
|
$SCP $DIR/boot.sh $BORNE:/tmp/boot.sh > /dev/null
|
|
|
|
# execution du script
|
|
echo "Execution du script"
|
|
$SSH /tmp/boot.sh
|
|
|
|
# destruction du fichier
|
|
rm -f $DIR/boot.sh
|
|
|
|
error=0
|
|
fi
|
|
|
|
#########################################################################
|
|
|
|
# Reconfiguration du firewall
|
|
|
|
if [[ "$1" == "--firewall" ]]
|
|
then
|
|
# génération du firewall
|
|
echo "Génération du firewall"
|
|
cat > $DIR/firewall.sh <<EOF
|
|
iptables -F
|
|
iptables -X
|
|
iptables -F -t nat
|
|
iptables -X -t nat
|
|
iptables -P FORWARD ACCEPT
|
|
iptables -t nat -P PREROUTING DROP
|
|
iptables -t nat -A PREROUTING -i vlan0 -j ACCEPT
|
|
iptables -t nat -A PREROUTING -i vlan1 -s ! 138.231.136.10 -p tcp --dport 80 -j DNAT --to 138.231.136.10:3128
|
|
EOF
|
|
|
|
cat $MACS | sed 's/ //g' | grep -v '#' | grep -v '^$' | while true
|
|
do
|
|
read mac
|
|
if [ "$mac" = "" ] ; then break ; fi
|
|
echo "iptables -t nat -A PREROUTING -i vlan1 -m mac --mac-source $mac -j ACCEPT" >> $DIR/firewall.sh
|
|
done
|
|
|
|
echo "iptables -A POSTROUTING -t nat -o vlan0 -j MASQUERADE" >> $DIR/firewall.sh
|
|
|
|
# envoi du fichier et execution
|
|
chmod 744 $DIR/firewall.sh
|
|
echo "Envoi du firewall"
|
|
$SCP $DIR/firewall.sh $BORNE:/tmp/firewall.sh > /dev/null
|
|
|
|
# execution du script
|
|
echo "Lancement du firewall"
|
|
$SSH /tmp/firewall.sh
|
|
|
|
# destruction du fichier
|
|
rm -f $DIR/firewall.sh
|
|
|
|
error=0
|
|
fi
|
|
|
|
#########################################################################
|
|
|
|
if [ "$error" = "1" ]
|
|
then
|
|
usage
|
|
exit 2
|
|
fi
|