Router reboot
sanctusmob opened this issue · 2 comments
sanctusmob commented
Hello nikolas.
I am trying to reboot router via bash script but with no luck.
All GET request with session id to other endpoints are working perfect
This is my script.
#!/bin/bash
_modemip="192.168.1.1";
_username="admin";
_password="admin";
_session_id=$(curl -s "http://$_modemip/data/Login.json" -c - -H 'Accept-Language: en-US,en;q=0.7,el;q=0.3' --data-raw "username=$_username&password=$_password&showpw=0" | grep -oP "[0-Z]{32}")
#echo $_session_id
_time=$(date +%s%N)
echo "Reboot"
curl -v "http://$_modemip/data/Reboot.json?_time=${_time:0:13}&_rand=883" -X POST -H 'Accept-Language: en-US,en;q=0.7,el;q=0.3' -H 'Content-Type: application/x-www-form-urlencoded' -H "Cookie: session_id=$_session_id" --data-raw "reboot_device=true&sessionid=$_session_id"
The response from last curl is empty.
Can you help?
nikolas-n commented
I've tried to replicate the POST Request from curl as I see it in the browser (doing something similar as you do in your script) but to no avail. I'll be uploading here the javascript files of the router just in case someone can see what we're missing.
sanctusmob commented
I have manage to fix the problem and successful reboot the modem.
It is needed first to make a get request to html/content/config/problem_handling.html
Here is the script.
#!/bin/bash
_modemip="192.168.1.1";
_username="admin";
_password="admin";
_session_id=$(curl -s "http://$_modemip/data/Login.json" -c - -H 'Accept-Language: en-US,en;q=0.7,el;q=0.3' --data-raw "username=$_username&password=$_password&showpw=0" | grep -oP "[0-Z]{32}")
curl -s "http://$_modemip/html/content/config/problem_handling.html" -X GET -c - -H 'Accept-Language: en-US,en;q=0.7,el;q=0.3' -H "Cookie: session_id=$_session_id" > /dev/null
curl -s "http://$_modemip/data/Reboot.json" -X POST --max-time 30 -H 'Accept-Language: en-US,en;q=0.7,el;q=0.3' -H 'Content-Type: application/x-www-form-urlencoded' -H "Cookie: session_id=$_session_id" --data-raw "reboot_device=true&sessionid=$_session_id" > /dev/null