Skip to content

Instantly share code, notes, and snippets.

@alimbada
Last active March 16, 2021 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alimbada/e5ed0d9a3242be812db4d7b697084d8e to your computer and use it in GitHub Desktop.
Save alimbada/e5ed0d9a3242be812db4d7b697084d8e to your computer and use it in GitHub Desktop.
Reboots Plusnet Hub One
#!/bin/sh
# Reboots Plusnet Hub One
routerip="192.168.1.254"
pass="<PASSWORD>"
# Call index page, store the output, then parse out whatever is needed
page=$(curl -Ls "http://$routerip/index.cgi?active_page=9148" -H 'Cookie: rg_cookie_session_id=' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'DNT: 1' --data 'active_page=9121' --cookie-jar cookies.txt)
posttoken=$(echo $page |grep post_token |awk 'BEGIN { FS = "\"post_token\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
requestid=$(echo $page |grep request_id |awk 'BEGIN { FS = "\"request_id\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
authkey=$(echo $page |grep auth_key |awk 'BEGIN { FS = "\"auth_key\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
passwordid=$(echo $page |grep password_ |awk 'BEGIN { FS = "\"password_" } ; {print $2}'| awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
pass=$pass$authkey
passhash=$(echo -n $pass | md5sum | awk '{print $1}')
# Construct query string for login
postvars="request_id=$requestid&active_page=9148&active_page_str=bt_login&mimic_button_field=submit_button_login_submit%3A+..&button_value=&post_token=$posttoken&password_$passwordid=&md5_pass=$passhash&auth_key=$authkey"
# Login and store the output to parse out the new post_token
# post_token changes between each request
page=$(curl -Ls "http://$routerip/index.cgi" -H 'Content-Type: application/x-www-form-urlencoded' -H 'Cache-Control: max-age=0' -H 'Referer: http://$routerip/index.cgi?active_page=9121' -H 'Connection: keep-alive' -H 'DNT: 1' --data "$postvars" --cookie cookies.txt)
posttoken=$(echo $page |grep post_token |awk 'BEGIN { FS = "\"post_token\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
# Reboot
curl -Ls "http://$routerip/index.cgi" \
-H 'Cache-Control: max-age=0' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'DNT: 1' \
-H 'Referer: http://$routerip/index.cgi?active_page=9121' \
--cookie cookies.txt \
--data request_id=$requestid \
--data active_page=9128 \
--data active_page_str=page_settings_a_restart \
--data 'mimic_button_field=submit_button_restart_my_home_hub%3A+..' \
--data button_value= \
--data "post_token=$posttoken" > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment