Resolve Sala Inmersiva workgroup names from CED

This commit is contained in:
alexrg committed 2026-10-01 15:48:04 -06:00
1 parent 2c90802930
commit 046a815962
3 files changed
+146 -3

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
# Local elevated setup for the workgroup administration PC, LCI-77.
# Domain computers receive the existing CED DNS GPO instead.
[CmdletBinding()]
param(
[string]$InterfaceAlias = 'Wi-Fi',
[string]$BackupPath = 'C:\Users\alex\Documents\CED-Network-Private\LCI77-Sala-DNS-before.json'
)
$ErrorActionPreference = 'Stop'
if ($env:COMPUTERNAME -ne 'LCI-77') { throw 'This setup is only for LCI-77.' }
$client = Get-DnsClient -InterfaceAlias $InterfaceAlias
if (-not (Test-Path -LiteralPath $BackupPath)) {
$client | Select-Object InterfaceAlias, ConnectionSpecificSuffix |
ConvertTo-Json | Set-Content -LiteralPath $BackupPath -Encoding UTF8
}
Set-DnsClient -InterfaceAlias $InterfaceAlias -ConnectionSpecificSuffix 'lci.lasalle.mx'
$rules = @(Get-DnsClientNrptRule | Where-Object { $_.Namespace -contains '.lci.lasalle.mx' })
if ($rules.Count -gt 0 -and ($rules.Count -ne 1 -or $rules[0].NameServers -ne '192.168.54.211')) {
throw 'An existing domain DNS rule needs review; it was not overwritten.'
}
if ($rules.Count -eq 0) {
Add-DnsClientNrptRule -Namespace '.lci.lasalle.mx' -NameServers '192.168.54.211' -Comment 'CED domain DNS for local administrator Wi-Fi'
}
Clear-DnsClientCache
[pscustomobject]@{
Computer = $env:COMPUTERNAME
Suffix = (Get-DnsClient -InterfaceAlias $InterfaceAlias).ConnectionSpecificSuffix
SI04 = @([Net.Dns]::GetHostAddresses('SI-04') | ForEach-Object IPAddressToString)
}
+69
View File
@@ -0,0 +1,69 @@
# Run locally on SGU-DC02 as SYSTEM. The protected manifest owns only explicitly
# approved workgroup names; never import arbitrary router clients into AD DNS.
[CmdletBinding()]
param(
[string]$ManifestPath = 'C:\ProgramData\LCI-Admin\Sala-DNS\manifest.json'
)
$ErrorActionPreference = 'Stop'
Import-Module DnsServer
Import-Module ActiveDirectory
if ($env:COMPUTERNAME -ne 'SGU-DC02') { throw 'Run this sync on SGU-DC02.' }
$manifest = Get-Content -LiteralPath $ManifestPath -Raw | ConvertFrom-Json
if ($manifest.Zone -ne 'lci.lasalle.mx' -or $manifest.RouterDns -ne '192.168.55.1') {
throw 'Unexpected DNS zone or router in the manifest.'
}
$results = @()
$failed = $false
foreach ($entry in $manifest.Records) {
$result = [ordered]@{ Name = $entry.Name; Status = ''; IP = $null; Error = $null }
try {
if ($entry.Name -notmatch '^si-\d{2}$') { throw 'Name is outside the approved SI naming pattern.' }
# After domain enrollment, leave DNS management to the machine's secure
# registration. Do not fight a domain client or overwrite someone else's A.
$adObject = Get-ADComputer -Server $env:COMPUTERNAME -Filter "Name -eq '$($entry.Name)'"
if ($adObject) {
$result.Status = 'DomainManaged'
} else {
$records = @(Get-DnsServerResourceRecord -ZoneName $manifest.Zone -Name $entry.Name -ErrorAction SilentlyContinue)
if ($records.Count -gt 0 -and ($records.Count -ne 1 -or $records[0].RecordType -ne 'A' -or
$records[0].RecordData.IPv4Address.IPAddressToString -ne $entry.LastPublishedIP)) {
throw 'DNS record differs from the owned record; refusing to overwrite it.'
}
$addresses = @(Resolve-DnsName -Name "$($entry.Name)." -Server $manifest.RouterDns -Type A -DnsOnly -QuickTimeout |
Where-Object Type -eq A | Select-Object -ExpandProperty IPAddress -Unique)
if ($addresses.Count -ne 1 -or $addresses[0] -notmatch '^192\.168\.55\.(\d{1,3})$' -or
[int]$Matches[1] -lt 2 -or [int]$Matches[1] -gt 254) {
throw 'Router did not return a single host address in Sala Inmersiva.'
}
$address = $addresses[0]
if ($records.Count -eq 0) {
Add-DnsServerResourceRecordA -ZoneName $manifest.Zone -Name $entry.Name -IPv4Address $address -TimeToLive ([TimeSpan]::FromMinutes(5))
$result.Status = 'Created'
} elseif ($address -ne $entry.LastPublishedIP) {
$updated = $records[0].Clone()
$updated.RecordData.IPv4Address = [Net.IPAddress]::Parse($address)
$updated.TimeToLive = [TimeSpan]::FromMinutes(5)
Set-DnsServerResourceRecord -ZoneName $manifest.Zone -OldInputObject $records[0] -NewInputObject $updated
$result.Status = 'Updated'
} else {
$result.Status = 'Current'
}
$entry.LastPublishedIP = $address
$result.IP = $address
}
} catch {
$result.Status = 'Error'
$result.Error = $_.Exception.Message
$failed = $true
}
$results += [pscustomobject]$result
}
# A failed router query preserves the last record. TTL limits client caching,
# not record lifetime: operators must review errors instead of assuming freshness.
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath "$ManifestPath.next" -Encoding UTF8
Move-Item -LiteralPath "$ManifestPath.next" -Destination $ManifestPath -Force
[pscustomobject]@{ Time = (Get-Date).ToString('o'); Records = $results } |
ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path (Split-Path $ManifestPath) 'last-result.json') -Encoding UTF8
$results
if ($failed) { throw 'One or more Sala DNS records could not be synchronized. See last-result.json.' }