diff --git a/easyBox_getIp.sh b/easyBox_getIp.sh new file mode 100755 index 0000000..e697591 --- /dev/null +++ b/easyBox_getIp.sh @@ -0,0 +1,127 @@ +#!/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 "${DM_COOKIE_STEP3_STEP1}vodafone${PASSWORD_MD5}0" > 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 "${DM_COOKIE_STEP3}1InternetGatewayDevice.WANDevice.6.WANConnectionDevice.4.WANPPPConnection.1.ExternalIPAddress" > 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; diff --git a/easyBox_restart.sh b/easyBox_restart.sh new file mode 100644 index 0000000..5644d33 --- /dev/null +++ b/easyBox_restart.sh @@ -0,0 +1,160 @@ +#!/bin/bash +# Reconnect for 'EasyBox 804' +# Firmware version: CIS804-01.02 + +# Enter your 'EasyBox-Kennwort' here: +PASSWORD_EASYBOX804="t0p_,_s3CREt" + +# 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.2.1" + +# Notes: +# The reconnect duration of the EasyBox 804 is quite long, it can be up to 180 seconds. + +# * * * NO MORE CHANGES DOWN HERE * * * + +if [ "1" == "1" ]; then # Step 1: before sending the password + curl "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 "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 "${DM_COOKIE_STEP3_STEP1}vodafone${PASSWORD_MD5}0" > step1_soap_data.xml + + + rm -v step2_answer.html + rm -v step2_cookies.txt + # Now logging in (sending the password): + # The DOUBLE APOSTROPHE in >> -H "Cookie: wbm[...]=${...}" << is crucial! + curl "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} + + rm -v step3_answer.html + curl "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 [ "0" == "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 "${DM_COOKIE_STEP3}1InternetGatewayDevice.WANDevice.3.WANConnectionDevice.1.WANPPPConnection.1.ExternalIPAddress" > step4_soap_data.xml + + rm step4_answer.html + # The DOUBLE APOSTROPHE in >> -H "Cookie: [...]" << is very important! + curl "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" + + # firefox step4_answer.html +fi + +MONITOR_IP=1 +if [ "$MONITOR_IP" == "1" ]; then # Montior IP Change & reconnect duration + wget http://mxtoolbox.com/WhatIsMyIP/ -q --tries=1 --timeout=2 -O ip.html + IP_0=$( cat ip.html | grep "ctl00_ContentPlaceHolder1_hlIP" | awk -F">" '{ print $2 }' | awk -F"<" '{ print $1 }' ); + rm ip.html + DATUM0=$(date +%s); +fi + +if [ "1" == "1" ]; then # Step 5: Reconnect + + echo -e "${DM_COOKIE_STEP3}InternetGatewayDevice.WANDevice.6.X_JUNGO_COM_Reconnect1" > step5_soap_data.xml + + + rm -v step5_answer.html + # The DOUBLE APOSTROPHE in >> -H "Cookie: [...]" << is very important! + curl "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: 430' -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:SetParameterValues' -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 @step5_soap_data.xml \ + -o "step5_answer.html" + + #firefox step5_answer.html +fi + +if [ "$MONITOR_IP" == "1" ]; then # Montior IP Change & reconnect duration + echo "IP before Reconnect = $IP_0" + + for (( I=1; $I >= 1; I++ )) ; do + wget http://mxtoolbox.com/WhatIsMyIP/ -q --tries=1 --timeout=2 -O ip.html + IP_1=$( cat ip.html | grep "ctl00_ContentPlaceHolder1_hlIP" | awk -F">" '{ print $2 }' | awk -F"<" '{ print $1 }' ); + rm ip.html + + if [ "$IP_1" == "$IP_0" ]; then + echo "Reconnect not yet completed..."; + sleep 1; + elif [ "$IP_1" == "" ]; then + echo "Reconnecting: Offline now (${I}) ..."; + sleep 10; + else + DATUM1=$(date +%s); + duration=$((DATUM1-DATUM0)) + echo "Old IP = $IP_0 // New IP = $IP_1" + echo "Reconnect Duration: $duration seconds" + IP_0=$IP_1; #Update of old IP + break + fi + + done; +fi + +rm step1_rg_config.js +rm step1_answer.html +rm step1_cookie_special.txt +rm step1_cookie.txt +rm step1_soap_data.xml +rm step2_answer.html +rm step2_cookies.txt +rm step3_answer.html + +rm step4_answer.html +rm step4_soap_data.xml + +rm step5_answer.html +rm step5_soap_data.xml +rm wget-log + +exit 0;