Add the last callers, feedback, user details, a line about oneself, expert menus

- Last callers (L, and a callers menu action): each login is recorded
  (calls: the newest 10000 kept); GET /api/v1/callers.
- Feedback to the sysop (K, a feedback action): mail any caller may
  send, whatever their level allows.
- The user list picks a user: their details (a sysop sees their access
  and files too), and mail to them from there.
- A line about oneself, on the profile (Y; - clears it) and PATCH /me's
  about, shown with one's details.
- Expert menus (the expert setting, X on a text terminal's profile): a
  menu is its prompt, "Command (? for the menu): ", and ? shows it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
This commit is contained in:
Claude committed 2026-10-12 17:33:55 +00:00
1 parent 8ab9e8a24b
commit dd788e26a3
22 files changed
+386 -33

No files matched your search

+4 -1
View File
@@ -62,7 +62,10 @@ What there is:
- [VT terminals identified](https://github.com/Neo-Desktop/bbs-sec/wiki/Terminal-Identification) (answerback, DA1, DA2, XTVERSION, VT52): DEC line drawing and Latin-1, bold on monochrome VTs, VT52 escapes
- who's online (and how each caller came: ssh, telnet, tn3270, rlogin, modem
with its rate), the user list, system info
- your profile: where you call from, your password, SSH keys, ANSI and UTF-8
- the last callers (*L*), feedback to the sysop (*K*, which any caller may
send), the user list with each user's details and a line about themselves
- your profile: where you call from, a line about yourself, expert menus
(the prompt alone, `?` for the rest), your password, SSH keys, ANSI and UTF-8
- [file areas](https://github.com/Neo-Desktop/bbs-sec/wiki/Files-and-FTP): files listed with their size, uploader, downloads and
SHA-256, moved by XMODEM, YMODEM, ZMODEM or Kermit on the text BBS, by
IND$FILE on a 3270, or by FTP (FTPS); deleted by their uploader or the
+1 -1
View File
@@ -112,7 +112,7 @@ begin comments), then what it does:
| action | |
|---|---|
| `areas` `mail` `who` `users` `profile` `info` `files` `doors` `chat` `page` | the built-in parts |
| `areas` `mail` `who` `users` `profile` `info` `files` `doors` `chat` `page` `callers` `feedback` | the built-in parts (`callers`: the last callers; `feedback`: mail to the sysop) |
| `terminal` | a 3270's terminal details |
| `logoff` | log off (asking first on a text terminal) |
| `back` | back to the menu before |
+3 -1
View File
@@ -133,7 +133,9 @@ The full-screen editor: its text (wrapping as typed and as given, a word
too long for a line, joining lines by Backspace and Delete, moving over
line ends, quoting, the line limit), and an SSH caller writing a post
with the cursor keys, replying with lines from the quote window and
`/S`, then choosing the line editor; keeping callers out (the deny file
`/S`, then choosing the line editor; the last callers, feedback to the
sysop, a user's details (more of them to a sysop) and mail from there, a
line about oneself, expert menus and `?` on a text terminal; keeping callers out (the deny file
read again as it changes, networks and IPv6, bans after the throttle and
their end, name patterns, the hack log's lines; telnet over TLS with a
login, a plain client on the TLS port getting nothing, a denied address
+2 -1
View File
@@ -63,7 +63,8 @@ Errors are `{"error": "...", "code": "..."}`.
| `POST /login`, `POST /logout` | a session token; ending it | (none), any |
| `GET /system` | the name, sysop, counts, features | anonymous |
| `GET /who` | who is online (with each `terminal`, as it said what it is) | anonymous |
| `GET`, `PATCH /me` | your account, access and settings; change your location, password or settings (`{"prefs": {"ansi": "off"}}`; `""` forgets one) | read |
| `GET /callers?limit=` | the last callers, newest first | read |
| `GET`, `PATCH /me` | your account, access and settings; change your location, a line about yourself (`about`), password or settings (`{"prefs": {"ansi": "off"}}`; `""` forgets one) | read |
| `GET /me/tokens`, `DELETE /me/tokens/{id}` | your tokens; revoke one | any |
| `GET /me/keys` | your SSH keys | read |
| `POST /me/keys`, `DELETE /me/keys/{id}` | add an SSH key (`{"key": "ssh-ed25519 ..."}`, from a login's session only); delete one | any |
+4 -1
View File
@@ -62,7 +62,10 @@ What there is:
- [VT terminals identified](Terminal-Identification) (answerback, DA1, DA2, XTVERSION, VT52): DEC line drawing and Latin-1, bold on monochrome VTs, VT52 escapes
- who's online (and how each caller came: ssh, telnet, tn3270, rlogin, modem
with its rate), the user list, system info
- your profile: where you call from, your password, SSH keys, ANSI and UTF-8
- the last callers (*L*), feedback to the sysop (*K*, which any caller may
send), the user list with each user's details and a line about themselves
- your profile: where you call from, a line about yourself, expert menus
(the prompt alone, `?` for the rest), your password, SSH keys, ANSI and UTF-8
- [file areas](Files-and-FTP): files listed with their size, uploader, downloads and
SHA-256, moved by XMODEM, YMODEM, ZMODEM or Kermit on the text BBS, by
IND$FILE on a 3270 ([file transfers](File-Transfers)), or by FTP (FTPS); deleted by their uploader or the
+1
View File
@@ -85,6 +85,7 @@ begins their next call:
| `rip` | `on`, `off` | the same for RIPscrip |
| `width` | `40`, `80` | a Commodore's columns |
| `editor` | `full`, `line` | the full-screen editor or the line editor |
| `expert` | `on`, `off` | menus as their prompt alone, `?` for the rest |
A Commodore and a VT52 take only what applies to them. The settings are
`prefs` at `GET /api/v1/me`, changed with `PATCH /api/v1/me`
+21
View File
@@ -742,3 +742,24 @@ func TestBansAndHackLog(t *testing.T) {
t.Errorf("hack log: %d %v", code, l)
}
}
func TestCallersAndAbout(t *testing.T) {
s := setup(t, Settings{})
alice := s.login("alice", "alicepass1")
n, _ := s.b.Enter(&bbs.Caller{Via: "telnet"}, nil)
if _, err := n.Login("bob", "bobpass123"); err != nil {
t.Fatal(err)
}
n.Leave()
if code, _, l := s.do("GET", "/api/v1/callers", alice, nil); code != 200 || len(l) != 1 ||
l[0].(map[string]any)["user"] != "bob" || l[0].(map[string]any)["via"] != "telnet" {
t.Errorf("callers: %d %v", code, l)
}
if code, m, _ := s.do("PATCH", "/api/v1/me", alice, map[string]any{"about": "I like \x1b[2Jterminals"}); code != 200 ||
m["user"].(map[string]any)["about"] != "I like [2Jterminals" {
t.Errorf("about: %d %v", code, m)
}
if _, m, _ := s.do("GET", "/api/v1/users/alice", alice, nil); m["about"] != "I like [2Jterminals" {
t.Errorf("user: %v", m)
}
}
+4 -2
View File
@@ -27,6 +27,7 @@ var ops = []op{
{"DELETE", "/api/v1/me/keys/{id}", "Delete an SSH key of yours", "any", "", "", 204},
{"GET", "/api/v1/users", "The users", "read", "", "Users", 200},
{"GET", "/api/v1/users/{name}", "A user", "read", "", "User", 200},
{"GET", "/api/v1/callers", "The last callers, newest first (?limit=, up to 200)", "read", "", "Callers", 200},
{"GET", "/api/v1/areas", "Message areas, with your unread", "read", "", "Areas", 200},
{"GET", "/api/v1/areas/{id}", "A message area", "read", "", "Area", 200},
{"GET", "/api/v1/areas/{id}/messages", "Messages after an id (?after=, ?limit= up to 200, ?body=no)", "read", "", "MessagePage", 200},
@@ -92,10 +93,10 @@ var schemas = map[string]any{
"System": obj(map[string]any{"name": str, "sysop": str, "location": str, "motd": str, "users": num, "messages": num, "areas": num, "online": num, "features": map[string]any{"type": "object"}}),
"Node": obj(map[string]any{"node": num, "user": str, "via": str, "since": date, "doing": str, "terminal": str}),
"Nodes": arr("Node"),
"User": obj(map[string]any{"name": str, "location": str, "sysop": boo, "created": date, "last_login": date, "calls": num, "posts": num, "node": num, "locked": boo, "level": num, "flags": str}),
"User": obj(map[string]any{"name": str, "location": str, "sysop": boo, "created": date, "last_login": date, "calls": num, "posts": num, "node": num, "locked": boo, "level": num, "flags": str, "about": str}),
"Users": arr("User"),
"Me": obj(map[string]any{"user": ref("User"), "unread_mail": num, "access": map[string]any{"type": "object"}, "prefs": ref("Prefs"), "scopes": map[string]any{"type": "array", "items": str}}),
"PatchMe": obj(map[string]any{"location": str, "old_password": str, "new_password": str, "prefs": ref("Prefs")}),
"PatchMe": obj(map[string]any{"location": str, "about": str, "old_password": str, "new_password": str, "prefs": ref("Prefs")}),
"Prefs": map[string]any{"type": "object", "description": "settings: ansi, utf8, sixel, rip (on, off), width (40, 80), editor (full, line); \"\" forgets one", "additionalProperties": str},
"SSHKey": obj(map[string]any{"id": num, "type": str, "fingerprint": str, "comment": str, "key": str, "created": date, "last_used": date}),
"SSHKeys": arr("SSHKey"),
@@ -111,6 +112,7 @@ var schemas = map[string]any{
"Sent": obj(map[string]any{"sent": boo}),
"FileAreas": map[string]any{"type": "array", "items": obj(map[string]any{"id": num, "name": str, "description": str, "sysop_upload": boo, "files": num, "can_upload": boo})},
"File": obj(map[string]any{"id": num, "area": num, "name": str, "description": str, "size": num, "sha256": str, "uploader": str, "created": date, "downloads": num, "long_description": str}),
"Callers": map[string]any{"type": "array", "items": obj(map[string]any{"user": str, "location": str, "via": str, "node": num, "at": date})},
"Bans": map[string]any{"type": "array", "items": obj(map[string]any{"ip": str, "until": date})},
"Lines": map[string]any{"type": "array", "items": str},
"Listing": map[string]any{"type": "array", "items": obj(map[string]any{"name": str, "size": num, "dir": boo, "modified": date})},
+26 -1
View File
@@ -33,6 +33,7 @@ func (s *Server) routes() map[string]route {
"DELETE /api/v1/me/keys/{id}": {scope: "any", h: s.delKey},
"GET /api/v1/users": {scope: "read", h: s.users},
"GET /api/v1/users/{name}": {scope: "read", h: s.user},
"GET /api/v1/callers": {scope: "read", h: s.callers},
"GET /api/v1/areas": {scope: "read", h: s.areas},
"GET /api/v1/areas/{id}": {scope: "read", h: s.area},
@@ -94,6 +95,7 @@ type userJSON struct {
Locked bool `json:"locked,omitempty"`
Level *int `json:"level,omitempty"` // to sysops and the user
Flags string `json:"flags,omitempty"`
About string `json:"about,omitempty"`
}
// userView is a user as the request's user may see them: their access
@@ -109,7 +111,7 @@ func (s *Server) userView(r *http.Request, u *store.User) userJSON {
func (s *Server) userOut(u *store.User) userJSON {
j := userJSON{Name: u.Name, Location: u.Location, Sysop: u.Sysop, Created: u.Created,
Calls: u.Logins, Posts: u.Posts, Locked: u.Locked}
Calls: u.Logins, Posts: u.Posts, Locked: u.Locked, About: u.About}
if !u.LastLogin.IsZero() {
t := u.LastLogin
j.LastLogin = &t
@@ -336,6 +338,7 @@ func (s *Server) patchMe(w http.ResponseWriter, r *http.Request) {
OldPassword string `json:"old_password"`
NewPassword string `json:"new_password"`
Prefs map[string]string `json:"prefs"`
About *string `json:"about"`
}
if !s.decode(w, r, &req) {
return
@@ -357,6 +360,9 @@ func (s *Server) patchMe(w http.ResponseWriter, r *http.Request) {
if req.Location != nil {
s.B.Store.SetLocation(u.ID, bbs.Clean(*req.Location, bbs.MaxLocationLen))
}
if req.About != nil {
s.B.Store.SetAbout(u.ID, bbs.Clean(*req.About, 60))
}
if req.NewPassword != "" {
if err := s.agent(r).ChangePassword(req.OldPassword, req.NewPassword); err != nil {
fail(w, http.StatusBadRequest, err.Error())
@@ -366,6 +372,25 @@ func (s *Server) patchMe(w http.ResponseWriter, r *http.Request) {
s.me(w, r)
}
// callers: the last callers, newest first
func (s *Server) callers(w http.ResponseWriter, r *http.Request) {
n, err := strconv.Atoi(r.URL.Query().Get("limit"))
if err != nil || n <= 0 || n > 200 {
n = 20
}
cs, err := s.B.Store.LastCalls(n)
if err != nil {
fail(w, http.StatusInternalServerError, err.Error())
return
}
out := []map[string]any{}
for _, c := range cs {
out = append(out, map[string]any{"user": c.Name, "location": c.Location, "via": c.Via,
"node": c.Node, "at": c.At})
}
writeJSON(w, http.StatusOK, out)
}
func (s *Server) myTokens(w http.ResponseWriter, r *http.Request) {
ts, _ := s.B.Store.Tokens(whoOf(r).user.ID)
out := []map[string]any{}
+15 -2
View File
@@ -184,11 +184,13 @@ func (s *Session) mainMenu(intro []view.Line) error {
items = append(items, view.Item{Key: "V", Label: fmt.Sprintf("Validate users (%d)", waiting)})
}
}
items = append(items, view.Item{Key: "L", Label: "Last callers"},
view.Item{Key: "K", Label: "Feedback to the sysop"})
if s.UI.Kind() == TN3270 {
items = append(items, view.Item{Key: "T", Label: "Your terminal"})
}
items = append(items, view.Item{Key: "G", Label: "Goodbye"})
k, err := s.UI.Menu(&view.Menu{Title: "Main menu", Intro: intro, Items: items})
k, err := s.UI.Menu(&view.Menu{Title: "Main menu", Intro: intro, Items: items, Brief: s.expert()})
intro = nil
if err != nil {
return err
@@ -198,6 +200,10 @@ func (s *Session) mainMenu(intro []view.Line) error {
err = s.areas()
case "E":
err = s.mail()
case "L":
err = s.lastCallers()
case "K":
err = s.feedback()
case "W":
err = s.who()
case "U":
@@ -237,6 +243,9 @@ func (s *Session) mainMenu(intro []view.Line) error {
}
}
// expert: the caller wants their menus brief.
func (s *Session) expert() bool { return s.N.Prefs()["expert"] == "on" }
// logoff: ErrLogoff once the front end has said goodbye.
func (s *Session) logoff() error {
ok, err := s.UI.Logoff()
@@ -256,7 +265,7 @@ func (s *Session) runMenu(full *bbs.Menu, depth int, intro []view.Line) error {
m := s.B.MenuFor(full, u)
title := screens.String(m.Title, vars)
s.N.Doing(title)
vm := &view.Menu{Title: title, Intro: intro, Screen: m.Screen}
vm := &view.Menu{Title: title, Intro: intro, Screen: m.Screen, Brief: s.expert()}
intro = nil
for _, it := range m.Items {
vm.Items = append(vm.Items, view.Item{Key: it.Key, Label: screens.String(it.Label, vars)})
@@ -333,6 +342,10 @@ func (s *Session) do(it *bbs.MenuItem, depth int) error {
s.UI.Say(view.Bad, "That door is not open to you.")
case "chat":
return s.UI.Chat("", "")
case "callers":
return s.lastCallers()
case "feedback":
return s.feedback()
case "page":
return s.page()
case "logoff":
+38 -1
View File
@@ -57,7 +57,11 @@ func get[T any](f *fake, what string) T {
func (f *fake) PageSize() int { return 10 }
func (f *fake) Narrow() bool { return false }
func (f *fake) Menu(m *view.Menu) (string, error) {
f.shown = append(f.shown, "menu "+m.Title)
brief := ""
if m.Brief {
brief = " (brief)"
}
f.shown = append(f.shown, "menu "+m.Title+brief)
return get[string](f, "menu"), nil
}
func (f *fake) Table(t *view.Table) (view.Choice, error) {
@@ -310,6 +314,39 @@ func TestFileBase(t *testing.T) {
}
}
func TestUserFeatures(t *testing.T) {
b, alice, sysop := setup(t)
// a call recorded by a login
n, _ := b.Enter(&bbs.Caller{Via: "ssh"}, nil)
if _, err := n.Login("alice", "password1"); err != nil {
t.Fatal(err)
}
n.Leave()
f := run(t, b, alice,
"L", view.Choice{Action: view.Back},
"K", draft{"ignored", "Feedback", []string{"Nice board."}},
"P", "about", map[string]string{"about": "Calls from a C64"}, "expert", view.Back,
"U", view.Choice{Action: view.Pick, Row: 1}, "mail", draft{"sysop", "Hello", []string{"Hi."}},
view.Choice{Action: view.Back})
has(t, "screens", f.shown, "table Last callers: alice|Here|ssh|")
has(t, "said", f.said, "Sent to sysop.")
has(t, "screens", f.shown, "panel Your profile: Name:alice; ")
has(t, "screens", f.shown, "Menus:in full")
has(t, "screens", f.shown, "menu Main menu (brief)")
has(t, "screens", f.shown, "panel sysop: Name:sysop; From:Here; ")
has(t, "said", f.said, "Sent.")
in, _ := b.Store.Inbox(sysop.User().ID)
if len(in) != 2 || in[0].Subject+in[1].Subject != "HelloFeedback" && in[0].Subject+in[1].Subject != "FeedbackHello" {
t.Errorf("the sysop's mail: %d", len(in))
}
if u := alice.Refresh(); u.About != "Calls from a C64" || alice.Prefs()["expert"] != "on" {
t.Errorf("alice: %q %v", u.About, alice.Prefs())
}
// the sysop sees more of a user
f = run(t, b, sysop, "U", view.Choice{Action: view.Pick, Row: 0}, view.Back, view.Choice{Action: view.Back})
has(t, "screens", f.shown, "About:Calls from a C64; Access:level 20 (Level 20)")
}
func TestMailAndWho(t *testing.T) {
b, alice, sysop := setup(t)
f := run(t, b, alice,
+143 -17
View File
@@ -8,6 +8,7 @@ import (
"time"
"github.com/Neo-Desktop/bbs-sec/internal/bbs"
"github.com/Neo-Desktop/bbs-sec/internal/store"
"github.com/Neo-Desktop/bbs-sec/internal/view"
)
@@ -58,21 +59,116 @@ func (s *Session) users() error {
if err != nil {
return err
}
t := &view.Table{Title: "User list",
Columns: []view.Column{{Title: "User", Width: 24}, {Title: "From", Width: 26},
{Title: "Posts", Width: 6, Right: true}, {Title: "Last call", Width: 10, Wide: true}}}
for _, u := range us {
last := "never"
if !u.LastLogin.IsZero() {
last = u.LastLogin.Format("2006-01-02")
for {
t := &view.Table{Title: "User list", Pick: "Number for their details",
Columns: []view.Column{{Title: "User", Width: 24}, {Title: "From", Width: 26},
{Title: "Posts", Width: 6, Right: true}, {Title: "Last call", Width: 10, Wide: true}}}
for i, u := range us {
last := "never"
if !u.LastLogin.IsZero() {
last = u.LastLogin.Format("2006-01-02")
}
t.Rows = append(t.Rows, view.Row{Num: strconv.Itoa(i + 1), Hot: u.Sysop,
Cells: []string{u.Name, u.Location, strconv.Itoa(u.Posts), last}})
}
t.Rows = append(t.Rows, view.Row{Hot: u.Sysop,
Cells: []string{u.Name, u.Location, strconv.Itoa(u.Posts), last}})
c, err := s.UI.Table(t)
if err != nil || c.Action == view.Back {
return err
}
if c.Action != view.Pick {
continue
}
if c.Row < 0 {
s.UI.Say(view.Bad, "No such user.")
continue
}
if err := s.userDetail(us[c.Row]); err != nil {
return err
}
}
}
// userDetail: what there is to know of a user, and mail to them
func (s *Session) userDetail(u *store.User) error {
last := "never"
if !u.LastLogin.IsZero() {
last = u.LastLogin.Format("2006-01-02 15:04")
}
p := &view.Panel{Title: u.Name, Lines: []view.Line{
view.V("Name:", u.Name),
view.V("From:", u.Location),
view.V("Member:", fmt.Sprintf("since %s, %d calls, %d posts", u.Created.Format("2006-01-02"), u.Logins, u.Posts)),
view.V("Last call:", last)}}
if u.About != "" {
p.Lines = append(p.Lines, view.V("About:", u.About))
}
if u.Sysop {
p.Lines = append(p.Lines, view.T(view.Bright, "The sysop."))
}
if me := s.User; me.Sysop {
// what sysops alone see
lvl := s.B.LevelOf(u)
p.Lines = append(p.Lines, view.V("Access:", fmt.Sprintf("level %d (%s), flags %q, %s",
u.Level, lvl.Name, u.Flags, map[bool]string{true: "locked", false: "not locked"}[u.Locked])),
view.V("Files:", fmt.Sprintf("%d downloaded, %d uploaded", u.Downloads, u.Uploads)))
}
if u.ID != s.User.ID {
p.Actions = []view.Action{{ID: "mail", Label: "Mail them", Key: 'M', PF: 5, Short: "Mail"}}
}
act, err := s.UI.Panel(p)
if err != nil || act != "mail" {
return err
}
return s.compose(u.Name, "", nil, 0)
}
// lastCallers: who called lately
func (s *Session) lastCallers() error {
s.N.Doing("Last callers")
cs, err := s.B.Store.LastCalls(20)
if err != nil {
return err
}
t := &view.Table{Title: "Last callers", Empty: "No one has called yet.",
Columns: []view.Column{{Title: "User", Width: 20}, {Title: "From", Width: 22, Wide: true},
{Title: "Via", Width: 8}, {Title: "Node", Width: 4, Right: true}, {Title: "When", Width: 11}}}
for _, c := range cs {
when := c.At.Format("01-02 15:04")
t.Rows = append(t.Rows, view.Row{Cells: []string{c.Name, c.Location, c.Via, strconv.Itoa(c.Node), when}})
}
_, err = s.UI.Table(t)
return err
}
// sysop is the sysop mail goes to: the first one not locked ("": none).
func (s *Session) sysop() string {
us, _ := s.B.Store.Users()
for _, u := range us {
if u.Sysop && !u.Locked {
return u.Name
}
}
return ""
}
// feedback: mail to the sysop (which any caller may send)
func (s *Session) feedback() error {
name := s.sysop()
if name == "" {
s.UI.Say(view.Plain, "There is no sysop to write to.")
return nil
}
s.N.Doing("Writing to the sysop")
sent, err := s.UI.Edit(&view.Draft{Title: "Feedback to the sysop", To: name, Subject: "Feedback",
Send: func(to, subject string, body []string) error {
return s.N.SendMail(name, subject, body, 0)
}})
if err == nil && sent {
s.UI.Say(view.Good, "Sent to "+name+".")
}
return err
}
func (s *Session) info() error {
s.N.Doing("System info")
b := s.B
@@ -133,6 +229,18 @@ func (s *Session) profile() error {
view.V("Today:", today),
view.V("Terminal:", s.UI.Terminal())},
Actions: []view.Action{{ID: "location", Label: "Location", Key: 'L', PF: 5}}}
if u.About != "" {
p.Lines = append(p.Lines, view.V("About:", u.About))
}
p.Actions = append(p.Actions, view.Action{ID: "about", Label: "About you", Key: 'Y', PF: 4, Short: "About"})
if s.UI.Kind() == Text {
mode := "off"
if s.expert() {
mode = "on"
}
p.Lines = append(p.Lines, view.V("Menus:", map[string]string{"on": "expert (the prompt alone)", "off": "in full"}[mode]))
p.Actions = append(p.Actions, view.Action{ID: "expert", Label: "Expert menus on/off", Key: 'X'})
}
p.Actions = append(p.Actions, s.UI.TerminalActions()...)
if !u.External {
p.Actions = append(p.Actions, view.Action{ID: "password", Label: "Password", Key: 'P', PF: 6},
@@ -158,6 +266,30 @@ func (s *Session) profile() error {
return err
}
}
case "about":
v, ok, err := s.UI.Form(&view.Form{Title: "About you", Submit: "Save", Fields: []view.Field{
{Name: "about", Label: "About you", Prompt: "A line about yourself (Enter keeps it, - clears it): ",
Width: 60, Value: u.About}}})
if err != nil {
return err
}
if ok {
about := bbs.Clean(v["about"], 60)
if about == "-" {
about = ""
}
if err := s.B.Store.SetAbout(u.ID, about); err != nil {
return err
}
}
case "expert":
v := "on"
if s.expert() {
v = "off"
}
if err := s.N.SetPref("expert", v); err != nil {
return err
}
case "password":
if u.External {
continue
@@ -363,14 +495,8 @@ func (s *Session) page() error {
if err != nil || !ok {
return err
}
us, err := s.B.Store.Users()
if err != nil {
return err
}
for _, u := range us {
if u.Sysop && !u.Locked {
return s.compose(u.Name, "Page: "+reason, nil, 0)
}
if name := s.sysop(); name != "" {
return s.compose(name, "Page: "+reason, nil, 0)
}
s.UI.Say(view.Plain, "There is no sysop to write to.")
return nil
+4
View File
@@ -436,6 +436,10 @@ func (n *Node) loggedIn(u *store.User, how string) (*store.User, error) {
}
n.SetUser(u)
n.startClock(u)
if err := n.b.Store.AddCall(&store.Call{UserID: u.ID, Name: u.Name, Location: u.Location,
Via: n.Caller.Via, Node: n.Num}); err != nil {
n.b.Log.Printf("node %d: the last callers: %v", n.Num, err)
}
n.b.Stats.Logins.Add(1)
n.Doing("Main menu")
n.b.Log.Printf("node %d: %s logged in (%s, %s from %s)", n.Num, u.Name, how,
+2
View File
@@ -53,6 +53,8 @@ var MenuActions = map[string]string{
"doors": "the doors",
"chat": "chat",
"page": "page the sysop",
"callers": "the last callers",
"feedback": "mail to the sysop",
"terminal": "a 3270's terminal details (nothing elsewhere)",
"back": "back to the menu before",
"logoff": "log off",
+1
View File
@@ -20,6 +20,7 @@ var prefValues = map[string][]string{
"rip": {"on", "off"}, // RIPscrip menus, where the terminal has them
"width": {"40", "80"}, // a Commodore's columns
"editor": {"full", "line"}, // the full-screen editor, or the line editor
"expert": {"on", "off"}, // menus as their prompt alone (? for the rest)
}
// PrefKeys are the settings' names, sorted.
+29
View File
@@ -0,0 +1,29 @@
package server
import (
"strings"
"testing"
)
// TestExpertMenus: an expert's menu is its prompt; ? shows the rest.
func TestExpertMenus(t *testing.T) {
e := start(t, nil, &Listener{Name: "modem", Kind: "raw", Address: "modem.sock", ANSI: "no"})
d := login(e, "alice", "alicepass1")
d.send("P")
d.expect("Menus: in full")
d.expect("[X] Expert menus on/off")
d.send("X")
d.expect("Menus: expert (the prompt alone)")
d.send("Q")
d.expect("Command (? for the menu): ")
if strings.Contains(string(d.got), "[M] Message areas") {
t.Errorf("an expert got the menu: %q", d.got)
}
d.send("?")
d.expect("[M] Message areas")
d.expect("[L] Last callers")
d.expect("Command (? for the menu): ")
d.send("L")
d.expect("Last callers")
d.expect("alice")
}
+51
View File
@@ -0,0 +1,51 @@
package store
import "time"
// Call is a login, for the last callers and the statistics.
type Call struct {
ID int64
UserID int64
Name string
Location string
Via string
Node int
At time.Time
}
// keepCalls is how many calls are kept.
const keepCalls = 10000
// AddCall records a login, forgetting the oldest beyond keepCalls.
func (s *Store) AddCall(c *Call) error {
id, err := s.db.insertID(`INSERT INTO calls (user_id, name, location, via, node, at) VALUES (?, ?, ?, ?, ?, ?)`,
c.UserID, c.Name, c.Location, c.Via, c.Node, now())
if err != nil {
return err
}
if id%100 == 0 {
_, err = s.db.Exec(`DELETE FROM calls WHERE id <= ?`, id-keepCalls)
}
return err
}
// LastCalls are the latest calls, newest first.
func (s *Store) LastCalls(limit int) ([]*Call, error) {
rows, err := s.db.Query(`SELECT id, user_id, name, location, via, node, at FROM calls
ORDER BY id DESC LIMIT ?`, limit)
if err != nil {
return nil, err
}
defer rows.Close()
var out []*Call
for rows.Next() {
var c Call
var at int64
if err := rows.Scan(&c.ID, &c.UserID, &c.Name, &c.Location, &c.Via, &c.Node, &at); err != nil {
return nil, err
}
c.At = unix(at)
out = append(out, &c)
}
return out, rows.Err()
}
+1 -1
View File
@@ -9,7 +9,7 @@ import (
// copyOrder is the tables in an order their references allow.
var copyOrder = []string{"users", "areas", "messages", "lastread", "scan_off", "mail", "file_areas", "files",
"history", "peer_groups", "peer_push", "netmail_out", "api_tokens", "ssh_keys", "script_data"}
"history", "peer_groups", "peer_push", "netmail_out", "api_tokens", "ssh_keys", "script_data", "calls"}
var columnPat = regexp.MustCompile(`(?m)^\s*("?\w+"?)\s+(\{\w+\})`)
+13 -1
View File
@@ -28,7 +28,8 @@ CREATE TABLE IF NOT EXISTS users (
dl_day {int} NOT NULL DEFAULT 0,
dl_count {int} NOT NULL DEFAULT 0,
prefs {str} NOT NULL DEFAULT '',
downloads {int} NOT NULL DEFAULT 0
downloads {int} NOT NULL DEFAULT 0,
about {str} NOT NULL DEFAULT ''
)`, `
CREATE TABLE IF NOT EXISTS areas (
id {id},
@@ -74,6 +75,15 @@ CREATE TABLE IF NOT EXISTS script_data (
value {text} NOT NULL,
PRIMARY KEY (script, user_id, name)
)`, `
CREATE TABLE IF NOT EXISTS calls (
id {id},
user_id {int} NOT NULL,
name {str} NOT NULL,
location {str} NOT NULL DEFAULT '',
via {str} NOT NULL DEFAULT '',
node {int} NOT NULL DEFAULT 0,
at {int} NOT NULL
)`, `
CREATE TABLE IF NOT EXISTS mail (
id {id},
from_id {int} NOT NULL,
@@ -172,6 +182,7 @@ var indexes = []struct {
{"messages_message_id", "messages", "message_id", true},
{"messages_created", "messages", "created", false},
{"files_created", "files", "created", false},
{"calls_at", "calls", "at", false},
{"areas_echotag", "areas", "echotag", true},
{"messages_ftn_msgid", "messages", "ftn_msgid", false},
{"api_tokens_user", "api_tokens", "user_id", false},
@@ -202,6 +213,7 @@ var added = []struct{ table, column, decl string }{
{"users", "prefs", "{str} NOT NULL DEFAULT ''"},
{"files", "long_desc", "{text}"},
{"users", "downloads", "{int} NOT NULL DEFAULT 0"},
{"users", "about", "{str} NOT NULL DEFAULT ''"},
}
// migrate makes the schema, or brings an older database up to it.
+8 -2
View File
@@ -49,6 +49,7 @@ type User struct {
Prefs string
// files downloaded ever, and uploaded (the files there now)
Downloads, Uploads int
About string // a line about themselves
}
// Area is a message area.
@@ -189,7 +190,7 @@ func HashPassword(pw string) (string, error) {
}
const userCols = `id, name, password, location, sysop, locked, created, last_login, logins, posts,
level, flags, time_day, time_used, dl_day, dl_count, prefs, downloads,
level, flags, time_day, time_used, dl_day, dl_count, prefs, downloads, about,
(SELECT COUNT(*) FROM files WHERE files.uploader_id = users.id)`
func scanUser(row interface{ Scan(...any) error }) (*User, string, error) {
@@ -198,7 +199,7 @@ func scanUser(row interface{ Scan(...any) error }) (*User, string, error) {
var created, last int64
err := row.Scan(&u.ID, &u.Name, &pw, &u.Location, &u.Sysop, &u.Locked,
&created, &last, &u.Logins, &u.Posts, &u.Level, &u.Flags, &u.TimeDay, &u.TimeUsed, &u.DLDay, &u.DLCount, &u.Prefs,
&u.Downloads, &u.Uploads)
&u.Downloads, &u.About, &u.Uploads)
if errors.Is(err, sql.ErrNoRows) {
return nil, "", ErrNotFound
}
@@ -281,6 +282,11 @@ func (s *Store) SetPrefs(id int64, prefs string) error {
return s.exec1(`UPDATE users SET prefs = ? WHERE id = ?`, prefs, id)
}
// SetAbout sets a user's line about themselves.
func (s *Store) SetAbout(id int64, about string) error {
return s.exec1(`UPDATE users SET about = ? WHERE id = ?`, about, id)
}
// SetSysop gives or takes a user's sysop rights.
func (s *Store) SetSysop(id int64, sysop bool) error {
return s.exec1(`UPDATE users SET sysop = ? WHERE id = ?`, sysop, id)
+12 -1
View File
@@ -114,7 +114,18 @@ func (s *session) Menu(m *view.Menu) (string, error) {
if prompt == "" {
prompt = s.str("command_prompt")
}
k, err := s.menu(m.Title, items, "\n"+prompt, !shown)
brief := m.Brief && !s.t.RIP && !shown
if brief {
if p := strings.TrimRight(prompt, " "); strings.HasSuffix(p, ":") {
prompt = strings.TrimSuffix(p, ":") + " (? for the menu): "
} else {
prompt = p + " (? for the menu) "
}
}
k, err := s.menu(m.Title, items, "\n"+prompt, !shown && !brief)
if err == nil && brief && k == '?' {
k, err = s.menu(m.Title, items, "\n"+prompt, true)
}
if err != nil || k == '\r' {
return "", err
}
+3
View File
@@ -79,6 +79,9 @@ type Menu struct {
Prompt string // "" the default
// a display file of the sysop's shown in place of the items
Screen string
// Brief: the prompt alone, the items when the caller asks (?): an
// expert's menus
Brief bool
}
// Column is a table's column.