Le 13487ième jour après Epoch, David BERCOT écrivait:
> Bonjour, > >> Perso, j'utilise whereami et ifplugd, et ça marche, y compris sans >> redémarrer le PC. Je passe le mien en mode veille la plupart du temps, >> et quand il se réveille, il regarde où il est et exécute les choses >> qui vont bien selon où il se trouve. >> >> Si tu as besoin de plus d'infos, n'hésite pas à me demander. > > Alors j'y vais ;-) Zut, je m'en doutais ;) > Avant toute chose, j'aimerais bien comprendre la cinématique du > produit. En effet, dans le cas de guessnet, je voyais bien que le > fichier /etc/network/interfaces était appelé lors du montage du réseau > et, dans celui-ci, on faisait appel à guessnet pour détecter l'endroit > et, ensuite, appliquer une configuration réseau... C'est à la fois simple et complexe. L'usage que j'en fais ne touche pas à /etc/network/interfaces. En gros: - La seule interface en auto est loopback - Les autres interfaces sont en mode manual avec le moins de données possibles. Ensuite: - Le fichier detect.conf va contenir tous les moyens pour "savoir" où tu es, puis une fois l'endroit trouvé le fichier whereami.conf va contenir (sous la forme [+|-]location command) les choses à faire quand on arrive ou qu'on repart de location. ifplugd est configuré pour appeler whereami dès qu'il détecte la présence d'un réseau (fil ou wifi), ou pour se déclencher au démarrage/réveil de la machine. Le fichier detect.conf va être parcouru séquentiellement avec comme objectif de collecter un ou plusieurs états. Tu peux êtres dans plusieurs états simultanément, et ces états seront ensuite utilisé dans le fichier whereami.conf. Ci-joint un exemple de mon fichier detect.conf, plus ou moins débarassé des SSID importants ou des passphrases ;)
# The detection configuration file for 'whereami' # # This file describes unique features of various environments you connect # to and associates them with those locations. # When a test is successful, no further tests will be conducted # until a subsequent 'if' or 'fi' statement, or if the line is preceded # by the word 'always' # # You may also set environment variables for the scripts (test and action) # subsequently called by whereami using "set <varname> <value>". # # See "man 5 detect.conf" for lots more information, especially for the # details of the helper scripts used here. # # It is a good idea to default to somewhere... default undocked # Test for the presence of an ethernet connection plugged into eth0 testmii eth0 lan_scan testplug eth1 wlan_scan # Uncomment this for exhaustive debugging output # set DEBUGWHEREAMI 1 # 'down' might be a location that is forced from the command line # like "whereami down" if down testdhcp eth0,stop testdhcp eth1,stop always at undocked always notat eth0,eth1,lan,wlan,lan_scan,wlan_scan elif stop # Or maybe we can't remember the exact command, so we do it twice! # like "whereami stop" this time testdhcp eth0,stop testdhcp eth1,stop always at undocked always notat eth0,eth1,lan,wlan,lan_scan,wlan_scan elif lan_scan # If the testmii at the top was successful set INTERFACE eth0 # Ici, eventuellement on mets en place les tests sur des adresse # physiques connues sans DHCP testdhcp start lan at mlan always notat lan_scan elif wlan_scan set INTERFACE eth1 testap scan wlan at mwlan always notat wlan_scan else testdhcp eth0,stop testdhcp eth1,stop always at undocked always notat eth0,eth1,lan,wlan,lan_scan,wlan_scan fi # # En mode réseau câblé ... # if lan # Freebox Chez_Mes_Parents testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:3D,xxx.xxx.xxx.254 chez_mes_parents # Mon_Boulot (Freebox et L'autre liaison) testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:64,xxx.xxx.xxx.253 mon_boulot testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:A2,xxx.xxx.xxx.252 mon_boulot # Maison testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:73,xxx.xxx.xxx.11 home # Maison (2) testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:5A,xxx.xxx.xxx.42 home # Un client testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:C8,xxx.xxx.xxx.2 hsadsl # Boulot ma femme testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:70,xxx.xxx.xxx.1 hsadsl # un autre boulot testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:3E,xxx.xxx.xxx.3 hsadsl testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:60,xxx.xxx.xxx.253,xxx.xxx.xxx.220 hsadsl # Chez le père Rodolphe testarp2 eth0,xx:xx:xx:xx:xx:xx:xx:3B,xxx.xxx.xxx.254 hsadsl always notat lan fi # # En mode réseau câblé ... Sans DHCP :( # if mlan testping eth0,xxx.xxx.xxx.3,xxx.xxx.xxx.220 autre_boulot always notat mlan fi # # En mode réseau Wifi # if wlan # PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP # Chez_Mes_Parents: Tourde-WL5430 # PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP #Chez_Mes_Parents chez véronique # PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP testap Rabada-Wifi,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP hsadsl,wdhcp testap Tourde-WL5430,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP chez_mes_parents,wdhcp # Neuf Wifi gare d'aix # testap 'default' inconnu,wdhcp testap 'Neuf.*' inconnu,wdhcp # Hotel TOURAINE # testap Touraine,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP hsadsl,wdhcp testap Touraine,PPPP-PPPP-72 hsadsl,wdhcp testap MCDONALDS_TRIGNAC,"" mcdo,wdhcp # Mon_Boulot # testap GNULINE,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP mon_boulot,wdhcp # Wallander-local # testap Wallander-Wireless,s:walland-wifig wallander,wman # Inconnu (hotel perpignan) # testap vity,* inconnu,wdhcp testap maison,* inconnu,wdhcp # testap METEOR,* inconnu,wdhcp # Maison testap Tourde-WAP54G,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP home,wdhcp # Parents KPou testap Kpoucine,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP kpou,wdhcp # autre boulot testap SSID,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP autre_boulot,wdhcp # JeanPierre testap THOMSON,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP hsadsl,wdhcp # Jean-charles # testap NETGEAR,* jcms,wdhcp testap DW-B-200-1ba66,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP jcms,wdhcp # Wallix # testap linksys,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP wallix,wdhcp # M. & Mme MOORE # testap linksys,PPPP-PPPP-PPPP-PPPP-PPPP-PPPP-PP moore,wdhcp always notat wlan fi # # Et on relance dhcp pour être sûr # if wdhcp set INTERFACE eth1 testdhcp restart testdhcp 'xxx.xxx.xxx.26' home always notat wdhcp fi
Au passage, j'ai dû un peu hacker les fonctions de test de whereami, ou en rajouter 2 ou 3... J'ai honte de pas avoir transmis tout ça à l'auteur, mais ça viendra un de ces 4. Je m'en suis vu pas mal à mettre au point ce genre de choses, mais une fois en place, c'est un vrai bonheur. Il ne me reste plus qu'à lancer automatiquement airsnort quand aucun des AP dispo n'est connu de moi. Mais c'est une autre histoire. Pour ce qui est du fichier whereami.conf, voilà 2/3 exemples: ----8<------8<------8<------8<------8<------8<------8<-- # Il arrive que ça chie un peu... +undocked /etc/init.d/fetchmail stop # # High Speed ADSL # +hsadsl /usr/sbin/exim4 -qf +hsadsl /etc/init.d/ntpdate force-reload +hsadsl /etc/init.d/fetchmail restart -hsadsl /etc/init.d/fetchmail stop # # A la maison, on peut tout faire +home /etc/init.d/ntpdate force-reload +home /usr/sbin/exim4 -qf +home /etc/init.d/fetchmail restart -home /etc/init.d/fetchmail stop +home /usr/bin/rsync -lavuz --delete /home/share/Photos/ cantor.tourde.org:/home/share/Photos/ +home /usr/bin/rsync -lavuz --delete /home/share/Musique/ cantor.tourde.org:/home/share/Musique/ +home /usr/bin/rsync -lavuz --delete /home/francois/html/ cantor.tourde.org:/home/francois/html/ +home /usr/bin/rsync -lavuz --delete /home/cvs/ cantor.tourde.org:/home/cvs/ +home /usr/bin/rsync -lavuz --delete cantor.tourde.org:/home/share/etc.tgz* /home/share #+home mount /mnt/Echanges #+home mount /mnt/Music #+home mount /mnt/Tmp #-home umount /mnt/Echanges #-home umount /mnt/Music #-home umount /mnt/Tmp ----8<------8<------8<------8<------8<------8<------8<-- A toi de jouer, maintenant ;)