Update samy.ps1

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

View File

@@ -177,24 +177,22 @@ if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage' -or
# Rebuild the original argument list as a string to pass through
$argList = @()
foreach ($a in $args) {
if ($a -is [string]) {
# Quote and escape any existing quotes
$escaped = $a.Replace('"','`"')
$argList += "`"$escaped`""
} else {
$argList += $a.ToString()
$argList += [string]$a
}
}
$argString = $argList -join ' '
# Only needed for the -Command path (string has to be re-parsed)
$argString = ($argList | ForEach-Object {
'"' + ($_ -replace '"','`"') + '"'
}) -join ' '
if ($PSCommandPath) {
# Script saved on disk: re-run same file with same args
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "`"$PSCommandPath`"" $argString
# FIX: do NOT pass $argString as one argument
# You want PowerShell to see each token separately.
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$PSCommandPath" @argList
} 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"
}
exit
}
@@ -1871,8 +1869,10 @@ function Install-DattoRMM {
if ($UseWebhook) {
# 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
}
try {
$resp = Invoke-RestMethod -Uri $WebhookUrl `
@@ -2057,23 +2057,22 @@ function Install-DattoRMM {
}
# ---- Task invocation ----
$task = $Global:SamyTasks | Where-Object Name -EQ $path $task = $Global:SamyTasks | Where-Object Name -EQ $path
if ($task) { if ($task) {
& $task.HandlerFn $Context
return $fn = $task.HandlerFn
} $cmd = Get-Command $fn -ErrorAction SilentlyContinue
$task = $Global:SamyTasks | Where-Object Name -EQ $path
if ($task) {
$fn = $task.HandlerFn
$cmd = Get-Command $fn -ErrorAction SilentlyContinue
if (-not $cmd) {
$Context.Response.StatusCode = 500
Send-Text $Context "Handler not found: $fn"
return
}
# 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')) {
& $fn -Context $Context
}
else {
& $fn
& $fn $Context # or & $fn with no args, up to you
}
return
}