mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-12-01 01:14:47 +00:00
feat(mail): give free members a webmail password at join@
The gateway opens mailboxes via the Dovecot master user (no member password), but webmail (Roundcube) needs the member to have a password. join@ now sets a fresh, readable webmail password via the Mailu API and shows it with the webmail URL + login, so free members can use webmail at mail.profullstack.com. - mailu: SetPassword (PATCH /user/<email> raw_password) + test. - main.go: setWebmailPassword + readablePassword; join@ displays url/login/password. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
1cc6a9c89e
commit
7a6e466977
3 changed files with 92 additions and 1 deletions
|
|
@ -31,6 +31,7 @@ import (
|
|||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
@ -637,6 +638,10 @@ func (a *app) handleJoin(s ssh.Session) {
|
|||
// mailbox at <name>@<mailDomain> (best-effort; mail is a bonus, never a gate).
|
||||
seedHomepage(filepath.Join(a.dataDir, "users", u.Name, "public_html"), u.Name, a.host)
|
||||
_ = a.ensureMailbox(u)
|
||||
// Give them a webmail password so free members can log into webmail. The
|
||||
// in-BBS reader uses the gateway master user and needs no password, but
|
||||
// Roundcube does. (Re)set on each join@; they can change it in webmail.
|
||||
webmailPW := a.setWebmailPassword(u)
|
||||
|
||||
includes := []string{
|
||||
" You're in. One login gets you everything — no other servers to ssh into:",
|
||||
|
|
@ -650,7 +655,15 @@ func (a *app) handleJoin(s ssh.Session) {
|
|||
" • the arcade & games",
|
||||
" • your homepage https://" + a.host + "/~" + u.Name,
|
||||
}
|
||||
if a.webmailURL != "" {
|
||||
if a.webmailURL != "" && webmailPW != "" {
|
||||
includes = append(includes,
|
||||
"",
|
||||
" Webmail (read your mail in a browser):",
|
||||
" • url "+a.webmailURL,
|
||||
" • login "+a.mailAddress(u.Name),
|
||||
" • password "+webmailPW+" (change it in webmail Settings)",
|
||||
)
|
||||
} else if a.webmailURL != "" {
|
||||
includes = append(includes, " • webmail "+a.webmailURL)
|
||||
}
|
||||
wish.Println(s, "\n"+strings.Join(includes, "\n"))
|
||||
|
|
@ -1337,6 +1350,41 @@ func (a *app) ensureMailbox(u store.User) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// setWebmailPassword sets (and returns) a fresh webmail password for the member
|
||||
// so free members can log into webmail. Best-effort: returns "" when Mailu isn't
|
||||
// configured or the API call fails. The in-BBS reader doesn't use this (it goes
|
||||
// through the gateway master user); only webmail needs a member password.
|
||||
func (a *app) setWebmailPassword(u store.User) string {
|
||||
if !a.mailEnabled() || u.Name == "" {
|
||||
return ""
|
||||
}
|
||||
pw := readablePassword()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
if err := a.mailu.SetPassword(ctx, u.Name, a.mailDomain, pw); err != nil {
|
||||
log.Error("set webmail password", "err", err, "address", a.mailAddress(u.Name))
|
||||
return ""
|
||||
}
|
||||
return pw
|
||||
}
|
||||
|
||||
// readablePassword returns a 16-char password from an unambiguous alphabet (no
|
||||
// 0/O/1/l/I) — easy to read off a terminal once and type into webmail.
|
||||
func readablePassword() string {
|
||||
const alphabet = "abcdefghijkmnpqrstuvwxyzACDEFGHJKLMNPQRSTUVWXYZ23456789"
|
||||
var b [16]byte
|
||||
if _, err := rand.Read(b[:]); err != nil {
|
||||
// Fall back to a hex token; correctness over readability.
|
||||
var f [12]byte
|
||||
_, _ = rand.Read(f[:])
|
||||
return hex.EncodeToString(f[:])
|
||||
}
|
||||
for i := range b {
|
||||
b[i] = alphabet[int(b[i])%len(alphabet)]
|
||||
}
|
||||
return string(b[:])
|
||||
}
|
||||
|
||||
// mailClientFor builds an AgentMail client for a member, connecting to the
|
||||
// self-hosted Mailu backend. IMAP uses Dovecot master-user auth (login
|
||||
// "<addr>*<master>") so the BBS gateway can open any member's mailbox with one
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue