1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-03 15:46:23 -07:00
This commit is contained in:
Joshua Merrell 2016-09-16 00:34:57 -07:00
commit 05ccabd7af
3 changed files with 12 additions and 14 deletions

View file

@ -179,11 +179,7 @@ func getRealIP(r *http.Request) (ip string) {
}
func validReferrer(request http.Request) (valid bool) {
if request.Referer() == "" || request.Referer()[7:len(config.SiteDomain)+7] != config.SiteDomain {
valid = false
} else {
valid = true
}
valid = !(request.Referer() == "" || len(request.Referer()) < len(config.SiteDomain) || request.Referer()[7:len(config.SiteDomain)+7] != config.SiteDomain)
return
}

View file

@ -3,11 +3,12 @@ package main
import (
"bytes"
"database/sql"
_ "github.com/ziutek/mymysql/godrv"
"io"
"io/ioutil"
"os"
"strings"
_ "github.com/ziutek/mymysql/godrv"
)
const (
@ -88,7 +89,7 @@ func connectToSQLServer() {
}
// Detect that there are at least the number of tables that we are setting up.
// If there are fewer than that, then we either half-way set up, or there's other tables in our database.
if num_rows >= 17 {
if num_rows >= 16 {
// the initial setup has already been run
needs_initial_setup = false
db_connected = true

View file

@ -4,7 +4,6 @@ import (
"crypto/md5"
"crypto/sha1"
"fmt"
"golang.org/x/crypto/bcrypt"
"io"
"io/ioutil"
"math/rand"
@ -15,6 +14,8 @@ import (
"regexp"
"strings"
"time"
"golang.org/x/crypto/bcrypt"
)
var (
@ -334,11 +335,11 @@ func checkAkismetAPIKey() {
}
}
func checkPostForSpam(userIp string, userAgent string, referrer string,
func checkPostForSpam(userIP string, userAgent string, referrer string,
author string, email string, postContent string) string {
if config.AkismetAPIKey != "" {
client := &http.Client{}
data := url.Values{"blog": {"http://" + config.SiteDomain}, "user_ip": {userIp}, "user_agent": {userAgent}, "referrer": {referrer},
data := url.Values{"blog": {"http://" + config.SiteDomain}, "user_ip": {userIP}, "user_agent": {userAgent}, "referrer": {referrer},
"comment_type": {"forum-post"}, "comment_author": {author}, "comment_author_email": {email},
"comment_content": {postContent}}
@ -364,7 +365,7 @@ func checkPostForSpam(userIp string, userAgent string, referrer string,
error_log.Print("Response from Akismet: " + string(body))
if string(body) == "true" {
if pro_tip, ok := resp.Header["X-akismet-pro-tip"]; ok && pro_tip[0] == "discard" {
if proTip, ok := resp.Header["X-akismet-pro-tip"]; ok && proTip[0] == "discard" {
return "discard"
}
return "spam"