From bdeb01681dad9fe11db78d9c2f50f7af6b22ad4a Mon Sep 17 00:00:00 2001 From: Mix Date: Sat, 17 Oct 2026 01:34:28 +0300 Subject: [PATCH] local-time: the panel in the container's zone, named on Settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agreed by the owner on 2026-10-13 (the local day, no "UTC" beside a time); the zone is the container's TZ in .env and Settings only shows it, his "Да" of 2026-10-17. Mockups c205106. Every time the panel shows is formatted in time.Local and says no zone: the logs' Time and the DMARC Received columns, a message's timeline, Overview's "Updated", Health's certificate and renewal, the filter lists, DMARC reports and windows, the auto limit's last recalculation. Stored instants stay UTC. The days counted are the zone's: delivery_log_days and sender_check_days key their rows by the local date, the sender check cuts downtime at local midnights (byDay), the log filters' days run from local midnight to local midnight. Notification mail and the test message write the zone's abbreviation after a time - they are read away from the panel. DMARC's one-day window label stays the reporter's (UTC) day. Settings box 05, Time zone, read-only: the name (UTC without TZ), its offset, and a TZ the image cannot load said to leave the times in UTC (time/zoneinfo_unix.go, initLocal) rather than named. TZ is passed by the compose file ("${TZ:-}"), in .env.example and the guide's table; tzdata is named in the image (supervisor's python3.13 brings it today). Postfix takes TZ through import_environment, so mail.log's stamps are the same zone, which closes the trap the roadmap wrote down: the tailer has always read them in time.Local. Tests: a TestMain runs view, handlers, store and cmd/panel in UTC whatever the machine's zone (as logtail's); TestSettingsShowsTheTimeZone, TestTimesAreTheContainersZone, TestByDayInTheContainersZone, a Moscow day in TestQueryInboundSpamFilters; envdoc's pattern takes two-letter names. e2e time_zone_is_the_containers recreates the stand with TZ=Europe/Moscow: date says MSK, Settings names the zone and UTC+03:00, a test message's page gives its time and its mail.log lines in Moscow's. go vet + go test (26 packages) and make e2e on the test server for this tree. Docs: guide (§ Settings, the TZ row, the days of Health and the logs), architecture, schema-migrations, help (word for word with the mockup), CHANGELOG [Unreleased] § Added, roadmap row done with the decision. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 10 +++ build/Dockerfile | 5 ++ cmd/panel/envdoc_test.go | 2 +- cmd/panel/httpserver.go | 1 + cmd/panel/main.go | 4 ++ cmd/panel/sendercheck.go | 12 ++-- cmd/panel/sendercheck_test.go | 12 ++++ cmd/panel/zone_main_test.go | 28 ++++++++ deploy/.env.example | 6 ++ deploy/docker-compose.yml | 3 + docs/architecture.md | 8 +-- docs/guide.md | 17 ++++- docs/roadmap.md | 22 +++++- docs/schema-migrations.md | 4 +- internal/health/cert.go | 4 +- internal/notify/text.go | 2 +- internal/store/deliverylog.go | 8 +-- internal/store/inboundspam.go | 15 ++-- internal/store/inboundspam_test.go | 18 +++-- internal/store/sendercheck.go | 14 ++-- internal/store/sendlog.go | 13 ++-- internal/store/zone_main_test.go | 28 ++++++++ internal/web/handlers/handlers.go | 1 + internal/web/handlers/handlers_apps.go | 2 +- .../web/handlers/handlers_dmarc_pages_test.go | 4 +- .../web/handlers/handlers_dmarc_reports.go | 4 +- .../web/handlers/handlers_health_page_test.go | 8 +-- .../web/handlers/handlers_inbound_log_test.go | 2 +- internal/web/handlers/handlers_monitor.go | 3 +- internal/web/handlers/handlers_settings.go | 1 + internal/web/handlers/handlers_status.go | 10 +-- internal/web/handlers/zone_main_test.go | 28 ++++++++ internal/web/view/account.go | 36 +++++++++- internal/web/view/components_test.go | 16 ++--- internal/web/view/dmarc.go | 8 +-- internal/web/view/dmarc_test.go | 8 +-- internal/web/view/fixtures_test.go | 17 +++-- internal/web/view/help.go | 4 +- internal/web/view/inbound_lists.go | 6 +- internal/web/view/inbound_log_test.go | 4 +- internal/web/view/kit.go | 6 +- internal/web/view/outbound.go | 2 +- internal/web/view/outbound_log.go | 8 +-- internal/web/view/outbound_log_test.go | 8 +-- internal/web/view/outbound_test.go | 4 +- internal/web/view/overview.go | 2 +- internal/web/view/pages_test.go | 42 ++++++++++- internal/web/view/templates/dmarc.html | 2 +- internal/web/view/templates/dmarc_domain.html | 2 +- internal/web/view/templates/in_log.html | 2 +- internal/web/view/templates/kit.html | 2 +- internal/web/view/templates/out_log_rows.html | 2 +- internal/web/view/templates/settings.html | 11 ++- internal/web/view/zone_main_test.go | 28 ++++++++ internal/web/web.go | 3 + test/e2e/health_served_test.go | 4 +- test/e2e/main_test.go | 4 ++ test/e2e/time_zone_test.go | 71 +++++++++++++++++++ 58 files changed, 484 insertions(+), 117 deletions(-) create mode 100644 cmd/panel/zone_main_test.go create mode 100644 internal/store/zone_main_test.go create mode 100644 internal/web/handlers/zone_main_test.go create mode 100644 internal/web/view/zone_main_test.go create mode 100644 test/e2e/time_zone_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index ec909ad..93f7894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); version ## [Unreleased] +### Added + +- **The panel in your time zone** (local-time): set `TZ` in `.env` (an IANA + name, e.g. `Europe/Moscow`) and every time the panel shows, every day it + counts - today on Health, the statistics' days, the days of the log + filters - and the stamps of `mail.log` are that zone's. The screens no + longer write "UTC" beside a time; **Server › Settings** names the zone in + a new read-only box. Unset, it is UTC as before. Changing it is a + restart; days counted before stay the old zone's. + ## [2.12.0] - 2026-10-17 A test message from Server › Health. No migration; schema 12. diff --git a/build/Dockerfile b/build/Dockerfile index 4309ce5..ed1842c 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -64,6 +64,10 @@ ENV DEBIAN_FRONTEND=noninteractive # than with the whole of systemd, the first alternative of its "Depends: # systemd | systemd-standalone-sysusers | systemd-sysusers" (dpkg -s in the # image, 2026-10-15). Nothing here runs systemd. +# tzdata is named for TZ (local-time): the zone of every time the panel shows +# and of the stamps Postfix writes in mail.log. supervisor's python3.13 brings +# it today (apt-cache rdepends --installed tzdata in the image, 2026-10-17); +# a TZ the image did not have would leave both in UTC without a word. RUN echo "postfix postfix/mailname string localhost" | debconf-set-selections \ && echo "postfix postfix/main_mailer_type string Internet Site" | debconf-set-selections \ && apt-get update \ @@ -78,6 +82,7 @@ RUN echo "postfix postfix/mailname string localhost" | debconf-set-selections \ openssl \ curl \ systemd-standalone-sysusers \ + tzdata \ && rm -rf /var/lib/apt/lists/* # Debian's postfix runs its chroot sync on every "postfix check" and "postfix diff --git a/cmd/panel/envdoc_test.go b/cmd/panel/envdoc_test.go index 8872f4b..4352388 100644 --- a/cmd/panel/envdoc_test.go +++ b/cmd/panel/envdoc_test.go @@ -22,7 +22,7 @@ import ( var ( goEnvRead = regexp.MustCompile(`(?:envDefault|envInt|envBool|envSeconds|envDuration|os\.Getenv|os\.LookupEnv)\("([A-Z][A-Z0-9_]+)"`) scriptEnvRead = regexp.MustCompile(`\$\{([A-Z][A-Z0-9_]+):[-?=]`) - docEnvName = regexp.MustCompile("`([A-Z][A-Z0-9_]{2,})`") + docEnvName = regexp.MustCompile("`([A-Z][A-Z0-9_]+)`") ) func readFile(t *testing.T, path string) string { diff --git a/cmd/panel/httpserver.go b/cmd/panel/httpserver.go index 82e04e5..c1d66b0 100644 --- a/cmd/panel/httpserver.go +++ b/cmd/panel/httpserver.go @@ -113,6 +113,7 @@ func newPanel(cfg config, st *store.Store) (*web.Server, error) { TLSCertFile: cfg.tlsCertFile, TLSServedCertFile: cfg.tlsServedCertFile, SMTPBanner: cfg.smtpBanner, + TimeZone: cfg.timeZone, TLSReloadInterval: cfg.tlsReloadInterval, SignSocket: cfg.signSocket, SignLocalSocket: cfg.signLocalSocket, diff --git a/cmd/panel/main.go b/cmd/panel/main.go index 32f4c27..f682ea9 100644 --- a/cmd/panel/main.go +++ b/cmd/panel/main.go @@ -100,6 +100,9 @@ type config struct { // smtpBanner is Postfix's smtpd_banner, expanded, read from postconf at // the start: Health shows the greeting it makes. smtpBanner string + // timeZone is TZ as the container was started with ("" for none): the + // zone of every time and day the panel shows, which Settings names. + timeZone string dkimDir string dkimSelectorDef string @@ -150,6 +153,7 @@ func loadConfig() config { manifestPath: filepath.Join(dataDir, backup.ManifestName), setupTokenPath: envDefault("SELFPOST_SETUP_TOKEN_FILE", filepath.Join(dataDir, "setup-token")), hostname: os.Getenv("SELFPOST_HOSTNAME"), + timeZone: os.Getenv("TZ"), // Secure cookies by default (security.md); PANEL_COOKIE_SECURE=false is a // development-only escape hatch for testing over plain HTTP. cookieSecure: envDefault("PANEL_COOKIE_SECURE", "true") != "false", diff --git a/cmd/panel/sendercheck.go b/cmd/panel/sendercheck.go index 86cad48..652f687 100644 --- a/cmd/panel/sendercheck.go +++ b/cmd/panel/sendercheck.go @@ -104,19 +104,21 @@ func senderCheckDowntime(markAt, now time.Time, ask func() postfixState) (down t return 0, false } -// dayPart is the part of a stretch of downtime that fell on one UTC day. +// dayPart is the part of a stretch of downtime that fell on one day of the +// container's zone. type dayPart struct { day time.Time down time.Duration } -// byDay cuts the time from 'from' to 'to' at the UTC midnights between them, -// so that a night's outage is not all booked on the morning it ended. +// byDay cuts the time from 'from' to 'to' at the midnights of the container's +// zone between them, so that a night's outage is not all booked on the morning +// it ended. func byDay(from, to time.Time) []dayPart { - from, to = from.UTC(), to.UTC() + from, to = from.Local(), to.Local() var parts []dayPart for from.Before(to) { - next := time.Date(from.Year(), from.Month(), from.Day(), 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1) + next := time.Date(from.Year(), from.Month(), from.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1) if next.After(to) { next = to } diff --git a/cmd/panel/sendercheck_test.go b/cmd/panel/sendercheck_test.go index df03724..f58362d 100644 --- a/cmd/panel/sendercheck_test.go +++ b/cmd/panel/sendercheck_test.go @@ -62,3 +62,15 @@ func TestByDay(t *testing.T) { t.Errorf("no time: %+v", none) } } + +// In a container with TZ=Europe/Moscow a day is Moscow's: an outage from +// 20:50 to 21:10 UTC crosses its midnight (21:00 UTC). +func TestByDayInTheContainersZone(t *testing.T) { + inZone(t, "Europe/Moscow") + from := time.Date(2026, 10, 12, 20, 50, 0, 0, time.UTC) + got := byDay(from, from.Add(20*time.Minute)) + if len(got) != 2 || got[0].down != 10*time.Minute || got[1].down != 10*time.Minute || + got[1].day.Format("2006-01-02 15:04") != "2026-10-13 00:00" { + t.Errorf("parts = %+v, want ten minutes on the 12th and ten from Moscow's midnight", got) + } +} diff --git a/cmd/panel/zone_main_test.go b/cmd/panel/zone_main_test.go new file mode 100644 index 0000000..05bff79 --- /dev/null +++ b/cmd/panel/zone_main_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "os" + "testing" + "time" +) + +// TestMain runs the tests in UTC, whatever the zone of the machine they run +// on: the panel shows times and counts days in time.Local, the container's +// zone (TZ), and the fixtures are written in UTC. The tests of another zone +// set it themselves (inZone). +func TestMain(m *testing.M) { + time.Local = time.UTC + os.Exit(m.Run()) +} + +// inZone runs the rest of the test in the zone name, as a container started +// with TZ=name; the test must not be parallel. +func inZone(t *testing.T, name string) { + t.Helper() + loc, err := time.LoadLocation(name) + if err != nil { + t.Skipf("no zone %s here: %v", name, err) + } + time.Local = loc + t.Cleanup(func() { time.Local = time.UTC }) +} diff --git a/deploy/.env.example b/deploy/.env.example index e6cbf45..5fe3652 100644 --- a/deploy/.env.example +++ b/deploy/.env.example @@ -60,6 +60,12 @@ PANEL_SESSION_IDLE_DAYS=7 # your own recursor, e.g. SELFPOST_DNS_RESOLVERS=10.0.0.2:53 # SELFPOST_DNS_RESOLVERS= +# Time zone of the container, an IANA name: every time the panel shows, the +# days it counts (today on Health, the days of the statistics, the log +# filters) and the stamps Postfix writes in mail.log. Leave unset for UTC; +# changing it is a restart. Server > Settings shows the zone in use. +# TZ=Europe/Moscow + # Comma-separated CIDRs (bare IPs allowed) of reverse proxies allowed to # supply X-Forwarded-For for login/setup rate-limiting. Leave unset unless # you know the exact address of your reverse proxy — trusting the wrong diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 88ef101..11c0fbb 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -56,6 +56,9 @@ services: # report what the internet sees rather than what this host's own stub # resolver synthesises. Empty uses public defaults. SELFPOST_DNS_RESOLVERS: "${SELFPOST_DNS_RESOLVERS:-}" + # The zone of every time the panel shows and of mail.log's stamps, e.g. + # Europe/Moscow. Empty is UTC. + TZ: "${TZ:-}" # Reverse-proxy CIDRs allowed to supply X-Forwarded-For for login/setup # rate-limiting. See docs/guide.md "Environment variables" — wrong value lets a # client spoof its rate-limit key. diff --git a/docs/architecture.md b/docs/architecture.md index 282a687..05b138d 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -475,10 +475,10 @@ the hole it closed was the same. cleanup process serves message after message, so each such warning is counted as a message. The two are counted apart (the owner, 2026-10-14): connections turned away in `deferred`, messages deferred mid-message in - `messages` of `sender_check_days`, a row per UTC day kept a year, and + `messages` of `sender_check_days`, a row per day of the container's zone (`TZ`) kept a year, and Server › Health shows today, 30 days and 12 months in a column each. The counts also see a panel that is running and not answering, which the mark - does not. Downtime is cut at the UTC midnights it crossed. A log read again + does not. Downtime is cut at the midnights of that zone it crossed. A log read again after an unclean stop does not count again: the count and the place in the log it reached (the file's fingerprint and the offset past the line) are saved in one transaction, and while the tailer catches up a warning at or @@ -712,7 +712,7 @@ lines are gone for good — rotated past fourteen files while the panel was down or deleted — or that the tailer was not reading. Whether the sweep earns its place is measured, not argued (audit 2026-10-12, -H3). `delivery_log_days` (migration `0007`) keeps, per UTC day for a year: +H3). `delivery_log_days` (migration `0007`) keeps, per day of the container's zone for a year: `reconcile_closed`, the rows the sweep closed; `reconcile_missed`, those of them whose final line - sent, bounced, or the message's expiry - was in `mail.log` or `mail.log.1` when the sweep closed them - the tailer did not @@ -1203,7 +1203,7 @@ The tables that carry the panel's model: `inbound_spam_list` (the filter lists), `dmarc_reports`, `dmarc_report_records`, `notify_state` and `notify_addressees` (what the notifier has said and to whom, § Notifications), `sender_check_days` (the - sender check's downtime and the mail it deferred, per UTC day) and + sender check's downtime and the mail it deferred, per day of the container's zone) and `delivery_log_days` (the queue sweep's measurements, § Log tailer). Two processes write: the panel, on one connection, and `dmarc-ingest`, which diff --git a/docs/guide.md b/docs/guide.md index 2ad978a..fe07742 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -249,6 +249,7 @@ expected to set; defaults match the code exactly. | `SEND_LOG_RETENTION_DAYS` | Initial default for how many days of send-log history are kept before the background sweep deletes rows, and with them the `mail.log` lines kept for each message (1–2 KB a message) — the main driver of `/data` growth over time and of the size of a full backup. After the first panel start, change retention under **Server › Settings** (global role); the env value is only used to seed SQLite when the setting has never been saved. | `90` | `.env` | | `PANEL_SESSION_IDLE_DAYS` | Sliding idle timeout for the panel login session, in days. There is no absolute cap: a user who keeps coming back stays signed in indefinitely. | `7` | `.env` | | `SELFPOST_DNS_RESOLVERS` | Comma-separated recursive resolvers the panel's PTR/SPF/DKIM/DMARC checks query directly (so they report what the internet sees, not what this host's stub resolver synthesises). Each is given 2 seconds to answer before the next is asked, and the one that answered last is asked first; a lookup none of them answered shows as not known, never as a wrong record. | `1.1.1.1:53`, `8.8.8.8:53`, `9.9.9.9:53` when unset | `.env` | +| `TZ` | Time zone of the container, an IANA name such as `Europe/Moscow`: every time the panel shows, every day it counts (today on Health, the days of the statistics, the days of the log filters) and the stamps Postfix writes in `mail.log`, so the two agree. Stored times stay UTC, so changing it is only a restart. *Server › Settings* shows the zone in use, and says so when the image does not know the name (the times are then UTC). | UTC | `.env` | | `TRUSTED_PROXY_CIDR` | Comma-separated CIDRs (bare IPs allowed) of reverse proxies allowed to supply `X-Forwarded-For` for login, setup, and account-change rate-limiting. **Leave unset unless you know the exact address of your reverse proxy.** A wrong value lets a client spoof its rate-limit key by sending a forged `X-Forwarded-For` header — the panel trusts the last hop only when the TCP peer matches one of these CIDRs. With Apache on the host (the default), the panel sees the proxy's connections come from the Docker network's gateway, e.g. `172.18.0.1` (`docker network inspect` shows it; measured 2026-10-15: the panel's `127.0.0.1:8080` is published through Docker's proxy, and a connection to such a port from the host arrives from the gateway). | *(empty — XFF ignored)* | `.env` | TLS certificate paths (`TLS_CERT_FILE`, `TLS_KEY_FILE`) are fixed in @@ -488,7 +489,7 @@ readings, in the order of what stops mail first: connects during an outage is counted too; a message refused in the middle is one the panel stopped answering for after it had begun. A time marked ≈ is at most what it shows: at that start supervisord could not say since - when Postfix ran. Days are UTC days. The card warns when + when Postfix ran. Days are those of the container's zone (`TZ`). The card warns when a connection was turned away or a message refused in the last 24 hours. If these numbers do not stay at nothing, the panel is in the way of your mail more than it should be - report it. @@ -575,6 +576,18 @@ that make them arrive, with when they were last checked; **Re-check DNS** at the top of the page checks them again once they are published (results are otherwise kept a few minutes). +The last box, **Time zone**, names the zone the panel is in: `TZ` in `.env` +([Environment variables](#environment-variables)), UTC when it is not set, +with its offset from UTC. Every time the panel shows is in that zone, and no +time on the screens says which - this box is where it is said. Every day it +counts is that zone's too: *today* on Health, the days of the statistics, +the days of the log filters. Postfix runs in the same zone, so the stamps of +the `mail.log` lines on Server › System log and on a message's page read the +same clock as the rest of the page. The database keeps its times in UTC, so +changing the zone is a restart and nothing more; the days counted before it +stay days of the old zone, a shift of a few hours in the statistics. A name +the image does not know leaves everything in UTC, and the box says so. + ### Notifications The panel writes to its users when something needs them. Four things are @@ -1544,7 +1557,7 @@ the only one of the two that does not depend on the panel process. ### Outbound log **Outbound › Log** (`/outbound/log`) is a searchable send log with server-side -filters by domain, application, status and day (from and to, UTC days, as on +filters by domain, application, status and day (from and to, days of the container's zone, as on the Inbound log); the status *rejected* is the three kinds of refusal together, which the table tells apart by their tags. A user with the *domain* role sees only the rows of their domains. The filters are kept by the pages, diff --git a/docs/roadmap.md b/docs/roadmap.md index ecabad8..bdf5290 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -38,7 +38,7 @@ in `git log` and [CHANGELOG.md](../CHANGELOG.md). | panel-notifications | E-mail notifications about important events | shipped `2.3.0` | 10/10 | [plans/panel-notifications.md](plans/panel-notifications.md) | | delivery-log-storage | Keep a message's `mail.log` lines with its send-log row | shipped `2.2.0` | 8/8 | [plans/delivery-log-storage.md](plans/delivery-log-storage.md) | | password-reset | Password reset by e-mail | agreed (2026-10-13) | — | — | -| local-time | The panel shows time, and counts its days, in a time zone other than UTC | agreed (2026-10-13; design questions open) | — | — | +| local-time | The panel shows time, and counts its days, in a time zone other than UTC | done 2026-10-17, unreleased | — | — | | notification-mail-recheck | The Notification mail records on Server › Settings can be checked again from where they are shown | shipped `2.9.0` | — | — | | settings-save-row | Server › Settings: the Save button no longer stands alone under a long right column | shipped `2.9.0` | — | — | | dns-record-collapse | A DNS record that is right is shown folded: its name and its tag, the values on request | shipped `2.9.0` | — | — | @@ -525,6 +525,26 @@ the database's stored instants and the e2e stay as they are. **Version:** `2.x` MINOR; `agreed`; the plan is written when it is taken up. +**Where the zone comes from, changed (owner, 2026-10-17):** not a setting +in the panel but the container's own zone, `TZ` in `.env`; Settings only +shows it ("Да" to "пояс в `.env`, на Settings только показ?"). His reason +was the trap above: a container cannot change its zone without a restart, +and only the container's zone moves Postfix's stamps with the rest. So the +trap is closed by the third way - the container runs in the zone, Postfix +stamps `mail.log` in it (`TZ` is in Postfix's `import_environment`), and the +tailer reads the stamps in the same zone, as it always did (`lineTime`, +`time.Local`). + +**Done (2026-10-17):** design c205106 (no "UTC" on any screen, Settings box +05 *Time zone*, read-only, the help topic). The panel formats every time in +`time.Local`; the day tables key their rows by the local date, the sender +check cuts downtime at local midnights, the log filters' days run from local +midnight; stored instants stay UTC. Notification mail and the test message +write the zone's abbreviation after a time (they are read away from the +panel). The year question settled as the mockups have it. `tzdata` is named +in the image. Tests run in UTC (a `TestMain` in each package that formats +or counts days) and in Moscow where the zone is the point. + --- ## phone-desktop-mode diff --git a/docs/schema-migrations.md b/docs/schema-migrations.md index 865351c..041b945 100644 --- a/docs/schema-migrations.md +++ b/docs/schema-migrations.md @@ -119,8 +119,8 @@ for operators upgrading from older 2.x images. | `inbound_spam_log` | Inbound antispam journal: one row per recipient of a message offered on port 25, with the decision (`accept`, `reject`, `tempfail`, `quarantine`) and who made it (`rspamd`, `postfix`, `selfpost`). Metadata only. `inbound_domain_id` (v8) ties a row to its domain by id (v2) | | `inbound_spam_list` | Allow / deny entries for the external filter (`address`, `domain`, `ip`), instance-wide; unique per list (v2) | | `notify_state` | What the panel has already written to its users about, one row per subject (`dns:`, `cert`, `queue`, `limit:`), so that each thing is said once and a restart says nothing again (v4) | -| `sender_check_days` | What the sender check costs, a row per UTC day that has something to say: seconds the panel did not answer while Postfix ran, connections turned away (`deferred`), messages deferred mid-message (`messages`), and whether the day's downtime is an upper bound (`estimated`). Kept a year (v6, v9) | -| `delivery_log_days` | What the reconcile sweep and the log tailer did, a row per UTC day, kept a year. Read off a copy of the database; no page shows it (v7) | +| `sender_check_days` | What the sender check costs, a row per day of the container's zone (`TZ`) that has something to say: seconds the panel did not answer while Postfix ran, connections turned away (`deferred`), messages deferred mid-message (`messages`), and whether the day's downtime is an upper bound (`estimated`). Kept a year (v6, v9) | +| `delivery_log_days` | What the reconcile sweep and the log tailer did, a row per day of the container's zone, kept a year. Read off a copy of the database; no page shows it (v7) | | `notify_addressees` | Who a subject's notification is owed to and whether each was handed it; goes with the subject's `notify_state` row (v11) | | `send_log_lines` | The `mail.log` lines Postfix wrote under a queue id, with the line's own time; what a message's page shows once the log has rotated. No reference to `send_log`: a line belongs to a row by queue id and time, and goes when no row carries its id (v3) | diff --git a/internal/health/cert.go b/internal/health/cert.go index e086cde..3f5bbfb 100644 --- a/internal/health/cert.go +++ b/internal/health/cert.go @@ -151,8 +151,8 @@ func CheckServedCertificate(served, mounted string, interval time.Duration, now switch { case r.Late: c.Status = Worst(c.Status, StatusWarn) - c.Detail = fmt.Sprintf("A renewed certificate has been in the mounted file since %s UTC, longer than Postfix's check for a renewal allows, and Postfix still serves the one above. cert-reload's lines in the container log say why.", - r.Mounted.UTC().Format("2006-01-02 15:04")) + c.Detail = fmt.Sprintf("A renewed certificate has been in the mounted file since %s, longer than Postfix's check for a renewal allows, and Postfix still serves the one above. cert-reload's lines in the container log say why.", + r.Mounted.Local().Format("2006-01-02 15:04")) case c.Status == StatusError: c.Detail += " A renewed one is waiting in the mounted file; Postfix takes it up at its next check for a renewal, at most " + intervalText(interval) + " after it was mounted." default: diff --git a/internal/notify/text.go b/internal/notify/text.go index e9b4be8..4918c64 100644 --- a/internal/notify/text.go +++ b/internal/notify/text.go @@ -33,7 +33,7 @@ func compose(hostname, subject string, paragraphs ...string) message { } } -func stamp(t time.Time) string { return t.UTC().Format("2006-01-02 15:04 UTC") } +func stamp(t time.Time) string { return t.Local().Format("2006-01-02 15:04 MST") } // plain makes text that came from outside fit for a message body: a queued // message's sender is whatever its sender wrote, and a DNS finding may quote a diff --git a/internal/store/deliverylog.go b/internal/store/deliverylog.go index ac20a82..647ba0c 100644 --- a/internal/store/deliverylog.go +++ b/internal/store/deliverylog.go @@ -6,7 +6,7 @@ import ( ) // The counters of delivery_log_days (migration 0007): what the reconcile sweep -// and the log tailer did, a row per UTC day, read off a copy of the database +// and the log tailer did, a row per day of the container's zone, read off a copy of the database // to decide the sweep's fate (audit 2026-10-12, stage 1). No page shows them. // deliveryLogKeepDays is how long a day of the counters is kept. @@ -29,7 +29,7 @@ func (s *Store) addDeliveryLogDay(at time.Time, column string, n int64) error { _, err := s.db.Exec(fmt.Sprintf( `INSERT INTO delivery_log_days (day, %[1]s) VALUES (?, ?) ON CONFLICT (day) DO UPDATE SET %[1]s = %[1]s + excluded.%[1]s`, column), - at.UTC().Format(dayLayout), n, + at.Local().Format(dayLayout), n, ) if err != nil { return fmt.Errorf("delivery log day, %s: %w", column, err) @@ -61,7 +61,7 @@ func (s *Store) SetQueuedOverLifetime(at time.Time, n int64) error { _, err := s.db.Exec( `INSERT INTO delivery_log_days (day, queued_over_lifetime) VALUES (?, ?) ON CONFLICT (day) DO UPDATE SET queued_over_lifetime = excluded.queued_over_lifetime`, - at.UTC().Format(dayLayout), n, + at.Local().Format(dayLayout), n, ) if err != nil { return fmt.Errorf("delivery log day, queued_over_lifetime: %w", err) @@ -113,7 +113,7 @@ func (s *Store) DeliveryLogDays() ([]DeliveryLogDay, error) { // PruneDeliveryLogDays deletes the days older than a year. func (s *Store) PruneDeliveryLogDays(now time.Time) error { _, err := s.db.Exec(`DELETE FROM delivery_log_days WHERE day < ?`, - now.UTC().AddDate(0, 0, -deliveryLogKeepDays).Format(dayLayout)) + now.Local().AddDate(0, 0, -deliveryLogKeepDays).Format(dayLayout)) if err != nil { return fmt.Errorf("prune delivery log days: %w", err) } diff --git a/internal/store/inboundspam.go b/internal/store/inboundspam.go index 274f987..5abbff9 100644 --- a/internal/store/inboundspam.go +++ b/internal/store/inboundspam.go @@ -231,7 +231,8 @@ type InboundSpamRow struct { // // Domain, Decision, Since and Until are the operator's own filters, chosen in // the UI: an empty field matches everything. Since and Until are days, both -// inclusive and read as UTC days whatever the time of day they carry. +// inclusive and read as days of the container's zone whatever the time of +// day they carry. // // DomainIDs is the authorization scope, which no query parameter may widen: // the exhaustive set of inbound domains the caller may read, by id - a row of @@ -325,17 +326,17 @@ func inboundSpamWhere(f InboundSpamFilter) (string, []any) { args = append(args, f.Decision) } // created_at is RFC3339 UTC, so comparing it as text against the same - // format is comparing moments: from midnight of the first day up to, not - // including, midnight after the last. + // format is comparing moments: from the container zone's midnight of the + // first day up to, not including, its midnight after the last. if !f.Since.IsZero() { - y, m, d := f.Since.UTC().Date() + y, m, d := f.Since.Date() clauses = append(clauses, "created_at >= ?") - args = append(args, time.Date(y, m, d, 0, 0, 0, 0, time.UTC).Format(time.RFC3339)) + args = append(args, time.Date(y, m, d, 0, 0, 0, 0, time.Local).UTC().Format(time.RFC3339)) } if !f.Until.IsZero() { - y, m, d := f.Until.UTC().Date() + y, m, d := f.Until.Date() clauses = append(clauses, "created_at < ?") - args = append(args, time.Date(y, m, d+1, 0, 0, 0, 0, time.UTC).Format(time.RFC3339)) + args = append(args, time.Date(y, m, d+1, 0, 0, 0, 0, time.Local).UTC().Format(time.RFC3339)) } if len(clauses) == 0 { return "", nil diff --git a/internal/store/inboundspam_test.go b/internal/store/inboundspam_test.go index e3b4bff..9b76622 100644 --- a/internal/store/inboundspam_test.go +++ b/internal/store/inboundspam_test.go @@ -215,7 +215,8 @@ func TestQueryInboundSpamFilters(t *testing.T) { if got := to(InboundSpamFilter{Decision: SpamDecisionReject}); got != "25" { t.Errorf("decision = %q, want 25", got) } - // Days are whole UTC days and both ends are in: 21 st is 00:00 up to 23:59. + // Days are whole days of the container's zone (UTC here, TestMain) and + // both ends are in: 21 st is 00:00 up to 23:59. if got := to(InboundSpamFilter{Since: day(21, 15), Until: day(21, 3)}); got != "32" { t.Errorf("one day = %q, want 32", got) } @@ -225,10 +226,11 @@ func TestQueryInboundSpamFilters(t *testing.T) { if got := to(InboundSpamFilter{Until: day(20, 0)}); got != "15" { t.Errorf("until = %q, want 15", got) } - // A time in another zone is read as the UTC day it falls on. + // A day is the date it carries, whatever zone the time is in: the 22nd at + // 02:00 in Moscow is the 22nd. msk := time.FixedZone("msk", 3*3600) - if got := to(InboundSpamFilter{Since: time.Date(2026, 9, 22, 2, 0, 0, 0, msk)}); got != "432" { - t.Errorf("since in another zone = %q, want 432 (it is the 21st in UTC)", got) + if got := to(InboundSpamFilter{Since: time.Date(2026, 9, 22, 2, 0, 0, 0, msk)}); got != "4" { + t.Errorf("since in another zone = %q, want 4 (the 22nd)", got) } if got := to(InboundSpamFilter{Domain: "b.example", Decision: SpamDecisionAccept, Since: day(21, 0), Until: day(21, 0)}); got != "3" { t.Errorf("all filters = %q, want 3", got) @@ -260,6 +262,14 @@ func TestQueryInboundSpamFilters(t *testing.T) { if got := to(InboundSpamFilter{Domain: "a.example' OR '1'='1"}); got != "" { t.Errorf("injected domain = %q", got) } + + // In a container with TZ=Europe/Moscow the 21st is that zone's: from 20 Sep + // 21:00 UTC, so it takes the row of the 20th at 23:00 UTC and leaves the + // 22nd's at 00:00 UTC, which is 03:00 there. + inZone(t, "Europe/Moscow") + if got := to(InboundSpamFilter{Since: day(21, 0), Until: day(21, 0)}); got != "321" { + t.Errorf("one day in Moscow = %q, want 321", got) + } } func TestListSpamListHits(t *testing.T) { diff --git a/internal/store/sendercheck.go b/internal/store/sendercheck.go index ec086f2..666b356 100644 --- a/internal/store/sendercheck.go +++ b/internal/store/sendercheck.go @@ -26,7 +26,7 @@ const ( // Settings keys of the sender check's statistics. const ( - // settingSenderCheckSince is the first UTC day the statistics cover. + // settingSenderCheckSince is the first day (of the container's zone) the statistics cover. settingSenderCheckSince = "sender_check_since" // settingSenderCheckDeferredAt is when a message was last deferred because // the check did not answer (RFC3339 UTC). @@ -66,7 +66,7 @@ func (s *Store) StartSenderCheckStats(now time.Time) error { if err != nil || v != "" { return err } - return s.SetSetting(settingSenderCheckSince, now.UTC().Format(dayLayout)) + return s.SetSetting(settingSenderCheckSince, now.Local().Format(dayLayout)) } // AddSenderCheckDown adds to the day of at the time the panel did not answer @@ -81,7 +81,7 @@ func (s *Store) AddSenderCheckDown(at time.Time, d time.Duration, estimated bool `INSERT INTO sender_check_days (day, down_seconds, estimated) VALUES (?, ?, ?) ON CONFLICT (day) DO UPDATE SET down_seconds = down_seconds + excluded.down_seconds, estimated = MAX(estimated, excluded.estimated)`, - at.UTC().Format(dayLayout), secs, estimated, + at.Local().Format(dayLayout), secs, estimated, ) if err != nil { return fmt.Errorf("sender check downtime: %w", err) @@ -114,7 +114,7 @@ func (s *Store) AddSenderCheckDeferred(at time.Time, n int64, place string, mess if _, err := tx.Exec(fmt.Sprintf( `INSERT INTO sender_check_days (day, %[1]s) VALUES (?, ?) ON CONFLICT (day) DO UPDATE SET %[1]s = %[1]s + excluded.%[1]s`, column), - at.UTC().Format(dayLayout), n, + at.Local().Format(dayLayout), n, ); err != nil { return fmt.Errorf("sender check deferred: %w", err) } @@ -163,7 +163,7 @@ func (s *Store) SenderCheckDeferredAt() (time.Time, error) { // SenderCheckStats sums the days up to now: today, the last 30 days and the // last 12 months, each including today. func (s *Store) SenderCheckStats(now time.Time) (SenderCheckStats, error) { - now = now.UTC() + now = now.Local() var out SenderCheckStats sum := func(days int) (SenderCheckTotals, error) { var secs, deferred, messages, estimated int64 @@ -193,7 +193,7 @@ func (s *Store) SenderCheckStats(now time.Time) (SenderCheckStats, error) { if err != nil { return out, err } - out.Since, _ = time.Parse(dayLayout, since) + out.Since, _ = time.ParseInLocation(dayLayout, since, time.Local) deferredAt, err := s.GetSetting(settingSenderCheckDeferredAt) if err != nil { return out, err @@ -205,7 +205,7 @@ func (s *Store) SenderCheckStats(now time.Time) (SenderCheckStats, error) { // PruneSenderCheckDays deletes the days older than a year. func (s *Store) PruneSenderCheckDays(now time.Time) error { _, err := s.db.Exec(`DELETE FROM sender_check_days WHERE day < ?`, - now.UTC().AddDate(0, 0, -senderCheckKeepDays).Format(dayLayout)) + now.Local().AddDate(0, 0, -senderCheckKeepDays).Format(dayLayout)) if err != nil { return fmt.Errorf("prune sender check days: %w", err) } diff --git a/internal/store/sendlog.go b/internal/store/sendlog.go index fc4dbd0..118d481 100644 --- a/internal/store/sendlog.go +++ b/internal/store/sendlog.go @@ -224,7 +224,7 @@ func (s *Store) UpdateStatus(queueID, recipient, status string) (int64, error) { if _, err := tx.Exec( `INSERT INTO delivery_log_days (day, reconcile_contradicted) VALUES (?, ?) ON CONFLICT (day) DO UPDATE SET reconcile_contradicted = reconcile_contradicted + excluded.reconcile_contradicted`, - now.Format(dayLayout), contradicted, + now.Local().Format(dayLayout), contradicted, ); err != nil { return 0, fmt.Errorf("update send_log status: count the contradicted sweep: %w", err) } @@ -500,7 +500,8 @@ type SendLogFilter struct { DomainIDs []int64 AllDomains bool // Status is a row's status, and Since and Until are days: from the - // first's midnight up to, not including, midnight after the last, UTC. + // first's midnight up to, not including, midnight after the last, in the + // container's zone. // Zero values do not narrow. Status string Since, Until time.Time @@ -589,14 +590,14 @@ func sendLogWhere(f SendLogFilter) (string, []any) { // created_at is RFC3339 UTC, so comparing it as text against the same // format is comparing moments (as InboundSpamFilter's days). if !f.Since.IsZero() { - y, m, d := f.Since.UTC().Date() + y, m, d := f.Since.Date() clauses = append(clauses, "created_at >= ?") - args = append(args, time.Date(y, m, d, 0, 0, 0, 0, time.UTC).Format(time.RFC3339)) + args = append(args, time.Date(y, m, d, 0, 0, 0, 0, time.Local).UTC().Format(time.RFC3339)) } if !f.Until.IsZero() { - y, m, d := f.Until.UTC().Date() + y, m, d := f.Until.Date() clauses = append(clauses, "created_at < ?") - args = append(args, time.Date(y, m, d+1, 0, 0, 0, 0, time.UTC).Format(time.RFC3339)) + args = append(args, time.Date(y, m, d+1, 0, 0, 0, 0, time.Local).UTC().Format(time.RFC3339)) } if len(clauses) == 0 { return "", nil diff --git a/internal/store/zone_main_test.go b/internal/store/zone_main_test.go new file mode 100644 index 0000000..92d2f92 --- /dev/null +++ b/internal/store/zone_main_test.go @@ -0,0 +1,28 @@ +package store + +import ( + "os" + "testing" + "time" +) + +// TestMain runs the tests in UTC, whatever the zone of the machine they run +// on: the panel shows times and counts days in time.Local, the container's +// zone (TZ), and the fixtures are written in UTC. The tests of another zone +// set it themselves (inZone). +func TestMain(m *testing.M) { + time.Local = time.UTC + os.Exit(m.Run()) +} + +// inZone runs the rest of the test in the zone name, as a container started +// with TZ=name; the test must not be parallel. +func inZone(t *testing.T, name string) { + t.Helper() + loc, err := time.LoadLocation(name) + if err != nil { + t.Skipf("no zone %s here: %v", name, err) + } + time.Local = loc + t.Cleanup(func() { time.Local = time.UTC }) +} diff --git a/internal/web/handlers/handlers.go b/internal/web/handlers/handlers.go index 744bd4d..ff50cbb 100644 --- a/internal/web/handlers/handlers.go +++ b/internal/web/handlers/handlers.go @@ -31,6 +31,7 @@ type Config struct { TLSServedCertFile string TLSReloadInterval time.Duration SMTPBanner string + TimeZone string SignSocket string SignLocalSocket string JournalSocket string diff --git a/internal/web/handlers/handlers_apps.go b/internal/web/handlers/handlers_apps.go index 9bb0309..7c3381e 100644 --- a/internal/web/handlers/handlers_apps.go +++ b/internal/web/handlers/handlers_apps.go @@ -316,7 +316,7 @@ func formatAutoUpdated(t time.Time) string { if t.IsZero() { return "" } - return t.UTC().Format("2006-01-02 15:04 UTC") + return t.Local().Format("2006-01-02 15:04") } // detailFlash maps a fixed redirect flag to a fixed message, so status text diff --git a/internal/web/handlers/handlers_dmarc_pages_test.go b/internal/web/handlers/handlers_dmarc_pages_test.go index b64a34a..f0340c8 100644 --- a/internal/web/handlers/handlers_dmarc_pages_test.go +++ b/internal/web/handlers/handlers_dmarc_pages_test.go @@ -133,10 +133,12 @@ func TestDMARCReportShowsPolicyAndRecords(t *testing.T) { has(t, "report", body, `

Outlook.com · `, `DMARC reports /`, `example.org /`, "1\u00a0903 pass", `7 fail`, - `5f1c9a0e7b2d4e61a3`, `noreply-dmarc@outlook.example`, ` UTC`, + `5f1c9a0e7b2d4e61a3`, `noreply-dmarc@outlook.example`, `none / none / 100`, `
r / r
`, `dmarc-reports@mail.example.org`, `

Records

`, `Parsed from the aggregate XML`, `203.0.113.25`, `198.51.100.44`, `fail`, `pass`) + // The times are the container's zone's, and say no zone (local-time). + lacks(t, "report", body, ` UTC`) } // DMARC is a feature of the deployment: with ingest off none of its pages diff --git a/internal/web/handlers/handlers_dmarc_reports.go b/internal/web/handlers/handlers_dmarc_reports.go index 630bc17..1f083fb 100644 --- a/internal/web/handlers/handlers_dmarc_reports.go +++ b/internal/web/handlers/handlers_dmarc_reports.go @@ -199,8 +199,8 @@ func (h *Handlers) HandleDMARCReport(w http.ResponseWriter, r *http.Request) { ID: rep.ID, Reporter: rep.Reporter, ReportID: rep.ReportID, Domain: rep.Domain, DomainID: d.ID, Contact: rep.ContactEmail, Pass: rep.PassCount, Fail: rep.FailCount, Window: formatDMARCWindow(rep.PeriodBegin, rep.PeriodEnd), - Period: rep.PeriodBegin.UTC().Format(stamp) + " – " + rep.PeriodEnd.UTC().Format(stamp) + " UTC", - Received: rep.ReceivedAt.UTC().Format("2006-01-02 15:04") + " UTC", + Period: rep.PeriodBegin.Local().Format(stamp) + " – " + rep.PeriodEnd.Local().Format(stamp), + Received: rep.ReceivedAt.Local().Format("2006-01-02 15:04"), PolicyP: rep.PolicyP, PolicySP: rep.PolicySP, PolicyPct: rep.PolicyPct, PolicyADKIM: rep.PolicyADKIM, PolicyASPF: rep.PolicyASPF, Recipient: rep.Recipient, Hub: true, diff --git a/internal/web/handlers/handlers_health_page_test.go b/internal/web/handlers/handlers_health_page_test.go index 27836e5..3ef65b4 100644 --- a/internal/web/handlers/handlers_health_page_test.go +++ b/internal/web/handlers/handlers_health_page_test.go @@ -74,7 +74,7 @@ func TestHealthPageRendersEveryCheck(t *testing.T) { out := renderHealth(t, h, healthReading(), "") for _, want := range []string{ "panel", "fatal", "exited too quickly", - "mail.example.com", "203.0.113.10 → no PTR record", "2026-11-08 09:14 UTC", + "mail.example.com", "203.0.113.10 → no PTR record", "2026-11-08 09:14", `action="/server/health/reload"`, `action="/server/health/recheck"`, `hx-get="/server/health/fragment"`, `error`, // postfix, and the reverse DNS box @@ -164,9 +164,9 @@ func TestHealthPageNamesARenewalWaiting(t *testing.T) { c.Cert = cert out := renderHealth(t, h, c, "") for _, want := range []string{ - "
Expires
", "2026-11-08 09:14 UTC", - "
Renewal expires
", "2027-01-31 08:02 UTC", - "
Renewal mounted
", "2026-10-15 03:12 UTC", + "
Expires
", "2026-11-08 09:14", + "
Renewal expires
", "2027-01-31 08:02", + "
Renewal mounted
", "2026-10-15 03:12", "Postfix still serves the certificate above.", } { if !strings.Contains(out, want) { diff --git a/internal/web/handlers/handlers_inbound_log_test.go b/internal/web/handlers/handlers_inbound_log_test.go index b75c5d1..0f1d8d0 100644 --- a/internal/web/handlers/handlers_inbound_log_test.go +++ b/internal/web/handlers/handlers_inbound_log_test.go @@ -529,7 +529,7 @@ func TestFilterListsWhereTheyGo(t *testing.T) { } body = s.get(s.h.HandleFilterLists, "/inbound/filter-lists", globalPrincipal).Body.String() has(t, "filter on", body, `applied`, - `rspamd, from map files it rereads within seconds of a change`, `
Last written
2026-09-11 08:40 UTC
`, + `rspamd, from map files it rereads within seconds of a change`, `
Last written
2026-09-11 08:40
`, `/data/antispam/`) lacks(t, "filter on", body, `not applied`, `Nothing — the spam filter is off`, `INBOUND_ANTISPAM_MILTER`) } diff --git a/internal/web/handlers/handlers_monitor.go b/internal/web/handlers/handlers_monitor.go index 02f4ded..6f04e5c 100644 --- a/internal/web/handlers/handlers_monitor.go +++ b/internal/web/handlers/handlers_monitor.go @@ -387,7 +387,8 @@ func (h *Handlers) outLogPage(r *http.Request) (*view.OutLog, error) { } form := view.OutLogFilter{Domain: filter.Domain, App: filter.AppLogin, Status: filter.Status} // The days, as on the Inbound log: from the first's midnight to the end of - // the last, UTC; a day that does not parse is no narrowing. + // the last, in the container's zone; a day that does not parse is no + // narrowing. if t, err := time.Parse(logDay, q.Get("from")); err == nil { form.From, filter.Since = t.Format(logDay), t } diff --git a/internal/web/handlers/handlers_settings.go b/internal/web/handlers/handlers_settings.go index e7365f8..85c826e 100644 --- a/internal/web/handlers/handlers_settings.go +++ b/internal/web/handlers/handlers_settings.go @@ -60,6 +60,7 @@ func (h *Handlers) renderServerSettings(w http.ResponseWriter, r *http.Request, page.WithNotifications(on, notify.From(h.cfg.Hostname)) mail := h.serverMail(false) page.WithMail(mail.records, view.FormatAge(mail.checked, time.Now())) + page.WithTimeZone(h.cfg.TimeZone, time.Local, time.Now()) // The inbound field exists while there is an inbound journal to keep. if h.cfg.InboundEnabled { page.WithInbound(strconv.Itoa(form.inbound)) diff --git a/internal/web/handlers/handlers_status.go b/internal/web/handlers/handlers_status.go index 647b303..31112b1 100644 --- a/internal/web/handlers/handlers_status.go +++ b/internal/web/handlers/handlers_status.go @@ -194,9 +194,9 @@ func (h *Handlers) HandleTestMessage(w http.ResponseWriter, r *http.Request) { return } const subject = "SelfPost test message" - now := time.Now().UTC() + now := time.Now() body := "A test message from SelfPost at " + h.cfg.Hostname + ", sent from Server › Health on " + - now.Format("2006-01-02 at 15:04 UTC") + ".\n\nIt came from this server, signed with the DKIM key of its own name. " + + now.Format("2006-01-02 at 15:04 MST") + ".\n\nIt came from this server, signed with the DKIM key of its own name. " + "Its page in the panel's Outbound log shows what this mail server answered.\n" row, err := h.store.InsertTestMessage(h.cfg.Hostname, from, to, subject) if err != nil { @@ -290,7 +290,7 @@ func healthPage(m view.Meta, c healthReadings, flash string) *view.Health { cert := c.Cert page.Certificate.End = view.Verdict(string(cert.Status)) if !cert.NotAfter.IsZero() { - page.CertFacts = append(page.CertFacts, view.Fact{Label: "Expires", Value: view.Plain(cert.NotAfter.UTC().Format("2006-01-02 15:04 UTC")), Mono: true}) + page.CertFacts = append(page.CertFacts, view.Fact{Label: "Expires", Value: view.Plain(cert.NotAfter.Local().Format("2006-01-02 15:04")), Mono: true}) } if len(cert.Names) > 0 { names := view.Fact{Label: "Names", Value: view.Plain(strings.Join(cert.Names, ", ")), Mono: true} @@ -304,8 +304,8 @@ func healthPage(m view.Meta, c healthReadings, flash string) *view.Health { } if r := cert.Renewal; r != nil { page.CertFacts = append(page.CertFacts, - view.Fact{Label: "Renewal expires", Value: view.Plain(r.NotAfter.UTC().Format("2006-01-02 15:04 UTC")), Mono: true}, - view.Fact{Label: "Renewal mounted", Value: view.Plain(r.Mounted.UTC().Format("2006-01-02 15:04 UTC")), Mono: true}) + view.Fact{Label: "Renewal expires", Value: view.Plain(r.NotAfter.Local().Format("2006-01-02 15:04")), Mono: true}, + view.Fact{Label: "Renewal mounted", Value: view.Plain(r.Mounted.Local().Format("2006-01-02 15:04")), Mono: true}) } page.CertDetail, page.CertProblem = cert.Detail, cert.Status != health.StatusOK diff --git a/internal/web/handlers/zone_main_test.go b/internal/web/handlers/zone_main_test.go new file mode 100644 index 0000000..392880d --- /dev/null +++ b/internal/web/handlers/zone_main_test.go @@ -0,0 +1,28 @@ +package handlers + +import ( + "os" + "testing" + "time" +) + +// TestMain runs the tests in UTC, whatever the zone of the machine they run +// on: the panel shows times and counts days in time.Local, the container's +// zone (TZ), and the fixtures are written in UTC. The tests of another zone +// set it themselves (inZone). +func TestMain(m *testing.M) { + time.Local = time.UTC + os.Exit(m.Run()) +} + +// inZone runs the rest of the test in the zone name, as a container started +// with TZ=name; the test must not be parallel. +func inZone(t *testing.T, name string) { + t.Helper() + loc, err := time.LoadLocation(name) + if err != nil { + t.Skipf("no zone %s here: %v", name, err) + } + time.Local = loc + t.Cleanup(func() { time.Local = time.UTC }) +} diff --git a/internal/web/view/account.go b/internal/web/view/account.go index 1281ad4..272d983 100644 --- a/internal/web/view/account.go +++ b/internal/web/view/account.go @@ -6,7 +6,12 @@ package view // user's own — who they are to the panel and their password — and every role // has it. Settings is the instance's. -import "strconv" +import ( + "fmt" + "strconv" + "strings" + "time" +) // Account is the data of the Account page. Two forms, each its own POST: the // profile (Username, Email) and the password. The fields hold what was stored, @@ -78,6 +83,11 @@ type Settings struct { // are signed and authorised with, drawn like a domain's. Mail Box MailRecords []Record + + // TimeZone names the container's zone, which every time and day the + // panel shows is in; it is set in .env, so the box only shows it. + TimeZone Box + ZoneFacts []Fact } // NewSettings builds the page. retention is what the field shows (the stored @@ -106,6 +116,7 @@ func NewSettings(m Meta, retention, level1 string) *Settings { Notifications: Box{No: "02", Title: "Notifications", ID: "notifications", Help: topicLink(HelpNotifications, "What is sent and when")}, Mail: Box{No: "03", Title: "Notification mail", ID: "notification-mail", End: Plain("DNS records of the server's own name"), Help: topicLink(HelpNotifications, "What the panel sends and what makes it arrive")}, + TimeZone: Box{No: "05", Title: "Time zone", ID: "time-zone", End: Plain("Read-only"), Help: topicLink(HelpSettings, "Times and days of the panel")}, } } @@ -133,6 +144,29 @@ func (s *Settings) WithMail(records []Record, checked string) *Settings { return s } +// WithTimeZone names the zone: tz is TZ as the container has it ("" is UTC, +// Go's and the C library's default), loc the zone the process took from it +// (time.Local), at now for its offset. A TZ Go cannot load leaves time.Local +// UTC (time/zoneinfo_unix.go, initLocal), and the box says so rather than name +// a zone the times are not in. +func (s *Settings) WithTimeZone(tz string, loc *time.Location, now time.Time) *Settings { + name := strings.TrimPrefix(tz, ":") + if name == "" { + name = "UTC" + } + _, offset := now.In(loc).Zone() + sign := "+" + if offset < 0 { + sign, offset = "-", -offset + } + note := Rich(fmt.Sprintf("UTC%s%02d:%02d. Set in ", sign, offset/3600, offset%3600/60), Code(".env"), " (", Code("TZ"), "); restart to change.") + if name != "UTC" && loc.String() != name { + note = Rich("Not a zone this image knows, so the times are UTC. Set in ", Code(".env"), " (", Code("TZ"), "); restart to change.") + } + s.ZoneFacts = []Fact{{Label: "Zone", Value: Plain(name), Mono: true, Note: note}} + return s +} + // WithInbound adds the retention of the Inbound log to the Log retention box. // days is what the field shows, like retention in NewSettings. The field exists // only while the inbound relay is on: with it off there is no journal to keep. diff --git a/internal/web/view/components_test.go b/internal/web/view/components_test.go index d31fe92..2f712c6 100644 --- a/internal/web/view/components_test.go +++ b/internal/web/view/components_test.go @@ -169,7 +169,7 @@ func TestPageHeadStates(t *testing.T) { Crumbs: []Crumb{{Href: "/outbound/domains", Label: "Outbound domains"}, {Label: "Applications"}}, Title: "New password for", Code: "prod-server", Lead: Rich("Lead with ", Code("code")), - Note: []string{"Updated 14:02:31 UTC", "refreshes every 10 s"}, + Note: []string{"Updated 14:02:31", "refreshes every 10 s"}, Actions: []Action{{Label: "Re-check DNS", Icon: "ti-refresh", Post: "/x/dns-recheck"}, {Label: "Add", Icon: "ti-plus", Href: "/x/new", Primary: true}, {Label: "Delete", Href: "/x/delete", Danger: true}}, })) mustContain(t, out, @@ -177,7 +177,7 @@ func TestPageHeadStates(t *testing.T) { `

