added printer tab

This commit is contained in:
2025-12-05 11:52:11 -05:00
parent 18dd5b099f
commit 8fec22610a

159
samy.ps1
View File

@@ -1111,6 +1111,7 @@ $cssContent
<button class="tab-button" data-tab="offboardTab">Off-Boarding</button>
<button class="tab-button" data-tab="tweaksTab">Tweaks</button>
<button class="tab-button" data-tab="SVSAppsTab">SVS APPs</button>
<button class="tab-button" data-tab="devicesTab">Devices</button>
<div id="status-box" style="margin-top: 1em; font-family: monospace;"></div>
</div>
@@ -1198,6 +1199,48 @@ $cssContent
</div>
</div>
</div>
<!-- NEW: Devices tab for printers and future stuff -->
<div id="devicesTab" class="tab-content">
<h2>Devices</h2>
<h3 class="subtitle">Manage printers and other client devices.</h3>
<!-- Printer password + fetch -->
<div id="printerPasswordContainer" style="margin-bottom:1em;">
<label for="PrinterPassword">Enter Printer Password:</label>
<div style="display:flex; gap:5px;">
<input type="password"
id="PrinterPassword"
placeholder="Enter printer password"
style="flex:1;" />
<button onclick="fetchPrinters()" class="go-button">Get Printers</button>
</div>
</div>
<!-- Client code dropdown -->
<div id="printerClientContainer" style="display:none; margin-bottom:1em;">
<label for="printerClientDropdown">Select Client:</label>
<select id="printerClientDropdown" style="width:100%;">
<option disabled selected>Fetch printers first...</option>
</select>
</div>
<!-- Printer checkbox list -->
<div id="printerListContainer" style="display:none; margin-bottom:1em;">
<label>Printers for selected client:</label>
<div id="printerCheckboxContainer"
style="max-height:200px; overflow-y:auto; border:1px solid #444; padding:6px; border-radius:4px;">
<!-- Populated by JS -->
</div>
<button id="installPrintersButton"
class="go-button"
style="margin-top:8px;"
onclick="installSelectedPrinters()">
Install Selected Printers
</button>
</div>
</div>
</div>
</div>
@@ -1644,6 +1687,111 @@ function Invoke-CleanupSVSMSP {
#endregion Offboarding handlers
#region Printer handlers
function Invoke-GetPrinters {
param($Context)
try {
if ($Context.Request.HttpMethod -ne 'POST') {
$Context.Response.StatusCode = 405
Send-Text $Context 'Use POST'
return
}
# Read JSON body: { "password": "..." }
$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
}
$password = $body.password
if (-not $password) {
$Context.Response.StatusCode = 400
Send-Text $Context 'Password is required.'
return
}
$uri = 'https://bananas.svstools.ca/getprinters'
Write-LogHybrid "Fetching printers from $uri" Info Printers -LogToEvent
# NOTE: We never log the actual password
$printers = Get-SamyClientListFromServer -Uri $uri -Password $password
# Return raw objects as JSON; JS will filter/group
Send-JSON $Context $printers
}
catch {
Write-LogHybrid "Invoke-GetPrinters error: $($_.Exception.Message)" Error Printers -LogToEvent
$Context.Response.StatusCode = 500
Send-Text $Context "Internal server error fetching printers."
}
}
function Invoke-InstallPrinters {
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
}
$printers = $body.printers
if (-not $printers -or $printers.Count -eq 0) {
$Context.Response.StatusCode = 400
Send-Text $Context 'No printers specified.'
return
}
foreach ($p in $printers) {
# TODO: Replace this with your real install logic once ready
$msg = "Requested install: ClientCode=$($p.ClientCode) ProfileName=$($p.ProfileName) DisplayName=$($p.DisplayName) Location=$($p.Location)"
Write-LogHybrid $msg Info Printers -LogToEvent
}
$result = @{
Success = $true
Count = $printers.Count
Message = "Printer install requests logged on the SAMY server."
}
Send-JSON $Context $result
}
catch {
Write-LogHybrid "Invoke-InstallPrinters error: $($_.Exception.Message)" Error Printers -LogToEvent
$Context.Response.StatusCode = 500
Send-Text $Context "Internal server error installing printers."
}
}
#endregion Printer handlers
#endregion Handler Stubs
@@ -1905,6 +2053,17 @@ function Install-DattoRMM {
return
}
# ---- Printer endpoints ----
if ($Context.Request.HttpMethod -eq 'POST' -and $path -eq 'getprinters') {
Invoke-GetPrinters $Context
return
}
if ($Context.Request.HttpMethod -eq 'POST' -and $path -eq 'installprinters') {
Invoke-InstallPrinters $Context
return
}
# ---- Serve UI pages ----
if ($path -in @('', 'onboard', 'offboard', 'tweaks', 'SVSApps')) {
$page = if ($path -eq '') { 'onboard' } else { $path }