Update SVSTaskGate.ps1

This commit is contained in:
2025-01-05 01:35:13 -05:00
parent a7125417d3
commit 6f0f3e3c56

View File

@@ -845,17 +845,31 @@ try {
$data = ConvertFrom-Json $body $data = ConvertFrom-Json $body
$password = $data.password $password = $data.password
Get-N8nWebhookData -AuthHeaderValue $password # Fetch data using Get-N8nWebhookData
$sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly $webhookData = Get-N8nWebhookData -AuthHeaderValue $password
if (-not $sites) {
Write-Host "No sites returned. Please check the API." -ForegroundColor Red if (-not $webhookData) {
Write-Host "No data returned from Get-N8nWebhookData. Please check the password or API." -ForegroundColor Red
$response.StatusCode = 500 $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.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close() $response.OutputStream.Close()
continue continue
} }
$responseData = $sites | ConvertTo-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) $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
$response.ContentType = "application/json" $response.ContentType = "application/json"
$response.ContentLength64 = $buffer.Length $response.ContentLength64 = $buffer.Length
@@ -864,6 +878,7 @@ try {
} }
} }
"/installrmm" { "/installrmm" {
if ($request.HttpMethod -eq "POST") { if ($request.HttpMethod -eq "POST") {
$bodyStream = New-Object IO.StreamReader $request.InputStream $bodyStream = New-Object IO.StreamReader $request.InputStream