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'
- $global:configfile = Resolve-Path -Path ".\config.txt" | select -ExpandProperty Path
- function token
- {
- if ($Pass) {
- $Prompt = "Gateway Management Password was previously entered -- hit [ENTER] to re-use it or type another password."
- } else {
- $Prompt = "Enter the Gateway Management Password"
- }
- $PassSecure = Read-Host "$Prompt" -AsSecureString
- if ($PassSecure.Length -gt 1) {
- $global:Pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($PassSecure))
- }
- $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 Wifi."
- Write-Host "2: Press '2' to Turn On Wifi."
- Write-Host "3: Press '3' to Reboot Gateway."
- Write-Host "4: Press '4' to Download Config to Verify Changes."
- Write-Host "5: Press '5' to View Config in Notepad."
- Write-Host "6: Press '6' to change Config file path (currently '$configfile')."
- Write-Host "Q: Press 'Q' to Quit."
- }
- function wifi-off
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -headers $global:header -o "$configfile"
- ((Get-Content -path "$configfile" -Raw) -Replace '"isRadioEnabled": true','"isRadioEnabled": false') | Set-Content -Path "$configfile"
- $response = Invoke-RestMethod -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap" -headers $global:header -body (Get-Content "$configfile") -ContentType "application/json"
- }
- function wifi-on
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -headers $global:header -o "$configfile"
- ((Get-Content -path "$configfile" -Raw) -Replace '"isRadioEnabled": false','"isRadioEnabled": true') | Set-Content -Path "$configfile"
- $response = Invoke-RestMethod -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?set=ap" -headers $global:header -body (Get-Content "$configfile") -ContentType "application/json"
- }
- function config
- {
- $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -headers $global:header -o "$configfile"
- }
- function reboot
- {
- $response = Invoke-RestMethod -TimeoutSec 90 -Method POST -Uri "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot" -headers $global:header
- }
- function changeoutputfile {
- Add-Type -AssemblyName System.Windows.Forms
- $targetFile = New-Object System.Windows.Forms.SaveFileDialog
- $targetFile.Filename = "$configfile"
- if ($targetFile.ShowDialog() -eq "OK") {
- $global:configfile = $targetFile.FileName
- }
- }
- function menu
- {
- Show-Menu -Title 'My Menu'
- $selection = Read-Host "Please make a selection"
- switch ($selection)
- {
- '1' {
- token
- 'Turning off Wifi'
- wifi-off
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '2' {
- token
- 'Turning on Wifi'
- wifi-on
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '3' {
- token
- 'Rebooting Gateway'
- Start-Sleep -s 1
- reboot
- menu
- } '4' {
- token
- 'Downloading config'
- config
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '5' {
- 'Viewing config'
- notepad "$configfile"
- 'Returning to Menu'
- Start-Sleep -s 1
- menu
- } '6' {
- 'Choose config file name'
- changeoutputfile
- "New config file path is '$configfile'"
- Start-Sleep -s 2
- menu
- } 'q' {
- return
- }
- }
- }
- menu
- $response
Advertisement
Comments
-
- Hi Nate, thanks for this! Here's an updated version which works with the newer firmware and adds a few tweaks.
- https://pastebin.com/09z1rcKz
-
- Great thanks Gregcmcse! Are you ok with me incorporating your code into this pastebin file so my previous links will reference the correct code? I'd include a script # comment calling out your username (or anything else you'd like)
-
- Absolutely -- my work is a donation to you to help you keep on keeping on and thank you for providing the fix to the community in the first place. Like the first guy who helped you put it into a nicer menu-script, I'm just trying to help keep it up to date and improve the interface/options a little more. If you comment-mention me, you should comment-mention the original author first. Have a good one!
-
- Do we need to use text above in Powershell as text or convert the text file into PS1 extension? Please reply. Thx
-
- For instructions on how to use the script go to https://youtu.be/FTI9AOaYedc
-
- I tried to create this for Mac using ChatGPT and BASH if someone wants to check it
- https://pastebin.com/tQxPftxD
-
- thanks, these actually do work for Mac already. Just have to install powershell for Mac OS.
-
- I could not get this to work! I followed the youtube and no luck at all! please help
Add Comment
Please, Sign In to add comment
Advertisement