Update samy.ps1

This commit is contained in:
2025-12-20 15:54:04 -05:00
parent 84fd019430
commit 14ea4f025f

View File

@@ -174,27 +174,25 @@ if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage' -or
Write-Host "[Info] Relaunching with ExecutionPolicy Bypass..." -ForegroundColor Yellow Write-Host "[Info] Relaunching with ExecutionPolicy Bypass..." -ForegroundColor Yellow
# Rebuild the original argument list as a string to pass through # Rebuild the original argument list as a string to pass through
$argList = @() $argList = @()
foreach ($a in $args) { foreach ($a in $args) {
if ($a -is [string]) { $argList += [string]$a
# Quote and escape any existing quotes
$escaped = $a.Replace('"','`"')
$argList += "`"$escaped`""
} else {
$argList += $a.ToString()
}
} }
$argString = $argList -join ' '
# Only needed for the -Command path (string has to be re-parsed)
$argString = ($argList | ForEach-Object {
'"' + ($_ -replace '"','`"') + '"'
}) -join ' '
if ($PSCommandPath) { if ($PSCommandPath) {
# Script saved on disk: re-run same file with same args # FIX: do NOT pass $argString as one argument
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "`"$PSCommandPath`"" $argString # You want PowerShell to see each token separately.
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$PSCommandPath" @argList
} else { } else {
# iwr | iex scenario: re-download SAMY and apply same args # Here, argString is fine because -Command is a single string
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& { iwr 'https://samy.svstools.ca' -UseBasicParsing | iex } $argString" powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& { iwr 'https://samy.svstools.ca' -UseBasicParsing | iex } $argString"
} }
exit exit
} }
@@ -1871,8 +1869,10 @@ function Install-DattoRMM {
if ($UseWebhook) { if ($UseWebhook) {
# Allow blank for IP allowlist scenario. Only treat true $null as missing. # Allow blank for IP allowlist scenario. Only treat true $null as missing.
if ($null -eq $WebhookPassword) { $WebhookPassword = '' } if ($null -eq $WebhookPassword) {
$WebhookPassword = ''
Write-LogHybrid "Webhook password not provided (null). Treating as blank for allowlisted IP flow." Warning DattoRMM -LogToEvent Write-LogHybrid "Webhook password not provided (null). Treating as blank for allowlisted IP flow." Warning DattoRMM -LogToEvent
}
try { try {
$resp = Invoke-RestMethod -Uri $WebhookUrl ` $resp = Invoke-RestMethod -Uri $WebhookUrl `
@@ -2056,24 +2056,23 @@ function Install-DattoRMM {
return return
} }
# ---- Task invocation ---- # ---- Task invocation ----
$task = $Global:SamyTasks | Where-Object Name -EQ $path $task = $Global:SamyTasks | Where-Object Name -EQ $path $task = $Global:SamyTasks | Where-Object Name -EQ $path
if ($task) { if ($task) { if ($task) {
& $task.HandlerFn $Context $fn = $task.HandlerFn
return $fn = $task.HandlerFn $cmd = Get-Command $fn -ErrorAction SilentlyContinue
} $cmd = Get-Command $fn -ErrorAction SilentlyContinue
if (-not $cmd) { if (-not $cmd) {
$Context.Response.StatusCode = 500 $Context.Response.StatusCode = 500
Send-Text $Context "Handler not found: $fn" Send-Text $Context "Handler not found: $fn"
return return
} }
# If the handler declares a Context parameter, pass it by name. # If the handler declares a Context parameter, pass it by name.
# Otherwise, call it with no args (prevents HttpListenerContext getting bound to -Mode).
if ($cmd.Parameters.ContainsKey('Context')) { if ($cmd.Parameters.ContainsKey('Context')) {
& $fn -Context $Context & $fn -Context $Context
} }
else { else {
& $fn & $fn $Context # or & $fn with no args, up to you
} }
return return
} }