a simple wrapper for wget to enable/disable PoE on all ports of DGS-1210-10P

#!/bin/bash
################################################################################
#
# Enable/disable PoE on all ports of DGS-1210-10P
#
# USAGE:
#   poe.sh host password [cmd]
#
# EXAMPLE:
#   ./poe.sh 10.1.1.99 SuperSecure! on
#
# if [cmd] is ommitted PoE is disabled for all ports
#
# NOTES
# - This is probably adaptable for the other PoE variants from the DGS-1210
#   series (see parameter port_f)
# - Instead of all or nothing uproach one could
#   toggle specific ports or port ranges (see parameter port_h & port_f)
#
# Author:
#   Tobias Sachs diespambox@gmx.net
#
################################################################################

host=$1
pw=$2
cmd=$3

token=$(
    wget -q -O - \
    --post-data 'Login=admin&Password='$pw'&BrowsingPage=index_dlink.htm' \
    http://$host/homepage.htm \
    | grep "Gambit=.*\" " \
    | sed 's/.*\(Gambit=.*\)" .*/\1/'
    )

post_data=$token;
post_data=$token'&FormName=portset&port_f=00&port_t=07&TimeRangeID=0&Priority=2&PDDetect=2&post_url=cgi_port.'

if [ "${cmd}x" == "onx" ]; then
    post_data=$post_data'PoE_Enable=1&PowerLimit=1'
else
    post_data=$post_data'&PoE_Enable=0'
fi

wget -q -O -  \
     --load-cookie=cookie.txt \
    --post-data $post_data \
    http://$host/iss/specific/PoEPortSetting.js &> /dev/null