Update SVSTaskGate.ps1
This commit is contained in:
@@ -838,32 +838,47 @@ try {
|
|||||||
$response.OutputStream.Close()
|
$response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
"/getn8npw" {
|
"/getn8npw" {
|
||||||
if ($request.HttpMethod -eq "POST") {
|
if ($request.HttpMethod -eq "POST") {
|
||||||
$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
|
# 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
|
|
||||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
# Populate API-related variables
|
||||||
$response.ContentType = "application/json"
|
$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.ContentLength64 = $buffer.Length
|
||||||
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||||
$response.OutputStream.Close()
|
$response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"/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
|
||||||
|
|||||||
Reference in New Issue
Block a user