From ae228616f2c8ba54548ddbdfcc6dd569eece8557 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Oct 2026 23:39:12 +0000 Subject: [PATCH] Web forum themes: a classic theme in the manner of IPB 2 The forum can wear more than one look. A theme is a stylesheet and, in themes/NAME/, templates of its own for the pages it lays out differently, parsed over the default's. - ipb2: a board of the mid-2000s in the manner of Invision Power Board 2's default skin: white page, navy-outlined boxes, gradient title and sub-title bars, pale blue rows, Logged in as / Welcome Guest bars, Last Post Info, topic folders, post tables with Member No. and Top, quote boxes, big blue buttons, Fast Reply, the footer bar. Its own CSS and templates; no code or images taken from IPB. - ipb3: the existing look (its stylesheet now ipb3.css) - a theme chooser at the foot of every page, for guests too, kept in a cookie; [http] forum_theme sets the forum's own, checked by bbs check - docs: Web-Forum themes, configuration, development Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr --- README.md | 2 +- bbs.conf.sample | 3 + docs/wiki/Development.md | 7 +- docs/wiki/HTTP-API.md | 2 +- docs/wiki/Home.md | 2 +- docs/wiki/Web-Forum.md | 24 +- internal/api/api.go | 1 + internal/api/forum.go | 2 +- internal/forum/format.go | 18 + internal/forum/forum.go | 87 +++- internal/forum/forum_test.go | 66 ++- internal/forum/static/ipb2.css | 386 ++++++++++++++++++ internal/forum/static/{forum.css => ipb3.css} | 2 + internal/forum/templates/layout.html | 9 +- internal/forum/themes/ipb2/area.html | 44 ++ internal/forum/themes/ipb2/index.html | 43 ++ internal/forum/themes/ipb2/layout.html | 53 +++ internal/forum/themes/ipb2/profile.html | 39 ++ internal/forum/themes/ipb2/topic.html | 89 ++++ internal/server/httpconfig.go | 8 + 20 files changed, 865 insertions(+), 22 deletions(-) create mode 100644 internal/forum/static/ipb2.css rename internal/forum/static/{forum.css => ipb3.css} (98%) create mode 100644 internal/forum/themes/ipb2/area.html create mode 100644 internal/forum/themes/ipb2/index.html create mode 100644 internal/forum/themes/ipb2/layout.html create mode 100644 internal/forum/themes/ipb2/profile.html create mode 100644 internal/forum/themes/ipb2/topic.html diff --git a/README.md b/README.md index 5177ac5..4cd25e2 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ What there is: elsewhere by telnet or RLogin, and the door networks BBSLink and DoorParty - [chat](https://github.com/Neo-Desktop/bbs-sec/wiki/Chat-and-Paging): rooms, messages to a node, paging the sysop - [finger and gopher](https://github.com/Neo-Desktop/bbs-sec/wiki/Finger-and-Gopher): who is on, and chosen areas in gopherspace -- [a web forum](https://github.com/Neo-Desktop/bbs-sec/wiki/Web-Forum): the message areas as a bulletin board in the browser, in the manner of Invision Power Board 3 +- [a web forum](https://github.com/Neo-Desktop/bbs-sec/wiki/Web-Forum): the message areas as a bulletin board in the browser, in the manner of Invision Power Board 3, or of IPB 2 (themes) - [a web terminal](https://github.com/Neo-Desktop/bbs-sec/wiki/HTTP-API#the-web-terminal): the BBS in a browser (xterm.js, built in) - [an HTTP API](https://github.com/Neo-Desktop/bbs-sec/wiki/HTTP-API): REST, server-sent events, and WebSockets (JSON or protobuf) where web clients chat with terminal callers; Prometheus metrics - [customization](https://github.com/Neo-Desktop/bbs-sec/wiki/Customization): ANSI art and 3270 screens, menus of the sysop's, @-codes, the prompts' words diff --git a/bbs.conf.sample b/bbs.conf.sample index 2021cee..ecb5c59 100644 --- a/bbs.conf.sample +++ b/bbs.conf.sample @@ -211,6 +211,9 @@ address = 127.0.0.1:2513 ; forum_guests: those not logged in read the areas anyone may read ;forum = yes ;forum_guests = yes +; the forum's theme until a caller chooses (at the foot of each page): +; ipb3 (in the manner of Invision Power Board 3) or ipb2 (classic, as IPB 2) +;forum_theme = ipb3 ; Access levels: a user's level (0-255) gets what the [level] at or ; below it says; areas, doors and menus may require a level and flags diff --git a/docs/wiki/Development.md b/docs/wiki/Development.md index d79dad6..6adbd9c 100644 --- a/docs/wiki/Development.md +++ b/docs/wiki/Development.md @@ -30,7 +30,7 @@ | `doors/dosemu2` | the Docker image DOS doors run in: dosemu2, its FOSSIL on COM1 | | `internal/finger` | the finger server | | `internal/gopher` | the gopher server | -| `internal/forum` | the web forum: its pages (html/template), the skin's CSS (`static/`), sessions by the API's tokens | +| `internal/forum` | the web forum: its pages (html/template; `themes/NAME/` a theme's own, over `templates/`), the themes' CSS (`static/`), sessions by the API's tokens | | `internal/api` | the HTTP API: REST, server-sent events, WebSockets, metrics, OpenAPI; the web terminal page (`web/`: xterm.js, the page) | | `proto` | the WebSocket protocol, `bbs.v1` (`make proto` regenerates `internal/api/pb`) | | `internal/tcpserv` | what finger and gopher share: limits, timeouts | @@ -240,7 +240,10 @@ topics and areas, aliases hiding the writer, deleting (the writer's own, the sysop's any), news-only areas, search and who's online; in the store, topics threaded across areas, read marks, a topic mended when its first post or its replies' parent goes, and threads found for messages from -before. Updating xterm.js: +before. Every page in each theme, for a guest and a member; choosing a +theme (a member's form needing its token, an unknown theme refused, no +going back off the forum), and the forum's own theme until a caller +chooses. Updating xterm.js: `npm pack @xterm/xterm @xterm/addon-fit`, and copy `lib/xterm.js`, `css/xterm.css`, `lib/addon-fit.js` and the license into `internal/api/web` (without their source map lines). diff --git a/docs/wiki/HTTP-API.md b/docs/wiki/HTTP-API.md index 20322c7..1e5abac 100644 --- a/docs/wiki/HTTP-API.md +++ b/docs/wiki/HTTP-API.md @@ -26,7 +26,7 @@ key_file = /etc/bbs/tls/key.pem | `rate`, `burst` | `10`, `20` | requests a second per token (per address without one), and how many may come at once | | `session_hours` | `24` | how long a login's token lasts | | `terminal` | `yes` | the web terminal page (below) | -| `forum`, `forum_guests` | `yes`, `yes` | the [web forum](Web-Forum), and guests reading it | +| `forum`, `forum_guests`, `forum_theme` | `yes`, `yes`, `ipb3` | the [web forum](Web-Forum), guests reading it, and its theme (`ipb3` or `ipb2`) | The OpenAPI 3.1 description is at `/api/v1/openapi.json`. diff --git a/docs/wiki/Home.md b/docs/wiki/Home.md index eb565be..0f42b5f 100644 --- a/docs/wiki/Home.md +++ b/docs/wiki/Home.md @@ -83,7 +83,7 @@ What there is: [IRC](IRC) channels too, for IRC clients, and [MRC](MRC)'s rooms join the BBSes' Multi Relay Chat - [finger and gopher](Finger-and-Gopher): who is on, and chosen areas in gopherspace -- [a web forum](Web-Forum): the message areas as a bulletin board in the browser, in the manner of Invision Power Board 3 +- [a web forum](Web-Forum): the message areas as a bulletin board in the browser, in the manner of Invision Power Board 3, or of IPB 2 (themes) - [a web terminal](HTTP-API#the-web-terminal): the BBS in a browser (xterm.js, built in) - [an HTTP API](HTTP-API): REST, server-sent events, and WebSockets (JSON or protobuf) where web clients chat with terminal callers; Prometheus metrics - [customization](Customization): ANSI art and 3270 screens, menus of the sysop's, @-codes, the prompts' words diff --git a/docs/wiki/Web-Forum.md b/docs/wiki/Web-Forum.md index fb72a93..1bd0903 100644 --- a/docs/wiki/Web-Forum.md +++ b/docs/wiki/Web-Forum.md @@ -2,10 +2,10 @@ The HTTP API's server also serves the message areas as a web forum, at `/forum/` (and `/`, which goes there). It is laid out like the bulletin -boards of the early 2010s (Invision Power Board 3 and its kind): -categories of forums, topics, and posts with their authors beside them. -The look is the BBS's own CSS, built into the `bbs` binary; nothing is -loaded from elsewhere, and no script runs on the pages. +boards of their day: categories of forums, topics, and posts with their +authors beside them, in one of two [themes](#themes). The look is the +BBS's own CSS, built into the `bbs` binary; nothing is loaded from +elsewhere, and no script runs on the pages. It is the same BBS: the same accounts, areas and messages. A post on the forum is a message on the terminals, in QWK packets, on NNTP and FidoNet @@ -16,12 +16,14 @@ forum is a message on the terminals, in QWK packets, on NNTP and FidoNet address = :8443 ;forum = yes ;forum_guests = yes +;forum_theme = ipb3 ``` | setting | default | | |---|---|---| | `forum` | `yes` | the forum at `/forum/` (with `no`, `/` goes to the web terminal again) | | `forum_guests` | `yes` | those not logged in may read the areas anyone may read (areas with a `read` requirement never) | +| `forum_theme` | `ipb3` | the theme callers get until they choose one ([below](#themes)) | ## The pages @@ -67,6 +69,20 @@ On a post: - A poll is answered by those who may post in its area; answering again changes the answer. +## Themes + +| theme | | +|---|---| +| `ipb3` | the default: a board of the early 2010s in the manner of Invision Power Board 3: a dark user bar, a navy header with tabs, rounded blue category bars, posts with their author's column on the left | +| `ipb2` | classic: a board of the mid-2000s in the manner of Invision Power Board 2: a white page, boxes outlined in navy, blue gradient title bars, pale blue rows, small Verdana; *Logged in as* and *Welcome Guest* bars, *Last Post Info*, *Fast Reply*, big blue buttons | + +Both are this BBS's own CSS and templates, drawn to look like the boards +they recall; no code or images are taken from them. `forum_theme` is the +forum's; anyone (guests too) may choose another at the foot of every page, +kept in a cookie (`bbs_forum_theme`) for a year. A theme lays out the +board, topic lists, topics and profiles its own way, and shows the rest +(posting, searching, signing in) in its colors. + ## Logins A login is the HTTP API's session token (lasting `session_hours`), kept in diff --git a/internal/api/api.go b/internal/api/api.go index a384547..bf31952 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -46,6 +46,7 @@ type Settings struct { Terminal bool // the web terminal page (if Server.Terminal is set) Forum bool // the web forum, /forum/ Guests bool // the forum's guests read the areas anyone may + Theme string // the forum's theme until a caller chooses ("": the default) } // Server serves the API. diff --git a/internal/api/forum.go b/internal/api/forum.go index 5877e03..3cb0668 100644 --- a/internal/api/forum.go +++ b/internal/api/forum.go @@ -50,7 +50,7 @@ func (f forumSessions) Logout(secret string) { // caller's address as the API's are. func (s *Server) forum() (http.Handler, error) { f := &forum.Server{B: s.B, Sessions: forumSessions{s}, Guests: s.S.Guests, Secure: s.S.TLS, - Terminal: s.terminalOn(), TTL: s.S.SessionTTL} + Terminal: s.terminalOn(), TTL: s.S.SessionTTL, Theme: s.S.Theme} h, err := f.Handler() if err != nil { return nil, err diff --git a/internal/forum/format.go b/internal/forum/format.go index 1d9b95b..200c9db 100644 --- a/internal/forum/format.go +++ b/internal/forum/format.go @@ -20,6 +20,7 @@ var funcs = template.FuncMap{ "body": renderBody, "when": when, "date": func(t time.Time) string { return t.Format("02 January 2006") }, + "longdate": longDate, "initial": initial, "avatar": avatarClass, "group": groupTitle, @@ -60,6 +61,23 @@ func when(t time.Time) string { return t.Format("02 January 2006 - 03:04 PM") } +// longDate is a time in full, as "12th October 2026 - 11:21 PM". +func longDate(t time.Time) string { + d := t.Day() + suffix := "th" + if d < 11 || d > 13 { + switch d % 10 { + case 1: + suffix = "st" + case 2: + suffix = "nd" + case 3: + suffix = "rd" + } + } + return strconv.Itoa(d) + suffix + t.Format(" January 2006 - 03:04 PM") +} + func plural(n int, one, many string) string { if n == 1 { return groupDigits(n) + " " + one diff --git a/internal/forum/forum.go b/internal/forum/forum.go index f845d92..b2ca587 100644 --- a/internal/forum/forum.go +++ b/internal/forum/forum.go @@ -24,7 +24,7 @@ import ( "github.com/Neo-Desktop/bbs-sec/internal/store" ) -//go:embed templates/*.html static/* +//go:embed templates/*.html themes/*/*.html static/* var content embed.FS // Sessions are the logins: the HTTP API's session tokens. @@ -38,6 +38,30 @@ type Sessions interface { Logout(secret string) } +// Theme is a look the forum can wear: its own stylesheet, and templates +// of its own in themes// for the pages it lays out differently +// (the rest are the default's). +type Theme struct { + Name string // as in bbs.conf's forum_theme + Title string // as the theme chooser shows it +} + +// Themes are the forum's looks; the first is the default. +var Themes = []Theme{ + {"ipb3", "Default (IPB 3 style)"}, + {"ipb2", "Classic (IPB 2 style)"}, +} + +// KnownTheme says whether there is a theme of the name. +func KnownTheme(name string) bool { + for _, t := range Themes { + if t.Name == name { + return true + } + } + return false +} + // Server serves the forum. type Server struct { B *bbs.BBS @@ -46,27 +70,41 @@ type Server struct { Secure bool // the cookie only over TLS Terminal bool // the web terminal is there to link to TTL time.Duration // a login's + Theme string // the theme callers get until they choose ("": the first) - tmpl *template.Template - key []byte // for forms' CSRF tokens + tmpl map[string]*template.Template // by theme + key []byte // for forms' CSRF tokens } // Base is where the forum is. const Base = "/forum" const ( - cookieName = "bbs_forum" - perPage = 20 + cookieName = "bbs_forum" + themeCookie = "bbs_forum_theme" + perPage = 20 ) // Handler is the forum's routes, under Base. func (s *Server) Handler() (http.Handler, error) { if s.tmpl == nil { - t, err := template.New("").Funcs(funcs).ParseFS(content, "templates/*.html") + base, err := template.New("").Funcs(funcs).ParseFS(content, "templates/*.html") if err != nil { return nil, err } - s.tmpl = t + s.tmpl = map[string]*template.Template{} + for _, th := range Themes { + t, err := base.Clone() + if err != nil { + return nil, err + } + if own, _ := fs.Glob(content, "themes/"+th.Name+"/*.html"); len(own) > 0 { + if t, err = t.ParseFS(content, own...); err != nil { + return nil, fmt.Errorf("theme %s: %w", th.Name, err) + } + } + s.tmpl[th.Name] = t + } s.key = make([]byte, 32) rand.Read(s.key) } @@ -93,6 +131,7 @@ func (s *Server) Handler() (http.Handler, error) { "POST " + Base + "/logout": s.logout, "GET " + Base + "/register": s.register, "POST " + Base + "/register": s.register, + "POST " + Base + "/theme": s.chooseTheme, } { mux.HandleFunc(pattern, s.wrap(h)) } @@ -220,7 +259,10 @@ type page struct { Notice string Now time.Time Online int - Body any // the page's own + Theme string // the theme in use + Themes []Theme // to choose from + Path string // this page's, to come back to + Body any // the page's own } type crumb struct { @@ -230,7 +272,8 @@ type crumb struct { // render shows a page. func (q *req) render(status int, name, title string, crumbs []crumb, body any) { p := page{Title: title, BBS: q.s.B.Name, User: q.user, CSRF: q.csrf(), Crumbs: crumbs, Terminal: q.s.Terminal, - Register: q.user == nil && q.s.B.NewUsers, Now: time.Now(), Body: body, Notice: q.r.URL.Query().Get("notice")} + Register: q.user == nil && q.s.B.NewUsers, Now: time.Now(), Body: body, Notice: q.r.URL.Query().Get("notice"), + Theme: q.theme(), Themes: Themes, Path: q.r.URL.RequestURI()} switch { case strings.HasPrefix(name, "online"): p.Tab = "online" @@ -245,7 +288,7 @@ func (q *req) render(status int, name, title string, crumbs []crumb, body any) { } } var buf strings.Builder - if err := q.s.tmpl.ExecuteTemplate(&buf, name, p); err != nil { + if err := q.s.tmpl[p.Theme].ExecuteTemplate(&buf, name, p); err != nil { q.s.B.Log.Printf("forum: %s: %v", name, err) http.Error(q.w, "the page could not be made", http.StatusInternalServerError) return @@ -256,6 +299,30 @@ func (q *req) render(status int, name, title string, crumbs []crumb, body any) { fmt.Fprint(q.w, buf.String()) } +// theme is the theme the caller chose, or the forum's. +func (q *req) theme() string { + if c, err := q.r.Cookie(themeCookie); err == nil && KnownTheme(c.Value) { + return c.Value + } + if KnownTheme(q.s.Theme) { + return q.s.Theme + } + return Themes[0].Name +} + +// chooseTheme keeps the caller's choice of theme (in a cookie: guests +// choose too) and goes back to the page they chose it on. +func (s *Server) chooseTheme(q *req) { + name := q.r.PostForm.Get("theme") + if !KnownTheme(name) { + q.fail(http.StatusBadRequest, "There is no such theme.") + return + } + http.SetCookie(q.w, &http.Cookie{Name: themeCookie, Value: name, Path: Base, MaxAge: 365 * 24 * 3600, + HttpOnly: true, Secure: s.Secure, SameSite: http.SameSiteLaxMode}) + q.redirect(safeBack(q.r.PostForm.Get("back"))) +} + // fail shows an error page. func (q *req) fail(status int, msg string) { q.render(status, "error.html", "Error", nil, map[string]any{"Message": msg, "Status": status}) diff --git a/internal/forum/forum_test.go b/internal/forum/forum_test.go index b7133f3..27aa7c8 100644 --- a/internal/forum/forum_test.go +++ b/internal/forum/forum_test.go @@ -65,6 +65,7 @@ type site struct { b *bbs.BBS ts *httptest.Server ar map[string]*store.Area + fs *Server } func setup(t *testing.T) *site { @@ -101,7 +102,7 @@ func setup(t *testing.T) *site { } ts := httptest.NewServer(h) t.Cleanup(ts.Close) - return &site{t: t, b: b, ts: ts, ar: ar} + return &site{t: t, b: b, ts: ts, ar: ar, fs: fs} } // browser is a client with its cookies. @@ -369,3 +370,66 @@ func TestRenderBody(t *testing.T) { t.Error(groupDigits(1234567)) } } + +func TestThemes(t *testing.T) { + s := setup(t) + alice, guest := s.browser(), s.browser() + alice.login("alice") + gen := "/forum/area/" + itoa(s.ar["General"].ID) + _, topic, _ := alice.post(gen+"/new", gen+"/new", url.Values{"subject": {"Old skins"}, + "body": {"Remember these?"}, "poll": {"Yes\nNo"}}) + alice.post(topic, topic+"/reply", url.Values{"body": {"alice wrote:\n> Remember these?\n\nI do."}}) + pages := []string{"/forum/", gen, gen + "/new", topic, "/forum/user/alice", "/forum/online", + "/forum/search?q=skins", "/forum/area/999"} + + // the default theme, and the chooser offering both + _, _, body := guest.get("/forum/") + has(t, "default", body, "/forum/static/ipb3.css", `