Advertisement
BAKzzzzzzzz

Draft code for Tmobile Mac

Sep 9th, 2023
304
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.83 KB | Software | 0 0
  1. #!/bin/bash
  2. set -e
  3.  
  4. error_action_preference="SilentlyContinue"
  5. configfile="./config.txt"
  6.  
  7. token() {
  8.     if [[ -n "$Pass" ]]; then
  9.         Prompt="Gateway Management Password was previously entered -- hit [ENTER] to re-use it or type another password."
  10.     else
  11.         Prompt="Enter the Gateway Management Password"
  12.     fi
  13.  
  14.     read -rsp "$Prompt: " PassSecure
  15.     echo
  16.  
  17.     if [[ ${#PassSecure} -gt 1 ]]; then
  18.         Pass=$(echo "$PassSecure" | tr -d '\n')
  19.     fi
  20.  
  21.     body=$(cat <<-EOF
  22. {
  23.   "username": "admin",
  24.   "password": "$Pass"
  25. }
  26. EOF
  27. )
  28.  
  29.     login=$(curl -s -X POST -H "Content-Type: application/json" -d "$body" "http://192.168.12.1/TMI/v1/auth/login")
  30.     token=$(echo "$login" | jq -r '.auth.token')
  31.     header=("Authorization: Bearer $token")
  32. }
  33.  
  34. show_menu() {
  35.     clear
  36.     echo "Options for Gateway"
  37.     echo "1: Press '1' to Turn Off Wifi."
  38.     echo "2: Press '2' to Turn On Wifi."
  39.     echo "3: Press '3' to Reboot Gateway."
  40.     echo "4: Press '4' to Download Config to Verify Changes."
  41.     echo "5: Press '5' to View Config."
  42.     echo "6: Press '6' to change Config file path (currently '$configfile')."
  43.     echo "Q: Press 'Q' to Quit."
  44. }
  45.  
  46. wifi_off() {
  47.     response=$(curl -s -X GET -H "${header[@]}" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o "$configfile")
  48.     jq '(.[] | select(.isRadioEnabled == true)).isRadioEnabled = false' "$configfile" > "$configfile.tmp" && mv "$configfile.tmp" "$configfile"
  49.     response=$(curl -s -X POST -H "${header[@]}" -d @"$configfile" -H "Content-Type: application/json" "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap")
  50. }
  51.  
  52. wifi_on() {
  53.     response=$(curl -s -X GET -H "${header[@]}" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o "$configfile")
  54.     jq '(.[] | select(.isRadioEnabled == false)).isRadioEnabled = true' "$configfile" > "$configfile.tmp" && mv "$configfile.tmp" "$configfile"
  55.     response=$(curl -s -X POST -H "${header[@]}" -d @"$configfile" -H "Content-Type: application/json" "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap")
  56. }
  57.  
  58. config() {
  59.     response=$(curl -s -X GET -H "${header[@]}" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o "$configfile")
  60. }
  61.  
  62. reboot() {
  63.     response=$(curl -s -X POST -H "${header[@]}" -d '{"rebootType": "Reboot"}' "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot")
  64. }
  65.  
  66. change_output_file() {
  67.     read -p "Enter new config file path: " new_configfile
  68.     configfile="$new_configfile"
  69.     echo "New config file path is '$configfile'"
  70. }
  71.  
  72. menu() {
  73.     while true; do
  74.         show_menu
  75.         read -rp "Please make a selection: " selection
  76.         case "$selection" in
  77.             '1')
  78.                 token
  79.                 echo 'Turning off Wifi'
  80.                 wifi_off
  81.                 echo 'Returning to Menu'
  82.                 sleep 1
  83.                 ;;
  84.             '2')
  85.                 token
  86.                 echo 'Turning on Wifi'
  87.                 wifi_on
  88.                 echo 'Returning to Menu'
  89.                 sleep 1
  90.                 ;;
  91.             '3')
  92.                 token
  93.                 echo 'Rebooting Gateway'
  94.                 sleep 1
  95.                 reboot
  96.                 ;;
  97.             '4')
  98.                 token
  99.                 echo 'Downloading config'
  100.                 config
  101.                 echo 'Returning to Menu'
  102.                 sleep 1
  103.                 ;;
  104.             '5')
  105.                 echo 'Viewing config'
  106.                 cat "$configfile"
  107.                 echo 'Returning to Menu'
  108.                 sleep 1
  109.                 ;;
  110.             '6')
  111.                 change_output_file
  112.                 ;;
  113.             'q')
  114.                 return
  115.                 ;;
  116.             *)
  117.                 echo "Invalid selection. Please try again."
  118.                 sleep 1
  119.                 ;;
  120.         esac
  121.     done
  122. }
  123.  
  124. menu
  125.  
Advertisement
Comments
  • BAKzzzzzzzz
    1 year
    # text 0.12 KB | 0 0
    1. This is an automated conversion from https://pastebin.com/vKaNtqwE#cJ8cn1qF
    2. in an attempt to make it work from Terminal
Add Comment
Please, Sign In to add comment
Advertisement