Add DisablePostIP configuration setting.
This commit is contained in:
parent
aed409ae9e
commit
b39d90e4b6
|
@ -22,11 +22,12 @@ type DefaultIPSearcher struct {
|
|||
// NewDefaultIPSearcher gives you a new instance of DefaultIPSearcher
|
||||
func NewDefaultIPSearcher() (*DefaultIPSearcher, error) {
|
||||
acc := qgen.NewAcc()
|
||||
uu := "users"
|
||||
return &DefaultIPSearcher{
|
||||
searchUsers: acc.Select("users").Columns("uid").Where("last_ip=? OR last_ip LIKE CONCAT('%-',?)").Prepare(),
|
||||
searchTopics: acc.Select("users").Columns("uid").InQ("uid", acc.Select("topics").Columns("createdBy").Where("ipaddress=?")).Prepare(),
|
||||
searchReplies: acc.Select("users").Columns("uid").InQ("uid", acc.Select("replies").Columns("createdBy").Where("ipaddress=?")).Prepare(),
|
||||
searchUsersReplies: acc.Select("users").Columns("uid").InQ("uid", acc.Select("users_replies").Columns("createdBy").Where("ipaddress=?")).Prepare(),
|
||||
searchUsers: acc.Select(uu).Columns("uid").Where("last_ip=? OR last_ip LIKE CONCAT('%-',?)").Prepare(),
|
||||
searchTopics: acc.Select(uu).Columns("uid").InQ("uid", acc.Select("topics").Columns("createdBy").Where("ipaddress=?")).Prepare(),
|
||||
searchReplies: acc.Select(uu).Columns("uid").InQ("uid", acc.Select("replies").Columns("createdBy").Where("ipaddress=?")).Prepare(),
|
||||
searchUsersReplies: acc.Select(uu).Columns("uid").InQ("uid", acc.Select("users_replies").Columns("createdBy").Where("ipaddress=?")).Prepare(),
|
||||
}, acc.FirstError()
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ type PollStore interface {
|
|||
Get(id int) (*Poll, error)
|
||||
Exists(id int) bool
|
||||
Create(parent Pollable, pollType int, pollOptions map[int]string) (int, error)
|
||||
CastVote(optionIndex int, pollID int, uid int, ipaddress string) error
|
||||
CastVote(optionIndex int, pollID int, uid int, ip string) error
|
||||
Reload(id int) error
|
||||
//Count() int
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ var Prstore ProfileReplyStore
|
|||
|
||||
type ProfileReplyStore interface {
|
||||
Get(id int) (*ProfileReply, error)
|
||||
Create(profileID int, content string, createdBy int, ipaddress string) (id int, err error)
|
||||
Create(profileID int, content string, createdBy int, ip string) (id int, err error)
|
||||
Count() (count int)
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,11 @@ func (s *SQLProfileReplyStore) Get(id int) (*ProfileReply, error) {
|
|||
return &r, err
|
||||
}
|
||||
|
||||
func (s *SQLProfileReplyStore) Create(profileID int, content string, createdBy int, ipaddress string) (id int, err error) {
|
||||
res, err := s.create.Exec(profileID, content, ParseMessage(content, 0, "", nil), createdBy, ipaddress)
|
||||
func (s *SQLProfileReplyStore) Create(profileID int, content string, createdBy int, ip string) (id int, err error) {
|
||||
if Config.DisablePostIP {
|
||||
ip = "0"
|
||||
}
|
||||
res, err := s.create.Exec(profileID, content, ParseMessage(content, 0, "", nil), createdBy, ip)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package common
|
||||
|
||||
//import "log"
|
||||
import "database/sql"
|
||||
import "github.com/Azareal/Gosora/query_gen"
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
qgen "github.com/Azareal/Gosora/query_gen"
|
||||
)
|
||||
|
||||
var Rstore ReplyStore
|
||||
|
||||
|
@ -52,6 +55,9 @@ func (s *SQLReplyStore) Get(id int) (*Reply, error) {
|
|||
|
||||
// TODO: Write a test for this
|
||||
func (s *SQLReplyStore) Create(t *Topic, content string, ip string, uid int) (rid int, err error) {
|
||||
if Config.DisablePostIP {
|
||||
ip = "0"
|
||||
}
|
||||
res, err := s.create.Exec(t.ID, content, ParseMessage(content, t.ParentID, "forums", nil), ip, WordCount(content), uid)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -44,7 +44,11 @@ func (s *DefaultReportStore) Create(title string, content string, u *User, itemT
|
|||
return 0, ErrAlreadyReported
|
||||
}
|
||||
|
||||
res, err := s.create.Exec(title, content, ParseMessage(content, 0, "", nil), u.GetIP(), u.ID, u.ID, itemType+"_"+strconv.Itoa(itemID), ReportForumID)
|
||||
ip := u.GetIP()
|
||||
if Config.DisablePostIP {
|
||||
ip = "0"
|
||||
}
|
||||
res, err := s.create.Exec(title, content, ParseMessage(content, 0, "", nil), ip, u.ID, u.ID, itemType+"_"+strconv.Itoa(itemID), ReportForumID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -97,6 +97,7 @@ type config struct {
|
|||
LogPruneCutoff int
|
||||
|
||||
DisableLastIP bool
|
||||
DisablePostIP bool
|
||||
DisablePollIP bool
|
||||
|
||||
DisableLiveTopicList bool
|
||||
|
|
|
@ -382,6 +382,9 @@ func (t *Topic) SetPoll(pollID int) error {
|
|||
|
||||
// TODO: Have this go through the ReplyStore?
|
||||
func (t *Topic) CreateActionReply(action string, ip string, uid int) (err error) {
|
||||
if Config.DisablePostIP {
|
||||
ip = "0"
|
||||
}
|
||||
res, err := topicStmts.createAction.Exec(t.ID, action, ip, uid)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Azareal/Gosora/query_gen"
|
||||
qgen "github.com/Azareal/Gosora/query_gen"
|
||||
)
|
||||
|
||||
// TODO: Add the watchdog goroutine
|
||||
|
@ -60,7 +60,7 @@ func NewDefaultTopicStore(cache TopicCache) (*DefaultTopicStore, error) {
|
|||
return &DefaultTopicStore{
|
||||
cache: cache,
|
||||
get: acc.Select(t).Columns("title, content, createdBy, createdAt, lastReplyBy, lastReplyAt, lastReplyID, is_closed, sticky, parentID, ipaddress, views, postCount, likeCount, attachCount, poll, data").Where("tid = ?").Prepare(),
|
||||
exists: acc.Exists(t,"tid").Prepare(),
|
||||
exists: acc.Exists(t, "tid").Prepare(),
|
||||
count: acc.Count(t).Prepare(),
|
||||
create: acc.Insert(t).Columns("parentID, title, content, parsed_content, createdAt, lastReplyAt, lastReplyBy, ipaddress, words, createdBy").Fields("?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,?").Prepare(),
|
||||
}, acc.FirstError()
|
||||
|
@ -137,7 +137,7 @@ func (s *DefaultTopicStore) BulkGetMap(ids []int) (list map[int]*Topic, err erro
|
|||
|
||||
// TODO: Add a function for the qlist stuff
|
||||
var q string
|
||||
idList := make([]interface{},len(ids))
|
||||
idList := make([]interface{}, len(ids))
|
||||
for i, id := range ids {
|
||||
idList[i] = strconv.Itoa(id)
|
||||
q += "?,"
|
||||
|
@ -212,6 +212,9 @@ func (s *DefaultTopicStore) Create(fid int, name string, content string, uid int
|
|||
}
|
||||
|
||||
// TODO: Move this statement into the topic store
|
||||
if Config.DisablePostIP {
|
||||
ip = "0"
|
||||
}
|
||||
res, err := s.create.Exec(fid, name, content, parsedContent, uid, ip, WordCount(content), uid)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -92,6 +92,8 @@ PollIPCutoff - The number of days which need to pass before the IP data for a po
|
|||
|
||||
DisableLastIP - Disable storing last IPs for users and purge any existing user last IP data. Default: false
|
||||
|
||||
DisablePostIP - Disable storing post IPs for users and purge any existing post IP data. Default: false
|
||||
|
||||
DisablePollIP - Disable storing poll vote IPs and purge any existing poll vote IP data. Default: false
|
||||
|
||||
LogPruneCutoff - The number of days which need to pass before the login and registration logs are pruned. 0 defaults to whatever the current default is, currently 180 and -1 disables this feature.
|
||||
|
|
|
@ -479,7 +479,7 @@ func topicStoreTest(t *testing.T, newID int) {
|
|||
count := c.Topics.Count()
|
||||
expect(t, count == 1, fmt.Sprintf("Global count for topics should be 1, not %d", count))
|
||||
|
||||
//Create(fid int, topicName string, content string, uid int, ipaddress string) (tid int, err error)
|
||||
//Create(fid int, topicName string, content string, uid int, ip string) (tid int, err error)
|
||||
tid, err := c.Topics.Create(2, "Test Topic", "Topic Content", 1, "::1")
|
||||
expectNilErr(t, err)
|
||||
expect(t, tid == newID, fmt.Sprintf("TID for the new topic should be %d, not %d", newID, tid))
|
||||
|
|
12
tickloop.go
12
tickloop.go
|
@ -181,7 +181,17 @@ func dailies() {
|
|||
f("registration_logs")
|
||||
}
|
||||
|
||||
if c.Config.PostIPCutoff > -1 {
|
||||
if c.Config.DisablePostIP {
|
||||
f := func(tbl string) {
|
||||
_, err := qgen.NewAcc().Update(tbl).Set("ipaddress='0'").Where("ipaddress!='0'").Exec()
|
||||
if err != nil {
|
||||
c.LogError(err)
|
||||
}
|
||||
}
|
||||
f("topics")
|
||||
f("replies")
|
||||
f("users_replies")
|
||||
} else if c.Config.PostIPCutoff > -1 {
|
||||
// TODO: Use unixtime to remove this MySQLesque logic?
|
||||
f := func(tbl string) {
|
||||
_, err := qgen.NewAcc().Update(tbl).Set("ipaddress='0'").DateOlderThan("createdAt", c.Config.PostIPCutoff, "day").Where("ipaddress!='0'").Exec()
|
||||
|
|
Loading…
Reference in New Issue