Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Function to get authentication token
- token() {
- read -sp "Enter Password For The Gateway: " password
- body="{\"username\": \"admin\", \"password\": \"$password\"}"
- 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')
- echo "token: $token"
- HEADER="Authorization: Bearer $token"
- }
- # Function to display the menu
- show_menu() {
- clear
- echo "Options for Gateway:"
- echo "1: Turn Off 2.4G WiFi"
- echo "2: Turn On 2.4G WiFi"
- echo "3: Turn Off 5G WiFi"
- echo "4: Turn On 5G WiFi"
- echo "5: Reboot Gateway"
- echo "6: Download Config to Verify Changes"
- echo "7: Update Config"
- echo "Q: Quit"
- }
- # Function to turn off 2.4G WiFi
- wifi_off_24() {
- echo "Turning off 2.4G WiFi..."
- echo "$HEADER"
- curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
- sed -i 's/"2.4ghz":{"isRadioEnabled":true}/"2.4ghz":{"isRadioEnabled":false}/' config.json
- 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"
- }
- # Function to turn on 2.4G WiFi
- wifi_on_24() {
- echo "$HEADER"
- curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
- sed -i 's/"2.4ghz":{"isRadioEnabled":false}/"2.4ghz":{"isRadioEnabled":true}/' config.json
- 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"
- }
- # Function to turn off 5G WiFi
- wifi_off_5() {
- echo "$HEADER"
- curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
- sed -i 's/"5.0ghz":{"isRadioEnabled":true}/"5.0ghz":{"isRadioEnabled":false}/' config.json
- 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"
- }
- # Function to turn on 5G WiFi
- wifi_on_5() {
- curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
- sed -i 's/"5.0ghz":{"isRadioEnabled":false}/"5.0ghz":{"isRadioEnabled":true}/' config.json
- 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"
- }
- # Function to download the current configuration
- config() {
- curl -s -H "$HEADER" "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -o config.json
- }
- update_config() {
- 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"
- }
- # Function to reboot the gateway
- reboot() {
- curl -s -X POST -H "$HEADER" "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot"
- }
- # Main function to control menu and actions
- menu() {
- show_menu
- read -p "Please make a selection: " choice
- case "$choice" in
- 1) echo "Turning off 2.4G WiFi..."
- wifi_off_24
- ;;
- 2) echo "Turning on 2.4G WiFi..."
- wifi_on_24
- ;;
- 3) echo "Turning off 5G WiFi..."
- wifi_off_5
- ;;
- 4) echo "Turning on 5G WiFi..."
- wifi_on_5
- ;;
- 5) echo "Rebooting Gateway..."
- reboot
- ;;
- 6) echo "Downloading config..."
- config
- ;;
- 7) echo "Updating config..."
- update_config
- ;;
- "Q"|"q") echo "Quitting..."
- exit 0
- ;;
- *) echo "Invalid option. Please try again."
- ;;
- esac
- echo "Returning to Menu"
- sleep 2
- menu
- }
- # Initialize script by obtaining token and showing menu
- token
- menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement