diff --git a/AGENTS.md b/AGENTS.md index 7ea68bc..c6d60a6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -354,7 +354,8 @@ Der Start ist idempotent (Migrationen + `cache clear_all`). Der Healthcheck prü `.gitea/workflows/docker.yml` baut bei Push auf `main` und pusht `:latest` + `:` in die Gitea-Registry (Variablen `DOCKER_REPO`, `IMAGE_NAME`, Secret `PAT`). Beispiel: `docker-compose.yml`. -Produktiv auf dem Server in `config/.env`: `DEBUG=false`, `APP_FULL_BASE_URL`, `SECURITY_SALT`, SMTP. +Produktiv auf dem Server in `config/.env`: `DEBUG=false`, `APP_FULL_BASE_URL`, `SECURITY_SALT`, SMTP +(`SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`, `SMTP_TLS` – einzelne Variablen statt URL; `EMAIL_TRANSPORT_DEFAULT_URL` geht weiter als Altlast). Ohne `DEBUG=false` steht die per Composer erzeugte `app_local.php` auf debug=true und zeigt Admin-Links direkt an. Document-Root zeigt idealerweise auf `webroot/`; liegt die App direkt im Document-Root (z. B. `public_html`), leiten `.htaccess` + `index.php` im Projektroot alles nach `webroot/` weiter. diff --git a/README.md b/README.md index 2c51af9..84ab820 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,8 @@ haben Vorrang vor der Datei. | `APP_FULL_BASE_URL` | Absolute URL, wird für Links in E-Mails gebraucht (Pflicht in Produktion). In Produktion wird außerdem der Host-Header dagegen geprüft | | `SECURITY_SALT` | Langer Zufallswert. **Nicht nachträglich ändern** – damit werden Admin-Tokens verschlüsselt und Teilnehmer-IDs gehasht | | `DATABASE_URL` | Leer = SQLite in `data/`. Sonst z. B. `mysql://user:pw@host/plenario?encoding=utf8mb4` oder `postgres://user:pw@host/plenario` | -| `EMAIL_TRANSPORT_DEFAULT_URL` | z. B. `smtp://user:pw@mail.example.org:587?tls=true`. Ohne diese Variable werden Mails nur als Datei abgelegt | +| `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD` | Mailserver (Port Standard 587). Ohne `SMTP_HOST` werden Mails nur als Datei abgelegt | +| `SMTP_TLS` | `true` (Standard) = STARTTLS; Port 465 nutzt automatisch SSL; `false` = unverschlüsselt | | `MAIL_FROM`, `MAIL_FROM_NAME` | Absender | | `CAPTCHA_TYPE` | `none`, `math` (Standard) oder `recaptcha` | | `RECAPTCHA_SITE_KEY`, `RECAPTCHA_SECRET_KEY` | Für reCAPTCHA v2 („Ich bin kein Roboter“) | @@ -149,7 +150,8 @@ docker run -d --name plenario -p 8765:8765 -v plenario-data:/data \ -e SECURITY_SALT="$(openssl rand -hex 32)" \ -e APP_FULL_BASE_URL=https://plenario.example.org \ -e MAIL_FROM=noreply@example.org \ - -e EMAIL_TRANSPORT_DEFAULT_URL='smtp://user:pw@mail.example.org:587?tls=true' \ + -e SMTP_HOST=mail.example.org -e SMTP_PORT=587 \ + -e SMTP_USER=noreply@example.org -e SMTP_PASSWORD='geheim' \ --restart unless-stopped \ gitea.gnilebein.de/gnilebein/plenario:latest ``` @@ -163,7 +165,11 @@ docker run -d --name plenario -p 8765:8765 -v plenario-data:/data \ APP_FULL_BASE_URL=https://plenario.example.org MAIL_FROM=noreply@example.org MAIL_FROM_NAME=PlenarIO - EMAIL_TRANSPORT_DEFAULT_URL=smtp://user:pw@mail.example.org:587?tls=true + SMTP_HOST=mail.example.org + SMTP_PORT=587 + SMTP_USER=noreply@example.org + SMTP_PASSWORD=geheim + SMTP_TLS=true CAPTCHA_TYPE=math ``` @@ -192,7 +198,7 @@ aktivieren oder `docker build -t plenario .` ausführen. Admin-Tokens unlesbar und Teilnehmer-IDs ungültig). - **`APP_FULL_BASE_URL` muss die öffentliche URL sein**, inklusive `https://`. Sie wird für die Links in E-Mails verwendet, und in Produktion wird der Host-Header dagegen geprüft. -- **Mail-Versand einrichten.** Ohne `EMAIL_TRANSPORT_DEFAULT_URL` schreibt PlenarIO Mails nur als Datei ins +- **Mail-Versand einrichten.** Ohne `SMTP_HOST` schreibt PlenarIO Mails nur als Datei ins Container-Dateisystem – der Admin-Link kommt dann **nie** bei den Nutzenden an. - **TLS-Proxy davorschalten** (Caddy, nginx, Traefik, …), der `X-Forwarded-Proto` setzt. Der eingebaute PHP-Server spricht nur HTTP. Beispiel für Caddy: diff --git a/config/.env.example b/config/.env.example index d8c526d..d3b8cc8 100644 --- a/config/.env.example +++ b/config/.env.example @@ -17,7 +17,12 @@ APP_DEFAULT_LOCALE=de_DE # --- Mail ------------------------------------------------------------------- # Empty = .eml files in tmp/mails/ (development only!) -# EMAIL_TRANSPORT_DEFAULT_URL=smtp://user:password@mail.example.org:587?tls=true +# SMTP_HOST=mail.example.org +# SMTP_PORT=587 +# SMTP_USER=noreply@example.org +# SMTP_PASSWORD=secret +# true = STARTTLS (port 587); port 465 uses implicit SSL automatically; false = unencrypted +# SMTP_TLS=true MAIL_FROM=noreply@plenario.example.org MAIL_FROM_NAME=PlenarIO diff --git a/config/app.php b/config/app.php index 1ba847d..c0ecff4 100644 --- a/config/app.php +++ b/config/app.php @@ -6,8 +6,15 @@ use Cake\Database\Connection; use Cake\Database\Driver\Sqlite; use Cake\Log\Engine\FileLog; use Cake\Mailer\Transport\MailTransport; +use Cake\Mailer\Transport\SmtpTransport; use function Cake\Core\env; +// SMTP from single variables (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_TLS) instead of a URL: +// no escaping of special characters in the password. Port 465 = implicit SSL, otherwise STARTTLS (SMTP_TLS). +$smtpHost = trim((string)env('SMTP_HOST', '')); +$smtpPort = (int)env('SMTP_PORT', 587); +$smtpSsl = $smtpPort === 465; + return [ /* * PlenarIO application settings. @@ -281,21 +288,19 @@ return [ */ 'EmailTransport' => [ 'default' => [ - 'className' => MailTransport::class, + 'className' => $smtpHost !== '' ? SmtpTransport::class : MailTransport::class, /* * The keys host, port, timeout, username, password, client and tls - * are used in SMTP transports + * are used in SMTP transports. Set them via SMTP_* environment variables. */ - 'host' => 'localhost', - 'port' => 25, + 'host' => $smtpHost !== '' ? ($smtpSsl ? 'ssl://' : '') . $smtpHost : 'localhost', + 'port' => $smtpHost !== '' ? $smtpPort : 25, 'timeout' => 30, - /* - * It is recommended to set these options through your environment or app_local.php - */ - //'username' => null, - //'password' => null, + 'username' => env('SMTP_USER') ?: null, + 'password' => env('SMTP_PASSWORD') ?: null, 'client' => null, - 'tls' => false, + 'tls' => !$smtpSsl && filter_var(env('SMTP_TLS', true), FILTER_VALIDATE_BOOLEAN), + // Legacy alternative to the SMTP_* variables 'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null), ], ], diff --git a/config/app_local.example.php b/config/app_local.example.php index 9da5517..44ae202 100644 --- a/config/app_local.example.php +++ b/config/app_local.example.php @@ -57,12 +57,11 @@ return [ 'EmailTransport' => [ /* * Local default: mails are written as .eml files to tmp/mails/. - * For production use SMTP, e.g. - * EMAIL_TRANSPORT_DEFAULT_URL=smtp://user:pass@mail.example.org:587?tls=true + * For real delivery set SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD and SMTP_TLS + * (see config/.env.example); then this override is skipped. */ - 'default' => [ + 'default' => env('SMTP_HOST') || env('EMAIL_TRANSPORT_DEFAULT_URL') ? [] : [ 'className' => \App\Mailer\Transport\FileTransport::class, - 'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null), ], ], ];