Files
ddns/easyBox_getIp.sh
2020-05-04 17:34:27 +02:00

128 lines
5.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Reconnect for 'EasyBox 804'
# Firmware version: CIS804-01.02
# Enter your 'EasyBox-Kennwort' here:
PASSWORD_EASYBOX804=""
# Enter hostname/adress of your EasyBox 804:
HOST="easy.box.local"
# If you can't reach the Box via http://easy.box.local use it's IP instad:
HOST="192.168.0.2"
# Notes:
# The reconnect duration of the EasyBox 804 is quite long, it can be up to 180 seconds.
# * * * NO MORE CHANGES DOWN HERE * * *
read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
if [ "1" == "1" ]; then # Step 1: before sending the password
curl -s "http://${HOST}/main.cgi?page=login.html" -c step1_cookie.txt \
-o step1_answer.html
COOKIE_STEP1=$(cat step1_cookie.txt | grep "wbm_cookie_session_id" | awk -F"\t" '{ print $7 }')
echo "COOKIE_STEP1 = "${COOKIE_STEP1}
# 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_special.txt
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.
# If no cookies are sent, a 'new auth_key' is generated, not matching the cookies stored by this bash script.
curl -s "http://${HOST}/main.cgi?js=rg_config.js" -b step1_cookie.txt \
-o step1_rg_config.js
AUTH_KEY=$(cat step1_rg_config.js | grep "auth_key" | awk -F"auth_key = '" '{ print $2 }' | awk -F"'" '{ print $1 }')
echo "AUTH_KEY = "${AUTH_KEY}
# The sent md5-encrypted password consists of your 'Easybox-Kennwort' ...
# ... and the 'auth_key' from http://easy.box.local/main.cgi?js=rg_config.js !
# The original Javascript-function is defined here: http://easy.box.local/main.cgi?js=wbm_be.js
PASSWORD_MD5=$(echo -n ${PASSWORD_EASYBOX804}${AUTH_KEY} | md5sum | awk '{ print $1 }')
echo "PASSWORD_MD5 = "${PASSWORD_MD5}
echo -e "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header><DMCookie>${DM_COOKIE_STEP3_STEP1}</DMCookie></soapenv:Header><soapenv:Body><cwmp:Login xmlns=\"\"><ParameterList><Username>vodafone</Username><Password>${PASSWORD_MD5}</Password><AllowRelogin>0</AllowRelogin></ParameterList></cwmp:Login></soapenv:Body></soapenv:Envelope>" > step1_soap_data.xml
# Now logging in (sending the password):
# The DOUBLE APOSTROPHE in >> -H "Cookie: wbm[...]=${...}" << is crucial!
curl -s "http://${HOST}/data_model.cgi" --cookie step1_cookie_special.txt --cookie-jar step2_cookies.txt -X POST -H 'Accept: application/xml, text/xml, */*; q=0.01' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' -H 'Content-Length: 387' -H 'Content-Type: text/xml; charset="utf-8"' -H "Cookie: wbm_cookie_session_id=${COOKIE_STEP1}" -H "Host: ${HOST}" -H 'Method: POST' -H 'Pragma: no-cache' -H 'Referer: http://${HOST}/main.cgi?page=login.html' -H 'SOAPAction: cwmp:Login' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36' -H 'X-Requested-With: XMLHttpRequest' \
--data @step1_soap_data.xml \
-o "step2_answer.html"
#cat step2_answer.html
fi
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 }')
echo "COOKIE_STEP3 = "${COOKIE_STEP3}
curl -s "http://${HOST}/main.cgi?page=app.html" -b step2_cookies.txt \
-o "step3_answer.html"
DM_COOKIE_STEP3=$(cat step3_answer.html | grep dm_cookie | awk -F"dm_cookie='" '{ print $2 }' | awk -F"'" '{ print $1 }')
echo "DM_COOKIE_STEP3 = "$DM_COOKIE_STEP3
# firefox step3_answer.html
fi
if [ "1" == "1" ]; then # Step 4: Accessing the WAN IP (for testing the successful login without the timeconsuming reconnect)
# Only for testing purposes NOT NECESSARY FOR RECONNECT !
# (Output of WAN iP)
echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header><DMCookie>${DM_COOKIE_STEP3}</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>" > step4_soap_data.xml
# The DOUBLE APOSTROPHE in >> -H "Cookie: [...]" << is very important!
curl -s \
"http://${HOST}/data_model.cgi" \
-b step2_cookies.txt \
-X POST \
-H 'Accept: application/xml, text/xml, */*; q=0.01' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 452' \
-H 'Content-Type: text/xml; charset="utf-8"' \
-H "Cookie: wbm_cookie_session_id=${COOKIE_STEP3}" \
-H "Host: ${HOST}" \
-H 'Method: POST' \
-H 'Pragma: no-cache' \
-H "Referer: http://${HOST}/main.cgi?page=app.html" \
-H 'SOAPAction: cwmp:GetParameterValues' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36' \
-H 'X-Requested-With: XMLHttpRequest' \
--data @step4_soap_data.xml \
-o "step4_answer.html"
while read_dom; do
#echo "$ENTITY => $CONTENT"
if [[ $ENTITY = "Value xsi:type=\"xsd:string\"" ]] ; then
echo $CONTENT
fi
done < step4_answer.html
# firefox step4_answer.html
fi
exit 0;