Update samy.ps1
This commit is contained in:
153
samy.ps1
153
samy.ps1
@@ -658,6 +658,103 @@ if (-not [System.Diagnostics.EventLog]::SourceExists('$EventSource')) {
|
||||
|
||||
#endregion Write-Log
|
||||
|
||||
#region Remote Assets + Task Loading
|
||||
|
||||
function Get-RemoteText {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
try {
|
||||
$resp = Invoke-WebRequest -Uri $Url -UseBasicParsing -ErrorAction Stop
|
||||
return $resp.Content
|
||||
}
|
||||
catch {
|
||||
# Write-LogHybrid is available here (we placed this block after it)
|
||||
Write-LogHybrid "Get-RemoteText failed for ${Url}: $($_.Exception.Message)" Warning UI -LogToEvent
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function Get-SamyTasks {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
try {
|
||||
$json = Get-RemoteText -Url $Url
|
||||
if ([string]::IsNullOrWhiteSpace($json)) {
|
||||
throw "Tasks JSON was empty."
|
||||
}
|
||||
|
||||
$tasks = $json | ConvertFrom-Json -ErrorAction Stop
|
||||
if (-not $tasks -or @($tasks).Count -eq 0) {
|
||||
throw "Tasks JSON parsed but contained no tasks."
|
||||
}
|
||||
|
||||
return @($tasks)
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Failed to load tasks from ${Url}: $($_.Exception.Message)" Warning UI -LogToEvent
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
function Initialize-SamyTasks {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Url,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[object[]]$FallbackTasks
|
||||
)
|
||||
|
||||
$tasks = Get-SamyTasks -Url $Url
|
||||
if (-not $tasks) {
|
||||
$tasks = @($FallbackTasks)
|
||||
Write-LogHybrid "Using embedded fallback tasks ($($tasks.Count))" Info UI -LogToEvent
|
||||
}
|
||||
else {
|
||||
Write-LogHybrid "Loaded remote tasks ($($tasks.Count))" Success UI -LogToEvent
|
||||
}
|
||||
|
||||
# Ensure every task has a tooltip (default to Label) + safe escaping for title=''
|
||||
foreach ($t in $tasks) {
|
||||
$tooltip = $null
|
||||
if ($t.PSObject.Properties.Name -contains 'Tooltip') {
|
||||
$tooltip = [string]$t.Tooltip
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($tooltip)) {
|
||||
$tooltip = [string]$t.Label
|
||||
}
|
||||
|
||||
# Minimal HTML escaping for attribute usage
|
||||
$tooltip = $tooltip -replace '&', '&'
|
||||
$tooltip = $tooltip -replace "'", '''
|
||||
$tooltip = $tooltip -replace '"', '"'
|
||||
$tooltip = $tooltip -replace '<', '<'
|
||||
$tooltip = $tooltip -replace '>', '>'
|
||||
|
||||
if ($t.PSObject.Properties.Name -contains 'Tooltip') {
|
||||
$t.Tooltip = $tooltip
|
||||
}
|
||||
else {
|
||||
$t | Add-Member -NotePropertyName Tooltip -NotePropertyValue $tooltip -Force
|
||||
}
|
||||
}
|
||||
|
||||
return $tasks
|
||||
}
|
||||
|
||||
#endregion Remote Assets + Task Loading
|
||||
|
||||
|
||||
#region Computer rename helpers
|
||||
|
||||
function Test-ComputerName {
|
||||
@@ -706,7 +803,7 @@ $Script:EmbeddedSamyTasks = @(
|
||||
@{ Id='enableBitLocker'; Name='EnableBitLocker'; Label='Enable BitLocker'; HandlerFn='Set-SVSBitLocker'; Page='onboard'; Column='right' },
|
||||
@{ Id='setEdgeDefaultSearch';Name='setedgedefaultsearch';Label='Set Edge Default Search'; Tooltip='Will configure Edge to use Google as default search provider'; HandlerFn='Invoke-SetEdgeDefaultSearchEngine';Page='onboard'; Column='right' },
|
||||
@{ Id='renameComputer'; Name='renameComputer'; Label='Rename Computer'; HandlerFn ='Invoke-RenameComputer'; Page='onboard';Column= 'right' },
|
||||
@{ Id='disableAnimations'; Name='disableAnimations'; Label='Disable Animations'; HandlerFn='Disable-Animations'; Page='onboard' },
|
||||
@{ Id='disableAnimations'; Name='disableAnimations'; Label='Disable Animations'; HandlerFn='Disable-Animations'; Page='onboard';Column= 'right' },
|
||||
@{ Id='wingetChrome'; Name='wingetChrome'; Label='Google Chrome'; HandlerFn='Invoke-InstallChrome'; Page='onboard';Column= 'right' },
|
||||
@{ Id='wingetAcrobat'; Name='wingetAcrobat'; Label='Adobe Acrobat Reader (64-bit)'; HandlerFn='Invoke-InstallAcrobat'; Page='onboard';Column= 'right' },
|
||||
|
||||
@@ -717,18 +814,10 @@ $Script:EmbeddedSamyTasks = @(
|
||||
@{ Id='offUninstallRocketCyber'; Name='offUninstallRocketCyber'; Label='Uninstall RocketCyber'; HandlerFn='Invoke-UninstallRocketCyber'; Page='offboard' },
|
||||
@{ Id='offCleanupSVSMSPModule'; Name='offCleanupSVSMSPModule'; Label='Cleanup SVSMSP Toolkit'; HandlerFn='Invoke-CleanupSVSMSP'; Page='offboard' }
|
||||
|
||||
)
|
||||
|
||||
# Primary: load from repo JSON
|
||||
$loaded = Get-SamyTasks
|
||||
if ($loaded) {
|
||||
$Global:SamyTasks = $loaded
|
||||
} else {
|
||||
$Global:SamyTasks = $Script:EmbeddedSamyTasks
|
||||
}
|
||||
|
||||
) | ForEach-Object { [pscustomobject]$_ }
|
||||
|
||||
|
||||
$Global:SamyTasks = Initialize-SamyTasks -Url $Script:SamyTasksUrl -FallbackTasks $Script:EmbeddedSamyTasks
|
||||
|
||||
#endregion building the Menus
|
||||
|
||||
@@ -879,21 +968,6 @@ if ($loaded) {
|
||||
|
||||
#region UIHtml
|
||||
|
||||
function Get-RemoteText {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$Url
|
||||
)
|
||||
|
||||
try {
|
||||
$resp = Invoke-WebRequest -Uri $Url -UseBasicParsing -ErrorAction Stop
|
||||
return $resp.Content
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Get-RemoteText failed for ${Url}: $($_.Exception.Message)" Warning UI -LogToEvent
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function Get-UIHtml {
|
||||
param([string]$Page = 'onboard')
|
||||
@@ -976,33 +1050,6 @@ function Get-UIHtml {
|
||||
return $html
|
||||
}
|
||||
|
||||
function Get-SamyTasks {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
try {
|
||||
$json = Get-RemoteText -Url $Url
|
||||
if ([string]::IsNullOrWhiteSpace($json)) {
|
||||
throw "Tasks JSON was empty."
|
||||
}
|
||||
|
||||
$tasks = $json | ConvertFrom-Json -ErrorAction Stop
|
||||
|
||||
if (-not $tasks -or $tasks.Count -eq 0) {
|
||||
throw "Tasks JSON parsed but contained no tasks."
|
||||
}
|
||||
|
||||
return $tasks
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Failed to load tasks from ${Url}: $($_.Exception.Message)" Warning UI -LogToEvent
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion UIHtml
|
||||
|
||||
Reference in New Issue
Block a user