Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- error_action_preference="SilentlyContinue"
- configfile="./config.txt"
- token() {
- if [[ -n "$Pass" ]]; then
- Prompt="Gateway Management Password was previously entered -- hit [ENTER] to re-use it or type another password."
- else
- Prompt="Enter the Gateway Management Password"
- fi
- read -rsp "$Prompt: " PassSecure
- echo
- if [[ ${#PassSecure} -gt 1 ]]; then
- Pass=$(echo "$PassSecure" | tr -d '\n')
- fi
- body=$(cat <<-EOF
- {
- "username": "admin",
- "password": "$Pass"
- }
- EOF
- )
- login=$(curl -s -X POST -H "Content-Type: application/json" -d "$body" "http://192.168.12.1/TMI/v1/auth/login")
- token=$(echo "$login" | jq -r '.auth.token')
- header=("Authorization: Bearer $token")
- }
- show_menu() {
- clear
- echo "Options for Gateway"
- echo "1: Press '1' to Turn Off Wifi."
- echo "2: Press '2' to Turn On Wifi."
- echo "3: Press '3' to Reboot Gateway."
- echo "4: Press '4' to Download Config to Verify Changes."
- echo "5: Press '5' to View Config."
- echo "6: Press '6' to change Config file path (currently '$configfile')."
- echo "Q: Press 'Q' to Quit."
- }
- wifi_off() {
- response=$(curl -s -X GET -H "${header[@]}" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o "$configfile")
- jq '(.[] | select(.isRadioEnabled == true)).isRadioEnabled = false' "$configfile" > "$configfile.tmp" && mv "$configfile.tmp" "$configfile"
- 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")
- }
- wifi_on() {
- response=$(curl -s -X GET -H "${header[@]}" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o "$configfile")
- jq '(.[] | select(.isRadioEnabled == false)).isRadioEnabled = true' "$configfile" > "$configfile.tmp" && mv "$configfile.tmp" "$configfile"
- 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")
- }
- config() {
- response=$(curl -s -X GET -H "${header[@]}" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o "$configfile")
- }
- reboot() {
- response=$(curl -s -X POST -H "${header[@]}" -d '{"rebootType": "Reboot"}' "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot")
- }
- change_output_file() {
- read -p "Enter new config file path: " new_configfile
- configfile="$new_configfile"
- echo "New config file path is '$configfile'"
- }
- menu() {
- while true; do
- show_menu
- read -rp "Please make a selection: " selection
- case "$selection" in
- '1')
- token
- echo 'Turning off Wifi'
- wifi_off
- echo 'Returning to Menu'
- sleep 1
- ;;
- '2')
- token
- echo 'Turning on Wifi'
- wifi_on
- echo 'Returning to Menu'
- sleep 1
- ;;
- '3')
- token
- echo 'Rebooting Gateway'
- sleep 1
- reboot
- ;;
- '4')
- token
- echo 'Downloading config'
- config
- echo 'Returning to Menu'
- sleep 1
- ;;
- '5')
- echo 'Viewing config'
- cat "$configfile"
- echo 'Returning to Menu'
- sleep 1
- ;;
- '6')
- change_output_file
- ;;
- 'q')
- return
- ;;
- *)
- echo "Invalid selection. Please try again."
- sleep 1
- ;;
- esac
- done
- }
- menu
Advertisement
Comments
-
- This is an automated conversion from https://pastebin.com/vKaNtqwE#cJ8cn1qF
- in an attempt to make it work from Terminal
Add Comment
Please, Sign In to add comment
Advertisement