From 0a387f2a243ca3aaf2bd8c114abd46167b7c0f98 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 5 Jan 2025 00:18:28 -0500 Subject: [PATCH] Update SVSTaskGate.ps1 --- SVSTaskGate.ps1 | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/SVSTaskGate.ps1 b/SVSTaskGate.ps1 index d40da48..df2dd9d 100644 --- a/SVSTaskGate.ps1 +++ b/SVSTaskGate.ps1 @@ -830,29 +830,32 @@ try { $response.OutputStream.Close() } + "/getn8npw" { - if ($request.HttpMethod -eq "POST") { - # Parse the received JSON - $bodyStream = New-Object IO.StreamReader $request.InputStream - $body = $bodyStream.ReadToEnd() - $data = ConvertFrom-Json $body - $password = $data.password - Get-N8nWebhookData -AuthHeaderValue $password - # Fetch the list of Datto RMM client sites - $sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly + if ($request.HttpMethod -eq "POST") { + $bodyStream = New-Object IO.StreamReader $request.InputStream + $body = $bodyStream.ReadToEnd() + $data = ConvertFrom-Json $body + $password = $data.password - # Check if sites are fetched - if (-not $sites) { - Write-Host "No sites were returned from the API. Please check the API connection." -ForegroundColor Red - return + Get-N8nWebhookData -AuthHeaderValue $password + $sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly + if (-not $sites) { + Write-Host "No sites returned. Please check the API." -ForegroundColor Red + $response.StatusCode = 500 + $buffer = [System.Text.Encoding]::UTF8.GetBytes("No sites found") + $response.OutputStream.Write($buffer, 0, $buffer.Length) + $response.OutputStream.Close() + continue + } + $responseData = $sites | ConvertTo-Json + $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData) + $response.ContentType = "application/json" + $response.ContentLength64 = $buffer.Length + $response.OutputStream.Write($buffer, 0, $buffer.Length) + $response.OutputStream.Close() } - - # Convert the site list into JavaScript for populating the dropdown - $siteOptions = ($sites | ForEach-Object { - "document.getElementById('dattoRmmDropdown').innerHTML += '';" - }) -join "`n" } - }