From 2dde224072367cc4fe5a70cd1658257831f7a8fe Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Thu, 29 May 2025 01:55:01 -0400 Subject: [PATCH] reverted some line in the Handle-fetchsite to powershell 5 commands --- StackMonkey.ps1 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 5d1bc0e..cc5c0e2 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -266,10 +266,12 @@ function Handle-FetchSites { param($Context) # 1) Read incoming JSON (using block auto-disposes the reader) - using ($reader = [IO.StreamReader]::new($Context.Request.InputStream)) { + + + <# powershell v7 + using ($reader = [IO.StreamReader]::new($Context.Request.InputStream)) { $raw = $reader.ReadToEnd() } - try { $pw = (ConvertFrom-Json $raw).password if (-not $pw) { throw "Missing `password` field" } @@ -278,6 +280,22 @@ function Handle-FetchSites { returnRespondEmpty $Context 400 return } + #> + + $reader = [IO.StreamReader]::new($Context.Request.InputStream) + try { + $raw = $reader.ReadToEnd() + } finally { + $reader.Close() + } + + try { + $pw = (ConvertFrom-Json $raw).password + } catch { + Write-LogHybrid "Invalid JSON in /getpw payload: $($_.Exception.Message)" "Error" "FetchSites" + returnRespondEmpty $Context + return + } # 2) Fetch your Datto API creds from the webhook Write-LogHybrid "Calling webhook for Datto credentials…" "Info" "FetchSites"