diff options
author | Amelia <47868520+knotteye@users.noreply.github.com> | 2021-07-02 01:31:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-02 01:31:19 +0000 |
commit | 9180db359438a4d2833c2e094ebc870da37262ef (patch) | |
tree | 14d00b65657e1f26bd562351c154b103c1c8d232 /tripcode.go | |
parent | 168225daa21fe494bcd74ab6c90d6498ecf9f1e3 (diff) | |
parent | a122d62f78e5f1fd66efc28994809d720a2841ab (diff) |
Merge branch 'FChannel0:master' into master
Diffstat (limited to 'tripcode.go')
-rw-r--r-- | tripcode.go | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/tripcode.go b/tripcode.go new file mode 100644 index 0000000..7e19cf0 --- /dev/null +++ b/tripcode.go @@ -0,0 +1,111 @@ +package main + +import ( + "golang.org/x/text/encoding/japanese" + "golang.org/x/text/transform" + "github.com/simia-tech/crypt" + "strings" + "bytes" + "regexp" + "database/sql" + _ "github.com/lib/pq" + "net/http" +) + +const SaltTable = "" + + "................................" + + ".............../0123456789ABCDEF" + + "GABCDEFGHIJKLMNOPQRSTUVWXYZabcde" + + "fabcdefghijklmnopqrstuvwxyz....." + + "................................" + + "................................" + + "................................" + + "................................" + + +func TripCode(pass string) string { + + 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[:])) + + CheckError(err, "crypt broke") + + return enc[len(enc) - 10 : len(enc)] +} + +func TripCodeSecure(pass string) string { + + pass = TripCodeConvert(pass) + + enc, err := crypt.Crypt(pass, "$1$" + Salt) + + CheckError(err, "crypt secure broke") + + return enc[len(enc) - 10 : len(enc)] +} + +func TripCodeConvert(str string) string { + + var s bytes.Buffer + transform.NewWriter(&s, japanese.ShiftJIS.NewEncoder()).Write([]byte(str)) + + re := strings.NewReplacer( + "&", "&", + "\"", """, + "<", "<", + ">", ">", + ) + + return re.Replace(s.String()) +} + +func CreateNameTripCode(r *http.Request, db *sql.DB) (string, string) { + 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(db, modcred, board)) { + return tripSecure.ReplaceAllString(input, ""), "#Admin" + } + + hash := TripCodeSecure(chunck) + return tripSecure.ReplaceAllString(input, ""), "!!" + hash + } + + 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 := TripCode(chunck) + return trip.ReplaceAllString(input, ""), "!" + hash + } + + return input, "" +} |