From 6f0f3e3c56c27eafe60b9b4b0d618ad4f6205381 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 5 Jan 2025 01:35:13 -0500 Subject: [PATCH] Update SVSTaskGate.ps1 --- SVSTaskGate.ps1 | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/SVSTaskGate.ps1 b/SVSTaskGate.ps1 index 4e0191c..ac3c2a2 100644 --- a/SVSTaskGate.ps1 +++ b/SVSTaskGate.ps1 @@ -838,32 +838,47 @@ try { $response.OutputStream.Close() } - "/getn8npw" { + "/getn8npw" { if ($request.HttpMethod -eq "POST") { $bodyStream = New-Object IO.StreamReader $request.InputStream $body = $bodyStream.ReadToEnd() $data = ConvertFrom-Json $body $password = $data.password - 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 + # Fetch data using Get-N8nWebhookData + $webhookData = Get-N8nWebhookData -AuthHeaderValue $password + + if (-not $webhookData) { + Write-Host "No data returned from Get-N8nWebhookData. Please check the password or API." -ForegroundColor Red $response.StatusCode = 500 - $buffer = [System.Text.Encoding]::UTF8.GetBytes("No sites found") + $buffer = [System.Text.Encoding]::UTF8.GetBytes("Failed to fetch data") $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" + + # Populate API-related variables + $global:ApiUrl = $webhookData.ApiUrl + $global:ApiKey = $webhookData.ApiKey + $global:ApiSecretKey = $webhookData.ApiSecretKey + + # Include the API variables in the response + $responseData = @{ + ApiUrl = $global:ApiUrl + ApiKey = $global:ApiKey + ApiSecretKey = $global:ApiSecretKey + Sites = Install-DattoRMM -ApiUrl $global:ApiUrl -ApiKey $global:ApiKey -ApiSecretKey $global:ApiSecretKey -FetchSitesOnly + } | ConvertTo-Json -Depth 10 + + $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() } } + "/installrmm" { if ($request.HttpMethod -eq "POST") { $bodyStream = New-Object IO.StreamReader $request.InputStream