Guest User

Untitled

a guest
Jun 14th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. . .\NewXMLDocument.ps1
  2.  
  3. $rdp_domainname = "MicrosoftAccount"
  4. $rdp_username = "fred"
  5. $ssh_username = "fred"
  6. $vnc_username = "fred"
  7.  
  8. $rdp_password = "changeme!"
  9. $ssh_password = "changeme!"
  10. $vnc_password = "changeme!"
  11.  
  12. $Network = "192.168.1."
  13.  
  14.  
  15. $NetworkAddresses = 1..254 | ForEach-Object {
  16. @{
  17. ComputerName = "$($Network)$($_)"
  18. }
  19. }
  20.  
  21. $Connections = $NetworkAddresses | ForEach-Object {
  22. if (Test-Connection -ComputerName $_ -Count 1 -TimeToLive 10) {
  23. if ((Test-NetConnection -ComputerName $_ -Port 22).TcpTestSucceeded) {
  24. $ssh = $true
  25. }
  26. if ((Test-NetConnection -ComputerName $_ -Port 5900).TcpTestSucceeded) {
  27. $vnc = $true
  28. }
  29. if ((Test-NetConnection -ComputerName $_ -Port 3389).TcpTestSucceeded) {
  30. $rdp = $true
  31. }
  32. [PSCustomObject]@{
  33. 'address' = $_
  34. 'ssh' = $ssh
  35. 'vnc' = $vnc
  36. 'rdp' = $rdp
  37. }
  38. }
  39. }
  40.  
  41. ## used for testing
  42. # $Connections = @(
  43. # [PSCustomObject]@{
  44. # 'address' = "192.168.1.1"
  45. # 'ssh' = $true
  46. # 'vnc' = $false
  47. # 'rdp' = $false
  48. # }
  49. # [PSCustomObject]@{
  50. # 'address' = "192.168.1.2"
  51. # 'ssh' = $false
  52. # 'vnc' = $false
  53. # 'rdp' = $true
  54. # }
  55. # [PSCustomObject]@{
  56. # 'address' = "192.168.1.3"
  57. # 'ssh' = $true
  58. # 'vnc' = $false
  59. # 'rdp' = $true
  60. # }
  61. # )
  62.  
  63.  
  64. $xml = New-XmlDocument -ScriptBlock {
  65. user-mapping {
  66. authorize {
  67. username = $ssh_username
  68. password = $ssh_password
  69. $Connections | ForEach-Object {
  70. $Address = $_.address
  71. if ($_.rdp) {
  72. connection {
  73. name = "$([System.Net.Dns]::gethostentry($Address)) Desktop(RDP)"
  74. #name = "$Address Desktop(RDP)" # used for testing
  75. protocol {
  76. 'rdp'
  77. }
  78. param {
  79. name = "hostname"
  80. "$Address"
  81. }
  82. param {
  83. name = "security"
  84. 'nla'
  85. }
  86. param {
  87. name = "ignore-cert"
  88. 'true'
  89. }
  90. param {
  91. name = "domain"
  92. "$rdp_domainname"
  93. }
  94. param {
  95. name = "username"
  96. '${GUAC_USERNAME}'
  97. }
  98. param {
  99. name = "password"
  100. '${GUAC_PASSWORD}'
  101. }
  102. }
  103. }
  104. elseif ($_.vnc) {
  105. connection {
  106. name = "$([System.Net.Dns]::gethostentry($Address)) Desktop(VNC)"
  107. #name = "$Address Desktop(VNC)" # used for testing
  108. protocol {
  109. 'vnc'
  110. }
  111. param {
  112. name = "hostname"
  113. "$Address"
  114. }
  115. param {
  116. name = "username"
  117. '${GUAC_USERNAME}'
  118. }
  119. param {
  120. name = "password"
  121. '${GUAC_PASSWORD}'
  122. }
  123. }
  124. }
  125. if ($_.ssh) {
  126. connection {
  127. name = "$([System.Net.Dns]::gethostentry($Address)) Terminal"
  128. #name = "$Address Terminal" # used for testing
  129. protocol {
  130. 'ssh'
  131. }
  132. param {
  133. name = "hostname"
  134. "$Address"
  135. }
  136. param {
  137. name = "port"
  138. '22'
  139. }
  140. param {
  141. name = "username"
  142. '${GUAC_USERNAME}'
  143. }
  144. param {
  145. name = "password"
  146. '${GUAC_PASSWORD}'
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154.  
  155. ## For testing
  156. #$xml.ToString()
  157.  
  158. # remove old user mappings
  159. Remove-Item "/etc/guacamole/user-mappings.xml" -Force
  160.  
  161. # Output $xml to "/etc/guacamole/user-mappings.xml"
  162. $xml.Save("/etc/guacamole/user-mappings.xml")
Add Comment
Please, Sign In to add comment