Update samy.ps1
This commit is contained in:
47
samy.ps1
47
samy.ps1
@@ -174,27 +174,25 @@ if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage' -or
|
||||
|
||||
Write-Host "[Info] Relaunching with ExecutionPolicy Bypass..." -ForegroundColor Yellow
|
||||
|
||||
# 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()
|
||||
}
|
||||
# Rebuild the original argument list as a string to pass through
|
||||
$argList = @()
|
||||
foreach ($a in $args) {
|
||||
$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 `
|
||||
@@ -2056,24 +2056,23 @@ function Install-DattoRMM {
|
||||
return
|
||||
}
|
||||
|
||||
# ---- 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 invocation ----
|
||||
$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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user