1 |
root |
1 |
#/bin/sh
|
|
|
2 |
# by rexy
|
|
|
3 |
# Ce script permet de déconnecter les usagers dont
|
|
|
4 |
# - les équipementis réseau ne répondent plus
|
|
|
5 |
# - les adresses MAC sont usurpées
|
|
|
6 |
# The aim of this script is to disconnect users whose
|
|
|
7 |
# - PCs are quiet
|
|
|
8 |
# - MAC address are in used by other systems (usurped)
|
|
|
9 |
|
|
|
10 |
INTIF="eth1"
|
|
|
11 |
PRIVATE_IP="192.168.182.1"
|
|
|
12 |
tmp_file="/tmp/watchdog.txt"
|
|
|
13 |
IFS=$'\n'
|
|
|
14 |
# lecture du fichier contenant les adresses IP des stations muettes
|
|
|
15 |
if [ -e $tmp_file ]; then
|
|
|
16 |
cat $tmp_file | while read noresponse
|
|
|
17 |
do
|
|
|
18 |
noresponse_ip=`echo $noresponse | cut -d" " -f1`
|
|
|
19 |
noresponse_mac=`echo $noresponse | cut -d" " -f2`
|
|
|
20 |
arp_reply=`/usr/sbin/arping -b -I$INTIF -s$PRIVATE_IP -c1 $noresponse_ip|grep response|cut -d" " -f2`
|
|
|
21 |
if [[ $(expr $arp_reply) -eq 0 ]]
|
|
|
22 |
then
|
18 |
franck |
23 |
logger "alcasar-watchdog $noresponse_ip ($noresponse_mac) reste muette. On déconnecte."
|
1 |
root |
24 |
/usr/sbin/chilli_query logout $noresponse_mac
|
|
|
25 |
fi
|
|
|
26 |
done
|
|
|
27 |
rm $tmp_file
|
|
|
28 |
fi
|
|
|
29 |
# on traite chaque équipements connus de chilli
|
|
|
30 |
for system in `/usr/sbin/chilli_query list`
|
|
|
31 |
do
|
|
|
32 |
active_ip=`echo $system |cut -d" " -f2`
|
|
|
33 |
active_session=`echo $system |cut -d" " -f5`
|
|
|
34 |
active_mac=`echo $system | cut -d" " -f1`
|
|
|
35 |
# on ne traite que les équipements exploitées par un usager authentifié
|
|
|
36 |
if [[ $(expr $active_session) -eq 1 ]]
|
|
|
37 |
then
|
|
|
38 |
arp_reply=`/usr/sbin/arping -b -I$INTIF -s$PRIVATE_IP -c2 $active_ip|grep response|cut -d" " -f2`
|
|
|
39 |
# on stocke les adresses IP des stations muettes
|
|
|
40 |
if [[ $(expr $arp_reply) -eq 0 ]]
|
|
|
41 |
then
|
|
|
42 |
echo "$active_ip $active_mac" >> $tmp_file
|
|
|
43 |
fi
|
|
|
44 |
# on deconnecte l'usager d'une stations usurpée (@MAC)
|
|
|
45 |
if [[ $(expr $arp_reply) -gt 2 ]]
|
|
|
46 |
then
|
18 |
franck |
47 |
logger "alcasar-watchdog : $active_ip est usurpée ($active_mac). On déconnecte."
|
1 |
root |
48 |
/usr/sbin/chilli_query logout $active_mac
|
|
|
49 |
fi
|
|
|
50 |
fi
|
|
|
51 |
done
|