Add role-specific welcome wallpapers
This commit is contained in:
1 parent
c7c0f941d4
commit
fd051dee80
17 files changed
+345
-35
No files matched your search
@@ -2,6 +2,8 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$BaseImagePath = (Join-Path $env:ProgramData 'SGU\Branding\darkblue.jpg'),
|
||||
[string]$AdministrativeBaseImagePath = (Join-Path $env:ProgramData 'SGU\Branding\darkgray-administrative.png'),
|
||||
[string]$ProfessorBaseImagePath = (Join-Path $env:ProgramData 'SGU\Branding\darkred-professor.png'),
|
||||
[string]$FontsPath = (Join-Path $env:ProgramData 'SGU\Branding\fonts'),
|
||||
[string]$OutputPath,
|
||||
[string]$DisplayName,
|
||||
@@ -10,6 +12,8 @@ param(
|
||||
[string]$OrganizationalUnit,
|
||||
[ValidateSet('Male', 'Female')]
|
||||
[string]$Gender,
|
||||
[ValidateSet('Administrative', 'Professor')]
|
||||
[string]$InstitutionalRole,
|
||||
[ValidateRange(640, 16384)]
|
||||
[int]$CanvasWidth,
|
||||
[ValidateRange(480, 16384)]
|
||||
@@ -249,6 +253,92 @@ function Get-WelcomeHeading {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-SguSessionInstitutionalRole {
|
||||
# The role comes from the logon token rather than a directory query. That
|
||||
# keeps the correct institutional base available when a domain controller
|
||||
# is temporarily unavailable after an interactive sign-in.
|
||||
try {
|
||||
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$roles = @()
|
||||
foreach ($groupSid in @($identity.Groups)) {
|
||||
try {
|
||||
$accountName = [string]$groupSid.Translate([Security.Principal.NTAccount]).Value
|
||||
$groupName = ($accountName -split '\\')[-1]
|
||||
if ([string]::Equals($groupName, 'SGU-Administrativos', [StringComparison]::OrdinalIgnoreCase)) {
|
||||
$roles += 'Administrative'
|
||||
}
|
||||
elseif ([string]::Equals($groupName, 'SGU-Docentes', [StringComparison]::OrdinalIgnoreCase)) {
|
||||
$roles += 'Professor'
|
||||
}
|
||||
}
|
||||
catch {
|
||||
# A stale or unresolved SID must not prevent desktop startup.
|
||||
}
|
||||
}
|
||||
$roles = @($roles | Select-Object -Unique)
|
||||
if ($roles.Count -eq 1) {
|
||||
return [string]$roles[0]
|
||||
}
|
||||
if ($roles.Count -gt 1) {
|
||||
Write-WelcomeLog -Message 'WARN Multiple SGU role groups were present; using the neutral desktop base.'
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-WelcomeLog -Message ('WARN SGU role lookup was unavailable: ' + $_.Exception.Message)
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Resolve-SguWelcomeBaseImage {
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$DefaultPath,
|
||||
[string]$AdministrativePath,
|
||||
[string]$ProfessorPath,
|
||||
[string]$Role
|
||||
)
|
||||
|
||||
$rolePath = switch ($Role) {
|
||||
'Administrative' { $AdministrativePath; break }
|
||||
'Professor' { $ProfessorPath; break }
|
||||
default { $null }
|
||||
}
|
||||
if ($rolePath -and (Test-Path -LiteralPath $rolePath -PathType Leaf)) {
|
||||
return $rolePath
|
||||
}
|
||||
if ($rolePath) {
|
||||
Write-WelcomeLog -Message ("WARN The {0} wallpaper base is missing; using the neutral base." -f $Role)
|
||||
}
|
||||
return $DefaultPath
|
||||
}
|
||||
|
||||
function Get-SguWelcomePalette {
|
||||
param([string]$Role)
|
||||
|
||||
switch ($Role) {
|
||||
'Professor' {
|
||||
return [pscustomobject]@{
|
||||
Panel = [Drawing.Color]::FromArgb(82, 45, 0, 9)
|
||||
Accent = [Drawing.Color]::FromArgb(255, 255, 226, 232)
|
||||
Line = [Drawing.Color]::FromArgb(160, 255, 226, 232)
|
||||
}
|
||||
}
|
||||
'Administrative' {
|
||||
return [pscustomobject]@{
|
||||
Panel = [Drawing.Color]::FromArgb(82, 8, 8, 8)
|
||||
Accent = [Drawing.Color]::FromArgb(255, 238, 238, 238)
|
||||
Line = [Drawing.Color]::FromArgb(160, 238, 238, 238)
|
||||
}
|
||||
}
|
||||
default {
|
||||
return [pscustomobject]@{
|
||||
Panel = [Drawing.Color]::FromArgb(72, 0, 13, 58)
|
||||
Accent = [Drawing.Color]::FromArgb(255, 211, 226, 255)
|
||||
Line = [Drawing.Color]::FromArgb(155, 211, 226, 255)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Get-AvailableFontFamily {
|
||||
param(
|
||||
[Parameter(Mandatory)][string[]]$Candidates,
|
||||
@@ -311,10 +401,6 @@ trap {
|
||||
throw
|
||||
}
|
||||
|
||||
if (-not (Test-Path -LiteralPath $BaseImagePath -PathType Leaf)) {
|
||||
throw "The welcome wallpaper base image does not exist: $BaseImagePath"
|
||||
}
|
||||
|
||||
$userName = [Environment]::UserName
|
||||
$metadata = $null
|
||||
$machineLocation = [Environment]::GetEnvironmentVariable('SGU_WELCOME_LOCATION', 'Machine')
|
||||
@@ -340,6 +426,22 @@ if (-not $PSBoundParameters.ContainsKey('DisplayName')) {
|
||||
if (-not $DisplayName) {
|
||||
$DisplayName = $userName
|
||||
}
|
||||
if (-not $PSBoundParameters.ContainsKey('InstitutionalRole')) {
|
||||
$detectedInstitutionalRole = Get-SguSessionInstitutionalRole
|
||||
# Like Gender, InstitutionalRole is ValidateSet-bound. Do not assign a
|
||||
# missing token role because PowerShell validates even an explicit $null.
|
||||
if ($detectedInstitutionalRole -in @('Administrative', 'Professor')) {
|
||||
$InstitutionalRole = $detectedInstitutionalRole
|
||||
}
|
||||
}
|
||||
$selectedBaseImagePath = Resolve-SguWelcomeBaseImage `
|
||||
-DefaultPath $BaseImagePath `
|
||||
-AdministrativePath $AdministrativeBaseImagePath `
|
||||
-ProfessorPath $ProfessorBaseImagePath `
|
||||
-Role $InstitutionalRole
|
||||
if (-not (Test-Path -LiteralPath $selectedBaseImagePath -PathType Leaf)) {
|
||||
throw "The welcome wallpaper base image does not exist: $selectedBaseImagePath"
|
||||
}
|
||||
if (-not $PSBoundParameters.ContainsKey('Location')) {
|
||||
$Location = if ($machineLocation) { $machineLocation } elseif ($metadata) { $metadata.Location } else { $null }
|
||||
}
|
||||
@@ -386,7 +488,7 @@ if (-not $OutputPath) {
|
||||
}
|
||||
New-Item -ItemType Directory -Path (Split-Path $OutputPath -Parent) -Force | Out-Null
|
||||
|
||||
$source = [Drawing.Image]::FromFile($BaseImagePath)
|
||||
$source = [Drawing.Image]::FromFile($selectedBaseImagePath)
|
||||
$canvas = [Drawing.Bitmap]::new($CanvasWidth, $CanvasHeight, [Drawing.Imaging.PixelFormat]::Format24bppRgb)
|
||||
try {
|
||||
$graphics = [Drawing.Graphics]::FromImage($canvas)
|
||||
@@ -424,10 +526,11 @@ try {
|
||||
$panelHeight = [single](310 * $scale)
|
||||
$panelX = [single](($CanvasWidth - $panelWidth) / 2)
|
||||
$panelY = [single]($CanvasHeight * 0.50 - ($panelHeight / 2))
|
||||
$panelBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(72, 0, 13, 58))
|
||||
$palette = Get-SguWelcomePalette -Role $InstitutionalRole
|
||||
$panelBrush = [Drawing.SolidBrush]::new($palette.Panel)
|
||||
$whiteBrush = [Drawing.SolidBrush]::new([Drawing.Color]::White)
|
||||
$accentBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(255, 211, 226, 255))
|
||||
$linePen = [Drawing.Pen]::new([Drawing.Color]::FromArgb(155, 211, 226, 255), [single](2 * $scale))
|
||||
$accentBrush = [Drawing.SolidBrush]::new($palette.Accent)
|
||||
$linePen = [Drawing.Pen]::new($palette.Line, [single](2 * $scale))
|
||||
$privateFonts = [Drawing.Text.PrivateFontCollection]::new()
|
||||
if (Test-Path -LiteralPath $FontsPath -PathType Container) {
|
||||
foreach ($fontFile in Get-ChildItem -LiteralPath $FontsPath -File |
|
||||
@@ -536,13 +639,16 @@ namespace Sgu {
|
||||
}
|
||||
|
||||
$genderLogValue = if ($Gender) { $Gender } else { 'Neutral' }
|
||||
Write-WelcomeLog -Message ("OK computer={0}; gender={1}; location={2}; ou={3}; output={4}" -f $ComputerName,$genderLogValue,[bool]$Location,[bool]$OrganizationalUnit,$OutputPath)
|
||||
$roleLogValue = if ($InstitutionalRole) { $InstitutionalRole } else { 'Neutral' }
|
||||
Write-WelcomeLog -Message ("OK computer={0}; gender={1}; role={2}; location={3}; ou={4}; output={5}" -f $ComputerName,$genderLogValue,$roleLogValue,[bool]$Location,[bool]$OrganizationalUnit,$OutputPath)
|
||||
[pscustomobject]@{
|
||||
DisplayName = $DisplayName
|
||||
ComputerName = $ComputerName
|
||||
Location = $Location
|
||||
OrganizationalUnit = $OrganizationalUnit
|
||||
Gender = $Gender
|
||||
InstitutionalRole = $InstitutionalRole
|
||||
BaseImagePath = $selectedBaseImagePath
|
||||
WelcomeHeading = $welcomeHeading
|
||||
LocationText = $locationText
|
||||
LocationPrimaryText = $locationPrimaryText
|
||||
|
||||
Reference in new issue
Block a user