mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 19:56:22 -07:00
Merge branch 'master' of https://github.com/eggbertx/gochan
This commit is contained in:
commit
05ccabd7af
3 changed files with 12 additions and 14 deletions
|
@ -179,11 +179,7 @@ func getRealIP(r *http.Request) (ip string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func validReferrer(request http.Request) (valid bool) {
|
func validReferrer(request http.Request) (valid bool) {
|
||||||
if request.Referer() == "" || request.Referer()[7:len(config.SiteDomain)+7] != config.SiteDomain {
|
valid = !(request.Referer() == "" || len(request.Referer()) < len(config.SiteDomain) || request.Referer()[7:len(config.SiteDomain)+7] != config.SiteDomain)
|
||||||
valid = false
|
|
||||||
} else {
|
|
||||||
valid = true
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
_ "github.com/ziutek/mymysql/godrv"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
_ "github.com/ziutek/mymysql/godrv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -88,7 +89,7 @@ func connectToSQLServer() {
|
||||||
}
|
}
|
||||||
// Detect that there are at least the number of tables that we are setting up.
|
// 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 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
|
// the initial setup has already been run
|
||||||
needs_initial_setup = false
|
needs_initial_setup = false
|
||||||
db_connected = true
|
db_connected = true
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
@ -15,6 +14,8 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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 {
|
author string, email string, postContent string) string {
|
||||||
if config.AkismetAPIKey != "" {
|
if config.AkismetAPIKey != "" {
|
||||||
client := &http.Client{}
|
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_type": {"forum-post"}, "comment_author": {author}, "comment_author_email": {email},
|
||||||
"comment_content": {postContent}}
|
"comment_content": {postContent}}
|
||||||
|
|
||||||
|
@ -364,7 +365,7 @@ func checkPostForSpam(userIp string, userAgent string, referrer string,
|
||||||
error_log.Print("Response from Akismet: " + string(body))
|
error_log.Print("Response from Akismet: " + string(body))
|
||||||
|
|
||||||
if string(body) == "true" {
|
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 "discard"
|
||||||
}
|
}
|
||||||
return "spam"
|
return "spam"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue