aboutsummaryrefslogtreecommitdiff
path: root/tripcode.go
diff options
context:
space:
mode:
authorFChannel <>2022-04-30 22:17:32 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit503a6637b8294aeb8e5e5546f8acbd2b3d6c4744 (patch)
tree56614d955df0d3e7284baa997bbf1a8dcc2e78f5 /tripcode.go
parent1892327cee2c3fa1d3bea729bd08eb63c2189a96 (diff)
first steps in posting connected. can make reply with no quote or quote OP
do not recommend working on this branch for the time being since things are being moved around a lot
Diffstat (limited to 'tripcode.go')
-rw-r--r--tripcode.go116
1 files changed, 0 insertions, 116 deletions
diff --git a/tripcode.go b/tripcode.go
deleted file mode 100644
index 44651bb..0000000
--- a/tripcode.go
+++ /dev/null
@@ -1,116 +0,0 @@
-package main
-
-import (
- "bytes"
- "net/http"
- "regexp"
- "strings"
-
- "github.com/FChannel0/FChannel-Server/config"
- _ "github.com/lib/pq"
- "github.com/simia-tech/crypt"
- "golang.org/x/text/encoding/japanese"
- "golang.org/x/text/transform"
-)
-
-const SaltTable = "" +
- "................................" +
- ".............../0123456789ABCDEF" +
- "GABCDEFGHIJKLMNOPQRSTUVWXYZabcde" +
- "fabcdefghijklmnopqrstuvwxyz....." +
- "................................" +
- "................................" +
- "................................" +
- "................................"
-
-func TripCode(pass string) (string, error) {
- pass = TripCodeConvert(pass)
-
- var salt [2]rune
-
- s := []rune(pass + "H..")[1:3]
-
- for i, r := range s {
- salt[i] = rune(SaltTable[r%256])
- }
-
- enc, err := crypt.Crypt(pass, "$1$"+string(salt[:]))
- if err != nil {
- return "", err
- }
-
- // normally i would just return error here but if the encrypt fails, this operation may fail and as a result cause a panic
- return enc[len(enc)-10 : len(enc)], nil
-}
-
-func TripCodeSecure(pass string) (string, error) {
- pass = TripCodeConvert(pass)
-
- enc, err := crypt.Crypt(pass, "$1$"+config.Salt)
- if err != nil {
- return "", err
- }
-
- return enc[len(enc)-10 : len(enc)], nil
-}
-
-func TripCodeConvert(str string) string {
- var s bytes.Buffer
-
- transform.NewWriter(&s, japanese.ShiftJIS.NewEncoder()).Write([]byte(str))
-
- re := strings.NewReplacer(
- "&", "&amp;",
- "\"", "&quot;",
- "<", "&lt;",
- ">", "&gt;",
- )
-
- return re.Replace(s.String())
-}
-
-func CreateNameTripCode(r *http.Request) (string, string, error) {
- // TODO: to allow this to compile, this will fail for the case of the admin
- // this can be easily fixed when the rest of the code gets converted to fiber
-
- input := r.FormValue("name")
-
- tripSecure := regexp.MustCompile("##(.+)?")
-
- if tripSecure.MatchString(input) {
- chunck := tripSecure.FindString(input)
- chunck = strings.Replace(chunck, "##", "", 1)
-
- //ce := regexp.MustCompile(`(?i)Admin`)
- //admin := ce.MatchString(chunck)
-
- //board, modcred := GetPasswordFromSession(r)
-
- //if admin && HasAuth(modcred, board) {
- // return tripSecure.ReplaceAllString(input, ""), "#Admin"
- //}
-
- hash, err := TripCodeSecure(chunck)
- return tripSecure.ReplaceAllString(input, ""), "!!" + hash, err
- }
-
- trip := regexp.MustCompile("#(.+)?")
-
- if trip.MatchString(input) {
- chunck := trip.FindString(input)
- chunck = strings.Replace(chunck, "#", "", 1)
-
- //ce := regexp.MustCompile(`(?i)Admin`)
- //admin := ce.MatchString(chunck)
- //board, modcred := GetPasswordFromSession(r)
-
- //if admin && HasAuth(db, modcred, board) {
- // return trip.ReplaceAllString(input, ""), "#Admin"
- //}
-
- hash, err := TripCode(chunck)
- return trip.ReplaceAllString(input, ""), "!" + hash, err
- }
-
- return input, "", nil
-}