Update samy.ps1
This commit is contained in:
39
samy.ps1
39
samy.ps1
@@ -177,24 +177,22 @@ if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage' -or
|
|||||||
# 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 `
|
||||||
@@ -2057,23 +2057,22 @@ function Install-DattoRMM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ---- 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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user