liveboxGetInfo 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. ###########################################
  3. # Firmware Livebox 4 = 3.4.10 g0-f-sip-fr #
  4. # Script mis a jour le 06/04/2018 #
  5. ###########################################
  6. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/puppetlabs/bin"
  7. #############################
  8. # Declaration des variables #
  9. #############################
  10. myLivebox=192.168.1.1
  11. myPassword=$(cat /etc/.livebox)
  12. myBashDir=/var/lib/livebox
  13. mkdir -p $myBashDir
  14. myOutput=$myBashDir/myOutput.txt
  15. myCookies=$myBashDir/myCookies.txt
  16. ########################################
  17. # Connexion et recuperation du cookies #
  18. ########################################
  19. curl -s -o "$myOutput" -X POST -c "$myCookies" -H 'Content-Type: application/x-sah-ws-4-call+json' -H 'Authorization: X-Sah-Login' -d "{\"service\":\"sah.Device.Information\",\"method\":\"createContext\",\"parameters\":{\"applicationName\":\"so_sdkut\",\"username\":\"admin\",\"password\":\"$myPassword\"}}" http://$myLivebox/ws > /dev/null
  20. ##################################################
  21. # Lecture du cookies pour utilisation ulterieure #
  22. ##################################################
  23. myContextID=$(tail -n1 "$myOutput" | sed 's/{"status":0,"data":{"contextID":"//1'| sed 's/",//1' | sed 's/"groups":"http,admin//1' | sed 's/"}}//1')
  24. ###############################################################################################
  25. # Envoi des commandes pour recuperer les informtations et ecriture dans un fichier TXT separe #
  26. ###############################################################################################
  27. getDSLStats=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NeMo.Intf.dsl0\",\"method\":\"getDSLStats\",\"parameters\":{}}" http://$myLivebox/ws`
  28. getMIBs=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NeMo.Intf.data\",\"method\":\"getMIBs\",\"parameters\":{}}" http://$myLivebox/ws`
  29. getLan=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NeMo.Intf.lan\",\"method\":\"getMIBs\",\"parameters\":{}}" http://$myLivebox/ws`
  30. getWan=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NMC\",\"method\":\"getWANStatus\",\"parameters\":{}}" http://$myLivebox/ws`
  31. getPhone=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"VoiceService.VoiceApplication\",\"method\":\"listTrunks\",\"parameters\":{}}" http://$myLivebox/ws`
  32. getTV=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NMC.OrangeTV\",\"method\":\"getIPTVStatus\",\"parameters\":{}}" http://$myLivebox/ws`
  33. echo $getDSLStats > $myBashDir/DSLStats.json
  34. echo $getMIBs > $myBashDir/MIBs.json
  35. echo $getLan > $myBashDir/LAN.json
  36. echo $getWan > $myBashDir/WAN.json
  37. echo $getPhone > $myBashDir/Phone.json
  38. echo $getTV > $myBashDir/TV.json
  39. #######################################################
  40. # Deconnexion et suppression des fichiers temporaires #
  41. #######################################################
  42. curl -s -b "$myCookies" -X POST http://$myLivebox/logout &> /dev/null
  43. rm "$myCookies" "$myOutput"
  44. exit 0