Update SVSTaskGate.ps1
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user