#!/bin/bash
_BOXURL="http://fritz.box"
_USERNAME=""
_PASSWORD="GEHEIM"
_CHALLENGE=$(curl -s ${_BOXURL}/login.lua | grep "^g_challenge" | awk -F '"' '{ print $2 }')
_MD5=$(echo -n ${_CHALLENGE}"-"${_PASSWORD} | iconv -f ISO8859-1 -t UTF-16LE | md5sum -b | awk '{print substr($0,1,32)}')
_RESPONSE="${_CHALLENGE}-${_MD5}"
_SID=$(curl -i -s -k -d 'response='${_RESPONSE} -d 'page=' -d "username=${_USERNAME}" "${_BOXURL}/login.lua" | grep "Location:" | grep -Poi 'sid=[a-f\d]+' | cut -d '=' -f2)
# Box rebooten
echo 'Reboot in progress ... please allow up to 2 minutes for the box to come up!'
curl -s "${_BOXURL}/reboot.lua?sid=${_SID}&extern_reboot=1&ajax=1" >/dev/null