diff --git a/SVSTaskGate.ps1 b/SVSTaskGate.ps1 index f3c5345..d590e8b 100644 --- a/SVSTaskGate.ps1 +++ b/SVSTaskGate.ps1 @@ -858,11 +858,17 @@ try { } } - "/installrmm" { + "/installrmm" { if ($request.HttpMethod -eq "POST") { $bodyStream = New-Object IO.StreamReader $request.InputStream $body = $bodyStream.ReadToEnd() - + + # Ensure the request body is not empty + if (-not $body) { + Write-LogHybrid -Message "Request body is empty. Aborting..." -Level "Error" + return + } + # Log raw request body Write-LogHybrid -Message "Raw request body: $body" -Level "Info" @@ -875,19 +881,26 @@ try { return } - # Log the received request for debugging - Write-LogHybrid -Message "Received RMM installation request: $($selectedSite | ConvertTo-Json -Depth 10)" -Level "Info" - Write-LogHybrid -Message "Starting installation for site $($selectedSite.Name) ($($selectedSite.UID))..." -Level "Info" + # Validate required fields + if (-not $selectedSite.installRMMCommand -or -not $selectedSite.UID -or -not $selectedSite.Name) { + Write-LogHybrid -Message "Missing required fields in JSON payload. Aborting..." -Level "Error" + return + } + + # Log the received request + Write-LogHybrid -Message "Received RMM installation request for site $($selectedSite.Name) ($($selectedSite.UID))." -Level "Info" # Execute the installation command try { - Invoke-Expression $selectedSite.installRMMCommand + $output = Invoke-Expression $selectedSite.installRMMCommand + Write-LogHybrid -Message "Command output: $output" -Level "Info" Write-LogHybrid -Message "Installation for site $($selectedSite.Name) ($($selectedSite.UID)) completed successfully." -Level "Success" } catch { Write-LogHybrid -Message "Error during installation for site $($selectedSite.Name): $($_.Exception.Message)" -Level "Error" } + # Send response $responseString = "RMM installation triggered for site $($selectedSite.Name)." $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString) $response.ContentType = "text/plain" @@ -898,6 +911,7 @@ try { } + "/setSVSPowerplan" { if ($request.HttpMethod -eq "GET") { Set-SVSPowerPlan