feat: make DDNS domain_name the effective domain across all services
Unit Tests / test (push) Successful in 11m35s

- ConfigManager.get_effective_domain(): returns domain_name when DDNS
  active (pic_ngo/cloudflare/duckdns), domain otherwise. Used by all
  public-facing services so they use the real registered FQDN.
- ConfigManager.get_internal_domain(): always returns _identity.domain
  (CoreDNS zone name, dnsmasq, cell-link invites — stays internal).
- Silent migration: if domain_mode != lan and domain is generic "cell",
  auto-set to {cell_name}.local for unique CoreDNS zone naming.
- caddy_manager: fix custom_domain bug — cloudflare/http01 modes were
  reading identity.get('custom_domain') which never exists; now reads
  domain_name correctly.
- routes/config, app: expose effective_domain in GET /api/config and
  /api/status responses.
- email_manager, routes/email: use get_effective_domain() for
  OVERRIDE_HOSTNAME, POSTMASTER_ADDRESS, and new-user email defaults.
- ServiceBus.IDENTITY_CHANGED event: emitted from PUT /api/config and
  POST /api/ddns/register after identity writes; caddy_manager and
  email_manager subscribe to regenerate config automatically.
- Settings.jsx: hide Local Domain input in non-LAN modes; show
  read-only effective_domain with "managed by DDNS" badge and an
  Advanced toggle for the internal CoreDNS zone name.
- 11 new test classes covering all new helpers, event subscriptions,
  caddy/email handlers, and the custom_domain fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 02:48:47 -04:00
parent 393d56d4ca
commit 1f016de855
13 changed files with 403 additions and 25 deletions
+32
View File
@@ -45,6 +45,21 @@ class ConfigManager:
self.configs['connectivity'] = {'exits': {}, 'peer_exit_map': {}}
if not self.config_file.exists():
self._save_all_configs()
# Silent migration: when DDNS is active but the internal domain is still
# the generic "cell" default, give CoreDNS a unique zone name so multiple
# cells on the same LAN don't collide.
try:
_ident = self.configs.get('_identity', {})
_mode = _ident.get('domain_mode', 'lan')
_domain = _ident.get('domain', '')
_cell_name = _ident.get('cell_name', '')
if (_mode != 'lan' and _cell_name
and (_domain in ('cell', '', None))):
_new_domain = f'{_cell_name}.local'
self.configs['_identity']['domain'] = _new_domain
self._save_all_configs()
except Exception:
pass
def _load_service_schemas(self) -> Dict[str, Dict]:
"""Load configuration schemas for all services"""
@@ -478,6 +493,23 @@ class ConfigManager:
"""Return the current identity configuration."""
return self.configs.get('_identity', {})
def get_effective_domain(self) -> str:
"""Return the FQDN that public-facing services should use.
In lan mode: _identity.domain. Otherwise: _identity.domain_name
(falls back to domain if domain_name not yet registered)."""
ident = self.get_identity()
mode = ident.get('domain_mode', 'lan')
if mode == 'lan':
return ident.get('domain') or os.environ.get('CELL_DOMAIN', 'cell')
return (ident.get('domain_name')
or ident.get('domain')
or os.environ.get('CELL_DOMAIN', 'cell'))
def get_internal_domain(self) -> str:
"""Return the CoreDNS zone name (always _identity.domain)."""
ident = self.get_identity()
return ident.get('domain') or os.environ.get('CELL_DOMAIN', 'cell')
def set_identity_field(self, key: str, value: Any):
"""Set a single field in the identity configuration and persist."""
if '_identity' not in self.configs: