Harden generic installation and startup, preserve station settings and coalesce mail reads

This commit is contained in:
alberto committed 2026-10-16 21:03:18 +02:00
1 parent 3f6d35690b
commit 5358cad695
14 files changed
+398 -146

No files matched your search

+10 -3
View File
@@ -1,5 +1,12 @@
$ErrorActionPreference='Stop'
$config=Get-Content -LiteralPath (Join-Path $PSScriptRoot 'console.config.json') -Raw | ConvertFrom-Json
$identity=[Security.Principal.WindowsIdentity]::GetCurrent()
if(!([Security.Principal.WindowsPrincipal]::new($identity)).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){throw 'Per creare la regola firewall aprire PowerShell come amministratore.'}
$configPath=if($env:BPQ_CONSOLE_CONFIG){$env:BPQ_CONSOLE_CONFIG}else{Join-Path $PSScriptRoot 'console.config.json'}
$config=Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json
$port=if($env:BPQ_CONSOLE_PORT){[int]$env:BPQ_CONSOLE_PORT}else{[int]$config.port}
if($port -lt 1024 -or $port -gt 65535){throw 'Porta pannello non valida.'}
$nodeExe=if($config.nodeExe -and (Test-Path -LiteralPath $config.nodeExe)){$config.nodeExe}else{(Get-Command node.exe -ErrorAction Stop).Source}
Get-NetFirewallRule -DisplayName 'BPQ Web Console LAN' -ErrorAction SilentlyContinue | Remove-NetFirewallRule
New-NetFirewallRule -DisplayName 'BPQ Web Console LAN' -Direction Inbound -Action Allow -Protocol TCP -LocalPort $config.port -RemoteAddress LocalSubnet -Program $nodeExe -Profile Private | Out-Null
# Create the replacement before removing the previous rule, so failure keeps it intact.
$rule=New-NetFirewallRule -DisplayName 'BPQ Web Console LAN' -Direction Inbound -Action Allow -Protocol TCP -LocalPort $port -RemoteAddress LocalSubnet -Program $nodeExe -Profile Private -ErrorAction Stop
Get-NetFirewallRule -DisplayName 'BPQ Web Console LAN' -ErrorAction SilentlyContinue | Where-Object {$_.Name -ne $rule.Name} | Remove-NetFirewallRule
Write-Host "Accesso LAN abilitato sulla porta $port (rete Privata, sottorete locale)."