#!/bin/sh
#
# The FRITZ!Box Fon WLAN 7170 does not have any kind of SNMP to do monitoring
# on It DOES have some json/xml like response URI which can be used to gather
# traffic statistics of the box. If somebody knows how to use SNMP with the box
# please let me know, cause this is a very nasty hack.
#
# WARNING: This currently does not work when password is enabled, as the
# javascript password hashing has not be implemented 
#
# TODO Convert me to pyhon one day and provide usable output for nagios.
# 
# Rick van der Zwet <info@rickvanderzwet.nl>

HOST=${1:-192.168.178.1}
SID=`fetch -q -o - "http://${HOST}/cgi-bin/webcm?getpage=../html/" |  awk -F\" '/sid/ {print $6}'`

while true; do
  fetch -q -o - "http://${HOST}/cgi-bin/webcm?getpage=../html/de/internet/overviewdaten.xml&sid=${SID}"
  fetch -q -o - "http://${HOST}/cgi-bin/webcm?getpage=../html/de/home/../home/home_dsl.txt&sid=${SID}"
  fetch -q -o - "http://${HOST}/cgi-bin/webcm?getpage=../html/de/home/../home/home_coninf.txt&sid=${SID}"
  fetch -q -o - "http://${HOST}/cgi-bin/webcm?getpage=../html/de/internet/qos.txt&sid=${SID}"
  sleep 1
done
