Skip to main content

agentmux_srv/server/
lan_firewall_handlers.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! `lan:firewall:setup`: the AgentMux window's button that runs the Windows Firewall setup
5//! (`docs/specs/SPEC_LAN_FIREWALL_SETUP_2026_10_01.md` 4.2).
6//!
7//! **Window-only.** Windows asks the person for administrator permission, and that prompt should follow the person's own
8//! click, never an agent's call. Started only by this command: nothing starts it on its own, and a cancel is not retried.
9
10use std::sync::Arc;
11
12use crate::backend::lan::{firewall, firewall_setup};
13use crate::backend::rpc::engine::WshRpcEngine;
14use crate::backend::rpc_types::{CommandLanFirewallSetupData, LanFirewallSetupResult, RpcContext, COMMAND_LAN_FIREWALL_SETUP};
15
16const WHY: &str = "only the person asks for the firewall setup, in the AgentMux window";
17
18async fn setup(ctx: &RpcContext) -> Result<LanFirewallSetupResult, String> {
19    ctx.operator_only(WHY)?;
20    let result = tokio::task::spawn_blocking(firewall_setup::run_blocking).await.map_err(|e| format!("lan:firewall:setup: {e}"))?;
21    tracing::info!(outcome = ?result.outcome, "LAN firewall setup asked for from the window");
22    firewall::read_again_now();
23    Ok(result)
24}
25
26pub fn register(engine: &Arc<WshRpcEngine>) {
27    engine.register_typed(COMMAND_LAN_FIREWALL_SETUP, move |_cmd: CommandLanFirewallSetupData, ctx| async move { setup(&ctx).await });
28}