mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
Boards by directory with anonymous posts and images: thumbnails made in Go (JPEG, PNG, GIF, WebP, told by their bytes), JPEG metadata stripped, duplicates refused by MD5. Threads bump until a bump limit, sage, image limits, pruning off the last page, stickies and closed threads. Tripcodes are 2channel's (a DES crypt(3) of our own, checked against libc's) and secure ones; greentext, >>quotes with backlinks, cross-board links, spoilers and code. Index, thread pages, catalog, password deletion, reports; staff (sysops, a board's mods) delete, ban by address or range, and post with capcodes. Yotsuba, Yotsuba B, Futaba, Burichan, Photon and Tomorrow styles, and 4chan's read-only JSON. bbs chan board|ban on the command line; [chan] in bbs.conf. [http] trusted_proxies: requests from those take their caller's address from X-Forwarded-For (Forwarded, X-Real-IP), the last hop that is not a trusted proxy, for rate limits, logs, the deny lists and the image boards' bans; a proxy's connections are not held to max_per_ip. secure_cookies for TLS at the proxy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package imageboard
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/sha256"
|
|
"encoding/base64"
|
|
"strings"
|
|
|
|
"golang.org/x/text/encoding"
|
|
"golang.org/x/text/encoding/japanese"
|
|
)
|
|
|
|
// tripcode is a password's tripcode, as 2channel made them and every
|
|
// image board since: the password in Shift JIS, HTML-escaped, its salt
|
|
// its second and third characters, crypt(3)'s last ten.
|
|
func tripcode(pw string) string {
|
|
b, err := encoding.ReplaceUnsupported(japanese.ShiftJIS.NewEncoder()).Bytes([]byte(pw))
|
|
if err != nil {
|
|
b = []byte(pw)
|
|
}
|
|
b = []byte(strings.NewReplacer("&", "&", `"`, """, "<", "<", ">", ">").Replace(string(b)))
|
|
salt := []byte(string(b) + "H..")[1:3]
|
|
for i, c := range salt {
|
|
switch {
|
|
case c < '.' || c > 'z':
|
|
salt[i] = '.'
|
|
case strings.IndexByte(":;<=>?@[\\]^_`", c) >= 0:
|
|
salt[i] = "ABCDEFGabcdef"[strings.IndexByte(":;<=>?@[\\]^_`", c)]
|
|
}
|
|
}
|
|
c := desCrypt(b, string(salt))
|
|
return c[len(c)-10:]
|
|
}
|
|
|
|
// secureTrip is a secure tripcode: the password and the board's secret,
|
|
// so that it cannot be found by trying passwords elsewhere.
|
|
func secureTrip(pw string, secret []byte) string {
|
|
m := hmac.New(sha256.New, secret)
|
|
m.Write([]byte(pw))
|
|
return base64.StdEncoding.EncodeToString(m.Sum(nil))[:10]
|
|
}
|
|
|
|
// splitName splits what was typed as a name into the name and its
|
|
// tripcode: "Name#password" (!tripcode), "Name##password" (!!secure),
|
|
// "Name#password##secret" (both).
|
|
func splitName(typed string, secret []byte) (name, trip string) {
|
|
name, rest, ok := strings.Cut(typed, "#")
|
|
if !ok {
|
|
return strings.TrimSpace(typed), ""
|
|
}
|
|
pw, sec := rest, ""
|
|
if strings.HasPrefix(rest, "#") {
|
|
pw, sec = "", rest[1:]
|
|
} else if i := strings.Index(rest, "##"); i >= 0 {
|
|
pw, sec = rest[:i], rest[i+2:]
|
|
}
|
|
if pw != "" {
|
|
trip = "!" + tripcode(pw)
|
|
}
|
|
if sec != "" {
|
|
trip += "!!" + secureTrip(sec, secret)
|
|
}
|
|
return strings.TrimSpace(name), trip
|
|
}
|