Advertisement
NaterTater

NaterTater TMobile Arcadyan KVD21 Setting Script

Apr 27th, 2022 (edited)
23,744
1
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 1 0
  1. #thanks to the individual contributors that helped create and update this code!
  2.  
  3. $ErrorActionPreference = 'SilentlyContinue'
  4. $global:configfile = Resolve-Path -Path ".\config.txt" | select -ExpandProperty Path
  5. function token
  6. {
  7.  
  8. if ($Pass) {
  9. $Prompt = "Gateway Management Password was previously entered -- hit [ENTER] to re-use it or type another password."
  10. } else {
  11. $Prompt = "Enter the Gateway Management Password"
  12. }
  13. $PassSecure = Read-Host "$Prompt" -AsSecureString
  14. if ($PassSecure.Length -gt 1) {
  15. $global:Pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($PassSecure))
  16. }
  17.  
  18. $body = @"
  19. {
  20. "username": "admin",
  21. "password": "$Pass"
  22. }
  23. "@
  24.  
  25. $login = Invoke-RestMethod -Method POST -Uri "http://192.168.12.1/TMI/v1/auth/login" -Body $body
  26. $token = $login.auth.token
  27. $global:header = @{Authorization="Bearer $token"}
  28.  
  29. }
  30.  
  31. function Show-Menu
  32. {
  33. param (
  34. [string]$Title = 'My Menu'
  35. )
  36. Clear-Host
  37. Write-Host "Options for Gateway"
  38.  
  39. Write-Host "1: Press '1' to Turn Off Wifi."
  40. Write-Host "2: Press '2' to Turn On Wifi."
  41. Write-Host "3: Press '3' to Reboot Gateway."
  42. Write-Host "4: Press '4' to Download Config to Verify Changes."
  43. Write-Host "5: Press '5' to View Config in Notepad."
  44. Write-Host "6: Press '6' to change Config file path (currently '$configfile')."
  45. Write-Host "Q: Press 'Q' to Quit."
  46. }
  47.  
  48.  
  49. function wifi-off
  50. {
  51.  
  52. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -headers $global:header -o "$configfile"
  53. ((Get-Content -path "$configfile" -Raw) -Replace '"isRadioEnabled": true','"isRadioEnabled": false') | Set-Content -Path "$configfile"
  54. $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"
  55.  
  56. }
  57.  
  58.  
  59. function wifi-on
  60. {
  61.  
  62. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -headers $global:header -o "$configfile"
  63. ((Get-Content -path "$configfile" -Raw) -Replace '"isRadioEnabled": false','"isRadioEnabled": true') | Set-Content -Path "$configfile"
  64. $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"
  65.  
  66. }
  67.  
  68.  
  69. function config
  70. {
  71.  
  72. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration/v2?get=ap" -headers $global:header -o "$configfile"
  73.  
  74. }
  75.  
  76. function reboot
  77. {
  78.  
  79. $response = Invoke-RestMethod -TimeoutSec 90 -Method POST -Uri "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot" -headers $global:header
  80.  
  81. }
  82.  
  83. function changeoutputfile {
  84. Add-Type -AssemblyName System.Windows.Forms
  85. $targetFile = New-Object System.Windows.Forms.SaveFileDialog
  86. $targetFile.Filename = "$configfile"
  87. if ($targetFile.ShowDialog() -eq "OK") {
  88. $global:configfile = $targetFile.FileName
  89. }
  90. }
  91.  
  92.  
  93.  
  94. function menu
  95. {
  96.  
  97.  
  98. Show-Menu -Title 'My Menu'
  99. $selection = Read-Host "Please make a selection"
  100. switch ($selection)
  101. {
  102. '1' {
  103. token
  104. 'Turning off Wifi'
  105. wifi-off
  106. 'Returning to Menu'
  107. Start-Sleep -s 1
  108. menu
  109.  
  110. } '2' {
  111. token
  112. 'Turning on Wifi'
  113. wifi-on
  114. 'Returning to Menu'
  115. Start-Sleep -s 1
  116. menu
  117.  
  118. } '3' {
  119. token
  120. 'Rebooting Gateway'
  121. Start-Sleep -s 1
  122. reboot
  123. menu
  124.  
  125. } '4' {
  126. token
  127. 'Downloading config'
  128. config
  129. 'Returning to Menu'
  130. Start-Sleep -s 1
  131. menu
  132.  
  133. } '5' {
  134. 'Viewing config'
  135. notepad "$configfile"
  136. 'Returning to Menu'
  137. Start-Sleep -s 1
  138. menu
  139.  
  140. } '6' {
  141. 'Choose config file name'
  142. changeoutputfile
  143. "New config file path is '$configfile'"
  144. Start-Sleep -s 2
  145. menu
  146.  
  147. } 'q' {
  148. return
  149. }
  150.  
  151. }
  152.  
  153. }
  154.  
  155. menu
  156.  
  157. $response
  158.  
Advertisement
Comments
  • GregCMCSE
    1 year
    # text 0.14 KB | 1 0
    1. Hi Nate, thanks for this! Here's an updated version which works with the newer firmware and adds a few tweaks.
    2. https://pastebin.com/09z1rcKz
    3.  
    • NaterTater
      1 year
      # text 0.23 KB | 0 0
      1. 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)
      • GregCMCSE
        1 year
        # text 0.40 KB | 0 0
        1. 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!
  • onlyrahul2000
    343 days
    # text 0.11 KB | 0 0
    1. Do we need to use text above in Powershell as text or convert the text file into PS1 extension? Please reply. Thx
  • BAKzzzzzzzz
    239 days
    # text 0.11 KB | 0 0
    1. I tried to create this for Mac using ChatGPT and BASH if someone wants to check it
    2. https://pastebin.com/tQxPftxD
  • WallyVault14
    148 days
    # text 0.08 KB | 0 0
    1. I could not get this to work! I followed the youtube and no luck at all! please help
    2.  
Add Comment
Please, Sign In to add comment
Advertisement