Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #thanks to the individual contributors that helped create and update this code!
- $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"}
- $Date = (Get-Date -format "hh-mm-ss")
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\Backup-config-$Date.txt
- }
- function Show-Menu
- {
- param (
- [string]$Title = 'My Menu'
- )
- Clear-Host
- Write-Host "Options for Gateway"
- Write-Host "Press '1' to Download Config to Make Changes."
- Write-Host "Press '2' to Download Config to Verify Changes."
- Write-Host "Press '3' to Reboot Gateway."
- Write-Host "Press '4' to Upload Backup settings. Rename selected Backup to Backup-config.txt "
- Write-Host "Q: Press 'Q' to Quit."
- }
- function change
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
- Start-Process notepad .\config.txt -NoNewWindow -Wait
- $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"
- Remove-Item -Path .\config.txt
- }
- function Backup
- {
- $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 .\Backup-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
- Start-Process notepad .\config.txt -NoNewWindow -Wait
- Remove-Item -Path .\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' {
- 'Opening Config for changes'
- change
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '2' {
- 'Opening Config to Verify Changes'
- config
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- }'3'{
- 'Rebooting Gateway'
- Start-Sleep -s 1
- reboot
- return
- }'4'{
- 'Uploading Backup Config'
- Backup
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } 'q' {
- return
- }
- }
- }
- token
- menu
- $response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement