inbound-antispam-panel: Inbound > Log and Inbound > Filter lists
Step 6/12 of docs/plans/inbound-antispam-panel.md. Written by a Sonnet
subagent from the mockups, reviewed and corrected by me.
GET /inbound/log - the journal a page at a time (50), filtered by
domain, decision and day; QueryInboundSpam / CountInboundSpam with the
viewer's inbound domains as the scope. The global role reads all of it
and gets "Deny sender" / "Allow sender" links into the lists; a user
with the domain role reads the rows of the inbound domains assigned to
them, without the links. The plan said global-only for the journal;
the accepted mockup and 2.0's delegation of Inbound say otherwise -
recorded in the plan as built.
GET, POST /inbound/filter-lists and POST .../{id}/delete - global role,
404 otherwise. Add form (prefilled from the query), the two lists with
Remove as the kit's row action, and "Where the lists go" with the
filter's state and when the maps were last written
(Lists.LastWritten). A refused or duplicate entry is 422 with the
message and what was typed.
Server > Settings: "Keep inbound log rows, days" with the relay on.
Help: Inbound log, Filter lists. Navigation: Log for everyone who sees
Inbound, Filter lists for the global role (Shell.ShowFilterLists).
Status tags accept / reject / tempfail join the kit's mapping.
Tests: page fixtures for both screens, held to outlines.json; view and
handler tests (both roles, filters, paging, relay off, add / duplicate
/ invalid / delete, map file content, settings field, help). e2e reads
the journal from the page instead of the database and adds and removes
a deny entry through the panel, reading deny_domain.map after each.
Seen: both pages and Settings rendered from their fixtures and compared
with the mockups side by side (headless Edge, 1360 px) - same layout
and wording.
Checked on the test server, uncommitted tree: go vet ./... ok,
go test ./... ok (22 packages), make e2e ok.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,10 @@ type Settings struct {
|
||||
|
||||
Retention Box
|
||||
RetentionDays string
|
||||
// Inbound is whether the inbound relay is on, which gives the retention box
|
||||
// its second field; InboundRetentionDays is what that field shows.
|
||||
Inbound bool
|
||||
InboundRetentionDays string
|
||||
|
||||
RateLimits Box
|
||||
RateFacts []Fact
|
||||
@@ -86,6 +90,14 @@ func NewSettings(m Meta, retention, level1 string) *Settings {
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (s *Settings) WithInbound(days string) *Settings {
|
||||
s.Inbound, s.InboundRetentionDays = true, days
|
||||
return s
|
||||
}
|
||||
|
||||
// WithResult shows the result of the last action, or its refusal, between the
|
||||
// head and the form.
|
||||
func (s *Settings) WithResult(flash, formErr string) *Settings {
|
||||
|
||||
@@ -111,12 +111,14 @@ type Tag struct {
|
||||
var statusClass = map[string]string{
|
||||
"ok": "tag is-success is-light", "published": "tag is-success is-light",
|
||||
"running": "tag is-success is-light", "sent": "tag is-success is-light",
|
||||
"accept": "tag is-success is-light",
|
||||
|
||||
"warn": "tag is-warning is-light", "deferred": "tag is-warning is-light",
|
||||
"quiet": "tag is-warning is-light",
|
||||
"quiet": "tag is-warning is-light", "tempfail": "tag is-warning is-light",
|
||||
|
||||
"error": "tag is-danger is-light", "fail": "tag is-danger is-light",
|
||||
"mismatch": "tag is-danger is-light", "bounced": "tag is-danger is-light",
|
||||
"reject": "tag is-danger is-light",
|
||||
|
||||
"quarantine": "tag is-primary is-light", "held": "tag is-primary is-light",
|
||||
"global": "tag is-primary is-light",
|
||||
@@ -503,6 +505,9 @@ type Shell struct {
|
||||
ShowDMARC bool
|
||||
ShowInbound bool
|
||||
ShowServer bool
|
||||
// ShowFilterLists is the Filter lists entry of Inbound: the lists are the
|
||||
// instance's, so only the global role has them.
|
||||
ShowFilterLists bool
|
||||
}
|
||||
|
||||
// Frame is what layout.html is executed with: the shell and the page's own
|
||||
@@ -523,6 +528,8 @@ func (e *Engine) shell(m Meta, copyright, sourceURL string) Shell {
|
||||
ShowQueue: m.IsGlobal,
|
||||
ShowOutbound: m.IsGlobal || m.HasOutbound,
|
||||
ShowInbound: e.inboundEnabled && (m.IsGlobal || m.HasInbound),
|
||||
|
||||
ShowFilterLists: e.inboundEnabled && m.IsGlobal,
|
||||
}
|
||||
s.ShowDMARC = e.dmarcEnabled && s.ShowOutbound
|
||||
switch {
|
||||
|
||||
@@ -71,7 +71,8 @@ func TestStatusTagMapsEveryStatusOfTheKitTable(t *testing.T) {
|
||||
"ok": "tag is-success is-light", "published": "tag is-success is-light",
|
||||
"running": "tag is-success is-light", "sent": "tag is-success is-light",
|
||||
"warn": "tag is-warning is-light", "deferred": "tag is-warning is-light",
|
||||
"quiet": "tag is-warning is-light",
|
||||
"quiet": "tag is-warning is-light",
|
||||
"accept": "tag is-success is-light", "tempfail": "tag is-warning is-light", "reject": "tag is-danger is-light",
|
||||
"error": "tag is-danger is-light", "fail": "tag is-danger is-light",
|
||||
"mismatch": "tag is-danger is-light", "bounced": "tag is-danger is-light",
|
||||
"quarantine": "tag is-primary is-light", "global": "tag is-primary is-light",
|
||||
@@ -413,7 +414,7 @@ func TestShellVisibilityFollowsRoleAndFlags(t *testing.T) {
|
||||
wantIn bool
|
||||
}{
|
||||
{"global, everything on", on, Meta{IsGlobal: true},
|
||||
Shell{Home: "/overview", ShowOverview: true, ShowOutbound: true, ShowQueue: true, ShowDMARC: true, ShowInbound: true, ShowServer: true}, true},
|
||||
Shell{Home: "/overview", ShowOverview: true, ShowOutbound: true, ShowQueue: true, ShowDMARC: true, ShowInbound: true, ShowServer: true, ShowFilterLists: true}, true},
|
||||
{"global, inbound and DMARC off", off, Meta{IsGlobal: true},
|
||||
Shell{Home: "/overview", ShowOverview: true, ShowOutbound: true, ShowQueue: true, ShowServer: true}, true},
|
||||
{"domain admin with both reaches", on, Meta{HasOutbound: true, HasInbound: true},
|
||||
@@ -446,19 +447,19 @@ func renderShell(t *testing.T, e *Engine, m Meta) string {
|
||||
return rec.Body.String()
|
||||
}
|
||||
|
||||
// The menu has the 2.0 entries and none of the ones that are not in 2.0 (plan
|
||||
// § Routes): no Inbound Log, Queue, Quarantine or Filter lists, no Preflight.
|
||||
// The menu has the entries that are built and none of the ones that are not (plan
|
||||
// § Routes): no Inbound Queue or Quarantine, no Preflight.
|
||||
func TestMenuHoldsTheTwoDotZeroEntries(t *testing.T) {
|
||||
out := renderShell(t, kitEngine(t), Meta{Title: "t", User: "admin", IsGlobal: true})
|
||||
for _, href := range []string{
|
||||
"/overview", "/outbound/domains", "/outbound/log", "/outbound/queue", "/outbound/dmarc",
|
||||
"/inbound/domains", "/server/health", "/server/log", "/server/backup", "/server/users", "/server/settings",
|
||||
"/inbound/domains", "/inbound/log", "/inbound/filter-lists", "/server/health", "/server/log", "/server/backup", "/server/users", "/server/settings",
|
||||
"/account", "/help", "/license",
|
||||
} {
|
||||
mustContain(t, out, `href="`+href+`"`)
|
||||
}
|
||||
for _, gone := range []string{
|
||||
"/inbound/log", "/inbound/queue", "/inbound/quarantine", "/inbound/filter-lists", "/server/preflight",
|
||||
"/inbound/queue", "/inbound/quarantine", "/server/preflight",
|
||||
`href="/status"`, `href="/domains"`, `href="/users"`, `href="/settings"`,
|
||||
} {
|
||||
mustNotContain(t, out, gone)
|
||||
|
||||
@@ -38,6 +38,8 @@ var pageFixtures = map[string]func() any{
|
||||
"in-domains": func() any { return inDomainsFixture() },
|
||||
"in-domain": func() any { return inDomainFixture() },
|
||||
"in-domain-delete": func() any { return inDomainDeleteFixture() },
|
||||
"in-log": func() any { return inLogFixture() },
|
||||
"in-filter-lists": func() any { return inFilterListsFixture() },
|
||||
|
||||
"out-log": func() any { return outLogFixture() },
|
||||
"out-message": func() any { return outMessageFixture() },
|
||||
@@ -131,7 +133,7 @@ func accountFixture() *Account {
|
||||
// settingsFixture is the mockup's Settings: thirty days of log, a limit of 600
|
||||
// messages an hour.
|
||||
func settingsFixture() *Settings {
|
||||
return NewSettings(admin(), "30", FormatRate(600, 3600))
|
||||
return NewSettings(admin(), "30", FormatRate(600, 3600)).WithInbound("90")
|
||||
}
|
||||
|
||||
// outDomainsFixture is the mockup's Outbound domains: three domains, the first
|
||||
@@ -411,3 +413,47 @@ func userFixture() *UserForm {
|
||||
func userDeleteFixture() *UserDelete {
|
||||
return NewUserDelete(admin(), UserDeleteInput{ID: 3, Username: "acme-ops", AllOutbound: true, Inbound: []string{"acme.io"}})
|
||||
}
|
||||
|
||||
// inLogFixture is the mockup's Inbound log: six rows of a week's mail, as the
|
||||
// global role sees them - an accepted message scored as spam and one let through
|
||||
// by an Allow entry, refusals by Postfix and by the filter, and a tempfail.
|
||||
func inLogFixture() *InLog {
|
||||
p := NewInLog(admin(), 90, []string{"lists.example.org", "acme.io"},
|
||||
InLogFilter{From: "2026-09-14", To: "2026-09-21"})
|
||||
row := func(clock, from, client, to, subject, decision, engine, detail string) InLogRow {
|
||||
at, err := time.Parse("2006-01-02 15:04:05", "2026-09-21 "+clock)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return p.NewRow(InLogRowInput{At: at, From: from, Client: client, To: to, Subject: subject,
|
||||
Decision: decision, Engine: engine, Detail: detail})
|
||||
}
|
||||
return p.WithRows([]InLogRow{
|
||||
row("14:00:18", "t.berg@uni.example", "192.0.2.77", "dev@lists.example.org", "Re: [dev] patch series v3",
|
||||
"accept", "rspamd", "no action, score 0.40 / 15.00"),
|
||||
row("13:59:02", "invoice@partner-billing.example", "203.0.113.140", "owner@lists.example.org", "Outstanding invoice — action required",
|
||||
"accept", "rspamd", "add header, score 9.80 / 15.00; PHISHING(5.00) FORGED_SENDER(3.00) R_SPF_FAIL(1.00)"),
|
||||
row("13:57:41", "promo@bulk.example", "198.51.100.90", "sales@lists.example.org", "",
|
||||
"reject", "postfix", "550 5.1.1 <sales@lists.example.org>: Recipient address rejected: User unknown in relay recipient table"),
|
||||
row("13:51:30", "billing@partner.example", "198.51.100.12", "owner@lists.example.org", "",
|
||||
"reject", "rspamd", "5.7.1 Spam message rejected"),
|
||||
row("13:44:02", "hr@partner.example", "192.0.2.31", "jobs@acme.io", "",
|
||||
"tempfail", "rspamd", "4.7.1 Try again later"),
|
||||
row("13:30:55", "noreply@github.example", "192.0.2.200", "security@lists.example.org", "[advisory] new report",
|
||||
"accept", "rspamd", "no action, score -98.10 / 15.00; SELFPOST_ALLOW_FROM(-100.00) R_DKIM_ALLOW(-0.20)"),
|
||||
}, 1, 38)
|
||||
}
|
||||
|
||||
// inFilterListsFixture is the mockup's Filter lists: three senders denied, two
|
||||
// allowed, and a filter that reads them.
|
||||
func inFilterListsFixture() *FilterLists {
|
||||
day := func(m time.Month, d int) time.Time { return time.Date(2026, m, d, 0, 0, 0, 0, time.UTC) }
|
||||
return NewFilterLists(admin(), FilterListsInput{FilterOn: true, LastWritten: time.Date(2026, 9, 11, 8, 40, 0, 0, time.UTC)}).
|
||||
WithEntries([]FilterEntryInput{
|
||||
{ID: 1, List: "deny", Kind: "domain", Value: "bulk.example", Note: "newsletter nobody subscribed to", Added: day(9, 2)},
|
||||
{ID: 2, List: "deny", Kind: "ip", Value: "198.51.100.0/24", Note: "dictionary attack on lists.example.org", Added: day(8, 19)},
|
||||
{ID: 3, List: "deny", Kind: "address", Value: "win@lottery.example", Added: day(7, 30)},
|
||||
{ID: 4, List: "allow", Kind: "domain", Value: "partner.example", Note: "invoices were scored as spam", Added: day(9, 11)},
|
||||
{ID: 5, List: "allow", Kind: "address", Value: "noreply@github.example", Note: "security advisories", Added: day(6, 4)},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ const (
|
||||
HelpUpstream = "upstream"
|
||||
HelpRecipients = "recipients"
|
||||
HelpFilter = "filter"
|
||||
// HelpInboundLog and HelpFilterLists: the plain "log" is the Outbound log's.
|
||||
HelpInboundLog = "inbound-log"
|
||||
HelpFilterLists = "filter-lists"
|
||||
// Server
|
||||
HelpBackup = "backup"
|
||||
HelpUsers = "users"
|
||||
@@ -109,6 +112,8 @@ func NewHelp(m Meta, inbound bool) *Help {
|
||||
{Label: "Upstream", Icon: "ti-arrow-forward-up", Href: "#" + HelpUpstream},
|
||||
{Label: "Valid recipients", Icon: "ti-address-book", Href: "#" + HelpRecipients},
|
||||
{Label: "Spam filter", Icon: "ti-shield-check", Href: "#" + HelpFilter},
|
||||
{Label: "Inbound log", Icon: "ti-list-details", Href: "#" + HelpInboundLog},
|
||||
{Label: "Filter lists", Icon: "ti-filter", Href: "#" + HelpFilterLists},
|
||||
})
|
||||
}
|
||||
if m.IsGlobal {
|
||||
@@ -184,6 +189,24 @@ var inboundTopics = []HelpTopic{
|
||||
Rich("The spam filter belongs to the server, not to a domain. The server's administrator attaches it in the server's ", Code(".env"),
|
||||
", and from then on every inbound domain is screened by it before mail is handed on; the box shows on or off and has nothing to switch. Off means mail goes to the upstream unfiltered. While the filter is down, mail is either accepted unfiltered (the default) or deferred, so the sending server tries again later, as the server's setting says; the box states which."),
|
||||
}},
|
||||
{ID: HelpInboundLog, Title: "Inbound log", Body: []Text{
|
||||
Rich("One row per recipient of a message offered on port 25 for an inbound domain, with what was decided: ",
|
||||
TagOf("accept", ""), " — handed on to the upstream; ", TagOf("reject", ""), " — refused for good; ",
|
||||
TagOf("tempfail", ""), " — the sender was asked to come back later; ", TagOf("quarantine", ""), " — held by the filter. ",
|
||||
Em("Why"), " names who decided. ", Code("rspamd"), " is the spam filter, with its action, the score against the reject threshold and the heaviest symbols; ",
|
||||
Code("postfix"), " is the relay's own rule — an unknown recipient, a sender domain that does not exist — with its reply; ",
|
||||
Code("selfpost"), " means nobody judged the message: it was relayed with no filter attached. Accept says what this server did, not what the upstream did with the message afterwards.",
|
||||
Br(), Br(),
|
||||
"Accepted mail is recorded as it passes; refused mail is read from ", Code("mail.log"),
|
||||
", so its row has no subject, and a message refused after its text was sent is one row however many recipients it had. A refusal to relay for a domain that is not an inbound one is every scanner on the internet and is not recorded. Rows are kept for the number of days set in Settings, and never more than 10 000."),
|
||||
}},
|
||||
{ID: HelpFilterLists, Title: "Filter lists", Body: []Text{
|
||||
Rich("Two lists for the whole server that correct the spam filter by hand. An entry is a sender address, a sender domain — that domain, not its subdomains — or a client address or network in CIDR form. A sender on the Deny list is refused outright. A sender on the Allow list is given a weight no spam score outweighs, so the filter lets it through. When entries of both lists match one message, ",
|
||||
Strong("Deny wins"), ".",
|
||||
Br(), Br(),
|
||||
"SelfPost does not apply the lists itself: it writes them as files under ", Code("/data/antispam/"),
|
||||
", and rspamd rereads a file within seconds of a change. With the spam filter off the lists are kept and can be edited, but nothing reads them. The sender matched is the envelope sender — the one in the log — not the From line a mail program shows."),
|
||||
}},
|
||||
}
|
||||
|
||||
var serverTopics = []HelpTopic{
|
||||
@@ -208,7 +231,7 @@ var serverTopics = []HelpTopic{
|
||||
}},
|
||||
{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 ",
|
||||
Code("/data"), " grows. It does not change the rotation of ", Code("mail.log"),
|
||||
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."),
|
||||
}},
|
||||
|
||||
@@ -164,3 +164,30 @@ func TestHelpLinksStayInsideWhatTheirViewerIsShown(t *testing.T) {
|
||||
landsOn("DMARC hub", hub.Recent.Help)
|
||||
}
|
||||
}
|
||||
|
||||
// The Inbound log and Filter lists have their topics, after the spam filter's, in
|
||||
// the menu and on the page, for everyone who is shown Inbound; the Settings topic
|
||||
// mentions the second retention.
|
||||
func TestHelpHasTheInboundLogAndFilterListsTopics(t *testing.T) {
|
||||
out := renderSignedIn(t, "help", NewHelp(admin(), true))
|
||||
pageHas(t, "Help", out,
|
||||
`<li><a href="#inbound-log"><i class="ti ti-list-details"></i>Inbound log</a></li>`,
|
||||
`<li><a href="#filter-lists"><i class="ti ti-filter"></i>Filter lists</a></li>`,
|
||||
`<div class="sp-help-topic" id="inbound-log"><h3>Inbound log</h3>`,
|
||||
`<span class="tag is-primary is-light">quarantine</span> — held by the filter. <em>Why</em> names who decided.`,
|
||||
`a message refused after its text was sent is one row however many recipients it had.`,
|
||||
`and never more than 10 000.`,
|
||||
`<div class="sp-help-topic" id="filter-lists"><h3>Filter lists</h3>`,
|
||||
`<strong>Deny wins</strong>.`, `files under <code>/data/antispam/</code>`,
|
||||
`With the inbound relay on there is a second number, for the Inbound log, with the same range.`)
|
||||
for _, v := range helpViewers {
|
||||
out := renderSignedIn(t, "help", NewHelp(v.meta, v.inbound))
|
||||
shown := strings.Contains(out, `id="inbound-log"`)
|
||||
if want := v.inbound && (v.meta.IsGlobal || v.meta.HasInbound); shown != want {
|
||||
t.Errorf("%s: inbound log topic shown = %v, want %v", v.name, shown, want)
|
||||
}
|
||||
}
|
||||
if HelpInboundLog != "inbound-log" || HelpFilterLists != "filter-lists" {
|
||||
t.Errorf("anchors %q and %q", HelpInboundLog, HelpFilterLists)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestInDomainShowsTheMockupsBoxes(t *testing.T) {
|
||||
`<h2>Spam filter</h2>`, `href="#filter"`, `href="/inbound/domains/1/delete"`, `Delete domain`,
|
||||
)
|
||||
// What has no source in this build is not drawn.
|
||||
pageLacks(t, "Inbound domain", out, `rspamd`, `quarantine`, `Quarantine`, `Log for this domain`, `/inbound/log`, `/inbound/quarantine`, `Allow and deny`)
|
||||
pageLacks(t, "Inbound domain", out, `rspamd`, `quarantine`, `Quarantine`, `Log for this domain`, `/inbound/quarantine`, `Allow and deny`)
|
||||
}
|
||||
|
||||
// The Spam filter box states what the server is set up with, and what of it the
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package view
|
||||
|
||||
// The data of Inbound › Filter lists (templates/in_filter_lists.html, mockup
|
||||
// in-filter-lists.html): the allow and deny lists that correct the external spam
|
||||
// filter by hand. The lists are instance-wide, so the page is the global role's.
|
||||
//
|
||||
// A page is a typed struct that embeds Meta, built by a constructor and filled
|
||||
// by With… methods; the handler reads the lists, the view decides what is said
|
||||
// and how it is worded.
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const inboundFilterLists = "/inbound/filter-lists"
|
||||
|
||||
// FilterListsHref is the address of the page with the add form filled in: list
|
||||
// is "allow" or "deny", kind "address", "domain" or "ip". The Inbound log links
|
||||
// its rows here.
|
||||
func FilterListsHref(list, kind, value string) string {
|
||||
return inboundFilterLists + "?list=" + url.QueryEscape(list) + "&kind=" + url.QueryEscape(kind) + "&value=" + url.QueryEscape(value)
|
||||
}
|
||||
|
||||
// FilterLists is the data of the page: the form that adds an entry, the two
|
||||
// lists side by side and what happens to them after that.
|
||||
type FilterLists struct {
|
||||
Meta
|
||||
Head Head
|
||||
Flash *Flash
|
||||
|
||||
Add Box
|
||||
Action string
|
||||
ListOptions []Option
|
||||
KindOptions []Option
|
||||
// List, Kind, Value and Note are what the form shows: blank, prefilled from
|
||||
// the Inbound log, or what was typed into a form that was refused.
|
||||
List string
|
||||
Kind string
|
||||
Value string
|
||||
Note string
|
||||
|
||||
Deny FilterList
|
||||
Allow FilterList
|
||||
|
||||
Where Box
|
||||
WhereFacts []Fact
|
||||
}
|
||||
|
||||
// FilterList is one of the two boxes of entries.
|
||||
type FilterList struct {
|
||||
Box Box
|
||||
Rows []FilterRow
|
||||
Empty EmptyState
|
||||
}
|
||||
|
||||
// FilterRow is one entry of a list: the value with the kind of entry as a tag,
|
||||
// the operator's note, the day it was added and the way to remove it.
|
||||
type FilterRow struct {
|
||||
Value string
|
||||
Kind Tag
|
||||
Note string
|
||||
Added string
|
||||
Remove RowAction
|
||||
}
|
||||
|
||||
// FilterEntryInput is what the page knows of one entry of a list.
|
||||
type FilterEntryInput struct {
|
||||
ID int64
|
||||
List string
|
||||
Kind string
|
||||
Value string
|
||||
Note string
|
||||
Added time.Time
|
||||
}
|
||||
|
||||
// FilterListsInput is the state of the filter the lists are written for: whether
|
||||
// a filter is attached at all, and when the map files it reads were last written.
|
||||
type FilterListsInput struct {
|
||||
FilterOn bool
|
||||
LastWritten time.Time
|
||||
}
|
||||
|
||||
// NewFilterLists builds the page. The form starts on the Deny list for a sender
|
||||
// address, the commonest correction.
|
||||
func NewFilterLists(m Meta, in FilterListsInput) *FilterLists {
|
||||
m.Title, m.Section, m.Page = "Filter lists", "inbound", "filter-lists"
|
||||
p := &FilterLists{
|
||||
Meta: m,
|
||||
Head: Head{
|
||||
Kicker: "Inbound · global role",
|
||||
Title: "Filter lists",
|
||||
Lead: Plain("Correct the spam filter by hand: senders it must always let through, and senders it must always turn away. One pair of lists for the whole instance."),
|
||||
},
|
||||
Add: Box{No: "01", Title: "Add an entry", Help: topicLink(HelpFilterLists, "How the lists are applied")},
|
||||
Action: inboundFilterLists,
|
||||
ListOptions: []Option{
|
||||
{Value: "deny", Label: "Deny — always turn away"},
|
||||
{Value: "allow", Label: "Allow — always let through"},
|
||||
},
|
||||
KindOptions: []Option{
|
||||
{Value: "address", Label: "a sender address"},
|
||||
{Value: "domain", Label: "a sender domain"},
|
||||
{Value: "ip", Label: "a client address or network"},
|
||||
},
|
||||
List: "deny",
|
||||
Kind: "address",
|
||||
|
||||
Deny: FilterList{Box: Box{No: "02", Title: "Deny"}, Empty: EmptyState{Icon: "ti-filter", Text: Plain("No sender is turned away by hand.")}},
|
||||
Allow: FilterList{Box: Box{No: "03", Title: "Allow"}, Empty: EmptyState{Icon: "ti-filter", Text: Plain("No sender is let through by hand.")}},
|
||||
Where: Box{No: "04", Title: "Where the lists go"},
|
||||
}
|
||||
p.Deny.Box.End = Plain(plural(0, "entry", "entries") + " · wins over Allow")
|
||||
p.Allow.Box.End = Plain(plural(0, "entry", "entries"))
|
||||
p.setWhere(in)
|
||||
return p
|
||||
}
|
||||
|
||||
// setWhere writes box 04: the tag that says whether anything reads the lists,
|
||||
// and the four facts about where they go. With no filter attached the lists are
|
||||
// still kept and editable, and the box says so instead of promising an effect.
|
||||
func (p *FilterLists) setWhere(in FilterListsInput) {
|
||||
applied := Plain("rspamd, from map files it rereads within seconds of a change")
|
||||
p.Where.End = Rich(TagOf("ok", "applied"))
|
||||
if !in.FilterOn {
|
||||
p.Where.End = Rich(TagOf("off", "not applied"))
|
||||
applied = Rich("Nothing — the spam filter is off. The lists are kept and can be edited; nothing reads them until ",
|
||||
Code("INBOUND_ANTISPAM_MILTER"), " is set.")
|
||||
}
|
||||
written := "never"
|
||||
if !in.LastWritten.IsZero() {
|
||||
written = in.LastWritten.UTC().Format("2006-01-02 15:04") + " UTC"
|
||||
}
|
||||
p.WhereFacts = []Fact{
|
||||
{Label: "Applied by", Value: applied},
|
||||
{Label: "Files", Value: Rich(Mono("/data/antispam/"), " — six, one for each list and kind of entry")},
|
||||
{Label: "Last written", Value: Plain(written)},
|
||||
{Label: "When both lists match", Value: Plain("Deny wins, whichever entries they are.")},
|
||||
}
|
||||
}
|
||||
|
||||
// WithEntries sets the two tables, each counted in its box head.
|
||||
func (p *FilterLists) WithEntries(entries []FilterEntryInput) *FilterLists {
|
||||
p.Deny.Rows, p.Allow.Rows = nil, nil
|
||||
for _, e := range entries {
|
||||
row := FilterRow{
|
||||
Value: e.Value, Kind: Tag{Label: e.Kind}, Note: e.Note, Added: e.Added.UTC().Format("2006-01-02"),
|
||||
Remove: RowAction{Label: "Remove", Post: inboundFilterLists + "/" + strconv.FormatInt(e.ID, 10) + "/delete", Danger: true},
|
||||
}
|
||||
switch e.List {
|
||||
case "deny":
|
||||
p.Deny.Rows = append(p.Deny.Rows, row)
|
||||
case "allow":
|
||||
p.Allow.Rows = append(p.Allow.Rows, row)
|
||||
}
|
||||
}
|
||||
p.Deny.Box.End = Plain(plural(int64(len(p.Deny.Rows)), "entry", "entries") + " · wins over Allow")
|
||||
p.Allow.Box.End = Plain(plural(int64(len(p.Allow.Rows)), "entry", "entries"))
|
||||
return p
|
||||
}
|
||||
|
||||
// WithForm sets what the add form shows. The handler passes only what it has
|
||||
// checked to be a list and a kind the form offers, or what was submitted to a
|
||||
// form it is showing again.
|
||||
func (p *FilterLists) WithForm(list, kind, value, note string) *FilterLists {
|
||||
p.List, p.Kind, p.Value, p.Note = list, kind, value, note
|
||||
return p
|
||||
}
|
||||
|
||||
// WithResult shows the result of the last action, or the refusal of the add
|
||||
// form, between the head and the first box.
|
||||
func (p *FilterLists) WithResult(flash, formErr string) *FilterLists {
|
||||
p.Flash = resultFlash(flash, formErr)
|
||||
return p
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package view
|
||||
|
||||
// The data of the Inbound log (templates/in_log.html, mockup in-log.html): what
|
||||
// port 25 decided about each message offered for an inbound domain, one row per
|
||||
// recipient. Unlike the Outbound log it does not poll: a decision does not change
|
||||
// after it is made, and the page is read to find one row, not watched.
|
||||
//
|
||||
// A page is a typed struct that embeds Meta, built by a constructor and filled
|
||||
// by With… methods; the handler reads the journal, the view decides what is
|
||||
// said and how it is worded.
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const inboundLog = "/inbound/log"
|
||||
|
||||
// InLogFilter is what the filters of the Inbound log are set to, as the strings
|
||||
// the form sends: a domain name, a decision and two days (2006-01-02). Empty
|
||||
// means no narrowing.
|
||||
type InLogFilter struct {
|
||||
Domain string
|
||||
Decision string
|
||||
From string
|
||||
To string
|
||||
}
|
||||
|
||||
func (f InLogFilter) active() bool { return f != InLogFilter{} }
|
||||
|
||||
// query is the query string of a page of the log: the filters and the page, each
|
||||
// left out when it says nothing, so the first unfiltered page is the bare path.
|
||||
func (f InLogFilter) query(page int) string {
|
||||
q := url.Values{}
|
||||
for name, v := range map[string]string{"domain": f.Domain, "decision": f.Decision, "from": f.From, "to": f.To} {
|
||||
if v != "" {
|
||||
q.Set(name, v)
|
||||
}
|
||||
}
|
||||
if page > 1 {
|
||||
q.Set("p", strconv.Itoa(page))
|
||||
}
|
||||
if len(q) == 0 {
|
||||
return ""
|
||||
}
|
||||
return "?" + q.Encode()
|
||||
}
|
||||
|
||||
// InLogHref is the address of a page of the Inbound log.
|
||||
func InLogHref(f InLogFilter, page int) string { return inboundLog + f.query(page) }
|
||||
|
||||
// InLog is the data of the Inbound log: the decisions about mail for the inbound
|
||||
// domains the viewer reaches, filtered by domain, decision and day, a page at a
|
||||
// time.
|
||||
type InLog struct {
|
||||
Meta
|
||||
Head Head
|
||||
|
||||
Messages Box
|
||||
Rows []InLogRow
|
||||
Empty EmptyState
|
||||
Foot Foot
|
||||
|
||||
filter InLogFilter
|
||||
}
|
||||
|
||||
// InLogRow is one recipient of one message: when it was decided, who the mail
|
||||
// was from (and the address of the server that offered it) and for, its subject,
|
||||
// the decision as a tag, who decided and why, and — for the global role, who
|
||||
// alone edits the filter lists — the way to correct the decision.
|
||||
type InLogRow struct {
|
||||
Time string
|
||||
From string
|
||||
Client string
|
||||
To string
|
||||
Subject string
|
||||
Decision Tag
|
||||
Why string
|
||||
Action *Anchor
|
||||
}
|
||||
|
||||
// InLogRowInput is what the journal holds about one row. Subject, Detail and
|
||||
// From may be empty: refused mail is read from mail.log, which has no subject,
|
||||
// and a filter that said nothing has no detail.
|
||||
type InLogRowInput struct {
|
||||
At time.Time
|
||||
From string
|
||||
Client string
|
||||
To string
|
||||
Subject string
|
||||
Decision string
|
||||
Engine string
|
||||
Detail string
|
||||
}
|
||||
|
||||
// NewInLog builds the log for a viewer. domains are the choices of the domain
|
||||
// filter (only the inbound domains the viewer reaches) and filter is what is in
|
||||
// force. retentionDays is how long rows are kept; the global role, who can
|
||||
// change it and who edits the lists, is read from m.
|
||||
func NewInLog(m Meta, retentionDays int, domains []string, filter InLogFilter) *InLog {
|
||||
m.Title, m.Section, m.Page = "Inbound log", "inbound", "log"
|
||||
lead := Rich("What port 25 decided about each message, one row per recipient. Accepted mail is recorded as it passes, refused mail is read from ",
|
||||
Code("mail.log"), "; the filter's verdict appears when the spam filter is on. Rows older than "+plural(int64(retentionDays), "day", "days")+" are deleted")
|
||||
if m.IsGlobal {
|
||||
lead = append(lead, Inline{Text: " — change that in "}, Link("/server/settings", "Settings"))
|
||||
}
|
||||
lead = append(lead, Inline{Text: "."})
|
||||
|
||||
domainOptions := []Option{{Value: "", Label: "All domains"}}
|
||||
for _, d := range domains {
|
||||
domainOptions = append(domainOptions, Option{Value: d, Label: d})
|
||||
}
|
||||
decisionOptions := []Option{{Value: "", Label: "Any decision"}}
|
||||
for _, d := range []string{"accept", "reject", "tempfail", "quarantine"} {
|
||||
decisionOptions = append(decisionOptions, Option{Value: d, Label: d})
|
||||
}
|
||||
p := &InLog{
|
||||
Meta: m,
|
||||
Head: Head{Kicker: "Inbound", Title: "Inbound log", Lead: lead},
|
||||
Messages: Box{No: "01", Title: "Messages", Help: topicLink(HelpInboundLog, "What the decisions mean"), Filter: &Filter{
|
||||
Action: inboundLog,
|
||||
Selects: []Select{
|
||||
{Name: "domain", Label: "Domain", Options: domainOptions, Selected: filter.Domain},
|
||||
{Name: "decision", Label: "Decision", Options: decisionOptions, Selected: filter.Decision},
|
||||
},
|
||||
Dates: []DateInput{
|
||||
{Name: "from", Label: "From date", Value: filter.From},
|
||||
{Name: "to", Label: "To date", Value: filter.To},
|
||||
},
|
||||
}},
|
||||
Empty: EmptyState{Icon: "ti-list-details", Text: Plain("No messages logged yet.")},
|
||||
filter: filter,
|
||||
}
|
||||
if filter.active() {
|
||||
p.Empty.Text = Plain("No messages match these filters.")
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// NewRow words one row of the journal for the viewer of the page.
|
||||
func (p *InLog) NewRow(in InLogRowInput) InLogRow {
|
||||
why := in.Engine
|
||||
if in.Detail != "" {
|
||||
why += " · " + in.Detail
|
||||
}
|
||||
r := InLogRow{
|
||||
Time: FormatLogTime(in.At), From: orDash(in.From), Client: in.Client, To: in.To, Subject: in.Subject,
|
||||
Decision: Tag{Status: in.Decision}, Why: why,
|
||||
}
|
||||
if p.IsGlobal {
|
||||
r.Action = senderAction(in.Decision, in.Engine, in.From)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// senderAction is the way to correct a decision from its row, if there is one:
|
||||
// a message that got through is the one to deny its sender for, a message the
|
||||
// filter turned away or put off is the one to allow its sender for, and a
|
||||
// refusal by Postfix's own policy (an unknown recipient, say) can only be
|
||||
// answered by denying — allowing the sender would not change what Postfix
|
||||
// thinks of the recipient. A row with no sender has nobody to list.
|
||||
func senderAction(decision, engine, from string) *Anchor {
|
||||
if from == "" {
|
||||
return nil
|
||||
}
|
||||
list := ""
|
||||
switch {
|
||||
case decision == "accept":
|
||||
list = "deny"
|
||||
case engine == "rspamd":
|
||||
list = "allow"
|
||||
case decision == "reject" && engine == "postfix":
|
||||
list = "deny"
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
label := "Deny sender"
|
||||
if list == "allow" {
|
||||
label = "Allow sender"
|
||||
}
|
||||
return &Anchor{Href: FilterListsHref(list, "address", from), Label: label}
|
||||
}
|
||||
|
||||
// WithRows sets the table for page of last, and the foot under it: where the
|
||||
// viewer is, and the way to the newer and older rows. For the global role the
|
||||
// foot also says where the sender links lead.
|
||||
func (p *InLog) WithRows(rows []InLogRow, page, last int) *InLog {
|
||||
p.Rows = rows
|
||||
if len(rows) == 0 {
|
||||
return p
|
||||
}
|
||||
text := Rich("Page " + strconv.Itoa(page) + " of " + strconv.Itoa(last))
|
||||
if page > 1 {
|
||||
text = append(text, Inline{Text: " · "}, Link(InLogHref(p.filter, page-1), "← Newer"))
|
||||
}
|
||||
p.Foot.Text = text
|
||||
if page < last {
|
||||
p.Foot.Link = &Anchor{Href: InLogHref(p.filter, page+1), Label: "Older →"}
|
||||
}
|
||||
if p.IsGlobal {
|
||||
p.Foot.End = Rich("Allow / Deny sender opens ", Link(inboundFilterLists, "Filter lists"), " with the entry filled in")
|
||||
}
|
||||
return p
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ---- The log
|
||||
|
||||
// The log is the whole of what the journal holds about the viewer's inbound mail:
|
||||
// the filters offer what the viewer reaches, the head says how long rows live and
|
||||
// where to change it, and the global role is given the way to correct a decision.
|
||||
func TestInLogShowsTheRowsAndTheirFilters(t *testing.T) {
|
||||
out := renderSignedIn(t, "in-log", inLogFixture())
|
||||
pageHas(t, "Inbound log", out,
|
||||
`<h1 class="title is-3">Inbound log</h1>`,
|
||||
`refused mail is read from <code>mail.log</code>; the filter's verdict appears when the spam filter is on. Rows older than 90 days are deleted — change that in <a href="/server/settings">Settings</a>.`,
|
||||
`<form class="sp-end" method="get" action="/inbound/log">`,
|
||||
`<select name="domain" aria-label="Domain"><option value="" selected>All domains</option><option value="lists.example.org">lists.example.org</option><option value="acme.io">acme.io</option></select>`,
|
||||
`<select name="decision" aria-label="Decision"><option value="" selected>Any decision</option><option value="accept">accept</option><option value="reject">reject</option><option value="tempfail">tempfail</option><option value="quarantine">quarantine</option></select>`,
|
||||
`<input class="input" type="date" name="from" value="2026-09-14" aria-label="From date">`,
|
||||
`<input class="input" type="date" name="to" value="2026-09-21" aria-label="To date">`,
|
||||
`href="/help#inbound-log" title="What the decisions mean"`,
|
||||
`<th>Time, UTC</th><th>From · client</th><th>To</th><th>Subject</th><th>Decision</th><th>Why</th>`,
|
||||
`09-21 14:00:18`,
|
||||
`t.berg@<wbr>uni.example<br><span class="sp-mono sp-muted sp-small">192.0.2.77</span>`,
|
||||
`dev@<wbr>lists.example.org`, `title="Re: [dev] patch series v3"`,
|
||||
`<td class="sp-clip sp-muted">—</td>`,
|
||||
`<span class="tag is-success is-light">accept</span>`, `<span class="tag is-danger is-light">reject</span>`,
|
||||
`<span class="tag is-warning is-light">tempfail</span>`,
|
||||
`rspamd · no action, score 0.40 / 15.00`,
|
||||
`postfix · 550 5.1.1 <sales@lists.example.org>: Recipient address rejected`,
|
||||
`Page 1 of 38`, `<a href="/inbound/log?from=2026-09-14&p=2&to=2026-09-21">Older →</a>`,
|
||||
`Allow / Deny sender opens <a href="/inbound/filter-lists">Filter lists</a> with the entry filled in`,
|
||||
)
|
||||
pageLacks(t, "Inbound log", out, `← Newer`, `data-poll`, `hx-get`)
|
||||
|
||||
// Without the global role there is nowhere to change the retention, and
|
||||
// nowhere to send a sender.
|
||||
domain := NewInLog(Meta{User: "ops", HasInbound: true}, 7, []string{"acme.io"}, InLogFilter{})
|
||||
out = renderSignedIn(t, "in-log", domain.WithRows([]InLogRow{domain.NewRow(InLogRowInput{
|
||||
At: time.Date(2026, 9, 21, 14, 0, 0, 0, time.UTC), From: "a@example.net", To: "b@acme.io",
|
||||
Decision: "accept", Engine: "rspamd"})}, 1, 1))
|
||||
pageHas(t, "Inbound log", out, `Rows older than 7 days are deleted.`, `rspamd</td>`)
|
||||
pageLacks(t, "Inbound log", out, `/server/settings`, `/inbound/filter-lists`, `Deny sender`, `Allow sender`, `Allow / Deny`)
|
||||
}
|
||||
|
||||
// The lead's day count reads right for one day too, though the setting's range
|
||||
// starts at seven: the word follows the number, not the other way round.
|
||||
func TestInLogLeadCountsDays(t *testing.T) {
|
||||
out := renderSignedIn(t, "in-log", NewInLog(Meta{User: "ops", HasInbound: true}, 1, nil, InLogFilter{}))
|
||||
pageHas(t, "Inbound log", out, `Rows older than 1 day are deleted.`)
|
||||
}
|
||||
|
||||
// The filter in force is the one selected, and the paging and the empty state
|
||||
// carry and name it.
|
||||
func TestInLogCarriesItsFilters(t *testing.T) {
|
||||
f := InLogFilter{Domain: "acme.io", Decision: "reject", From: "2026-09-01", To: "2026-09-30"}
|
||||
p := NewInLog(admin(), 90, []string{"lists.example.org", "acme.io"}, f)
|
||||
p.WithRows([]InLogRow{p.NewRow(InLogRowInput{At: time.Date(2026, 9, 2, 1, 2, 3, 0, time.UTC),
|
||||
From: "a@example.net", To: "b@acme.io", Decision: "reject", Engine: "postfix"})}, 3, 5)
|
||||
out := renderSignedIn(t, "in-log", p)
|
||||
pageHas(t, "Inbound log", out,
|
||||
`<option value="acme.io" selected>acme.io</option>`, `<option value="reject" selected>reject</option>`,
|
||||
`name="from" value="2026-09-01"`, `name="to" value="2026-09-30"`,
|
||||
`Page 3 of 5 · <a href="/inbound/log?decision=reject&domain=acme.io&from=2026-09-01&p=2&to=2026-09-30">← Newer</a>`,
|
||||
`<a href="/inbound/log?decision=reject&domain=acme.io&from=2026-09-01&p=4&to=2026-09-30">Older →</a>`,
|
||||
)
|
||||
if got := InLogHref(InLogFilter{}, 1); got != "/inbound/log" {
|
||||
t.Errorf("the first unfiltered page is %q", got)
|
||||
}
|
||||
if got := InLogHref(InLogFilter{Domain: "a b&c"}, 2); got != "/inbound/log?domain=a+b%26c&p=2" {
|
||||
t.Errorf("a filter is not encoded: %q", got)
|
||||
}
|
||||
|
||||
out = renderSignedIn(t, "in-log", NewInLog(admin(), 90, nil, f).WithRows(nil, 1, 1))
|
||||
pageHas(t, "Inbound log", out, `No messages match these filters.`)
|
||||
out = renderSignedIn(t, "in-log", NewInLog(admin(), 90, nil, InLogFilter{}).WithRows(nil, 1, 1))
|
||||
pageHas(t, "Inbound log", out, `No messages logged yet.`)
|
||||
pageLacks(t, "Inbound log", out, `<table`, `Page 1`, `sp-box-foot`)
|
||||
}
|
||||
|
||||
// The last page has nothing older.
|
||||
func TestInLogLastPage(t *testing.T) {
|
||||
p := NewInLog(admin(), 90, nil, InLogFilter{})
|
||||
row := p.NewRow(InLogRowInput{At: time.Now(), From: "a@example.net", To: "b@acme.io", Decision: "accept", Engine: "selfpost"})
|
||||
out := renderSignedIn(t, "in-log", p.WithRows([]InLogRow{row}, 2, 2))
|
||||
pageHas(t, "Inbound log", out, `Page 2 of 2`, `← Newer</a>`)
|
||||
pageLacks(t, "Inbound log", out, `Older →`)
|
||||
}
|
||||
|
||||
// A row says who decided, and what they said when they said something; a message
|
||||
// refused before its sender was known has no sender to show or to list.
|
||||
func TestInLogRowWording(t *testing.T) {
|
||||
p := NewInLog(admin(), 90, nil, InLogFilter{})
|
||||
at := time.Date(2026, 9, 21, 14, 0, 18, 0, time.UTC)
|
||||
r := p.NewRow(InLogRowInput{At: at, From: "a@example.net", To: "b@acme.io", Decision: "accept", Engine: "selfpost"})
|
||||
if r.Why != "selfpost" || r.Time != "09-21 14:00:18" || r.Client != "" {
|
||||
t.Errorf("row = %+v", r)
|
||||
}
|
||||
r = p.NewRow(InLogRowInput{At: at, To: "b@acme.io", Decision: "reject", Engine: "postfix", Detail: "550 5.1.1 no"})
|
||||
if r.Why != "postfix · 550 5.1.1 no" || r.From != "—" || r.Action != nil {
|
||||
t.Errorf("row = %+v", r)
|
||||
}
|
||||
out := renderSignedIn(t, "in-log", p.WithRows([]InLogRow{r}, 1, 1))
|
||||
pageHas(t, "Inbound log", out, `<td>—</td>`)
|
||||
pageLacks(t, "Inbound log", out, `<br><span class="sp-mono sp-muted sp-small"></span>`)
|
||||
}
|
||||
|
||||
// Which decisions lead to which list, for the global role: the sender of mail
|
||||
// that got through can be denied, the sender of mail the filter turned away or
|
||||
// put off can be allowed, and a refusal that is Postfix's own can only be denied.
|
||||
func TestInLogSenderAction(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
decision, engine, from, label, href string
|
||||
}{
|
||||
{"accept", "rspamd", "a@example.net", "Deny sender", "/inbound/filter-lists?list=deny&kind=address&value=a%40example.net"},
|
||||
{"accept", "selfpost", "a@example.net", "Deny sender", "/inbound/filter-lists?list=deny&kind=address&value=a%40example.net"},
|
||||
{"reject", "rspamd", "a+b@example.net", "Allow sender", "/inbound/filter-lists?list=allow&kind=address&value=a%2Bb%40example.net"},
|
||||
{"tempfail", "rspamd", "a@example.net", "Allow sender", "/inbound/filter-lists?list=allow&kind=address&value=a%40example.net"},
|
||||
{"quarantine", "rspamd", "a@example.net", "Allow sender", "/inbound/filter-lists?list=allow&kind=address&value=a%40example.net"},
|
||||
{"reject", "postfix", "a@example.net", "Deny sender", "/inbound/filter-lists?list=deny&kind=address&value=a%40example.net"},
|
||||
{"tempfail", "postfix", "a@example.net", "", ""},
|
||||
{"reject", "selfpost", "a@example.net", "", ""},
|
||||
{"accept", "rspamd", "", "", ""},
|
||||
{"reject", "rspamd", "", "", ""},
|
||||
} {
|
||||
got := senderAction(c.decision, c.engine, c.from)
|
||||
switch {
|
||||
case c.label == "" && got != nil:
|
||||
t.Errorf("%s by %s from %q is offered %+v", c.decision, c.engine, c.from, *got)
|
||||
case c.label != "" && (got == nil || got.Label != c.label || got.Href != c.href):
|
||||
t.Errorf("%s by %s from %q is offered %+v, want %s -> %s", c.decision, c.engine, c.from, got, c.label, c.href)
|
||||
}
|
||||
}
|
||||
|
||||
// The address in the link is data: it cannot leave the attribute.
|
||||
p := NewInLog(admin(), 90, nil, InLogFilter{})
|
||||
row := p.NewRow(InLogRowInput{At: time.Now(), From: `"><script>1</script>@x`, To: "b@acme.io", Decision: "accept", Engine: "rspamd"})
|
||||
out := renderSignedIn(t, "in-log", p.WithRows([]InLogRow{row}, 1, 1))
|
||||
pageLacks(t, "Inbound log", out, `<script>1`)
|
||||
pageHas(t, "Inbound log", out, `value=%22%3E%3Cscript%3E1%3C%2Fscript%3E%40x`)
|
||||
}
|
||||
|
||||
// What a sender wrote is text on the page: an address, a subject or a reply from
|
||||
// a server is never markup.
|
||||
func TestInLogEscapesWhatSendersWrote(t *testing.T) {
|
||||
p := NewInLog(admin(), 90, nil, InLogFilter{})
|
||||
row := p.NewRow(InLogRowInput{At: time.Now(), From: `<img src=x onerror=alert(1)>@e.example`, Client: `<b>1</b>`,
|
||||
To: `<script>alert(2)</script>@acme.io`, Subject: `<script>alert(3)</script> "quoted"`,
|
||||
Decision: "reject", Engine: "rspamd", Detail: `<i>5.7.1</i>`})
|
||||
out := renderSignedIn(t, "in-log", p.WithRows([]InLogRow{row}, 1, 1))
|
||||
pageLacks(t, "Inbound log", out, `<script>alert`, `<img src=x`, `<b>1</b>`, `<i>5.7.1</i>`)
|
||||
pageHas(t, "Inbound log", out, `<script>alert(3)</script>`, `<i>5.7.1</i>`)
|
||||
}
|
||||
|
||||
// ---- Filter lists
|
||||
|
||||
// The page is the add form, the two lists with their counts, and where the lists
|
||||
// go - drawn as the mockup draws it.
|
||||
func TestFilterListsShowsTheFormTheListsAndWhereTheyGo(t *testing.T) {
|
||||
out := renderSignedIn(t, "in-filter-lists", inFilterListsFixture())
|
||||
pageHas(t, "Filter lists", out,
|
||||
`<p class="sp-kicker">Inbound · global role</p>`, `<h1 class="title is-3">Filter lists</h1>`,
|
||||
`<form class="sp-form" method="post" action="/inbound/filter-lists">`,
|
||||
`<select id="list" name="list_type">`, `<option value="deny" selected>Deny — always turn away</option>`,
|
||||
`<option value="allow">Allow — always let through</option>`,
|
||||
`<select id="etype" name="entry_type">`, `<option value="address" selected>a sender address</option>`,
|
||||
`<option value="domain">a sender domain</option>`, `<option value="ip">a client address or network</option>`,
|
||||
`<input class="input sp-mono" id="value" name="value" value="" placeholder="promo@bulk.example"`,
|
||||
`<input class="input" id="note" name="note" value=""`, `Add entry`,
|
||||
`href="/help#filter-lists" title="How the lists are applied"`,
|
||||
`<h2>Deny</h2><div class="sp-end">3 entries · wins over Allow</div>`,
|
||||
`<h2>Allow</h2><div class="sp-end">2 entries</div>`,
|
||||
`<td class="sp-mono sp-small">bulk.example <span class="tag is-light">domain</span></td><td class="sp-muted">newsletter nobody subscribed to</td><td class="sp-muted sp-nowrap sp-small">2026-09-02</td>`,
|
||||
`198.51.100.0/24 <span class="tag is-light">ip</span>`,
|
||||
`win@lottery.example <span class="tag is-light">address</span></td><td class="sp-muted">—</td>`,
|
||||
`<form method="post" action="/inbound/filter-lists/3/delete"><button type="submit" class="has-text-danger">Remove</button></form>`,
|
||||
`<h2>Where the lists go</h2><div class="sp-end"><span class="tag is-success is-light">applied</span></div>`,
|
||||
`rspamd, from map files it rereads within seconds of a change`,
|
||||
`<span class="sp-mono">/data/antispam/</span> — six, one for each list and kind of entry`,
|
||||
`2026-09-11 08:40 UTC`, `Deny wins, whichever entries they are.`,
|
||||
)
|
||||
if got := strings.Count(out, `<table`); got != 2 {
|
||||
t.Errorf("%d tables, want the two lists", got)
|
||||
}
|
||||
}
|
||||
|
||||
// With no filter attached the lists are still the operator's to edit, and the
|
||||
// box says nothing reads them; a list with no entries says so in its box.
|
||||
func TestFilterListsOffAndEmpty(t *testing.T) {
|
||||
p := NewFilterLists(admin(), FilterListsInput{}).WithEntries([]FilterEntryInput{
|
||||
{ID: 9, List: "allow", Kind: "ip", Value: "192.0.2.1", Added: time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)},
|
||||
})
|
||||
out := renderSignedIn(t, "in-filter-lists", p)
|
||||
pageHas(t, "Filter lists", out,
|
||||
`<span class="tag is-light">not applied</span>`,
|
||||
`Nothing — the spam filter is off. The lists are kept and can be edited; nothing reads them until <code>INBOUND_ANTISPAM_MILTER</code> is set.`,
|
||||
`<dt>Last written</dt><dd>never</dd>`,
|
||||
`<h2>Deny</h2><div class="sp-end">0 entries · wins over Allow</div>`,
|
||||
`<h2>Allow</h2><div class="sp-end">1 entry</div>`,
|
||||
`No sender is turned away by hand.`,
|
||||
)
|
||||
pageLacks(t, "Filter lists", out, `rspamd, from map files`, `is-success is-light">applied`, `No sender is let through by hand.`)
|
||||
if got := strings.Count(out, `<table`); got != 1 {
|
||||
t.Errorf("%d tables, want the one list that has entries", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The form shows what it is told to: prefilled from the log, or what was typed
|
||||
// into a form that was refused, with the refusal between the head and the form.
|
||||
func TestFilterListsFormAndRefusal(t *testing.T) {
|
||||
p := inFilterListsFixture().
|
||||
WithForm("allow", "domain", `x"><script>1</script>`, `a "note"`).
|
||||
WithResult("", "That entry is already on the list.")
|
||||
out := renderSignedIn(t, "in-filter-lists", p)
|
||||
pageHas(t, "Filter lists", out,
|
||||
`<option value="allow" selected>Allow — always let through</option>`, `<option value="domain" selected>a sender domain</option>`,
|
||||
`value="x"><script>1</script>"`, `value="a "note""`,
|
||||
`<div class="notification is-danger is-light">`, `That entry is already on the list.`)
|
||||
pageLacks(t, "Filter lists", out, `<script>1`, `<option value="deny" selected>`)
|
||||
if strings.Index(out, `class="notification`) < strings.Index(out, `class="sp-head"`) ||
|
||||
strings.Index(out, `class="notification`) > strings.Index(out, `<form class="sp-form"`) {
|
||||
t.Error("the refusal is not between the head and the form")
|
||||
}
|
||||
|
||||
out = renderSignedIn(t, "in-filter-lists", inFilterListsFixture().WithResult("Entry added.", ""))
|
||||
pageHas(t, "Filter lists", out, `<div class="notification is-success is-light">`, `Entry added.`)
|
||||
}
|
||||
|
||||
// What a person typed into a list is text on the page.
|
||||
func TestFilterListsEscapesTheEntries(t *testing.T) {
|
||||
p := NewFilterLists(admin(), FilterListsInput{FilterOn: true}).WithEntries([]FilterEntryInput{
|
||||
{ID: 1, List: "deny", Kind: "address", Value: `<img src=x>@a.example`, Note: `<script>alert(1)</script>`, Added: time.Now()},
|
||||
})
|
||||
out := renderSignedIn(t, "in-filter-lists", p)
|
||||
pageLacks(t, "Filter lists", out, `<img src=x>`, `<script>alert`)
|
||||
}
|
||||
|
||||
// The menu leads to both pages, the lists for the global role only.
|
||||
func TestInboundMenuHasLogAndFilterLists(t *testing.T) {
|
||||
out := renderSignedIn(t, "in-log", inLogFixture())
|
||||
pageHas(t, "Inbound log", out,
|
||||
`<a class="navbar-item is-active" href="/inbound/log"><i class="ti ti-list-details"></i>Log</a>`,
|
||||
`<a class="navbar-item" href="/inbound/filter-lists"><i class="ti ti-filter"></i>Filter lists</a>`,
|
||||
`<a href="/inbound/log" aria-current="page"><i class="ti ti-list-details"></i>Log</a><a href="/inbound/filter-lists"><i class="ti ti-filter"></i>Filter lists</a>`)
|
||||
out = renderSignedIn(t, "in-filter-lists", inFilterListsFixture())
|
||||
pageHas(t, "Filter lists", out,
|
||||
`<a class="navbar-item is-active" href="/inbound/filter-lists">`, `<a href="/inbound/filter-lists" aria-current="page">`)
|
||||
|
||||
domain := NewInLog(Meta{User: "ops", HasInbound: true}, 90, nil, InLogFilter{}).WithRows(nil, 1, 1)
|
||||
out = renderSignedIn(t, "in-log", domain)
|
||||
pageHas(t, "Inbound log", out, `<a class="navbar-item is-active" href="/inbound/log">`, `<a href="/inbound/log" aria-current="page">`)
|
||||
pageLacks(t, "Inbound log", out, `/inbound/filter-lists`)
|
||||
}
|
||||
@@ -92,9 +92,9 @@ func KitPage() *Kit {
|
||||
|
||||
StatusTag: Box{No: "03", Title: "status_tag", End: Plain("One mapping, one function")},
|
||||
StatusRows: []KitStatusRow{
|
||||
{"ok, published, running, sent", Tag{Status: "ok"}},
|
||||
{"warn, deferred, quiet", Tag{Status: "warn"}},
|
||||
{"error, fail, mismatch, bounced", Tag{Status: "fail"}},
|
||||
{"ok, published, running, sent, accept", Tag{Status: "ok"}},
|
||||
{"warn, deferred, quiet, tempfail", Tag{Status: "warn"}},
|
||||
{"error, fail, mismatch, bounced, reject", Tag{Status: "fail"}},
|
||||
{"unknown, off, neutral counts", Tag{Status: "off"}},
|
||||
{"held: quarantine · role: global", Tag{Status: "quarantine"}},
|
||||
},
|
||||
|
||||
@@ -402,3 +402,23 @@ func TestOverviewFragmentIsTheBoxAndTheHeadOutOfBand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// With the inbound relay on the retention box has a second field, for the Inbound
|
||||
// log; with it off the field is not there, since there is no journal to keep.
|
||||
func TestSettingsHasTheInboundRetentionOnlyWithTheRelay(t *testing.T) {
|
||||
out := renderSignedIn(t, "settings", settingsFixture())
|
||||
pageHas(t, "Settings", out,
|
||||
`for="inbound_spam_log_retention_days">Keep inbound log rows, days</label>`,
|
||||
`name="inbound_spam_log_retention_days" type="number" min="7" max="365" step="1" value="90" required`,
|
||||
`The inbound log also never holds more than 10 000 rows: refused mail is logged at the rate strangers knock on port 25.`,
|
||||
`name="send_log_retention_days"`)
|
||||
if got := strings.Count(out, `<form class="sp-form"`); got != 1 {
|
||||
t.Errorf("Settings has %d forms, want 1", got)
|
||||
}
|
||||
pageLacks(t, "Settings", renderSignedIn(t, "settings", NewSettings(admin(), "30", "600 / h")),
|
||||
`inbound_spam_log_retention_days`, `Keep inbound log rows`, `10 000 rows`)
|
||||
|
||||
// A refused value comes back as typed.
|
||||
out = renderSignedIn(t, "settings", NewSettings(admin(), "30", "600 / h").WithInbound("3").WithResult("", "Inbound log retention must be between 7 and 365."))
|
||||
pageHas(t, "Settings", out, `value="3"`, `between 7 and 365`)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
{{/* Inbound > Filter lists (mockup in-filter-lists.html): the allow and deny
|
||||
lists that correct the spam filter by hand, for the whole instance, and
|
||||
where they go. Global role only. The form adds an entry; each row of a list
|
||||
removes its own. */}}
|
||||
{{define "content"}}
|
||||
{{template "page_head" .Head}}
|
||||
{{if .Flash}}{{template "flash" .Flash}}{{end}}
|
||||
|
||||
{{template "box_open" .Add}}
|
||||
{{template "body_open"}}
|
||||
<form class="sp-form" method="post" action="/inbound/filter-lists">
|
||||
<div class="columns">
|
||||
<div class="column is-3">
|
||||
<div class="field"><label class="label" for="list">List</label>
|
||||
<div class="control"><div class="select is-fullwidth"><select id="list" name="list_type">{{$list := .List}}{{range .ListOptions}}
|
||||
<option value="{{.Value}}"{{if eq .Value $list}} selected{{end}}>{{.Label}}</option>{{end}}
|
||||
</select></div></div></div>
|
||||
</div>
|
||||
<div class="column is-3">
|
||||
<div class="field"><label class="label" for="etype">Entry is</label>
|
||||
<div class="control"><div class="select is-fullwidth"><select id="etype" name="entry_type">{{$kind := .Kind}}{{range .KindOptions}}
|
||||
<option value="{{.Value}}"{{if eq .Value $kind}} selected{{end}}>{{.Label}}</option>{{end}}
|
||||
</select></div></div></div>
|
||||
</div>
|
||||
<div class="column is-6">
|
||||
<div class="field"><label class="label" for="value">Value</label>
|
||||
<div class="control"><input class="input sp-mono" id="value" name="value" value="{{.Value}}" placeholder="promo@bulk.example" autocomplete="off" autocapitalize="none" spellcheck="false" required></div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field"><label class="label" for="note">Note</label>
|
||||
<div class="control"><input class="input" id="note" name="note" value="{{.Note}}" placeholder="Why — for whoever reads this list next year"></div></div>
|
||||
<button type="submit" class="button is-primary"><i class="ti ti-plus"></i>Add entry</button>
|
||||
</form>
|
||||
{{template "body_close"}}
|
||||
{{template "box_close"}}
|
||||
|
||||
<div class="columns">
|
||||
<div class="column is-6">
|
||||
{{template "filter_list" .Deny}}
|
||||
</div>
|
||||
<div class="column is-6">
|
||||
{{template "filter_list" .Allow}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{template "box_open" .Where}}
|
||||
{{template "body_open"}}
|
||||
{{template "facts" .WhereFacts}}
|
||||
{{template "body_close"}}
|
||||
{{template "box_close"}}
|
||||
{{end}}
|
||||
|
||||
{{/* filter_list is one of the two boxes of entries (input: FilterList): the
|
||||
table, or what is absent when the list is empty. */}}
|
||||
{{define "filter_list"}}{{template "box_open" .Box}}
|
||||
{{if .Rows}}<div class="table-container"><table class="table is-fullwidth is-hoverable">
|
||||
<thead><tr><th>Value</th><th>Note</th><th>Added</th><th></th></tr></thead>
|
||||
<tbody>{{range .Rows}}
|
||||
<tr><td class="sp-mono sp-small">{{.Value}} {{template "tag" .Kind}}</td>{{if .Note}}<td class="sp-muted">{{.Note}}</td>{{else}}<td class="sp-muted">—</td>{{end}}<td class="sp-muted sp-nowrap sp-small">{{.Added}}</td><td class="sp-actions">{{template "row_action" .Remove}}</td></tr>{{end}}
|
||||
</tbody>
|
||||
</table></div>
|
||||
{{else}}{{template "empty_state" .Empty}}
|
||||
{{end}}{{template "box_close"}}{{end}}
|
||||
@@ -0,0 +1,22 @@
|
||||
{{/* Inbound log (mockup in-log.html): what port 25 decided about each message
|
||||
offered for an inbound domain, one row per recipient, newest first,
|
||||
filtered by domain, decision and day. It does not poll. The last cell is
|
||||
the way to correct a decision in Filter lists, and only the global role,
|
||||
who alone edits the lists, is given it. */}}
|
||||
{{define "content"}}
|
||||
{{template "page_head" .Head}}
|
||||
|
||||
{{template "box_open" .Messages}}
|
||||
{{if .Rows}}
|
||||
<div class="table-container"><table class="table is-fullwidth is-hoverable">
|
||||
<thead><tr><th>Time, UTC</th><th>From · client</th><th>To</th><th>Subject</th><th>Decision</th><th>Why</th><th></th></tr></thead>
|
||||
<tbody>{{range .Rows}}
|
||||
<tr><td class="sp-mono sp-muted sp-nowrap sp-small">{{.Time}}</td><td>{{wbr_at .From}}{{if .Client}}<br><span class="sp-mono sp-muted sp-small">{{.Client}}</span>{{end}}</td><td>{{wbr_at .To}}</td>{{if .Subject}}<td class="sp-clip" title="{{.Subject}}">{{.Subject}}</td>{{else}}<td class="sp-clip sp-muted">—</td>{{end}}<td>{{template "tag" .Decision}}</td><td class="sp-muted sp-small">{{.Why}}</td><td class="sp-actions">{{if .Action}}<a href="{{.Action.Href}}">{{.Action.Label}}</a>{{end}}</td></tr>{{end}}
|
||||
</tbody>
|
||||
</table></div>
|
||||
{{template "box_foot" .Foot}}
|
||||
{{else}}
|
||||
{{template "empty_state" .Empty}}
|
||||
{{end}}
|
||||
{{template "box_close"}}
|
||||
{{end}}
|
||||
@@ -104,7 +104,9 @@
|
||||
<a class="navbar-link" href="/inbound/domains">Inbound</a>
|
||||
<div class="navbar-dropdown">
|
||||
<a class="navbar-item{{if and (eq .Section "inbound") (eq .Page "domains")}} is-active{{end}}" href="/inbound/domains"><i class="ti ti-world-download"></i>Domains</a>
|
||||
</div>
|
||||
<a class="navbar-item{{if and (eq .Section "inbound") (eq .Page "log")}} is-active{{end}}" href="/inbound/log"><i class="ti ti-list-details"></i>Log</a>
|
||||
{{if .ShowFilterLists}} <a class="navbar-item{{if and (eq .Section "inbound") (eq .Page "filter-lists")}} is-active{{end}}" href="/inbound/filter-lists"><i class="ti ti-filter"></i>Filter lists</a>
|
||||
{{end}} </div>
|
||||
</div>
|
||||
{{end}}{{if .ShowServer}} <div class="navbar-item has-dropdown is-hoverable{{if eq .Section "server"}} sp-current{{end}}">
|
||||
<a class="navbar-link" href="/server/health">Server</a>
|
||||
@@ -143,6 +145,6 @@
|
||||
pages of the current group, the current one marked. A page outside every
|
||||
group (the user menu, the kit page's neighbours) has none. */}}
|
||||
{{define "subnav"}}{{if and .ShowOutbound (eq .Section "outbound")}}<div class="sp-subnav"><div class="container"><a href="/outbound/domains"{{if eq .Page "domains"}} aria-current="page"{{end}}><i class="ti ti-world-upload"></i>Domains</a><a href="/outbound/log"{{if eq .Page "log"}} aria-current="page"{{end}}><i class="ti ti-list-details"></i>Log</a>{{if .ShowQueue}}<a href="/outbound/queue"{{if eq .Page "queue"}} aria-current="page"{{end}}><i class="ti ti-stack-2"></i>Queue</a>{{end}}{{if .ShowDMARC}}<a href="/outbound/dmarc"{{if eq .Page "dmarc"}} aria-current="page"{{end}}><i class="ti ti-report-analytics"></i>DMARC reports</a>{{end}}</div></div>
|
||||
{{else if and .ShowInbound (eq .Section "inbound")}}<div class="sp-subnav"><div class="container"><a href="/inbound/domains"{{if eq .Page "domains"}} aria-current="page"{{end}}><i class="ti ti-world-download"></i>Domains</a></div></div>
|
||||
{{else if and .ShowInbound (eq .Section "inbound")}}<div class="sp-subnav"><div class="container"><a href="/inbound/domains"{{if eq .Page "domains"}} aria-current="page"{{end}}><i class="ti ti-world-download"></i>Domains</a><a href="/inbound/log"{{if eq .Page "log"}} aria-current="page"{{end}}><i class="ti ti-list-details"></i>Log</a>{{if .ShowFilterLists}}<a href="/inbound/filter-lists"{{if eq .Page "filter-lists"}} aria-current="page"{{end}}><i class="ti ti-filter"></i>Filter lists</a>{{end}}</div></div>
|
||||
{{else if and .ShowServer (eq .Section "server")}}<div class="sp-subnav"><div class="container"><a href="/server/health"{{if eq .Page "health"}} aria-current="page"{{end}}><i class="ti ti-heartbeat"></i>Health</a><a href="/server/log"{{if eq .Page "log"}} aria-current="page"{{end}}><i class="ti ti-file-text"></i>System log</a><a href="/server/backup"{{if eq .Page "backup"}} aria-current="page"{{end}}><i class="ti ti-archive"></i>Backup</a><a href="/server/users"{{if eq .Page "users"}} aria-current="page"{{end}}><i class="ti ti-users"></i>Users</a><a href="/server/settings"{{if eq .Page "settings"}} aria-current="page"{{end}}><i class="ti ti-settings"></i>Settings</a></div></div>
|
||||
{{end}}{{end}}
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
<div class="field"><label class="label" for="send_log_retention_days">Keep outbound log rows, days</label>
|
||||
<div class="control"><input class="input" id="send_log_retention_days" name="send_log_retention_days" type="number" min="7" max="365" step="1" value="{{.RetentionDays}}" required></div>
|
||||
<p class="help">The main driver of <code>/data</code> growth. Does not affect <code>mail.log</code> rotation (fourteen daily files).</p></div>
|
||||
{{if .Inbound}}<div class="field"><label class="label" for="inbound_spam_log_retention_days">Keep inbound log rows, days</label>
|
||||
<div class="control"><input class="input" id="inbound_spam_log_retention_days" name="inbound_spam_log_retention_days" type="number" min="7" max="365" step="1" value="{{.InboundRetentionDays}}" required></div>
|
||||
<p class="help">The inbound log also never holds more than 10 000 rows: refused mail is logged at the rate strangers knock on port 25.</p></div>
|
||||
{{end}}
|
||||
{{template "body_close"}}
|
||||
{{template "box_close"}}
|
||||
</div>
|
||||
|
||||
@@ -54,6 +54,8 @@ var pageFiles = map[string][]string{
|
||||
"in-domains": {"templates/in_domains.html"},
|
||||
"in-domain": {"templates/in_domain.html"},
|
||||
"in-domain-delete": {"templates/in_domain_delete.html"},
|
||||
"in-log": {"templates/in_log.html"},
|
||||
"in-filter-lists": {"templates/in_filter_lists.html"},
|
||||
"out-log": {"templates/out_log.html", "templates/out_log_rows.html"},
|
||||
"out-message": {"templates/out_message.html"},
|
||||
"dmarc": {"templates/dmarc.html"},
|
||||
|
||||
Reference in New Issue
Block a user