Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ErrorActionPreference = 'SilentlyContinue'
- function token
- {
- $Pass = Read-Host "Enter Password For The Gateway"
- $body = @"
- {
- "username": "admin",
- "password": "$Pass"
- }
- "@
- $login = Invoke-RestMethod -Method POST -Uri "http://192.168.12.1/TMI/v1/auth/login" -Body $body
- $token = $login.auth.token
- $global:header = @{Authorization="Bearer $token"}
- }
- function Show-Menu
- {
- param (
- [string]$Title = 'My Menu'
- )
- Clear-Host
- Write-Host "Options for Gateway"
- Write-Host "1: Press '1' to Turn Off 2.4G Wifi."
- Write-Host "2: Press '2' to Turn On 2.4G Wifi."
- Write-Host "3: Press '3' to Turn Off 5G Wifi."
- Write-Host "4: Press '4' to Turn On 5G Wifi."
- Write-Host "5: Press '5' to Reboot Gateway."
- Write-Host "6: Press '6' to Download Config to Verify Changes."
- Write-Host "Q: Press 'Q' to Quit."
- }
- function wifi-off-24
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
- ((Get-Content -path .\config.txt -Raw) -Replace '"2.4ghz":{"isRadioEnabled":true','"2.4ghz":{"isRadioEnabled":false') | Set-Content -Path .\config.txt
- $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
- }
- function wifi-on-24
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
- ((Get-Content -path .\config.txt -Raw) -Replace '"2.4ghz":{"isRadioEnabled":false','"2.4ghz":{"isRadioEnabled":true') | Set-Content -Path .\config.txt
- $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
- }
- function wifi-off-5
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
- ((Get-Content -path .\config.txt -Raw) -Replace '"5.0ghz":{"isRadioEnabled":true','"5.0ghz":{"isRadioEnabled":false') | Set-Content -Path .\config.txt
- $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
- }
- function wifi-on-5
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
- ((Get-Content -path .\config.txt -Raw) -Replace '"5.0ghz":{"isRadioEnabled":false','"5.0ghz":{"isRadioEnabled":true') | Set-Content -Path .\config.txt
- $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
- }
- function config
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
- }
- function reboot
- {
- $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot" -headers $global:header
- }
- function menu
- {
- Show-Menu -Title 'My Menu'
- $selection = Read-Host "Please make a selection"
- switch ($selection)
- {
- '1' {
- 'Turning off 2.4G Wifi'
- wifi-off-24
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '2' {
- 'Turning on 2.4G Wifi'
- wifi-on-24
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- }'3' {
- 'Turning off 5G Wifi'
- wifi-off-5
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '4' {
- 'Turning on 5G Wifi'
- wifi-on-5
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '5' {
- 'Rebooting Gateway'
- Start-Sleep -s 1
- reboot
- return
- } '6' {
- 'Downloading config'
- config
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } 'q' {
- return
- }
- }
- }
- token
- menu
- $response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement