From aff73455d0d462341f64c2eba992570595f546bb Mon Sep 17 00:00:00 2001 From: Artur Moreira Date: Fri, 27 Mar 2026 10:57:57 +0000 Subject: [PATCH] feat(andebol): public WP login surface, auth nav, /entrar and /registar - Nginx: proxy wp-login.php, wp-includes, wp-admin css/js/images, and wp-content/languages without RFC1918 allow (works with real_ip); keep rest of wp-admin, wp-content, wp-json restricted. - Domain config: auth_links on andebol.net; optional DomainConfig field. - Astro: Portuguese/English auth labels, header/footer links, redirects. - Bridge: omit internal detail from 503 JSON (avoid leaking upstream msgs). - Docs: deployment + domains schema for auth and membership. Co-Authored-By: Paperclip Made-with: Cursor --- bridge/src/server.ts | 2 +- bridge/src/types.ts | 1 + config/domains/andebol.net.json | 7 +- deploy/nginx/newsproject.bitreport.pt.conf | 103 +++++--- docs/deployment.md | 4 +- docs/domains.md | 12 +- frontend/src/lib/auth-labels.ts | 8 + frontend/src/pages/entrar.astro | 9 + frontend/src/pages/registar.astro | 9 + .../src/themes/institutional/Footer.astro | 109 ++++++--- .../src/themes/institutional/Header.astro | 226 +++++++++++++++--- frontend/src/themes/sports/Footer.astro | 9 + frontend/src/themes/sports/Header.astro | 47 ++++ frontend/src/types/index.ts | 21 +- 14 files changed, 455 insertions(+), 112 deletions(-) create mode 100644 frontend/src/lib/auth-labels.ts create mode 100644 frontend/src/pages/entrar.astro create mode 100644 frontend/src/pages/registar.astro diff --git a/bridge/src/server.ts b/bridge/src/server.ts index c906f22..fadaaa9 100644 --- a/bridge/src/server.ts +++ b/bridge/src/server.ts @@ -42,7 +42,7 @@ app.setErrorHandler((err, req, reply) => { if (is_wp_down) { app.log.warn({ url: req.url, err: msg }, 'WP upstream unavailable'); - return reply.code(503).send({ error: 'Upstream unavailable', detail: msg }); + return reply.code(503).send({ error: 'Upstream unavailable' }); } if (err.statusCode && err.statusCode < 500) { diff --git a/bridge/src/types.ts b/bridge/src/types.ts index e97d0b5..4a28607 100644 --- a/bridge/src/types.ts +++ b/bridge/src/types.ts @@ -14,6 +14,7 @@ export interface DomainConfig { timezone: string; ads_enabled: boolean; analytics_id: string | null; + auth_links?: boolean; } export interface CategoryConfig { diff --git a/config/domains/andebol.net.json b/config/domains/andebol.net.json index d99919a..48c6551 100644 --- a/config/domains/andebol.net.json +++ b/config/domains/andebol.net.json @@ -15,10 +15,15 @@ { "slug": "competicoes", "label": "Competições" }, { "slug": "resultados", "label": "Resultados" } ], + "nav_groups": [ + { "id": "cobertura", "label": "Cobertura", "slugs": ["nacional", "internacional", "selecao"] }, + { "id": "competicao", "label": "Competição", "slugs": ["clubes", "competicoes", "resultados"] } + ], "bridge_endpoint": "http://127.0.0.1:3200", "wp_endpoint": "http://127.0.0.1:8081/wp-json", "locale": "pt-PT", "timezone": "Europe/Lisbon", "ads_enabled": false, - "analytics_id": null + "analytics_id": null, + "auth_links": true } diff --git a/deploy/nginx/newsproject.bitreport.pt.conf b/deploy/nginx/newsproject.bitreport.pt.conf index 1a4d593..beb13a3 100644 --- a/deploy/nginx/newsproject.bitreport.pt.conf +++ b/deploy/nginx/newsproject.bitreport.pt.conf @@ -42,6 +42,76 @@ server { proxy_send_timeout 30s; } + # --- Public WordPress login surface (before restricted wp-* blocks) --- + # Same-origin cookies for the site hostname. With real_ip enabled, RFC1918-only rules below + # would 403 public users on wp-login. Core login UI needs css/js/images and wp-includes. + location = /wp-login.php { + proxy_pass http://127.0.0.1:$news_wp_port; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $forwarded_proto; + proxy_read_timeout 120s; + proxy_send_timeout 120s; + } + + location ^~ /wp-admin/css/ { + proxy_pass http://127.0.0.1:$news_wp_port; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $forwarded_proto; + proxy_read_timeout 120s; + proxy_send_timeout 120s; + } + + location ^~ /wp-admin/images/ { + proxy_pass http://127.0.0.1:$news_wp_port; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $forwarded_proto; + proxy_read_timeout 120s; + proxy_send_timeout 120s; + } + + location ^~ /wp-admin/js/ { + proxy_pass http://127.0.0.1:$news_wp_port; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $forwarded_proto; + proxy_read_timeout 120s; + proxy_send_timeout 120s; + } + + location ^~ /wp-includes/ { + proxy_pass http://127.0.0.1:$news_wp_port; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $forwarded_proto; + proxy_read_timeout 120s; + proxy_send_timeout 120s; + } + + # Locales for wp-login (pt_PT, etc.) live under wp-content/languages. + location ^~ /wp-content/languages/ { + proxy_pass http://127.0.0.1:$news_wp_port; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $forwarded_proto; + proxy_read_timeout 120s; + proxy_send_timeout 120s; + } + # WordPress (Docker — port from $news_wp_port, usually 8080; andebol.net → 8081) — admin + REST. # allow/deny use $remote_addr on the CT (often the proxy hop, not the browser — see header comment). # Do not widen `allow` or remove `deny all` without board risk acceptance. @@ -62,22 +132,6 @@ server { proxy_send_timeout 120s; } - location = /wp-login.php { - allow 127.0.0.1; - allow 10.0.0.0/8; - allow 172.16.0.0/12; - allow 192.168.0.0/16; - deny all; - - proxy_pass http://127.0.0.1:$news_wp_port; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $forwarded_proto; - proxy_read_timeout 120s; - } - location ^~ /wp-content/ { allow 127.0.0.1; allow 10.0.0.0/8; @@ -92,22 +146,7 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $forwarded_proto; proxy_read_timeout 120s; - } - - location ^~ /wp-includes/ { - allow 127.0.0.1; - allow 10.0.0.0/8; - allow 172.16.0.0/12; - allow 192.168.0.0/16; - deny all; - - proxy_pass http://127.0.0.1:$news_wp_port; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $forwarded_proto; - proxy_read_timeout 120s; + proxy_send_timeout 120s; } # Block editor and plugins use the REST API from the browser (same allow list). diff --git a/docs/deployment.md b/docs/deployment.md index 72cf7e7..3adfe9f 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -91,7 +91,9 @@ server { HTTPS/TLS is terminated at Nginx Proxy Manager (NPM), which the board configures manually. -The checked-in `deploy/nginx/newsproject.bitreport.pt.conf` proxies **`/wp-admin/`**, **`wp-login.php`**, **`/wp-content/`**, **`/wp-includes/`**, and **`/wp-json/`** to WordPress on `127.0.0.1:8080` with **`allow`** for loopback and RFC1918 source addresses **as seen by this Nginx** (`$remote_addr`). O bloco `server` define `X-Forwarded-Proto` a partir de `$http_x_forwarded_proto` (NPM) com *fallback* para `$scheme`, para o WordPress não assumir HTTP plano quando o browser usa HTTPS. +The checked-in `deploy/nginx/newsproject.bitreport.pt.conf` proxies WordPress on `127.0.0.1:$news_wp_port` (see `conf.d/99-news-platform-wp-map.conf`). **`wp-login.php`**, **`/wp-includes/`**, **`/wp-admin/css/`**, **`/wp-admin/js/`**, **`/wp-admin/images/`**, and **`/wp-content/languages/`** are **public** (no `allow`/`deny`), so browsers can load the login UI and register when `real_ip` exposes the true client IP. **`/wp-admin/`** (remainder), **`/wp-content/`** (other than `languages/`), and **`/wp-json/`** still use **`allow`** for loopback and RFC1918 **`$remote_addr`**. O bloco `server` define `X-Forwarded-Proto` a partir de `$http_x_forwarded_proto` (NPM) com *fallback* para `$scheme`, para o WordPress não assumir HTTP plano quando o browser usa HTTPS. + +**Membership / registo:** in WordPress **Settings → General**, enable **Anyone can register** if the site should offer self-service signup (`/wp-login.php?action=register`, linked from the frontend as **`/registar`** when `auth_links` is true in `config/domains/.json`). **`wp-admin` and “public” reachability:** with **Nginx Proxy Manager** (or any reverse proxy on a private IP) in front of this CT, browsers worldwide connect to the public hostname, but the TCP client at the CT is the **proxy**. That address is usually inside `10.0.0.0/8` (or similar), so it matches `allow` — meaning **`https://…/wp-admin/` is reachable from the public Internet** through that chain, even though the config reads “RFC1918 only”. This matches operational reality; it is not a substitute for VPN-only admin unless you add controls at NPM/Cloudflare or enable **`ngx_http_realip_module`**: `set_real_ip_from` limited to **trusted** proxy IPs, `real_ip_header X-Forwarded-For`, then `allow`/`deny` apply to the restored client IP (test carefully; misconfiguration allows IP spoofing). diff --git a/docs/domains.md b/docs/domains.md index c4a72e1..f6d0698 100644 --- a/docs/domains.md +++ b/docs/domains.md @@ -88,11 +88,12 @@ A full sample lives at `config/domains/fpa-example.json`. "locale": "pt-PT", "timezone": "Europe/Lisbon", "ads_enabled": false, - "analytics_id": null + "analytics_id": null, + "auth_links": true } ``` -Live file: `config/domains/andebol.net.json`. The HTML document language uses the first segment of `locale` (e.g. `pt-PT` → `` in `Base.astro`). +Live file: `config/domains/andebol.net.json`. Set **`auth_links`** to show **Entrar** / **Registar** in the header and footer and to enable **`/entrar`** → `wp-login.php` and **`/registar`** → `wp-login.php?action=register`. The HTML document language uses the first segment of `locale` (e.g. `pt-PT` → `` in `Base.astro`). **Local smoke test:** the dev server does not read a `HOST` env var for the HTTP `Host` header. Map the hostname and open the site with that host (or send the header manually): @@ -131,7 +132,10 @@ Shape matches `DomainConfig` in `frontend/src/types/index.ts`: "timezone": "Europe/Lisbon", "ads_enabled": false, - "analytics_id": null + "analytics_id": null, + + // Optional: show login/register in chrome; /entrar and /registar redirect to WordPress + "auth_links": false } ``` @@ -142,7 +146,7 @@ Shape matches `DomainConfig` in `frontend/src/types/index.ts`: | Domain | Config file | Notes | |--------|-------------|--------| | `newsproject.bitreport.pt` | `newsproject.bitreport.pt.json` | `theme`: `sports` | -| `andebol.net` | `andebol.net.json` | `theme`: `institutional`; `wp_endpoint`: `:8081`; andebol news automation | +| `andebol.net` | `andebol.net.json` | `theme`: `institutional`; `wp_endpoint`: `:8081`; `auth_links`: true; andebol news automation | | Local dev | `localhost.json` | Fallback when hostname file is missing | --- diff --git a/frontend/src/lib/auth-labels.ts b/frontend/src/lib/auth-labels.ts new file mode 100644 index 0000000..71e74cf --- /dev/null +++ b/frontend/src/lib/auth-labels.ts @@ -0,0 +1,8 @@ +import type { DomainConfig } from '../types/index.js'; + +export function authNavLabels(config: DomainConfig): { login: string; register: string } { + const pt = config.locale.toLowerCase().startsWith('pt'); + return pt + ? { login: 'Entrar', register: 'Registar' } + : { login: 'Sign in', register: 'Register' }; +} diff --git a/frontend/src/pages/entrar.astro b/frontend/src/pages/entrar.astro new file mode 100644 index 0000000..90e52e3 --- /dev/null +++ b/frontend/src/pages/entrar.astro @@ -0,0 +1,9 @@ +--- +import { getDomainConfig } from '../lib/domain.js'; + +const config = getDomainConfig(Astro.url.hostname); +if (!config.auth_links) { + return Astro.redirect('/', 302); +} +return Astro.redirect('/wp-login.php', 302); +--- diff --git a/frontend/src/pages/registar.astro b/frontend/src/pages/registar.astro new file mode 100644 index 0000000..9c39eac --- /dev/null +++ b/frontend/src/pages/registar.astro @@ -0,0 +1,9 @@ +--- +import { getDomainConfig } from '../lib/domain.js'; + +const config = getDomainConfig(Astro.url.hostname); +if (!config.auth_links) { + return Astro.redirect('/', 302); +} +return Astro.redirect('/wp-login.php?action=register', 302); +--- diff --git a/frontend/src/themes/institutional/Footer.astro b/frontend/src/themes/institutional/Footer.astro index c28a5c2..2043f86 100644 --- a/frontend/src/themes/institutional/Footer.astro +++ b/frontend/src/themes/institutional/Footer.astro @@ -1,23 +1,46 @@ --- import type { DomainConfig } from '../../types/index.js'; +import { getUiStrings } from '../../lib/ui-i18n.js'; interface Props { config: DomainConfig; } const { config } = Astro.props; const year = new Date().getFullYear(); +const ui = getUiStrings(config.locale); --- @@ -25,56 +48,84 @@ const year = new Date().getFullYear(); .inst-footer { background: var(--color-accent); border-top: 1px solid var(--color-border); - padding: var(--space-10) 0 var(--space-8); + padding: var(--space-12) 0 var(--space-8); margin-top: var(--space-16); } - .inst-footer__main { - display: flex; - flex-direction: column; - gap: var(--space-4); - align-items: flex-start; + .inst-footer__grid { + display: grid; + grid-template-columns: 1fr; + gap: var(--space-10); + margin-bottom: var(--space-8); } @media (min-width: 640px) { - .inst-footer__main { - flex-direction: row; - align-items: center; - justify-content: space-between; + .inst-footer__grid { + grid-template-columns: repeat(2, 1fr); } } - .inst-footer__name { + @media (min-width: 1024px) { + .inst-footer__grid { + grid-template-columns: minmax(0, 1.4fr) 1fr 1fr; + align-items: start; + } + } + + .inst-footer__brand-link { font-family: var(--font-heading, inherit); font-size: var(--text-lg); font-weight: 600; color: var(--color-primary); - margin: 0; + text-decoration: none; + display: inline-block; + margin-bottom: var(--space-3); } - .inst-footer__legal { - display: flex; - flex-wrap: wrap; - gap: var(--space-4); + .inst-footer__brand-link:hover { + text-decoration: underline; + } + + .inst-footer__tagline { + margin: 0; + font-size: var(--text-sm); + line-height: 1.55; + color: var(--color-text-muted); + max-width: 28rem; + } + + .inst-footer__heading { + font-size: var(--text-xs); + font-weight: 700; + text-transform: uppercase; + letter-spacing: 0.08em; + color: var(--color-text-muted); + margin: 0 0 var(--space-4); + } + + .inst-footer__links { list-style: none; margin: 0; padding: 0; + display: flex; + flex-direction: column; + gap: var(--space-3); } - .inst-footer__legal a { + .inst-footer__links a { font-size: var(--text-sm); - color: var(--color-text-muted); + color: var(--color-text); text-decoration: none; transition: color 0.15s ease; } - .inst-footer__legal a:hover { + .inst-footer__links a:hover { color: var(--color-primary); } .inst-footer__copy { - margin: var(--space-8) 0 0; - padding-top: var(--space-6); + margin: 0; + padding-top: var(--space-8); border-top: 1px solid var(--color-border); font-size: var(--text-sm); color: var(--color-text-muted); diff --git a/frontend/src/themes/institutional/Header.astro b/frontend/src/themes/institutional/Header.astro index abf6fda..e123337 100644 --- a/frontend/src/themes/institutional/Header.astro +++ b/frontend/src/themes/institutional/Header.astro @@ -1,35 +1,115 @@ --- -import type { DomainConfig } from '../../types/index.js'; +import type { CategoryConfig, DomainConfig } from '../../types/index.js'; +import { getUiStrings } from '../../lib/ui-i18n.js'; interface Props { config: DomainConfig; } const { config } = Astro.props; const current_path = Astro.url.pathname; +const ui = getUiStrings(config.locale); + +type NavCluster = { id: string; label: string; items: CategoryConfig[] }; + +function resolveNavClusters(cfg: DomainConfig): NavCluster[] { + if (!cfg.nav_groups?.length) { + return [{ id: 'all', label: '', items: cfg.categories }]; + } + return cfg.nav_groups + .map(g => ({ + id: g.id, + label: g.label, + items: g.slugs + .map(slug => cfg.categories.find(c => c.slug === slug)) + .filter((c): c is CategoryConfig => c != null), + })) + .filter(g => g.items.length > 0); +} + +const nav_clusters = resolveNavClusters(config); + +type MobileRow = + | { kind: 'label'; text: string } + | { kind: 'link'; slug: string; label: string }; + +const mobile_rows: MobileRow[] = nav_clusters.flatMap(cluster => { + const rows: MobileRow[] = []; + if (cluster.label) { + rows.push({ kind: 'label', text: cluster.label }); + } + for (const cat of cluster.items) { + rows.push({ kind: 'link', slug: cat.slug, label: cat.label }); + } + return rows; +}); + +function isCategoryActive(slug: string): boolean { + return current_path === `/category/${slug}` || current_path.startsWith(`/category/${slug}/`); +} --- @@ -106,7 +194,7 @@ const current_path = Astro.url.pathname; background: #fff; border-bottom: 1px solid #e2e8f0; box-shadow: 0 1px 0 rgba(26, 58, 92, 0.06); - height: var(--header-height); + min-height: var(--header-height); } [data-theme="dark"] .inst-header { @@ -118,7 +206,16 @@ const current_path = Astro.url.pathname; display: flex; align-items: center; gap: var(--space-4); - height: 100%; + min-height: var(--header-height); + flex-wrap: wrap; + padding-block: var(--space-2); + } + + @media (min-width: 768px) { + .inst-header__inner { + flex-wrap: nowrap; + padding-block: 0; + } } .inst-header__skip { @@ -153,6 +250,7 @@ const current_path = Astro.url.pathname; .inst-header__nav { flex: 1; display: none; + min-width: 0; } @media (min-width: 768px) { @@ -165,6 +263,35 @@ const current_path = Astro.url.pathname; } .inst-header__nav-list { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: var(--space-2) var(--space-4); + list-style: none; + margin: 0; + padding: 0; + } + + .inst-header__nav-cluster { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: var(--space-2) var(--space-3); + list-style: none; + margin: 0; + padding: 0; + } + + .inst-header__nav-cluster-label { + font-size: var(--text-xs); + font-weight: 700; + text-transform: uppercase; + letter-spacing: 0.08em; + color: var(--color-text-muted); + white-space: nowrap; + } + + .inst-header__nav-cluster-list { display: flex; flex-wrap: wrap; gap: var(--space-1); @@ -191,7 +318,7 @@ const current_path = Astro.url.pathname; .inst-header__link:hover, .inst-header__link--active { color: var(--color-primary); - background: rgba(74, 111, 165, 0.1); + background: color-mix(in srgb, var(--color-secondary) 14%, transparent); } .inst-header__actions { @@ -261,6 +388,25 @@ const current_path = Astro.url.pathname; gap: var(--space-1); } + .inst-header__mobile-group { + list-style: none; + margin: 0; + padding: var(--space-3) 0 var(--space-1); + } + + .inst-header__mobile-group:first-of-type { + padding-top: var(--space-2); + } + + .inst-header__mobile-group-title { + display: block; + font-size: var(--text-xs); + font-weight: 700; + text-transform: uppercase; + letter-spacing: 0.08em; + color: var(--color-text-muted); + } + .inst-header__mobile-link { display: block; padding: var(--space-3) var(--space-4); @@ -282,11 +428,13 @@ const current_path = Astro.url.pathname; diff --git a/frontend/src/themes/sports/Footer.astro b/frontend/src/themes/sports/Footer.astro index c9968f2..2ed4cc9 100644 --- a/frontend/src/themes/sports/Footer.astro +++ b/frontend/src/themes/sports/Footer.astro @@ -1,11 +1,14 @@ --- import type { DomainConfig } from '../../types/index.js'; +import { authNavLabels } from '../../lib/auth-labels.js'; interface Props { config: DomainConfig; } const { config } = Astro.props; const year = new Date().getFullYear(); +const show_auth = config.auth_links === true; +const auth_labels = show_auth ? authNavLabels(config) : null; ---