diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-28 14:02:54 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-28 14:02:54 +0200 |
| commit | 0586599fc6020df996c4278230eeea99b9d070cb (patch) | |
| tree | a03b615039243f84fa2d69430b769676d1da9135 /internal | |
| parent | 44472bbe31475a3c672ae003d928d7caffb4b50a (diff) | |
| download | lectio-0586599fc6020df996c4278230eeea99b9d070cb.tar.gz lectio-0586599fc6020df996c4278230eeea99b9d070cb.zip | |
licence: relicense MIT -> AGPL-3.0-or-later
lectio was MIT, which let anyone take it closed. The concern is not people
selling it -- no licence stops that, and the AGPL does not try to -- but
someone building a proprietary product on it and giving nothing back.
Plain GPL would leave the obvious hole open: lectio-web is a network
service, and hosting is not distribution, so a modified lectio-web could be
run as a paid subscription API without ever publishing a line. AGPL section
13 closes exactly that.
LICENSE is the verbatim FSF text. README carries the standard notice.
Section 13 requires a modified network-reachable version to PROMINENTLY
offer its source to the users interacting with it, so the offer ships with
the code rather than living only in a file nobody fetches:
- GET /source plain text, no template or config dependency, so
it answers even when something else is broken
- page footers every full page (fragments render inside one)
- JSON envelope "source" / "license"
- iCal header X-LECTIO-SOURCE / X-LECTIO-LICENSE
The feed fields are not redundant: an /api/calendar.json consumer or an
.ics subscriber never loads a page, so the footer alone would miss them.
config.SourceURL is the single source of truth, and says in its comment
that a fork running as a service must repoint it -- an offer that leads to
someone else's code is not an offer.
Tests pin all of it. This is a licence obligation, not a feature, so it
should fail loudly if a later change drops it.
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/calfeed/ical.go | 8 | ||||
| -rw-r--r-- | internal/calfeed/ical_test.go | 18 | ||||
| -rw-r--r-- | internal/calfeed/json.go | 21 | ||||
| -rw-r--r-- | internal/calfeed/json_test.go | 27 | ||||
| -rw-r--r-- | internal/config/config.go | 17 | ||||
| -rw-r--r-- | internal/web/server.go | 27 | ||||
| -rw-r--r-- | internal/web/server_test.go | 49 | ||||
| -rw-r--r-- | internal/web/static/base.css | 14 | ||||
| -rw-r--r-- | internal/web/templates/bookmarks.html | 2 | ||||
| -rw-r--r-- | internal/web/templates/index.html | 4 | ||||
| -rw-r--r-- | internal/web/templates/reader.html | 2 | ||||
| -rw-r--r-- | internal/web/templates/settings.html | 2 |
12 files changed, 186 insertions, 5 deletions
diff --git a/internal/calfeed/ical.go b/internal/calfeed/ical.go index bce3710..810847d 100644 --- a/internal/calfeed/ical.go +++ b/internal/calfeed/ical.go @@ -4,6 +4,8 @@ import ( "strconv" "strings" "time" + + "github.com/lukaszkasprzak/lectio/internal/config" ) // icalEscape neutralises RFC-5545 TEXT specials AND all CR/LF, so untrusted @@ -58,6 +60,12 @@ func ICal(form string, days []DayView, stamp time.Time) []byte { add("PRODID:-//lectio//calendar//EN") add("CALSCALE:GREGORIAN") add("METHOD:PUBLISH") + // AGPL-3.0 §13 offer for subscribers who only ever see the .ics feed. + // X- properties are the RFC-5545 extension point; unknown ones are + // ignored by clients, so this is inert for consumers and present for + // anyone who looks. + add("X-LECTIO-SOURCE:" + icalEscape(config.SourceURL)) + add("X-LECTIO-LICENSE:" + icalEscape(config.License)) add("X-WR-CALNAME:" + icalEscape(calName(form))) ds := stamp.UTC().Format("20060102T150405Z") for _, d := range days { diff --git a/internal/calfeed/ical_test.go b/internal/calfeed/ical_test.go index fb7ee9a..215c0e3 100644 --- a/internal/calfeed/ical_test.go +++ b/internal/calfeed/ical_test.go @@ -4,6 +4,8 @@ import ( "strings" "testing" "time" + + "github.com/lukaszkasprzak/lectio/internal/config" ) func TestICalEscapeInjection(t *testing.T) { @@ -19,6 +21,22 @@ func TestICalEscapeInjection(t *testing.T) { } } +// TestICalCarriesSourceOffer pins the AGPL-3.0 §13 offer into the VCALENDAR +// header. Someone who subscribes to /calendar.ics in their calendar app sees +// no lectio page at all; the feed is their entire view of the program, so it +// carries the offer. X- properties are inert to clients that ignore them. +func TestICalCarriesSourceOffer(t *testing.T) { + out := string(ICal("new", nil, time.Date(2026, 7, 27, 12, 0, 0, 0, time.UTC))) + for _, want := range []string{ + "X-LECTIO-SOURCE:" + icalEscape(config.SourceURL), + "X-LECTIO-LICENSE:" + icalEscape(config.License), + } { + if !strings.Contains(out, want) { + t.Errorf("missing %q in:\n%s", want, out) + } + } +} + func TestICalStructure(t *testing.T) { days := []DayView{{ Date: "2026-01-06", Season: "time-after-epiphany", Week: 1, Colour: "white", diff --git a/internal/calfeed/json.go b/internal/calfeed/json.go index c1a50ca..1cb0b6f 100644 --- a/internal/calfeed/json.go +++ b/internal/calfeed/json.go @@ -1,17 +1,28 @@ package calfeed -import "encoding/json" +import ( + "encoding/json" + + "github.com/lukaszkasprzak/lectio/internal/config" +) const Schema = "lectio.calendar/1" // JSON renders days as the stable lectio.calendar/1 envelope. +// +// "source" and "license" carry the AGPL-3.0 §13 offer to consumers who only +// ever see this endpoint and never load the HTML UI. They are envelope +// metadata, not day data -- adding them does not change the schema version, +// since existing consumers read "days". func JSON(form string, days []DayView) ([]byte, error) { if days == nil { days = []DayView{} } return json.MarshalIndent(struct { - Schema string `json:"schema"` - Form string `json:"form"` - Days []DayView `json:"days"` - }{Schema, form, days}, "", " ") + Schema string `json:"schema"` + Form string `json:"form"` + Source string `json:"source"` + License string `json:"license"` + Days []DayView `json:"days"` + }{Schema, form, config.SourceURL, config.License, days}, "", " ") } diff --git a/internal/calfeed/json_test.go b/internal/calfeed/json_test.go index d2bc856..aec3d14 100644 --- a/internal/calfeed/json_test.go +++ b/internal/calfeed/json_test.go @@ -3,6 +3,8 @@ package calfeed import ( "encoding/json" "testing" + + "github.com/lukaszkasprzak/lectio/internal/config" ) func TestJSONShape(t *testing.T) { @@ -33,3 +35,28 @@ func TestJSONShape(t *testing.T) { t.Fatalf("bad day: %s", b) } } + +// TestJSONCarriesSourceOffer pins the AGPL-3.0 §13 offer into the envelope. +// A consumer of /api/calendar.json may never load a single HTML page, so the +// footer link does not reach them -- the feed itself has to say where the +// source is. Dropping these fields is a licence-compliance regression, not a +// cosmetic one, which is why it is asserted rather than left to review. +func TestJSONCarriesSourceOffer(t *testing.T) { + b, err := JSON("new", nil) + if err != nil { + t.Fatal(err) + } + var out struct { + Source string `json:"source"` + License string `json:"license"` + } + if err := json.Unmarshal(b, &out); err != nil { + t.Fatal(err) + } + if out.Source != config.SourceURL { + t.Errorf("source = %q, want %q", out.Source, config.SourceURL) + } + if out.License != config.License { + t.Errorf("license = %q, want %q", out.License, config.License) + } +} diff --git a/internal/config/config.go b/internal/config/config.go index 31e9078..b6c9e0e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -64,6 +64,23 @@ const configHeader = `# lectio configuration (INI). Full-line comments only (# o // -v/--version output (lectio, lectio-ui, lectio-web). const Version = "0.44.0" +// SourceURL is where lectio's corresponding source can be obtained. It is +// not decoration: lectio is AGPL-3.0-or-later, and section 13 requires a +// modified version reachable over a network to "prominently offer" its +// source to the users interacting with it. lectio-web therefore surfaces +// this on every page (footer -> GET /source) and inside both machine feeds +// (JSON envelope, iCal X-LECTIO-SOURCE), so an API consumer who never sees +// the HTML still gets the offer. +// +// If you fork lectio and run it as a service, point this at YOUR source. +// Leaving it aimed here while serving modified code does not satisfy §13 -- +// the offer must lead to the version actually running. +const SourceURL = "https://github.com/lukaszkasprzak/lectio" + +// License is the SPDX identifier lectio ships under, paired with SourceURL +// wherever the §13 offer is made. +const License = "AGPL-3.0-or-later" + // validVersions are the scripture versions lectio understands. All are // embedded corpora; the former "bt" (the niedziela.pl modern scrape) is gone // and a legacy config carrying it is migrated to "wuj" on load (see Load). diff --git a/internal/web/server.go b/internal/web/server.go index 6e76d3f..92cb758 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -74,6 +74,7 @@ func NewServer(cfg config.Config) http.Handler { mux.HandleFunc("GET /calendar.ics", func(w http.ResponseWriter, r *http.Request) { calendarICSHandler(s.get())(w, r) }) mux.HandleFunc("GET /reader", func(w http.ResponseWriter, r *http.Request) { readerHandler(s.get(), s.table())(w, r) }) mux.HandleFunc("GET /theme.css", func(w http.ResponseWriter, r *http.Request) { themeCSSHandler(s.get())(w, r) }) + mux.HandleFunc("GET /source", sourceHandler) mux.HandleFunc("GET /settings", settingsGet(s)) mux.HandleFunc("POST /settings", settingsPost(s)) mux.HandleFunc("POST /reader/bookmark", addBookmark(s)) @@ -691,6 +692,32 @@ func themeCSSHandler(cfg config.Config) http.HandlerFunc { } } +// sourceHandler serves the AGPL-3.0 §13 source offer: where to obtain the +// code this server is running. Every page footer links here, so a user +// interacting with lectio-web over a network is never more than one click +// from the corresponding source. +// +// Deliberately dependency-free (no template, no config read): it must answer +// even when config is broken or a template failed to parse, because a §13 +// offer that only works on healthy days is not an offer. Plain text keeps it +// readable by both a browser and curl. +func sourceHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.Header().Set("X-Content-Type-Options", "nosniff") + fmt.Fprintf(w, `lectio %s +Licence: %s (GNU Affero General Public License, version 3 or later) +Source: %s + +lectio is free software. You may use, study, share and modify it under the +terms of the AGPL. The full licence text ships with the source as LICENSE. + +Because this is the Affero GPL, section 13 applies to this server: if the +code running here has been MODIFIED, whoever operates it must offer you the +modified source. If this address does not lead to the version you are +talking to, that is the operator's obligation to fix, not lectio's. +`, config.Version, config.License, config.SourceURL) +} + // settingsData drives templates/settings.html. type settingsData struct { Cfg config.Config diff --git a/internal/web/server_test.go b/internal/web/server_test.go index 57286d5..42de0b5 100644 --- a/internal/web/server_test.go +++ b/internal/web/server_test.go @@ -630,3 +630,52 @@ func TestCalendarPDF(t *testing.T) { t.Errorf("not a pdf (len=%d)", len(b)) } } + +// TestSourceOffer covers the AGPL-3.0 §13 obligation: a user interacting with +// lectio-web over a network must be offered the corresponding source. That is +// a licence term, not a feature, so it is pinned here -- if someone later +// deletes the footer or the route, this fails rather than quietly putting the +// operator out of compliance. +func TestSourceOffer(t *testing.T) { + cfg := config.Default() + cfg.Offline = true // no network; the offer must not depend on readings + srv := NewServer(cfg) + + t.Run("/source names the licence and where to get the code", func(t *testing.T) { + rec := httptest.NewRecorder() + srv.ServeHTTP(rec, httptest.NewRequest("GET", "/source", nil)) + if rec.Code != http.StatusOK { + t.Fatalf("status = %d, want 200", rec.Code) + } + if ct := rec.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/plain") { + t.Errorf("content-type = %q, want text/plain", ct) + } + body := rec.Body.String() + for _, want := range []string{config.SourceURL, config.License, config.Version} { + if !strings.Contains(body, want) { + t.Errorf("body missing %q:\n%s", want, body) + } + } + }) + + // Every page a user can actually land on carries the link. Fragments + // (htmx partials) are excluded -- they render inside a full page that + // already has it. + for _, path := range []string{ + "/?date=2026-07-22&v=wuj", + "/reader?v=wuj&book=John&chapter=1", + "/settings", + "/bookmarks", + } { + t.Run("footer on "+path, func(t *testing.T) { + rec := httptest.NewRecorder() + srv.ServeHTTP(rec, httptest.NewRequest("GET", path, nil)) + if rec.Code != http.StatusOK { + t.Fatalf("status = %d, want 200", rec.Code) + } + if !strings.Contains(rec.Body.String(), `href="/source"`) { + t.Errorf("page has no source link (AGPL §13):\n%s", rec.Body.String()) + } + }) + } +} diff --git a/internal/web/static/base.css b/internal/web/static/base.css index d9d0e59..d367c15 100644 --- a/internal/web/static/base.css +++ b/internal/web/static/base.css @@ -296,3 +296,17 @@ a { /* Export links (download the readings). */ .export { font-family: var(--font-ui); font-size: 0.85rem; } .export a { margin: 0 0.15rem; } + +/* Licence footer: the AGPL-3.0 §13 source offer, on every full page. + * Quiet by design but never hidden -- §13 asks for a PROMINENT offer, so + * this must not be display:none'd or themed to invisibility. Colour (border + * and text) is the theme's, per this file's no-colour rule. */ +.licence { + max-width: var(--measure); + margin: var(--space-4) auto 0; + padding-top: var(--space-2); + border-top-width: 1px; + border-top-style: solid; + font-family: var(--font-ui); + font-size: 0.75rem; +} diff --git a/internal/web/templates/bookmarks.html b/internal/web/templates/bookmarks.html index efc988a..770c73a 100644 --- a/internal/web/templates/bookmarks.html +++ b/internal/web/templates/bookmarks.html @@ -46,5 +46,7 @@ {{end}} </div> + +<footer class="licence"><a href="/source">source</a> · AGPL-3.0-or-later</footer> </body> </html> diff --git a/internal/web/templates/index.html b/internal/web/templates/index.html index 762ed7b..b99725d 100644 --- a/internal/web/templates/index.html +++ b/internal/web/templates/index.html @@ -90,5 +90,9 @@ <div id="pane">{{.Reading}}</div> </div> + +{{/* AGPL-3.0 §13: the source offer must be visible to anyone using this + server over a network, so it sits on every full page, not just here. */}} +<footer class="licence"><a href="/source">source</a> · AGPL-3.0-or-later</footer> </body> </html> diff --git a/internal/web/templates/reader.html b/internal/web/templates/reader.html index ef144cc..36cc8a1 100644 --- a/internal/web/templates/reader.html +++ b/internal/web/templates/reader.html @@ -83,5 +83,7 @@ onchange="document.body.classList.toggle('mono', this.checked)"> {{.L.Mono}}</label> </div> + +<footer class="licence"><a href="/source">source</a> · AGPL-3.0-or-later</footer> </body> </html> diff --git a/internal/web/templates/settings.html b/internal/web/templates/settings.html index f4fae47..3ae2f41 100644 --- a/internal/web/templates/settings.html +++ b/internal/web/templates/settings.html @@ -104,5 +104,7 @@ </form> </div> + +<footer class="licence"><a href="/source">source</a> · AGPL-3.0-or-later</footer> </body> </html> |