Outbound domains / Applications /

`, `

New password for prod-server

`, `

Lead with code

`, - `
Updated 14:02:31 UTC
refreshes every 10 s
`, + `
Updated 14:02:31
refreshes every 10 s
`, `
`, `Add`, `Delete`) @@ -352,15 +352,15 @@ func TestSideMenu(t *testing.T) { func TestTimelineLevels(t *testing.T) { out := squash(partial(t, "timeline", []Step{ - {Time: "13:58:07 UTC", Strong: "Accepted", Text: Rich(" from ", Mono("alerts"))}, - {Time: "13:58:09 UTC", Strong: "Deferred", Text: Plain(" — later"), Level: LevelWarn}, - {Time: "14:40:00 UTC", Strong: "Bounced", Level: LevelFail}, + {Time: "13:58:07", Strong: "Accepted", Text: Rich(" from ", Mono("alerts"))}, + {Time: "13:58:09", Strong: "Deferred", Text: Plain(" — later"), Level: LevelWarn}, + {Time: "14:40:00", Strong: "Bounced", Level: LevelFail}, {Time: "next attempt", Text: Plain("Still queued"), Level: LevelPending}, })) mustContain(t, out, - `
  1. Accepted from alerts
  2. `, - `
  3. Deferred — later
  4. `, - `
  5. Bounced
  6. `, + `
    1. Accepted from alerts
    2. `, + `
    3. Deferred — later
    4. `, + `
    5. Bounced
    6. `, `
    7. Still queued
    8. `) } diff --git a/internal/web/view/dmarc.go b/internal/web/view/dmarc.go index 2aa75cf..a24a819 100644 --- a/internal/web/view/dmarc.go +++ b/internal/web/view/dmarc.go @@ -25,7 +25,7 @@ func DMARCDomainHref(id int64) string { return outboundDMARC + "/domains/" + str func DMARCReportHref(id int64) string { return outboundDMARC + "/reports/" + strconv.FormatInt(id, 10) } // FormatReceived is the time a report was received, as the tables show it. -func FormatReceived(t time.Time) string { return t.UTC().Format("01-02 15:04") } +func FormatReceived(t time.Time) string { return t.Local().Format("01-02 15:04") } // ---- The hub @@ -97,7 +97,7 @@ func NewDMARCHub(m Meta, in IngestInput) *DMARCHub { if in.Last.IsZero() { last.Note = Rich("Set a domain to SelfPost hosted in its Domain settings, publish the DMARC record it then shows, and publish MX for ", Mono(in.Host), " pointing at this server.") } else { - last.Value = Plain(in.Last.UTC().Format("2006-01-02 15:04") + " UTC") + last.Value = Plain(in.Last.Local().Format("2006-01-02 15:04")) } return &DMARCHub{ Meta: m, @@ -329,8 +329,8 @@ type ReportInput struct { Contact string Pass, Fail int Window string // the window in the title: "20 Sep" - Period string // the window with its times: "20 Sep 00:00 – 21 Sep 00:00 UTC" - Received string // "2026-09-21 04:40 UTC" + Period string // the window with its times: "20 Sep 00:00 – 21 Sep 00:00" + Received string // "2026-09-21 04:40" PolicyP string PolicySP string PolicyPct int diff --git a/internal/web/view/dmarc_test.go b/internal/web/view/dmarc_test.go index 1975897..d9cdca4 100644 --- a/internal/web/view/dmarc_test.go +++ b/internal/web/view/dmarc_test.go @@ -12,8 +12,8 @@ func TestDMARCHubShowsIngestAndTheLatestReports(t *testing.T) { pageHas(t, "DMARC reports", out, `

      DMARC reports

      `, `rua=`, `

      Ingest

      `, `ok`, - `
      2026-09-21 06:12 UTC
      `, `
      14 kept · 0 parse failures
      `, `
      Hosted addresses
      `, `
      dmarc-reports+<domain>@mail.example.org
      `, `
      500 reports a domain or 90 days
      `, - `Received, UTC`, `09-21 06:12`, `example.org`, + `
      2026-09-21 06:12
      `, `
      14 kept · 0 parse failures
      `, `
      Hosted addresses
      `, `
      dmarc-reports+<domain>@mail.example.org
      `, `
      500 reports a domain or 90 days
      `, + `Received`, `09-21 06:12`, `example.org`, "1 903", `7`, `0View`, ) } @@ -98,7 +98,7 @@ func TestDMARCReportShowsTheReportItsPolicyAndRecords(t *testing.T) { `

      Outlook.com · 20 Sep

      `, `DMARC reports / shop.example.org /`, "shop.example.org1 903 pass7 fail", - `

      Report

      `, `
      5f1c9a0e7b2d4e61a3
      `, `
      20 Sep 00:00 – 21 Sep 00:00 UTC
      `, `
      2026-09-21 04:40 UTC
      `, + `

      Report

      `, `
      5f1c9a0e7b2d4e61a3
      `, `
      20 Sep 00:00 – 21 Sep 00:00
      `, `
      2026-09-21 04:40
      `, `

      Published policy

      `, `
      none / none / 100
      `, `
      r / r
      `, `
      dmarc@mail.example.org
      `, `

      Records

      `, `Parsed from the aggregate XML`, `203.0.113.25 this relay`, "1 903", @@ -111,7 +111,7 @@ func TestDMARCReportShowsTheReportItsPolicyAndRecords(t *testing.T) { // nothing failed, and a report with no records says so. func TestDMARCReportOmitsWhatItDoesNotHold(t *testing.T) { p := NewDMARCReport(admin(), ReportInput{ID: 1, Reporter: "google.com", ReportID: "r1", Domain: "example.org", DomainID: 1, Pass: 5, - Period: "20 Sep 00:00 – 20 Sep 23:59 UTC", Received: "2026-09-21 04:40 UTC", PolicyP: "none", PolicySP: "none", PolicyPct: 100, PolicyADKIM: "r", PolicyASPF: "r"}) + Period: "20 Sep 00:00 – 20 Sep 23:59", Received: "2026-09-21 04:40", PolicyP: "none", PolicySP: "none", PolicyPct: 100, PolicyADKIM: "r", PolicyASPF: "r"}) out := renderSignedIn(t, "dmarc-report", p.WithRecords(nil)) pageHas(t, "DMARC report", out, `

      google.com

      `, `5 pass`, `This report holds no records.`) pageLacks(t, "DMARC report", out, `fail`, `Contact`, `
      rua
      `, ``) diff --git a/internal/web/view/fixtures_test.go b/internal/web/view/fixtures_test.go index 93c7031..b3bc324 100644 --- a/internal/web/view/fixtures_test.go +++ b/internal/web/view/fixtures_test.go @@ -113,7 +113,7 @@ func healthFixture(refresh bool) *Health { } h.Certificate.End = Verdict("warn") h.CertFacts = []Fact{ - {Label: "Expires", Value: Plain("2026-10-21 09:14 UTC"), Mono: true}, + {Label: "Expires", Value: Plain("2026-10-21 09:14"), Mono: true}, {Label: "Names", Value: Plain("mail.example.org"), Mono: true}, } h.CertDetail, h.CertProblem = "Expires in 12 day(s). Check that renewal on the host still works.", true @@ -149,16 +149,21 @@ func accountFixture() *Account { const mailFixtureDKIMHost = "sp2026._domainkey.mail.example.org" // settingsFixture is the mockup's Settings: thirty days of log, a limit of 600 -// messages an hour, notifications on, and the records of the server's own name -// with the DKIM one published and the SPF one missing. +// messages an hour, notifications on, the records of the server's own name +// with the DKIM one published and the SPF one missing, and Moscow's time. func settingsFixture() *Settings { + msk, err := time.LoadLocation("Europe/Moscow") + if err != nil { + msk = time.FixedZone("Europe/Moscow", 3*3600) + } key := "v=DKIM1; k=rsa; p=" + strings.Repeat("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A", 10) + "IDAQAB" return NewSettings(admin(), "30", FormatRate(600, 3600)).WithInbound("90"). WithNotifications(true, "postmaster@mail.example.org"). WithMail([]Record{ ServerMailDKIM("sp2026", mailFixtureDKIMHost, key, DNSCheck{Status: "ok"}), ServerMailSPF("mail.example.org", "v=spf1 a -all", DNSCheck{Status: "error", Detail: "No SPF record is published for mail.example.org."}), - }, "3 min ago") + }, "3 min ago"). + WithTimeZone("Europe/Moscow", msk, time.Date(2026, 10, 17, 12, 0, 0, 0, time.UTC)) } // outDomainsFixture is the mockup's Outbound domains: three domains, the first @@ -220,7 +225,7 @@ func outDomainSettingsFixture() *OutDomainSettings { p.WithExport(12) return p.WithRateLimit(DomainRateLimit{ Active: true, Auto: true, MaxMessages: "288", Window: "3600", Multiplier: "2.5", - Computed: "288", Peak: 96, Updated: "2026-10-09 03:00 UTC", + Computed: "288", Peak: 96, Updated: "2026-10-09 03:00", L1Messages: 600, L1Window: 3600, MinMultiplier: "1.5", MaxMultiplier: "5", DefaultMultiplier: "2.5", }) } @@ -338,7 +343,7 @@ func dmarcDomainFixture() *DMARCDomain { func dmarcReportFixture() *DMARCReport { return NewDMARCReport(admin(), ReportInput{ ID: 40, Reporter: "Outlook.com", ReportID: "5f1c9a0e7b2d4e61a3", Domain: "shop.example.org", DomainID: 2, - Pass: 1903, Fail: 7, Window: "20 Sep", Period: "20 Sep 00:00 – 21 Sep 00:00 UTC", Received: "2026-09-21 04:40 UTC", + Pass: 1903, Fail: 7, Window: "20 Sep", Period: "20 Sep 00:00 – 21 Sep 00:00", Received: "2026-09-21 04:40", PolicyP: "none", PolicySP: "none", PolicyPct: 100, PolicyADKIM: "r", PolicyASPF: "r", Recipient: "dmarc@mail.example.org", Hub: true, }).WithRecords([]DMARCRecordRow{ diff --git a/internal/web/view/help.go b/internal/web/view/help.go index 7ff776b..699e58f 100644 --- a/internal/web/view/help.go +++ b/internal/web/view/help.go @@ -263,7 +263,9 @@ var serverTopics = []HelpTopic{ " on either list. The only global user cannot be demoted or deleted, and you cannot delete the account you are signed in with. A new password set here signs that user out of their other sessions."), }}, {ID: HelpSettings, Title: "Settings", Body: []Text{ - Rich("Settings holds what is true of the whole instance. Log retention is how many days the Outbound log keeps its rows, from 7 to 365 and 90 by default; a sweep every six hours deletes older ones, and it is the main driver of how fast ", + Rich("Settings holds what is true of the whole instance. The time zone is the container's, ", Code("TZ"), " in ", Code(".env"), + " (UTC when it is not set): every time the panel shows and every day it counts is that zone's, as are the stamps Postfix writes in ", Code("mail.log"), + ", so the two always agree; changing it is a restart of the container. Log retention is how many days the Outbound log keeps its rows, from 7 to 365 and 90 by default; a sweep every six hours deletes older ones, and it is the main driver of how fast ", Code("/data"), " grows. With the inbound relay on there is a second number, for the Inbound log, with the same range. It does not change the rotation of ", Code("mail.log"), ", which is daily with about two weeks kept. The sending rate limit shown under it is level 1, the per-client-IP ceiling set in ", Code(".env"), ": changing it needs a restart, and no level-2 limit can exceed it. Notifications are turned on or off here for everyone."), diff --git a/internal/web/view/inbound_lists.go b/internal/web/view/inbound_lists.go index 94b90a4..6dc18bf 100644 --- a/internal/web/view/inbound_lists.go +++ b/internal/web/view/inbound_lists.go @@ -141,7 +141,7 @@ func (p *FilterLists) setWhere(in FilterListsInput) { } written := "never" if !in.LastWritten.IsZero() { - written = in.LastWritten.UTC().Format("2006-01-02 15:04") + " UTC" + written = in.LastWritten.Local().Format("2006-01-02 15:04") } p.WhereFacts = []Fact{ {Label: "Applied by", Value: applied}, @@ -159,7 +159,7 @@ func (p *FilterLists) WithEntries(entries []FilterEntryInput) *FilterLists { window := "in the last " + plural(int64(p.retentionDays), "day", "days") sheet := []SheetRow{ {Label: "Note", Lines: []string{orDash(e.Note)}}, - {Label: "Added", Lines: []string{e.Added.UTC().Format("2006-01-02")}, Mono: true}, + {Label: "Added", Lines: []string{e.Added.Local().Format("2006-01-02")}, Mono: true}, } row := FilterRow{ Value: e.Value, @@ -169,7 +169,7 @@ func (p *FilterLists) WithEntries(entries []FilterEntryInput) *FilterLists { row.Matched = strconv.Itoa(e.Hits) sheet = append(sheet, SheetRow{Label: "Matched", Lines: []string{row.Matched + " " + window}}, - SheetRow{Label: "Last match", Lines: []string{e.LastHit.UTC().Format("2006-01-02 15:04")}, Mono: true}) + SheetRow{Label: "Last match", Lines: []string{e.LastHit.Local().Format("2006-01-02 15:04")}, Mono: true}) } else { sheet = append(sheet, SheetRow{Label: "Matched", Lines: []string{"never " + window}}) } diff --git a/internal/web/view/inbound_log_test.go b/internal/web/view/inbound_log_test.go index 66bc6fb..5a22c63 100644 --- a/internal/web/view/inbound_log_test.go +++ b/internal/web/view/inbound_log_test.go @@ -22,7 +22,7 @@ func TestInLogShowsTheRowsAndTheirFilters(t *testing.T) { ``, ``, `href="/help#inbound-log" title="What the decisions mean"`, - `Time, UTCFromToSubjectDecisionUpstream`, + `TimeFromToSubjectDecisionUpstream`, // what the upstream answered: a tag that opens its last reply, a // plain tag while not tried, "—" for refused mail `
      `, @@ -219,7 +219,7 @@ func TestFilterListsShowsTheFormTheListsAndWhereTheyGo(t *testing.T) { `

      Where the lists go

      applied
      `, `rspamd, from map files it rereads within seconds of a change`, `/data/antispam/ — six, one for each list and kind of entry`, - `2026-09-11 08:40 UTC`, `Deny wins, whichever entries they are.`, + `2026-09-11 08:40`, `Deny wins, whichever entries they are.`, ) if got := strings.Count(out, ``); got != 2 { t.Errorf("%d list tables, want the two lists", got) diff --git a/internal/web/view/kit.go b/internal/web/view/kit.go index 6c88b65..6179ef7 100644 --- a/internal/web/view/kit.go +++ b/internal/web/view/kit.go @@ -151,9 +151,9 @@ func KitPage() *Kit { Timeline: Box{No: "08", Title: "timeline"}, Steps: []Step{ - {Time: "13:58:07 UTC", Strong: "Done", Text: Plain(" — default")}, - {Time: "13:58:09 UTC", Strong: "Deferred", Text: Plain(" — sp-warn"), Level: LevelWarn}, - {Time: "14:40:00 UTC", Strong: "Bounced", Text: Plain(" — sp-fail"), Level: LevelFail}, + {Time: "13:58:07", Strong: "Done", Text: Plain(" — default")}, + {Time: "13:58:09", Strong: "Deferred", Text: Plain(" — sp-warn"), Level: LevelWarn}, + {Time: "14:40:00", Strong: "Bounced", Text: Plain(" — sp-fail"), Level: LevelFail}, {Time: "not yet", Text: Plain("Expected next — sp-pending"), Level: LevelPending}, }, diff --git a/internal/web/view/outbound.go b/internal/web/view/outbound.go index 8f5f348..ce6c822 100644 --- a/internal/web/view/outbound.go +++ b/internal/web/view/outbound.go @@ -63,7 +63,7 @@ func FormatAge(t, now time.Time) string { case d < 48*time.Hour: return fmt.Sprintf("%d h ago", int(d/time.Hour)) default: - return t.UTC().Format("2006-01-02") + return t.Local().Format("2006-01-02") } } diff --git a/internal/web/view/outbound_log.go b/internal/web/view/outbound_log.go index 5ae1e2b..26c08a7 100644 --- a/internal/web/view/outbound_log.go +++ b/internal/web/view/outbound_log.go @@ -62,11 +62,11 @@ func LogHref(f OutLogFilter, page int) string { } // FormatLogTime is the time of a row of the log: month, day and the time of day -// in UTC, as the table's "Time, UTC" column shows it. -func FormatLogTime(t time.Time) string { return t.UTC().Format("01-02 15:04:05") } +// in the container's zone, as the table's "Time" column shows it. +func FormatLogTime(t time.Time) string { return t.Local().Format("01-02 15:04:05") } -// formatStamp is a moment on the page of one message, with its zone. -func formatStamp(t time.Time) string { return t.UTC().Format("2006-01-02 15:04:05") + " UTC" } +// formatStamp is a moment on the page of one message, in the container's zone. +func formatStamp(t time.Time) string { return t.Local().Format("2006-01-02 15:04:05") } // ---- The log diff --git a/internal/web/view/outbound_log_test.go b/internal/web/view/outbound_log_test.go index 41572a3..af84db4 100644 --- a/internal/web/view/outbound_log_test.go +++ b/internal/web/view/outbound_log_test.go @@ -19,7 +19,7 @@ func TestOutLogShowsTheRowsAndTheirFilters(t *testing.T) { ``, ``, - ``, `09-21 14:01:52`, + ``, `09-21 14:01:52`, `shop@shop.example.org`, `m.keller@gmx.de`, `title="[FIRING] disk usage above 90 % on db-2"`, `sent`, `deferred`, `bounced`, `rate-limited`, `wrong From`, @@ -113,9 +113,9 @@ func TestOutMessageShowsWhatTheJournalRecorded(t *testing.T) { `Outbound log /`, `

      alerts@example.orgnoc@example.orgdeferred

      `, `example.org`, `
      alerts
      `, - `2026-09-21 13:58:07 UTC`, `2026-09-21 13:58:09 UTC`, `
      4XcB7k2Jm9z1
      `, `
      184220
      `, - `
    9. Accepted and queued`, - `
    10. Deferred, will be retried`, + `2026-09-21 13:58:07`, `2026-09-21 13:58:09`, `
      4XcB7k2Jm9z1
      `, `
      184220
      `, + `
    11. Accepted and queued`, + `
    12. Deferred, will be retried`, `
    13. `, `Lines from mail.log with this queue id`, `
      `, `13:58:07 postfix/smtpd[2114]`,
       		`postfix/smtp[2123]: 4XcB7k2Jm9z1: to=<noc@example.org>`,
      diff --git a/internal/web/view/outbound_test.go b/internal/web/view/outbound_test.go
      index 0168553..b64ea46 100644
      --- a/internal/web/view/outbound_test.go
      +++ b/internal/web/view/outbound_test.go
      @@ -227,7 +227,7 @@ func TestOutDomainSettingsHasAFormPerBox(t *testing.T) {
       		`name="password"`, `name="password_confirm"`, `minlength="12"`, `at least 12 characters`,
       		`action="/outbound/domains/1/settings/ratelimit"`, `name="mode"`, `data-ratelimit-mode`, `data-manual-fields`, `data-auto-fields`,
       		`name="max_messages"`, `max="600"`, `name="window_seconds"`, `name="auto_multiplier"`, `min="1.5" max="5"`, `Multiplier (1.5–5, default 2.5)`,
      -		`Computed limit: 288 messages / 3600 s. Peak was 96 msg/h. Last recalculated 2026-10-09 03:00 UTC.`,
      +		`Computed limit: 288 messages / 3600 s. Peak was 96 msg/h. Last recalculated 2026-10-09 03:00.`,
       		`
    14. Time, UTCTime
      - + {{range .Rows}} {{end}} diff --git a/internal/web/view/templates/dmarc_domain.html b/internal/web/view/templates/dmarc_domain.html index 4b2aceb..fdba658 100644 --- a/internal/web/view/templates/dmarc_domain.html +++ b/internal/web/view/templates/dmarc_domain.html @@ -22,7 +22,7 @@ {{template "box_open" .Reports}} {{if .Rows}}
      Received, UTCDomainReporterWindowPassFail
      ReceivedDomainReporterWindowPassFail
      {{.Received}}{{if .DomainHref}}{{.Domain}}{{else}}{{.Domain}}{{end}}{{.Reporter}}{{.Window}}{{.PassText}}{{if .Fail}}{{template "tag" .FailTag}}{{else}}0{{end}}View
      - + {{range .Rows}} {{end}} diff --git a/internal/web/view/templates/in_log.html b/internal/web/view/templates/in_log.html index 4072a8c..50e06d3 100644 --- a/internal/web/view/templates/in_log.html +++ b/internal/web/view/templates/in_log.html @@ -11,7 +11,7 @@ {{template "box_open" .Messages}} {{if .Rows}}
      Received, UTCReporterWindowPassFail
      ReceivedReporterWindowPassFail
      {{.Received}}{{.Reporter}}{{.Window}}{{.PassText}}{{if .Fail}}{{template "tag" .FailTag}}{{else}}0{{end}}View
      - + {{range .Rows}} {{if .Subject}}{{else}}{{end}}{{if .Upstream}}{{else if .Pending}}{{else}}{{end}}{{end}} diff --git a/internal/web/view/templates/kit.html b/internal/web/view/templates/kit.html index ccd037e..b535b4b 100644 --- a/internal/web/view/templates/kit.html +++ b/internal/web/view/templates/kit.html @@ -72,7 +72,7 @@ {{template "box_open" .Tables}}
      Time, UTCFromToSubjectDecisionUpstream
      TimeFromToSubjectDecisionUpstream
      {{.Time}}{{wbr_at .From}}{{if .Client}}
      {{.Client}}{{end}}
      {{wbr_at .To}}{{.Subject}}—{{template "sheet_tag" .Why}}{{template "sheet_tag" .Upstream}}{{template "tag" .Pending}}—{{if .Action}}{{.Action.Label}}{{end}}
      - + diff --git a/internal/web/view/templates/out_log_rows.html b/internal/web/view/templates/out_log_rows.html index f3f25f4..8978bbe 100644 --- a/internal/web/view/templates/out_log_rows.html +++ b/internal/web/view/templates/out_log_rows.html @@ -5,7 +5,7 @@ so the page count follows the rows. */}} {{define "out_log_rows"}}
      {{if .Rows}}
      Time, UTCNamesp-clipStatus
      TimeNamesp-clipStatus
      09-21 14:01:52the row's linkA long subject is clipped with an ellipsis instead of wrapping the rowsentDetails{{template "row_action" .RowAction}}
      - + {{range .Rows}} {{end}} diff --git a/internal/web/view/templates/settings.html b/internal/web/view/templates/settings.html index 44fe4c8..88e9ca6 100644 --- a/internal/web/view/templates/settings.html +++ b/internal/web/view/templates/settings.html @@ -1,8 +1,8 @@ {{/* Server > Settings (mockup settings.html): what holds for the whole instance. One form, in the left column, with its Save button under its fields; the right column holds what is not a field - the records of the server's own - name, the ones notifications are signed and authorised with, and the - read-only rate limits. A user's own name, e-mail, password and DMARC + name, the ones notifications are signed and authorised with, the + read-only rate limits and the read-only time zone. A user's own name, e-mail, password and DMARC address are on Account (account.html). */}} {{define "content"}} {{template "page_head" .Head}} @@ -43,6 +43,13 @@ {{template "facts" .RateFacts}} {{template "body_close"}} {{template "box_close"}} + + {{template "box_open" .TimeZone}} + {{template "body_open"}} + {{template "facts" .ZoneFacts}} +

      Every time the panel shows, and every day it counts - today on Health, the days of the statistics - is this zone's, and so are the stamps of mail.log.

      + {{template "body_close"}} + {{template "box_close"}} {{end}} diff --git a/internal/web/view/zone_main_test.go b/internal/web/view/zone_main_test.go new file mode 100644 index 0000000..fa7d19a --- /dev/null +++ b/internal/web/view/zone_main_test.go @@ -0,0 +1,28 @@ +package view + +import ( + "os" + "testing" + "time" +) + +// TestMain runs the tests in UTC, whatever the zone of the machine they run +// on: the panel shows times and counts days in time.Local, the container's +// zone (TZ), and the fixtures are written in UTC. The tests of another zone +// set it themselves (inZone). +func TestMain(m *testing.M) { + time.Local = time.UTC + os.Exit(m.Run()) +} + +// inZone runs the rest of the test in the zone name, as a container started +// with TZ=name; the test must not be parallel. +func inZone(t *testing.T, name string) { + t.Helper() + loc, err := time.LoadLocation(name) + if err != nil { + t.Skipf("no zone %s here: %v", name, err) + } + time.Local = loc + t.Cleanup(func() { time.Local = time.UTC }) +} diff --git a/internal/web/web.go b/internal/web/web.go index 3a3333d..2df582a 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -69,6 +69,8 @@ type Config struct { // SMTPBanner is Postfix's smtpd_banner as postconf expands it, "" when // it could not be read (health.SMTPBanner). SMTPBanner string + // TimeZone is TZ as the container has it, "" for none (Settings names it). + TimeZone string // SignSocket and SignLocalSocket are the DKIM signer's two milter // sockets, applications' mail and the panel's own; JournalSocket is the // journal-milter's. The status page dials them: the signer's are required @@ -150,6 +152,7 @@ func New(st *store.Store, domains *domain.Service, apps *app.Service, inboundSvc TLSCertFile: cfg.TLSCertFile, TLSServedCertFile: cfg.TLSServedCertFile, SMTPBanner: cfg.SMTPBanner, + TimeZone: cfg.TimeZone, TLSReloadInterval: cfg.TLSReloadInterval, SignSocket: cfg.SignSocket, SignLocalSocket: cfg.SignLocalSocket, diff --git a/test/e2e/health_served_test.go b/test/e2e/health_served_test.go index dc5690d..f65b474 100644 --- a/test/e2e/health_served_test.go +++ b/test/e2e/health_served_test.go @@ -87,8 +87,8 @@ func testHealthShowsWhatIsServed(t *testing.T, sc *scenario) { } cert := box(health(), "certificate") for _, want := range []string{ - "
      Expires
      " + served.UTC().Format("2006-01-02 15:04 UTC"), - "
      Renewal expires
      " + renewalNotAfter.Format("2006-01-02 15:04 UTC"), + "
      Expires
      " + served.UTC().Format("2006-01-02 15:04"), + "
      Renewal expires
      " + renewalNotAfter.Format("2006-01-02 15:04"), "
      Renewal mounted
      ", "Postfix still serves the certificate above.", } { diff --git a/test/e2e/main_test.go b/test/e2e/main_test.go index f16f807..ac9ad08 100644 --- a/test/e2e/main_test.go +++ b/test/e2e/main_test.go @@ -401,6 +401,10 @@ func TestE2E(t *testing.T) { run("inbound_bare_newline_is_one_message", func(t *testing.T) { testInboundBareNewline(t, sc) }) + // Last: it recreates the container in another zone. + run("time_zone_is_the_containers", func(t *testing.T) { + testTimeZone(t, sc) + }) } // trimZoneSuffix strips the "e2e.test" suffix a fully-qualified DKIM record diff --git a/test/e2e/time_zone_test.go b/test/e2e/time_zone_test.go new file mode 100644 index 0000000..dccf93e --- /dev/null +++ b/test/e2e/time_zone_test.go @@ -0,0 +1,71 @@ +package e2e + +import ( + "net/url" + "regexp" + "strings" + "testing" + "time" +) + +// testTimeZone (local-time): the container started with TZ=Europe/Moscow is +// in that zone, all of it. Settings names the zone; a message's page gives +// its times in Moscow's; and Postfix, which takes TZ through +// import_environment, stamps mail.log in it too, so the lines on that page +// read the same clock. Moscow has kept UTC+3 all year since 2014, so a fixed +// zone stands for it here whatever zone data the machine running the tests +// has. +func testTimeZone(t *testing.T, sc *scenario) { + h.env = append(h.env, "TZ=Europe/Moscow") + if err := h.recreateSelfpost(); err != nil { + t.Fatalf("recreate selfpost with TZ: %v", err) + } + if err := waitForPanelReady(); err != nil { + t.Fatalf("panel after setting TZ: %v\n%s", err, h.logs("selfpost")) + } + if err := waitForSMTPSReady(60 * time.Second); err != nil { + t.Fatal(err) + } + if out, err := h.execIn("selfpost", "date", "+%Z"); err != nil || strings.TrimSpace(out) != "MSK" { + t.Fatalf("date +%%Z in the container = %q, %v; want MSK", out, err) + } + _, body, err := sc.panel.get("/server/settings") + if err != nil { + t.Fatal(err) + } + for _, want := range []string{`

      Time zone

      `, `
      Europe/Moscow
      `, `UTC+03:00. Set in`} { + if !strings.Contains(body, want) { + t.Fatalf("Settings is missing %q:\n%.4000s", want, body) + } + } + + msk := time.FixedZone("MSK", 3*3600) + sent := time.Now().In(msk) + resp, _, err := sc.panel.postForm("/server/health/test-message", url.Values{"recipient": {recipient}}) + if err != nil { + t.Fatal(err) + } + page := resp.Request.URL.Path + if !regexp.MustCompile(`^/outbound/log/\d+$`).MatchString(page) { + t.Fatalf("send a test message: landed on %s", page) + } + // The minute it was sent, or the next one if the clock turned between. + minutes := []string{sent.Format("2006-01-02 15:04"), sent.Add(time.Minute).Format("2006-01-02 15:04")} + stamps := []string{sent.Format("Jan _2 15:04"), sent.Add(time.Minute).Format("Jan _2 15:04")} + if err := waitFor("the test message's page to show it sent", 60*time.Second, time.Second, func() (bool, error) { + _, b, err := sc.panel.get(page) + body = b + return err == nil && strings.Contains(b, `sent`), err + }); err != nil { + t.Fatalf("%v\n%.3000s", err, body) + } + if !strings.Contains(body, "
      Time, UTCFromToSubjectStatus
      TimeFromToSubjectStatus
      {{.Time}}{{wbr_at .From}}{{wbr_at .To}}{{.Subject}}{{template "tag" .Status}}Details