started rewrite and cleanup + implemented retrieval of WAN IP without login
This commit is contained in:
@@ -14,29 +14,58 @@ HOST="192.168.0.2"
|
|||||||
# The reconnect duration of the EasyBox 804 is quite long, it can be up to 180 seconds.
|
# The reconnect duration of the EasyBox 804 is quite long, it can be up to 180 seconds.
|
||||||
|
|
||||||
|
|
||||||
|
# fake user agent
|
||||||
|
UA="Mozilla/5.0" # FIXME spaces won't work because of bash parameter handling
|
||||||
|
COOKIEFILE="/tmp/easyBoxCookies.txt"
|
||||||
|
|
||||||
|
|
||||||
|
WGET_OPTS=(
|
||||||
|
"--quiet"
|
||||||
|
"--load-cookies $COOKIEFILE"
|
||||||
|
"--save-cookies $COOKIEFILE"
|
||||||
|
"--keep-session-cookies"
|
||||||
|
"--user-agent=\"${UA}\""
|
||||||
|
"-O -"
|
||||||
|
)
|
||||||
|
WGET="/usr/bin/wget ${WGET_OPTS[@]}"
|
||||||
|
|
||||||
# * * * NO MORE CHANGES DOWN HERE * * *
|
# * * * NO MORE CHANGES DOWN HERE * * *
|
||||||
|
|
||||||
read_dom () {
|
RETVAL=""
|
||||||
local IFS=\>
|
touch $COOKIEFILE
|
||||||
read -d \< ENTITY CONTENT
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "1" == "1" ]; then # Step 1: before sending the password
|
echo "request: http://${HOST}/main.cgi?page=login.html" 1>&2
|
||||||
curl -s "http://${HOST}/main.cgi?page=login.html" -c step1_cookie.txt \
|
OUT=$($WGET "http://${HOST}/main.cgi?page=login.html" )
|
||||||
-o step1_answer.html
|
|
||||||
|
|
||||||
COOKIE_STEP1=$(cat step1_cookie.txt | grep "wbm_cookie_session_id" | awk -F"\t" '{ print $7 }')
|
DM_COOKIE=$(echo $OUT | grep dm_cookie | awk -F"dm_cookie='" '{ print $2 }' | awk -F"'" '{ print $1 }')
|
||||||
echo "COOKIE_STEP1 = "${COOKIE_STEP1}
|
echo "DM_COOKIE = "${DM_COOKIE} 1>&2
|
||||||
|
|
||||||
|
WBM_COOKIE=$(cat $COOKIEFILE | grep "wbm_cookie_session_id" | awk -F"\t" '{ print $7 }')
|
||||||
|
echo "WBM_COOKIE = "${WBM_COOKIE} 1>&2
|
||||||
|
|
||||||
# Create a 'special' cookie file without HOST and PATH (important):
|
# Create a 'special' cookie file without HOST and PATH (important):
|
||||||
cat step1_cookie.txt | sed "s/${HOST}//g" | sed 's/\t\/\t/\t\t/g' > step1_cookie_special.txt
|
# cat step1_cookie.txt | sed "s/${HOST}//g" | sed 's/\t\/\t/\t\t/g' > step1_cookie_special.txt
|
||||||
#cat step1_cookie_special.txt
|
#cat step1_cookie_special.txt
|
||||||
|
|
||||||
|
# get WAN IP without login
|
||||||
|
if [[ "$1" == "wan" && "$2" == "ip" ]]; then
|
||||||
|
echo "request: http://${HOST}/data_model.cgi" 1>&2
|
||||||
|
POST_DATA="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header><DMCookie>${DM_COOKIE}</DMCookie><SessionNotRefresh>1</SessionNotRefresh></soapenv:Header><soapenv:Body><cwmp:GetParameterValues xmlns=\"\"><ParameterNames><string>InternetGatewayDevice.WANDevice.6.WANConnectionDevice.4.WANPPPConnection.1.ExternalIPAddress</string></ParameterNames></cwmp:GetParameterValues></soapenv:Body></soapenv:Envelope>"
|
||||||
|
|
||||||
|
OUT=$($WGET \
|
||||||
|
--post-data="${POST_DATA}" \
|
||||||
|
"http://${HOST}/data_model.cgi")
|
||||||
|
|
||||||
|
RETVAL=$(echo "$OUT" | xmllint --xpath "//Value/text()" -)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$RETVAL"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DM_COOKIE_STEP3_STEP1=$(cat step1_answer.html | grep dm_cookie | awk -F"dm_cookie='" '{ print $2 }' | awk -F"'" '{ print $1 }')
|
|
||||||
echo "DM_COOKIE_STEP3_STEP1 = "${DM_COOKIE_STEP3_STEP1}
|
|
||||||
|
|
||||||
# Sending cookies at this step is very important.
|
# Sending cookies at this step is very important.
|
||||||
# If no cookies are sent, a 'new auth_key' is generated, not matching the cookies stored by this bash script.
|
# If no cookies are sent, a 'new auth_key' is generated, not matching the cookies stored by this bash script.
|
||||||
@@ -64,11 +93,6 @@ if [ "1" == "1" ]; then # Step 1: before sending the password
|
|||||||
|
|
||||||
#cat step2_answer.html
|
#cat step2_answer.html
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if [ "1" == "1" ]; then # Step 3: After sending the password
|
if [ "1" == "1" ]; then # Step 3: After sending the password
|
||||||
COOKIE_STEP3=$(cat step2_cookies.txt | grep "wbm_cookie_session_id" | awk -F"\t" '{ print $7 }')
|
COOKIE_STEP3=$(cat step2_cookies.txt | grep "wbm_cookie_session_id" | awk -F"\t" '{ print $7 }')
|
||||||
echo "COOKIE_STEP3 = "${COOKIE_STEP3}
|
echo "COOKIE_STEP3 = "${COOKIE_STEP3}
|
||||||
|
|||||||
Reference in New Issue
Block a user