You've already forked nyx
mirror of
https://github.com/rls-moe/nyx
synced 2025-08-19 06:18:38 +00:00
Improved stability, improved spam algorithm, fixed some bugs
This commit is contained in:
@@ -19,8 +19,19 @@ func (a *AdminPass) HashLogin(pass string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *AdminPass) VerifyLogin(pass string) error {
|
||||
var err error
|
||||
func (a *AdminPass) VerifyLogin(pass string) (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
var ok bool
|
||||
err, ok = r.(error)
|
||||
if !ok {
|
||||
err = fmt.Errorf("pkg: %v", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if a == nil {
|
||||
return errors.New("no login")
|
||||
}
|
||||
err = passlib.VerifyNoUpgrade(pass, a.Password)
|
||||
return err
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/tidwall/buntdb"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -19,6 +20,16 @@ const (
|
||||
adminPassPath = "/jack/./pass/admin/%s/admin-data"
|
||||
)
|
||||
|
||||
func GetHostnameFromKey(key string) (string, error) {
|
||||
regex := regexp.MustCompile(`^/jack/(.+)/(board|pass)`)
|
||||
res := regex.FindStringSubmatch(key)
|
||||
if len(res) != 3 {
|
||||
fmt.Printf("Found %d keys: %s", len(res), res)
|
||||
return "", errors.New("Could not find host in key")
|
||||
}
|
||||
return unescapeString(res[1]), nil
|
||||
}
|
||||
|
||||
func InitialSetup(db *buntdb.DB) error {
|
||||
return db.Update(func(tx *buntdb.Tx) error {
|
||||
if _, err := tx.Get(setup); err != nil {
|
||||
@@ -112,3 +123,17 @@ func escapeString(in string) string {
|
||||
in = strings.Replace(in, "<", ".arrow-right.", -1)
|
||||
return in
|
||||
}
|
||||
|
||||
func unescapeString(in string) string {
|
||||
in = strings.Replace(in, ".arrow-right.", "<", -1)
|
||||
in = strings.Replace(in, ".arrow-left.", ">", -1)
|
||||
in = strings.Replace(in, ".quote.", ">>", -1)
|
||||
in = strings.Replace(in, ".at.", "@", -1)
|
||||
in = strings.Replace(in, ".slash.", "/", -1)
|
||||
in = strings.Replace(in, ".ask.", "?", -1)
|
||||
in = strings.Replace(in, ".star.", "*", -1)
|
||||
in = strings.Replace(in, ".backslash.", "\\", -1)
|
||||
in = strings.Replace(in, ".minus.", "-", -1)
|
||||
in = strings.Replace(in, ".dot.", ".", -1)
|
||||
return in
|
||||
}
|
||||
|
@@ -2,9 +2,9 @@ package resources
|
||||
|
||||
import (
|
||||
"compress/flate"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"strings"
|
||||
@@ -34,6 +34,7 @@ var (
|
||||
"nazi",
|
||||
"beemovie",
|
||||
"bee movie",
|
||||
"honey",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -56,7 +57,13 @@ func SpamScore(spam string) (float64, error) {
|
||||
blScore += float64(strings.Count(spam, v))
|
||||
}
|
||||
|
||||
score := float64(len(spam)) / float64(counter.p)
|
||||
lines := strings.Count(spam, "\n")
|
||||
|
||||
if lines == 0 {
|
||||
lines = 1
|
||||
}
|
||||
|
||||
score := float64(len(spam)*lines) / float64(counter.p)
|
||||
|
||||
return (score * blScore) / 100, nil
|
||||
}
|
||||
@@ -70,15 +77,19 @@ func (b *byteCounter) Write(p []byte) (n int, err error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func CaptchaPass(spamScore float64) bool {
|
||||
chance := math.Max(
|
||||
func CaptchaProb(spamScore float64) float64 {
|
||||
return math.Max(
|
||||
passScoreLimitMin,
|
||||
math.Min(
|
||||
passScoreReactive*math.Atan(
|
||||
passScoreAggressive*spamScore,
|
||||
),
|
||||
passScoreLimitMax))
|
||||
}
|
||||
|
||||
func CaptchaPass(spamScore float64) bool {
|
||||
chance := CaptchaProb(spamScore)
|
||||
take := rand.Float64()
|
||||
fmt.Printf("Chance: %f, Take %f", chance, take)
|
||||
log.Printf("Chance: %f, Take %f\n", chance, take)
|
||||
return take > chance
|
||||
}
|
||||
|
@@ -91,6 +91,21 @@ func GetThread(tx *buntdb.Tx, host, board string, id int) (*Thread, error) {
|
||||
}
|
||||
|
||||
ret.intReply, err = GetReply(tx, host, board, id, ret.StartReply)
|
||||
if err != nil && err == buntdb.ErrNotFound {
|
||||
ret.intReply = &Reply{
|
||||
Board: ret.Board,
|
||||
Thread: ret.ID,
|
||||
ID: -1,
|
||||
Image: nil,
|
||||
Thumbnail: nil,
|
||||
Metadata: map[string]string{
|
||||
"deleted": "not found",
|
||||
},
|
||||
Text: "[not found]",
|
||||
}
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -132,7 +147,22 @@ func ListThreads(tx *buntdb.Tx, host, board string) ([]*Thread, error) {
|
||||
}
|
||||
thread.intReply, err = GetReply(tx, host, board, thread.ID, thread.StartReply)
|
||||
if err != nil {
|
||||
return false
|
||||
if err == buntdb.ErrNotFound {
|
||||
err = nil
|
||||
thread.intReply = &Reply{
|
||||
Board: thread.Board,
|
||||
Thread: thread.ID,
|
||||
ID: -1,
|
||||
Image: nil,
|
||||
Thumbnail: nil,
|
||||
Metadata: map[string]string{
|
||||
"deleted": "not found",
|
||||
},
|
||||
Text: "[not found]",
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
threadList = append(threadList, thread)
|
||||
|
Reference in New Issue
Block a user