Guest User

Untitled

a guest
Dec 28th, 2017
1,203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.11 KB | None | 0 0
  1. #!/bin/bash
  2. # Reconnect for 'EasyBox 804'
  3. # Firmware version: CIS804-01.02
  4.  
  5. # Enter your 'EasyBox-Kennwort' here:
  6. PASSWORD_EASYBOX804="t0p_,_s3CREt"
  7.  
  8. # Enter hostname/adress of your EasyBox 804:
  9. HOST="easy.box.local"
  10. # If you can't reach the Box via http://easy.box.local use it's IP instad:
  11. #HOST="192.168.2.1"
  12.  
  13. # Notes:
  14. # The reconnect duration of the EasyBox 804 is quite long, it can be up to 180 seconds.
  15.  
  16. # * * * NO MORE CHANGES DOWN HERE * * *
  17.  
  18. if [ "1" == "1" ]; then # Step 1: before sending the password
  19.     curl "http://${HOST}/main.cgi?page=login.html" -c step1_cookie.txt \
  20.     -o step1_answer.html
  21.  
  22.     COOKIE_STEP1=$(cat step1_cookie.txt | grep "wbm_cookie_session_id" | awk -F"\t" '{ print $7 }')
  23.     echo "COOKIE_STEP1 = "${COOKIE_STEP1}
  24.  
  25.     # Create a 'special' cookie file without HOST and PATH (important):
  26.     cat step1_cookie.txt | sed "s/${HOST}//g" | sed 's/\t\/\t/\t\t/g' > step1_cookie_special.txt
  27.     cat step1_cookie_special.txt
  28.  
  29.  
  30.     DM_COOKIE_STEP3_STEP1=$(cat step1_answer.html | grep dm_cookie | awk -F"dm_cookie='" '{ print $2 }' | awk -F"'" '{ print $1 }')
  31.     echo "DM_COOKIE_STEP3_STEP1 = "${DM_COOKIE_STEP3_STEP1}
  32.  
  33.     # Sending cookies at this step is very important.
  34.     # If no cookies are sent, a 'new auth_key' is generated, not matching the cookies stored by this bash script.
  35.     curl "http://${HOST}/main.cgi?js=rg_config.js" -b step1_cookie.txt \
  36.     -o step1_rg_config.js
  37.  
  38.     AUTH_KEY=$(cat step1_rg_config.js | grep "auth_key" | awk -F"auth_key = '" '{ print $2 }' | awk -F"'" '{ print $1 }')
  39.     echo "AUTH_KEY = "${AUTH_KEY}
  40.  
  41.     # The sent md5-encrypted password consists of your 'Easybox-Kennwort' ...
  42.     # ... and the 'auth_key' from http://easy.box.local/main.cgi?js=rg_config.js !
  43.     # The original Javascript-function is defined here: http://easy.box.local/main.cgi?js=wbm_be.js
  44.     PASSWORD_MD5=$(echo -n ${PASSWORD_EASYBOX804}${AUTH_KEY} | md5sum | awk '{ print $1 }')
  45.  
  46.     echo "PASSWORD_MD5 = "${PASSWORD_MD5}
  47.  
  48.     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
  49.  
  50.  
  51.     rm -v step2_answer.html
  52.     rm -v step2_cookies.txt
  53.     # Now logging in (sending the password):
  54.     # The DOUBLE APOSTROPHE in >> -H "Cookie: wbm[...]=${...}" << is crucial!
  55.     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' \
  56.     --data @step1_soap_data.xml \
  57.     -o "step2_answer.html"
  58.  
  59.     cat step2_answer.html
  60.  
  61. fi
  62.  
  63.  
  64.  
  65.  
  66. if [ "1" == "1" ]; then # Step 3: After sending the password
  67.     COOKIE_STEP3=$(cat step2_cookies.txt | grep "wbm_cookie_session_id" | awk -F"\t" '{ print $7 }')
  68.     echo "COOKIE_STEP3 = "${COOKIE_STEP3}
  69.  
  70.     rm -v step3_answer.html
  71.     curl "http://${HOST}/main.cgi?page=app.html" -b step2_cookies.txt \
  72.     -o "step3_answer.html"
  73.  
  74.     DM_COOKIE_STEP3=$(cat step3_answer.html | grep dm_cookie | awk -F"dm_cookie='" '{ print $2 }' | awk -F"'" '{ print $1 }')
  75.     echo "DM_COOKIE_STEP3 = "$DM_COOKIE_STEP3
  76.  
  77.     # firefox step3_answer.html
  78. fi
  79.  
  80.  
  81.  
  82. if [ "0" == "1" ]; then # Step 4: Accessing the WAN IP (for testing the successful login without the timeconsuming reconnect)
  83.     # Only for testing purposes – NOT NECESSARY FOR RECONNECT !
  84.     # (Output of WAN iP)
  85.     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.3.WANConnectionDevice.1.WANPPPConnection.1.ExternalIPAddress</string></ParameterNames></cwmp:GetParameterValues></soapenv:Body></soapenv:Envelope>" > step4_soap_data.xml
  86.  
  87.     rm step4_answer.html
  88.     # The DOUBLE APOSTROPHE in >> -H "Cookie: [...]" << is very important!
  89.     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' \
  90.     --data @step4_soap_data.xml \
  91.     -o "step4_answer.html"
  92.  
  93.     # firefox step4_answer.html
  94. fi
  95.  
  96. MONITOR_IP=1
  97. if [ "$MONITOR_IP" == "1" ]; then # Montior IP Change & reconnect duration
  98.     wget http://mxtoolbox.com/WhatIsMyIP/ -q --tries=1 --timeout=2  -O ip.html
  99.     IP_0=$( cat ip.html | grep "ctl00_ContentPlaceHolder1_hlIP" | awk -F">" '{ print $2 }' | awk -F"<" '{ print $1 }' );
  100.     rm ip.html
  101.     DATUM0=$(date +%s);
  102. fi
  103.  
  104. if [ "1" == "1" ]; then # Step 5: Reconnect
  105.  
  106.     echo -e "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header><DMCookie>${DM_COOKIE_STEP3}</DMCookie></soapenv:Header><soapenv:Body><cwmp:SetParameterValues xmlns=\"\"><ParameterList><ParameterValueStruct><Name>InternetGatewayDevice.WANDevice.6.X_JUNGO_COM_Reconnect</Name><Value>1</Value></ParameterValueStruct></ParameterList></cwmp:SetParameterValues></soapenv:Body></soapenv:Envelope>" > step5_soap_data.xml
  107.  
  108.  
  109.     rm -v step5_answer.html
  110.     # The DOUBLE APOSTROPHE in >> -H "Cookie: [...]" << is very important!
  111.     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' \
  112.     --data @step5_soap_data.xml \
  113.     -o "step5_answer.html"
  114.  
  115.     #firefox step5_answer.html
  116. fi
  117.  
  118. if [ "$MONITOR_IP" == "1" ]; then # Montior IP Change & reconnect duration
  119.     echo "IP before Reconnect = $IP_0"
  120.    
  121.     for (( I=1; $I >= 1; I++ )) ; do
  122.     wget http://mxtoolbox.com/WhatIsMyIP/ -q --tries=1 --timeout=2 -O ip.html
  123.     IP_1=$( cat ip.html | grep "ctl00_ContentPlaceHolder1_hlIP" | awk -F">" '{ print $2 }' | awk -F"<" '{ print $1 }' );
  124.     rm ip.html
  125.    
  126.         if [ "$IP_1" == "$IP_0" ]; then
  127.             echo "Reconnect not yet completed...";
  128.             sleep 1;
  129.         elif [ "$IP_1" == "" ]; then
  130.             echo "Reconnecting: Offline now (${I}) ...";
  131.             sleep 10;
  132.         else
  133.             DATUM1=$(date +%s);
  134.             duration=$((DATUM1-DATUM0))
  135.             echo "Old IP = $IP_0 // New IP = $IP_1"
  136.             echo "Reconnect Duration: $duration seconds"
  137.             IP_0=$IP_1; #Update of old IP
  138.             break
  139.         fi
  140.    
  141.     done;
  142. fi
  143.  
  144. rm step1_rg_config.js
  145. rm step1_answer.html
  146. rm step1_cookie_special.txt
  147. rm step1_cookie.txt
  148. rm step1_soap_data.xml
  149. rm step2_answer.html
  150. rm step2_cookies.txt
  151. rm step3_answer.html
  152.  
  153. rm step4_answer.html
  154. rm step4_soap_data.xml
  155.  
  156. rm step5_answer.html
  157. rm step5_soap_data.xml
  158. rm wget-log
  159.  
  160. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment