Forum Programmation.shell Contrôle de la Freebox V6 par le shell : wifi, reboot ...

Posté par .
Étiquettes :
13
24
oct.
2012

Bonjour,

Ce sujet fait suite au premier sujet que j'avais initialement créé pour contrôler le wifi de la freebox v6.
Vous en retrouverez le fil ici : http://linuxfr.org/forums/programmationshell/posts/activerd%C3%A9sactiver-le-wifi-dune-freebox-v6-depuis-le-r%C3%A9seau-local

J'y ajoute maintenant la possibilité de faire rebooter la freebox à distance.

Pour l'occasion, le script change de nom (fbxCtrl.sh) et la syntaxe des paramètres change légèrement.

Une petite entrée dans la crontab, dans la nuit des mardi/mercredi par exemple, puisque Free délivre ses firmwares le mardi souvent, et hop le tour est joué.

Exemple de crontab :
Reboot tous les mercredi à 2h05 du matin.

05 2 * * Wed /chemin/script/fbxCtrl.sh fbxReboot

Le script fbxCtrl.sh :

#!/bin/bash
fbxLogin='freebox'
fbxPasswd='monMotDePasse'
fbxCookieFile="/tmp/fbxCookie.txt"
fbxLogin() {
 curl --cookie-jar $fbxCookieFile -s -o /dev/null -L "http://mafreebox.freebox.fr/login.php?login=$fbxLogin&passwd=$fbxPasswd"
 if [ $? -ne 0 ]; then
echo "Login to Freebox failed!"
 exit 0
 fi
}
fbxLogout() {
 curl -b $fbxCookieFile -s -o /dev/null -L 'http://mafreebox.freebox.fr/login.php?logout=1'
 rm -f $fbxCookieFile
 if [ $? -ne 0 ]; then
echo "Logout of Freebox failed!"
 fi
}
wifiOn() {
 fbxLogin
 curl -b $fbxCookieFile -s -o /dev/null -d 'enabled=on&channel=9&ht_mode=20&method=wifi.ap_params_set&config=Valider' -H "X-Requested-With: XMLHttpRequest" -L 'http://mafreebox.freebox.fr/wifi.cgi'
 if [ $? -ne 0 ]; then
echo "Setting Freebox wifi ON failed!"
 fi
fbxLogout
}
wifiOff() {
 fbxLogin
 curl -b $fbxCookieFile -s -o /dev/null -d 'channel=9&ht_mode=20&method=wifi.ap_params_set&config=Valider' -H "X-Requested-With: XMLHttpRequest" -L 'http://mafreebox.freebox.fr/wifi.cgi'
 if [ $? -ne 0 ]; then
echo "Setting Freebox wifi OFF failed!"
 fi
fbxLogout
}
wifiStatus() {
 fbxLogin
 checked=$(curl -b $fbxCookieFile -s -L 'http://mafreebox.freebox.fr/settings.php?page=wifi_conf' | grep '<input type="checkbox" name="enabled" checked />')
 rc=0
 if [ "$checked" != "" ]; then
echo "Freebox Wifi is ON"
 rc=1
 else
echo "Freebox Wifi is OFF"
 fi
fbxLogout
 exit $rc
}
fbxReboot() {
 fbxLogin
 curl -b $fbxCookieFile -s -o /dev/null -d 'method=system.reboot&timeout=1&reboot=Red%C3%A9marrer+la+freebox' -H "X-Requested-With: XMLHttpRequest" -L 'http://mafreebox.freebox.fr/system.cgi' 2>/dev/null
 if [ $? -ne 0 ]; then
echo "Request to reboot the Freebox has failed!"
 fi
}
case "1ドル" in
 wifiOn)
 wifiOn
 exit 1
 ;;
 wifiOff)
 wifiOff
 exit 0
 ;;
 wifiStatus)
 wifiStatus
 exit $?
 ;;
 fbxReboot)
 fbxReboot
 exit $?
 ;;
 *)
 echo "Usage: 0ドル {wifiOn|wifiOff|wifiStatus|fbxReboot}"
 exit 0
esac
exit 0

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.