Advertisement
irezvi

Bash script to update T-Mobile Router Config

May 4th, 2024 (edited)
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Function to get authentication token
  4. token() {
  5.     read -sp "Enter Password For The Gateway: " password
  6.     body="{\"username\": \"admin\", \"password\": \"$password\"}"
  7.     token=$(curl -s -X POST -H "Content-Type: application/json" -d "$body" "http://192.168.12.1/TMI/v1/auth/login" | jq -r '.auth.token')
  8.     echo "token: $token"
  9.     HEADER="Authorization: Bearer $token"
  10. }
  11.  
  12. # Function to display the menu
  13. show_menu() {
  14.     clear
  15.     echo "Options for Gateway:"
  16.     echo "1: Turn Off 2.4G WiFi"
  17.     echo "2: Turn On 2.4G WiFi"
  18.     echo "3: Turn Off 5G WiFi"
  19.     echo "4: Turn On 5G WiFi"
  20.     echo "5: Reboot Gateway"
  21.     echo "6: Download Config to Verify Changes"
  22.     echo "7: Update Config"
  23.     echo "Q: Quit"
  24. }
  25.  
  26. # Function to turn off 2.4G WiFi
  27. wifi_off_24() {
  28.     echo "Turning off 2.4G WiFi..."
  29.     echo "$HEADER"
  30.     curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
  31.     sed -i 's/"2.4ghz":{"isRadioEnabled":true}/"2.4ghz":{"isRadioEnabled":false}/' config.json
  32.     curl -s -X POST -H "$HEADER" -H "Content-Type: application/json" -d @config.json "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap"
  33. }
  34.  
  35. # Function to turn on 2.4G WiFi
  36. wifi_on_24() {
  37.     echo "$HEADER"
  38.     curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
  39.     sed -i 's/"2.4ghz":{"isRadioEnabled":false}/"2.4ghz":{"isRadioEnabled":true}/' config.json
  40.     curl -s -X POST -H "$HEADER" -H "Content-Type: application/json" -d @config.json "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap"
  41. }
  42.  
  43. # Function to turn off 5G WiFi
  44. wifi_off_5() {
  45.     echo "$HEADER"
  46.     curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
  47.     sed -i 's/"5.0ghz":{"isRadioEnabled":true}/"5.0ghz":{"isRadioEnabled":false}/' config.json
  48.     curl -s -X POST -H "$HEADER" -H "Content-Type: application/json" -d @config.json "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap"
  49. }
  50.  
  51. # Function to turn on 5G WiFi
  52. wifi_on_5() {
  53.     curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
  54.     sed -i 's/"5.0ghz":{"isRadioEnabled":false}/"5.0ghz":{"isRadioEnabled":true}/' config.json
  55.     curl -s -X POST -H "$HEADER" -H "Content-Type: application/json" -d @config.json "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap"
  56. }
  57.  
  58. # Function to download the current configuration
  59. config() {
  60.     curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
  61. }
  62.  
  63. update_config() {
  64.     curl -s -X POST -H "$HEADER" -H "Content-Type: application/json" -d @config_custom.json "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap"
  65. }
  66.  
  67. # Function to reboot the gateway
  68. reboot() {
  69.     curl -s -X POST -H "$HEADER" "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot"
  70. }
  71.  
  72. # Main function to control menu and actions
  73. menu() {
  74.     show_menu
  75.     read -p "Please make a selection: " choice
  76.     case "$choice" in
  77.         1) echo "Turning off 2.4G WiFi..."
  78.            wifi_off_24
  79.            ;;
  80.         2) echo "Turning on 2.4G WiFi..."
  81.            wifi_on_24
  82.            ;;
  83.         3) echo "Turning off 5G WiFi..."
  84.            wifi_off_5
  85.            ;;
  86.         4) echo "Turning on 5G WiFi..."
  87.            wifi_on_5
  88.            ;;
  89.         5) echo "Rebooting Gateway..."
  90.            reboot
  91.            ;;
  92.         6) echo "Downloading config..."
  93.            config
  94.            ;;
  95.         7) echo "Updating config..."
  96.               update_config
  97.               ;;
  98.         "Q"|"q") echo "Quitting..."
  99.            exit 0
  100.            ;;
  101.         *) echo "Invalid option. Please try again."
  102.            ;;
  103.     esac
  104.     echo "Returning to Menu"
  105.     sleep 2
  106.     menu
  107. }
  108.  
  109. # Initialize script by obtaining token and showing menu
  110. token
  111. menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement