-
-
Save duraki/7da10aa8e1bf1f26782df88abb8470d8 to your computer and use it in GitHub Desktop.
Function to check for status reboot Technicolor CGA2121 router if connection is dropped
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Define the cookie jar and temp file for HTML content | |
COOKIE_JAR="cookie.txt" | |
HTML_FILE="response.html" | |
# URL details | |
LOGIN_URL="http://192.168.0.1/goform/logon" | |
RESTART_PAGE="http://192.168.0.1/ad_restart_gateway.html" | |
RESTART_ACTION="http://192.168.0.1/goform/ad_restart_gateway" | |
# Login credentials | |
USERNAME="XXXXXXXXX" | |
PASSWORD="XXXXXXXXX" | |
# Login and save the session cookie, suppressing output | |
curl --silent --location "$LOGIN_URL" \ | |
--header 'Content-Type: application/x-www-form-urlencoded' \ | |
-c $COOKIE_JAR \ | |
--data-urlencode "username_login=$USERNAME" \ | |
--data-urlencode "password_login=$PASSWORD" > /dev/null | |
# Fetch the page containing the CSRF token, suppressing output | |
curl --silent --location $RESTART_PAGE \ | |
-b $COOKIE_JAR \ | |
-c $COOKIE_JAR \ | |
-o $HTML_FILE > /dev/null | |
# Extract CSRF token from the HTML | |
CSRF_TOKEN=$(grep -oP 'name="csrftoken" value="\K[^"]*' $HTML_FILE) | |
# Send the POST request to restart the router with CSRF token and device restart field, suppressing output | |
curl --silent --location $RESTART_ACTION \ | |
-b $COOKIE_JAR \ | |
-c $COOKIE_JAR \ | |
--data-urlencode "csrftoken=$CSRF_TOKEN" \ | |
--data-urlencode "tch_devicerestart=0x00" \ | |
--data "reboot=Restart" > /dev/null | |
# Cleanup | |
rm $HTML_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment