feat: add gateway setup wizard and fix test suite

New zt-gateway-setup script with subcommands for configuring this
router as a ZeroTier exit gateway: bridge, routing (tables 100/101),
DHCP, hotplug, and persistence. Exposes setup ubus method via backend
with ACL and LuCI panel in overview.

Also fixes two pre-existing test issues:
- overview.spec.ts: active gateway radio is intentionally enabled
  (users need to re-trigger switch for the already-selected gateway)
- drain.spec.ts: stubs drain status via page.route() since Docker
  has no real conntrack entries; fixed Playwright glob pattern bug
  where **/ubus* fails to match /ubus/?timestamp (regex needed)
This commit is contained in:
2026-07-13 08:48:53 +05:30
parent fbbddd2850
commit cd429291ef
9 changed files with 728 additions and 23 deletions

View File

@@ -4,7 +4,7 @@
"read": {
"uci": ["zt-gateway", "network"],
"ubus": {
"zt-gateway": ["status", "health", "drain_status"]
"zt-gateway": ["status", "health", "drain_status", "setup"]
},
"file": {
"/etc/hotplug.d/net/99-zerotier-bridge": ["read"],
@@ -14,7 +14,7 @@
"write": {
"uci": ["zt-gateway", "network"],
"ubus": {
"zt-gateway": ["switch", "cancel_drain"]
"zt-gateway": ["switch", "cancel_drain", "setup"]
},
"file": {
"/etc/hotplug.d/net/99-zerotier-bridge": ["write"],

View File

@@ -181,10 +181,6 @@ return {
return { success: false, message: `Unknown gateway region: ${region}` };
}
const current_region = read_active_region();
if (current_region === region && !drain_active()) {
return { success: true, message: `Already on ${region}.` };
}
const result = run_switch_script_capture(gw.ip, mode);
if (result.code !== 0) {
@@ -297,6 +293,39 @@ return {
: (result.stderr || `Cancel failed with code ${result.code}`)
};
}
},
setup: {
args: {
command: 'string'
},
call: function(req) {
const command = req.args?.command;
if (!command || !match(command, /^(status|setup-bridge|setup-routing|setup-dhcp|setup-hotplug|setup-persistence|setup-all)$/)) {
return {
success: false,
message: 'Invalid command. Valid: status, setup-bridge, setup-routing, setup-dhcp, setup-hotplug, setup-persistence, setup-all'
};
}
const stderr_pipe = '/tmp/zt-gw-setup-stderr';
const code = system(`/usr/sbin/zt-gateway-setup ${shell_quote(command)} 2>${stderr_pipe}`);
const err = fs.readfile(stderr_pipe) ?? '';
fs.unlink(stderr_pipe);
if (code !== 0) {
return {
success: false,
message: trim(err) || `Setup failed with exit code ${code}`
};
}
return {
success: true,
message: trim(err) || `${command} completed successfully`,
command: command
};
}
}
}
};