136 lines
3.3 KiB
Bash
Executable file
136 lines
3.3 KiB
Bash
Executable file
#! /bin/sh
|
|
|
|
###################################
|
|
## Reconfigure une borne wifi ##
|
|
## du CR@NS en temps que routeur ##
|
|
###################################
|
|
|
|
# Ce scipt est à utiliser une fois que les interfaces de la bornes
|
|
# sont configurées
|
|
|
|
BORNE="install-party.crans.org"
|
|
DIR="/usr/scripts/install-party"
|
|
MACS="$DIR/MACS-install-party"
|
|
|
|
#########################################################################
|
|
|
|
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 --macs <borne> Modifie les MACS authorisées"
|
|
echo " $0 --services <borne> Relance les services"
|
|
echo " $0 --firewall <borne> Relance le firewall"
|
|
}
|
|
|
|
error=1
|
|
|
|
#########################################################################
|
|
|
|
# Edition du fichier de MACS
|
|
|
|
if [[ "$1" == "--macs" ]]
|
|
then
|
|
/usr/bin/jed $MACS
|
|
error=0
|
|
fi
|
|
|
|
#########################################################################
|
|
|
|
# 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
|