Update SVSTaskGate.ps1
This commit is contained in:
@@ -830,27 +830,30 @@ try {
|
|||||||
$response.OutputStream.Close()
|
$response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"/getn8npw" {
|
"/getn8npw" {
|
||||||
if ($request.HttpMethod -eq "POST") {
|
if ($request.HttpMethod -eq "POST") {
|
||||||
# Parse the received JSON
|
|
||||||
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
||||||
$body = $bodyStream.ReadToEnd()
|
$body = $bodyStream.ReadToEnd()
|
||||||
$data = ConvertFrom-Json $body
|
$data = ConvertFrom-Json $body
|
||||||
$password = $data.password
|
$password = $data.password
|
||||||
|
|
||||||
Get-N8nWebhookData -AuthHeaderValue $password
|
Get-N8nWebhookData -AuthHeaderValue $password
|
||||||
# Fetch the list of Datto RMM client sites
|
|
||||||
$sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly
|
$sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly
|
||||||
|
|
||||||
# Check if sites are fetched
|
|
||||||
if (-not $sites) {
|
if (-not $sites) {
|
||||||
Write-Host "No sites were returned from the API. Please check the API connection." -ForegroundColor Red
|
Write-Host "No sites returned. Please check the API." -ForegroundColor Red
|
||||||
return
|
$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
|
||||||
# Convert the site list into JavaScript for populating the dropdown
|
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
||||||
$siteOptions = ($sites | ForEach-Object {
|
$response.ContentType = "application/json"
|
||||||
"document.getElementById('dattoRmmDropdown').innerHTML += '<option value=`"$($_.UID)`">$($_.Name -replace "'", "'")</option>';"
|
$response.ContentLength64 = $buffer.Length
|
||||||
}) -join "`n"
|
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||||
|
$response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user