# DNS Viewer — Execução e versionamento

**Responsável:** Cursor Agent · **Aprovado por:** Roger  
**Data início:** 2026-06-25 · **Última actualização:** 2026-06-25  
**Spec:** [dns-viewer.md](../dns-viewer.md) · Rollback: [DNS-VIEWER-ROLLBACK.md](./DNS-VIEWER-ROLLBACK.md)

---

## Escopo desta execução

| Fase | Estado | VM | Entregável |
|------|--------|-----|------------|
| V0 | ✅ baseline | VM122 | `cloudflare_dns.py` + modal Desk CF |
| V1 | ✅ deploy OK | VM122 | `GET /api/v1/dns/viewer/{domain}` |
| V1b | ✅ deploy OK | VM122 | `dns-viewer.js` + modais Overview/IaaS |
| V2 | ✅ deploy OK | VM122 | `openpanel_dns.py` + `GET /api/v1/dns/openpanel/records` |
| V3 | ✅ deploy OK | VM123 | `/admin/dominio` + `DnsViewerPanel.jsx` |
| V4 | 📋 patches no repo | VM112 | Painel wizard — **deploy pendente** (SSH) |

---

## Checklist pré-deploy (obrigatório)

```bash
# CT130 — tag git
cd /opt/ligbox-spec-hub/repos/ligbox-ops-platform
git tag -a dns-viewer-pre-v1-$(date +%Y%m%d) -m "Antes DNS Viewer V1"

# VM122 — backup (CT130: export SSHPASS=805353)
export SSHPASS='805353'
bash specs/037-dns-multi-cloudflare-orchestration/deploy/scripts/preflight-dns-viewer.sh \
  --host root@10.10.10.122
```

Para V3 Console:

```bash
bash specs/037-dns-multi-cloudflare-orchestration/deploy/scripts/preflight-dns-viewer.sh \
  --host root@10.10.10.123 --console
```

---

## Ficheiros versionados (monorepo)

| Ficheiro | Fase | Notas |
|----------|------|-------|
| `projects/ops-desk/api/app/cloudflare_dns.py` | V0 | Provider CF — manter |
| `projects/ops-desk/api/app/dns_viewer.py` | V1 | Orquestrador |
| `projects/ops-desk/api/app/openpanel_dns.py` | V2 | BIND via `dig @10.10.10.123` |
| `projects/ops-desk/api/app/domain_console_routes.py` | V3 | Proxy Console |
| `projects/ops-desk/api/app/main.py` | V1+ | Rotas + `require_internal_or_user` |
| `projects/ops-desk/api/app/permissions.py` | V1 | `can_read_dns_viewer` |
| `projects/ops-desk/frontend/assets/dns-viewer.js` | V1b | Componente Desk |
| `projects/ops-desk/frontend/assets/app.js` | V1b | Integração modais |
| `specs/019-.../deploy/frontend/src/views/admin/AdminDominio.jsx` | V3 | Página Console |
| `specs/019-.../deploy/frontend/src/components/DnsViewerPanel.jsx` | V3 | Componente partilhado |
| `deploy/vm112-wizard/onboarding-dns-viewer-v4.patch.py` | V4 | Backend wizard |
| `deploy/vm112-wizard/frontend-dns-viewer-v4.patch.py` | V4 | Frontend wizard |
| `deploy/vm112-wizard/DNS-VIEWER-V4.md` | V4 | Runbook |

---

## Deploy VM122 (V1/V1b/V2)

```bash
REPO=/opt/ligbox-spec-hub/repos/ligbox-ops-platform
rsync -av "$REPO/projects/ops-desk/api/app/" root@10.10.10.122:/opt/ligbox-ops-platform/api/app/
rsync -av "$REPO/projects/ops-desk/frontend/assets/" root@10.10.10.122:/opt/ligbox-ops-platform/frontend/assets/

ssh root@10.10.10.122 'cd /opt/ligbox-ops-platform && \
  grep -q DNS_VIEWER_ENABLED .env || echo DNS_VIEWER_ENABLED=1 >> .env && \
  docker cp api/app/. ligbox-ops-platform_api_1:/app/app/ && \
  docker restart ligbox-ops-platform_api_1 && \
  docker compose -f docker-compose.mvp.yml up -d frontend'
```

**Importante:** API corre em container — `rsync` ao host **não** actualiza runtime sem `docker cp` ou rebuild.

---

## Deploy VM123 (V3 Console)

```bash
REPO=/opt/ligbox-spec-hub/repos/ligbox-ops-platform
cd "$REPO/specs/019-ops-console-active-operations/deploy/frontend"
npm run build
tar cf - dist | ssh root@10.10.10.123 'cd /opt/ligbox-ops-console && rm -rf frontend/* && tar xf - --strip-components=1 -C frontend'
ssh root@10.10.10.123 'cd /opt/ligbox-ops-console && docker compose up -d --build'
```

URL: `https://console.ligbox.com.br/admin/dominio`

---

## Deploy VM112 (V4 — pendente)

Ver **[deploy/vm112-wizard/DNS-VIEWER-V4.md](../../../deploy/vm112-wizard/DNS-VIEWER-V4.md)**.

Pré-requisitos env wizard:

```bash
DESK_API_URL=http://10.10.10.122:8080
OPS_INTERNAL_TOKEN=<mesmo token Desk>
```

SSH VM112: LAN `10.10.10.112` ou WAN `95.216.14.146:2512` (credencial distinta de VM122/123).

---

## Validação pós-deploy

```bash
bash specs/037-dns-multi-cloudflare-orchestration/deploy/scripts/verify-dns-viewer.sh \
  --host 10.10.10.122

# Console
curl -sS -o /dev/null -w '%{http_code}\n' https://console.ligbox.com.br/admin/dominio

# Manual UI
# Desk → Overview → domínio → secção DNS unificada
# Console → Admin → Domínio & DNS
```

---

## Rollback

Ver **[DNS-VIEWER-ROLLBACK.md](./DNS-VIEWER-ROLLBACK.md)** — ordem:

1. `DNS_VIEWER_ENABLED=0` (30 s)
2. Rollback frontend se UI partida
3. Rollback API se 500
4. `git revert` CT130 se necessário

---

## Registo de versões

| Data | Tag git | VM backup / Docker | Commit | Notas |
|------|---------|-------------------|--------|-------|
| 2026-06-25 | `dns-viewer-pre-v1-20260625` | `.backups/dns-viewer-20260625-161839` | `7e4920a` | Pré-deploy V1 |
| 2026-06-25 | — | Docker `post-dns-viewer-v1-20260625` | — | V1+V1b VM122 · verify PASSED |
| 2026-06-25 | — | VM123 frontend tar deploy | — | V3 Console `/admin/dominio` |
| 2026-06-25 | — | — | `038fb8f` | **Commit monorepo** — Spec 037 entrega V1–V3 + patches V4 |

---

## Pendente

- [ ] Deploy V4 VM112 (patches prontos; SSH bloqueado CT130→112)
- [ ] Formalizar `dns.viewer.read` em Spec 027
- [ ] Actualizar `verify-dns-viewer.sh` com smoke Console `/admin/dominio`
