mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
Users have a level (0-255) and flags (A-Z). [level N] sections say what
a range of levels may do: time online a day (warned at 5 and 1 minutes,
hung up at the end; doors' limits cut to what is left), downloads a day
(counted by every way: the BBS, 3270, FTP, the API), and whether they
may post, mail (else only the sysop), chat, page, download, upload and
open doors.
Requirements ("30 F !X", "sysop") are put on message areas (reading and
posting), file areas (downloading and uploading), doors, menus and menu
items ("x = menu:extras Extras | 50 X"). They are checked in the core,
so the text BBS, 3270s, FTP, NNTP and the API keep them alike: an area a
user may not read is not listed, opened or found by number or
Message-ID.
New users start at new_user_level and are told they wait; the sysop
validates them on the BBS (V on the main menu), by bbs user
waiting/validate/level/flags, or by PATCH /api/v1/admin/users. Users
see their access in the profile and /api/v1/me; no one changes their
own. Drop files carry the caller's level.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/Neo-Desktop/bbs-sec/internal/bbs"
|
|
"github.com/Neo-Desktop/bbs-sec/internal/config"
|
|
)
|
|
|
|
// levelSections reads [level N] and [general]'s new_user_level and
|
|
// validated_level.
|
|
func (c *Config) levelSections(cf *config.File) error {
|
|
s := &c.Settings
|
|
g := cf.Get("general", "")
|
|
var err error
|
|
if s.NewUserLevel, err = g.Int("new_user_level", s.NewUserLevel, 0, bbs.MaxLevel); err != nil {
|
|
return fmt.Errorf("[general] %w", err)
|
|
}
|
|
if s.ValidatedLevel, err = g.Int("validated_level", max(s.ValidatedLevel, s.NewUserLevel), 0, bbs.MaxLevel); err != nil {
|
|
return fmt.Errorf("[general] %w", err)
|
|
}
|
|
if s.ValidatedLevel < s.NewUserLevel {
|
|
return fmt.Errorf("[general] validated_level (%d) is below new_user_level (%d)", s.ValidatedLevel, s.NewUserLevel)
|
|
}
|
|
seen := map[int]bool{}
|
|
for _, sec := range cf.All("level") {
|
|
l, err := level(sec)
|
|
if err != nil {
|
|
return fmt.Errorf("[level %s] %w", sec.Name, err)
|
|
}
|
|
if seen[l.Num] {
|
|
return fmt.Errorf("[level %s] given twice", sec.Name)
|
|
}
|
|
seen[l.Num] = true
|
|
s.Levels = append(s.Levels, l)
|
|
}
|
|
bbs.SortLevels(s.Levels)
|
|
if len(s.Levels) > 0 && s.Levels[0].Num > 0 {
|
|
c.Warnings = append(c.Warnings, fmt.Sprintf("levels under %d have no [level]: no limits", s.Levels[0].Num))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func level(sec *config.Section) (bbs.Level, error) {
|
|
n, err := strconv.Atoi(sec.Name)
|
|
if err != nil || n < 0 || n > bbs.MaxLevel {
|
|
return bbs.Level{}, fmt.Errorf("a level is a number, 0 to %d: [level 20]", bbs.MaxLevel)
|
|
}
|
|
l := bbs.AllowAll(n, sec.String("name", "Level "+sec.Name))
|
|
mins, err := sec.Int("time", 0, 0, 24*60)
|
|
if err != nil {
|
|
return l, err
|
|
}
|
|
l.Time = time.Duration(mins) * time.Minute
|
|
if l.Downloads, err = sec.Int("downloads", 0, 0, 100000); err != nil {
|
|
return l, err
|
|
}
|
|
for _, b := range []struct {
|
|
key string
|
|
p *bool
|
|
}{{"post", &l.Post}, {"mail", &l.Mail}, {"chat", &l.Chat}, {"page", &l.Page},
|
|
{"download", &l.Download}, {"upload", &l.Upload}, {"doors", &l.Doors}} {
|
|
if *b.p, err = sec.Bool(b.key, true); err != nil {
|
|
return l, err
|
|
}
|
|
}
|
|
return l, nil
|
|
}
|