diff --git a/common/ip_search.go b/common/ip_search.go index d65498a2..59bcf09e 100644 --- a/common/ip_search.go +++ b/common/ip_search.go @@ -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() } diff --git a/common/poll_store.go b/common/poll_store.go index 298ce835..c886f371 100644 --- a/common/poll_store.go +++ b/common/poll_store.go @@ -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 diff --git a/common/profile_reply_store.go b/common/profile_reply_store.go index a7d67212..b59a8cc0 100644 --- a/common/profile_reply_store.go +++ b/common/profile_reply_store.go @@ -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 } diff --git a/common/reply_store.go b/common/reply_store.go index 99305f12..34e022ad 100644 --- a/common/reply_store.go +++ b/common/reply_store.go @@ -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 @@ -20,7 +23,7 @@ type SQLReplyStore struct { get *sql.Stmt create *sql.Stmt - count *sql.Stmt + count *sql.Stmt } func NewSQLReplyStore(acc *qgen.Accumulator, cache ReplyCache) (*SQLReplyStore, error) { @@ -32,7 +35,7 @@ func NewSQLReplyStore(acc *qgen.Accumulator, cache ReplyCache) (*SQLReplyStore, cache: cache, get: acc.Select(re).Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress, likeCount, attachCount, actionType").Where("rid = ?").Prepare(), create: acc.Insert(re).Columns("tid, content, parsed_content, createdAt, lastUpdated, ipaddress, words, createdBy").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?").Prepare(), - count: acc.Count(re).Prepare(), + count: acc.Count(re).Prepare(), }, acc.FirstError() } @@ -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 diff --git a/common/report_store.go b/common/report_store.go index 03be7313..9da5139a 100644 --- a/common/report_store.go +++ b/common/report_store.go @@ -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 } diff --git a/common/site.go b/common/site.go index 102112e2..5a751864 100644 --- a/common/site.go +++ b/common/site.go @@ -97,6 +97,7 @@ type config struct { LogPruneCutoff int DisableLastIP bool + DisablePostIP bool DisablePollIP bool DisableLiveTopicList bool diff --git a/common/topic.go b/common/topic.go index af6608f4..ec45e348 100644 --- a/common/topic.go +++ b/common/topic.go @@ -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 diff --git a/common/topic_store.go b/common/topic_store.go index 845da1c6..20923276 100644 --- a/common/topic_store.go +++ b/common/topic_store.go @@ -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 @@ -44,10 +44,10 @@ type TopicStore interface { type DefaultTopicStore struct { cache TopicCache - get *sql.Stmt - exists *sql.Stmt - count *sql.Stmt - create *sql.Stmt + get *sql.Stmt + exists *sql.Stmt + count *sql.Stmt + create *sql.Stmt } // NewDefaultTopicStore gives you a new instance of DefaultTopicStore @@ -58,11 +58,11 @@ func NewDefaultTopicStore(cache TopicCache) (*DefaultTopicStore, error) { } t := "topics" 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(), - 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(), + 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(), + 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 += "?," @@ -210,8 +210,11 @@ func (s *DefaultTopicStore) Create(fid int, name string, content string, uid int if parsedContent == "" { return 0, ErrNoBody } - + // 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 @@ -251,4 +254,4 @@ func (s *DefaultTopicStore) GetCache() TopicCache { return nil } return s.cache -} \ No newline at end of file +} diff --git a/docs/configuration.md b/docs/configuration.md index b4619552..0d1e928f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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. diff --git a/misc_test.go b/misc_test.go index 3efc1c5d..82b264c5 100644 --- a/misc_test.go +++ b/misc_test.go @@ -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)) diff --git a/tickloop.go b/tickloop.go index 3e8c8464..821d9952 100644 --- a/tickloop.go +++ b/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()