aboutsummaryrefslogtreecommitdiffstats
path: root/packaging/win/firewall.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'packaging/win/firewall.ps1')
-rw-r--r--packaging/win/firewall.ps122
1 files changed, 18 insertions, 4 deletions
diff --git a/packaging/win/firewall.ps1 b/packaging/win/firewall.ps1
index bf1b32b..9b3687a 100644
--- a/packaging/win/firewall.ps1
+++ b/packaging/win/firewall.ps1
@@ -29,20 +29,23 @@
Shipped as an extraResource at <install>\resources\firewall.ps1, so it
locates the two executables from its own path and takes no arguments
- beyond the action. Runs elevated and windowless, so it leaves a trace at
- %TEMP%\meshbay-firewall.log.
+ beyond the action. add/remove run elevated and windowless, leaving a
+ trace at %TEMP%\meshbay-firewall.log; check is a plain read (no admin
+ needed -- Get-NetFirewallRule does not require it, only New/Remove do)
+ that the installer runs first, unelevated, so re-running setup with the
+ rules already in place skips the prompt and the UAC entirely.
.PARAMETER Action
add (default) create/replace the rules
remove delete them
+ check exit 0 if all rules already exist, 1 otherwise -- no admin needed
#>
[CmdletBinding()]
param(
- [ValidateSet("add", "remove")]
+ [ValidateSet("add", "remove", "check")]
[string]$Action = "add"
)
-$ErrorActionPreference = "Stop"
$log = Join-Path $env:TEMP "meshbay-firewall.log"
"[{0}] {1}" -f (Get-Date -Format s), $Action | Add-Content $log
@@ -63,6 +66,17 @@ $rules = @(
@{ Name = "MeshBay Cast Discovery"; Path = $client; Protocol = "UDP"; LocalPort = "5353" }
)
+if ($Action -eq "check") {
+ $missing = $rules | Where-Object { -not (Get-NetFirewallRule -DisplayName $_.Name -ErrorAction SilentlyContinue) }
+ if ($missing) {
+ " check: missing $(($missing | ForEach-Object { $_.Name }) -join ', ')" | Add-Content $log
+ exit 1
+ }
+ " check: all rules present" | Add-Content $log
+ exit 0
+}
+
+$ErrorActionPreference = "Stop"
try {
foreach ($r in $rules) {
# Idempotent: clear any existing rule of this name first.