1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-02 10:56:25 -07:00

move getCountryCode() to util.go and remove now unnecessary geoip.go

This commit is contained in:
Joshua Merrell 2017-12-28 11:34:26 -08:00
parent 9aedc06232
commit 92a4ff638f
2 changed files with 27 additions and 29 deletions

View file

@ -1,16 +0,0 @@
package main
import (
"github.com/nranchev/go-libGeoIP"
)
func getCountryCode(ip string) (string, error) {
if config.EnableGeoIP && config.GeoIPDBlocation != "" {
gi, err := libgeo.Load(config.GeoIPDBlocation)
if err != nil {
return "", err
}
return gi.GetLocationByIP(ip).CountryCode, nil
}
return "", nil
}

View file

@ -4,6 +4,7 @@ import (
"crypto/md5" "crypto/md5"
"crypto/sha1" "crypto/sha1"
"fmt" "fmt"
"html"
"io" "io"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
@ -15,6 +16,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/nranchev/go-libGeoIP"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
@ -111,7 +113,7 @@ func getBoardArr(parameterList map[string]interface{}, extra string) (boards []B
} }
queryString += fmt.Sprintf(" %s ORDER BY `order`", extra) queryString += fmt.Sprintf(" %s ORDER BY `order`", extra)
printf(1, "queryString@getBoardArr: %s\n", queryString) printf(2, "queryString@getBoardArr: %s\n", queryString)
stmt, err := db.Prepare(queryString) stmt, err := db.Prepare(queryString)
defer func() { defer func() {
@ -188,7 +190,7 @@ func getPostArr(parameterList map[string]interface{}, extra string) (posts []int
} }
queryString += " " + extra // " ORDER BY `order`" queryString += " " + extra // " ORDER BY `order`"
printf(1, "queryString@getPostArr queryString: %s\n", queryString) printf(2, "queryString@getPostArr queryString: %s\n", queryString)
stmt, err := db.Prepare(queryString) stmt, err := db.Prepare(queryString)
defer func() { defer func() {
@ -262,6 +264,17 @@ func getCookie(name string) *http.Cookie {
return nil return nil
} }
func getCountryCode(ip string) (string, error) {
if config.EnableGeoIP && config.GeoIPDBlocation != "" {
gi, err := libgeo.Load(config.GeoIPDBlocation)
if err != nil {
return "", err
}
return gi.GetLocationByIP(ip).CountryCode, nil
}
return "", nil
}
func generateSalt() string { func generateSalt() string {
salt := make([]byte, 3) salt := make([]byte, 3)
salt[0] = chars[rand.Intn(86)] salt[0] = chars[rand.Intn(86)]
@ -290,15 +303,6 @@ func getFormattedFilesize(size float32) string {
return fmt.Sprintf("%0.2fGB", size/1024/1024/1024) return fmt.Sprintf("%0.2fGB", size/1024/1024/1024)
} }
func getSQLDateTime() string {
now := time.Now()
return now.Format(mysql_datetime_format)
}
func getSpecificSQLDateTime(t time.Time) string {
return t.Format(mysql_datetime_format)
}
func humanReadableTime(t time.Time) string { func humanReadableTime(t time.Time) string {
return t.Format(config.DateTimeFormat) return t.Format(config.DateTimeFormat)
} }
@ -363,6 +367,16 @@ func reverse(arr []interface{}) (reversed []interface{}) {
return return
} }
// sanitize/escape HTML strings in a post. This should be run immediately before
// the post is inserted into the database
func sanitizeHTML(post PostTable) PostTable {
sanitized := post
html.EscapeString(sanitized.Name)
html.EscapeString(sanitized.Email)
html.EscapeString(sanitized.Subject)
return sanitized
}
func searchStrings(item string, arr []string, permissive bool) int { func searchStrings(item string, arr []string, permissive bool) int {
for i, str := range arr { for i, str := range arr {
if item == str { if item == str {
@ -373,14 +387,14 @@ func searchStrings(item string, arr []string, permissive bool) int {
} }
func bToI(b bool) int { func bToI(b bool) int {
if b == true { if b {
return 1 return 1
} }
return 0 return 0
} }
func bToA(b bool) string { func bToA(b bool) string {
if b == true { if b {
return "1" return "1"
} }
return "0" return "0"