From 5d3d9aafa49c4996a34c339d8f519111c26aa830 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Wed, 14 Jan 2026 02:12:16 -0500 Subject: [PATCH] Add src/handlers.onboard.ps1 --- src/handlers.onboard.ps1 | 141 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/handlers.onboard.ps1 diff --git a/src/handlers.onboard.ps1 b/src/handlers.onboard.ps1 new file mode 100644 index 0000000..6f7b409 --- /dev/null +++ b/src/handlers.onboard.ps1 @@ -0,0 +1,141 @@ +function Invoke-SetSVSPowerPlan { + param($Context) + Set-SVSPowerPlan + Write-LogHybrid "PowerPlan set" "Success" "OnBoard" + Send-Text $Context "PowerPlan applied" +} + +function Invoke-InstallSVSMSP { + param($Context) + Write-LogHybrid "HTTP trigger: Invoke-InstallSVSMSP" "Info" "OnBoard" + try { + Install-SVSMSP -InstallToolkit + Send-Text $Context "SVSMSP Module installed/updated." + } catch { + Write-LogHybrid "Error in Install-SVSMSP: $_" "Error" "OnBoard" + Send-Text $Context "ERROR: $_" + } +} + +function Invoke-InstallCyberQP { param($Context) + Install-CyberQP + Write-LogHybrid "CyberQP installed" "Success" "OnBoard" + Send-Text $Context "CyberQP installed" +} + +function Invoke-InstallThreatLocker { param($Context) + Install-ThreatLocker + Write-LogHybrid "ThreatLocker installed" "Success" "OnBoard" + Send-Text $Context "ThreatLocker installed" +} + +function Invoke-InstallRocketCyber { param($Context) + Install-RocketCyber + Write-LogHybrid "RocketCyber installed" "Success" "OnBoard" + Send-Text $Context "RocketCyber installed" +} + +function Invoke-InstallHelpDesk { param($Context) + Install-svsHelpDesk + Write-LogHybrid "SVS HelpDesk installed" "Success" "OnBoard" + Send-Text $Context "SVS HelpDesk installed" +} + +function Invoke-SetEdgeDefaultSearchEngine { + param($Context) + + try { + Write-LogHybrid "Configuring Edge default search provider" Info OnBoard + set-EdgeDefaultSearchEngine + Write-LogHybrid "Edge default search set to Google" Success OnBoard + Send-Text $Context "Edge default search provider configured." + } catch { + Write-LogHybrid "Failed to set Edge default search: $($_.Exception.Message)" Error OnBoard + Send-Text $Context "ERROR: $($_.Exception.Message)" + } +} + +function Invoke-RenameComputer { + param($Context) + + try { + if ($Context.Request.HttpMethod -ne 'POST') { + $Context.Response.StatusCode = 405 + Send-Text $Context 'Use POST' + return + } + + $rawBody = (New-Object IO.StreamReader $Context.Request.InputStream).ReadToEnd() + if (-not $rawBody) { + $Context.Response.StatusCode = 400 + Send-Text $Context 'Missing request body.' + return + } + + try { $body = $rawBody | ConvertFrom-Json } + catch { + $Context.Response.StatusCode = 400 + Send-Text $Context 'Invalid JSON body.' + return + } + + $newName = $body.newName + + if (-not (Test-ComputerName -Name $newName)) { + Write-LogHybrid "RenameComputer: invalid computer name '$newName'." Error OnBoard -LogToEvent + $Context.Response.StatusCode = 400 + Send-JSON $Context @{ + Success = $false + Error = "Invalid computer name. Must be 1-15 characters and use only letters, numbers, and hyphens." + } + return + } + + Write-LogHybrid "RenameComputer: renaming computer to '$newName'." Info OnBoard -LogToEvent + + try { + Rename-Computer -NewName $newName -Force -ErrorAction Stop + } catch { + Write-LogHybrid "RenameComputer: rename failed: $($_.Exception.Message)" Error OnBoard -LogToEvent + $Context.Response.StatusCode = 500 + Send-JSON $Context @{ + Success = $false + Error = $_.Exception.Message + } + return + } + + Write-LogHybrid "RenameComputer: rename complete, reboot required for new name to apply." Success OnBoard -LogToEvent + Send-JSON $Context @{ + Success = $true + NewName = $newName + Note = "Rename successful. A reboot is required for the new name to take effect." + } + } catch { + Write-LogHybrid "Invoke-RenameComputer fatal error: $($_.Exception.Message)" Error OnBoard -LogToEvent + $Context.Response.StatusCode = 500 + Send-Text $Context "Internal error during computer rename." + } +} + +function Invoke-InstallChrome { param($Context) + try { + winget install --id=Google.Chrome --silent --accept-package-agreements --accept-source-agreements + Write-LogHybrid "Installed Google Chrome via winget" Success SVSApps -LogToEvent + Send-Text $Context "Chrome installed" + } catch { + Write-LogHybrid "Chrome install failed: $($_.Exception.Message)" Error SVSApps -LogToEvent + Send-Text $Context "ERROR: $($_.Exception.Message)" + } +} + +function Invoke-InstallAcrobat { param($Context) + try { + winget install --id=Adobe.Acrobat.Reader.64-bit --silent --accept-package-agreements --accept-source-agreements + Write-LogHybrid "Installed Adobe Acrobat Reader (64-bit) via winget" Success SVSApps -LogToEvent + Send-Text $Context "Acrobat Reader installed" + } catch { + Write-LogHybrid "Acrobat install failed: $($_.Exception.Message)" Error SVSApps -LogToEvent + Send-Text $Context "ERROR: $($_.Exception.Message)" + } +}