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
|
// NewDefaultIPSearcher gives you a new instance of DefaultIPSearcher
|
||||||
func NewDefaultIPSearcher() (*DefaultIPSearcher, error) {
|
func NewDefaultIPSearcher() (*DefaultIPSearcher, error) {
|
||||||
acc := qgen.NewAcc()
|
acc := qgen.NewAcc()
|
||||||
|
uu := "users"
|
||||||
return &DefaultIPSearcher{
|
return &DefaultIPSearcher{
|
||||||
searchUsers: acc.Select("users").Columns("uid").Where("last_ip=? OR last_ip LIKE CONCAT('%-',?)").Prepare(),
|
searchUsers: acc.Select(uu).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(),
|
searchTopics: acc.Select(uu).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(),
|
searchReplies: acc.Select(uu).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(),
|
searchUsersReplies: acc.Select(uu).Columns("uid").InQ("uid", acc.Select("users_replies").Columns("createdBy").Where("ipaddress=?")).Prepare(),
|
||||||
}, acc.FirstError()
|
}, acc.FirstError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ type PollStore interface {
|
||||||
Get(id int) (*Poll, error)
|
Get(id int) (*Poll, error)
|
||||||
Exists(id int) bool
|
Exists(id int) bool
|
||||||
Create(parent Pollable, pollType int, pollOptions map[int]string) (int, error)
|
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
|
Reload(id int) error
|
||||||
//Count() int
|
//Count() int
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ var Prstore ProfileReplyStore
|
||||||
|
|
||||||
type ProfileReplyStore interface {
|
type ProfileReplyStore interface {
|
||||||
Get(id int) (*ProfileReply, error)
|
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)
|
Count() (count int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,11 @@ func (s *SQLProfileReplyStore) Get(id int) (*ProfileReply, error) {
|
||||||
return &r, err
|
return &r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SQLProfileReplyStore) Create(profileID int, content string, createdBy int, ipaddress string) (id int, err error) {
|
func (s *SQLProfileReplyStore) Create(profileID int, content string, createdBy int, ip string) (id int, err error) {
|
||||||
res, err := s.create.Exec(profileID, content, ParseMessage(content, 0, "", nil), createdBy, ipaddress)
|
if Config.DisablePostIP {
|
||||||
|
ip = "0"
|
||||||
|
}
|
||||||
|
res, err := s.create.Exec(profileID, content, ParseMessage(content, 0, "", nil), createdBy, ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
//import "log"
|
//import "log"
|
||||||
import "database/sql"
|
import (
|
||||||
import "github.com/Azareal/Gosora/query_gen"
|
"database/sql"
|
||||||
|
|
||||||
|
qgen "github.com/Azareal/Gosora/query_gen"
|
||||||
|
)
|
||||||
|
|
||||||
var Rstore ReplyStore
|
var Rstore ReplyStore
|
||||||
|
|
||||||
|
@ -52,6 +55,9 @@ func (s *SQLReplyStore) Get(id int) (*Reply, error) {
|
||||||
|
|
||||||
// TODO: Write a test for this
|
// TODO: Write a test for this
|
||||||
func (s *SQLReplyStore) Create(t *Topic, content string, ip string, uid int) (rid int, err error) {
|
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)
|
res, err := s.create.Exec(t.ID, content, ParseMessage(content, t.ParentID, "forums", nil), ip, WordCount(content), uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
|
@ -44,7 +44,11 @@ func (s *DefaultReportStore) Create(title string, content string, u *User, itemT
|
||||||
return 0, ErrAlreadyReported
|
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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ type config struct {
|
||||||
LogPruneCutoff int
|
LogPruneCutoff int
|
||||||
|
|
||||||
DisableLastIP bool
|
DisableLastIP bool
|
||||||
|
DisablePostIP bool
|
||||||
DisablePollIP bool
|
DisablePollIP bool
|
||||||
|
|
||||||
DisableLiveTopicList bool
|
DisableLiveTopicList bool
|
||||||
|
|
|
@ -382,6 +382,9 @@ func (t *Topic) SetPoll(pollID int) error {
|
||||||
|
|
||||||
// TODO: Have this go through the ReplyStore?
|
// TODO: Have this go through the ReplyStore?
|
||||||
func (t *Topic) CreateActionReply(action string, ip string, uid int) (err error) {
|
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)
|
res, err := topicStmts.createAction.Exec(t.ID, action, ip, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Azareal/Gosora/query_gen"
|
qgen "github.com/Azareal/Gosora/query_gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Add the watchdog goroutine
|
// TODO: Add the watchdog goroutine
|
||||||
|
@ -212,6 +212,9 @@ func (s *DefaultTopicStore) Create(fid int, name string, content string, uid int
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move this statement into the topic store
|
// 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)
|
res, err := s.create.Exec(fid, name, content, parsedContent, uid, ip, WordCount(content), uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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
|
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
|
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.
|
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()
|
count := c.Topics.Count()
|
||||||
expect(t, count == 1, fmt.Sprintf("Global count for topics should be 1, not %d", 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")
|
tid, err := c.Topics.Create(2, "Test Topic", "Topic Content", 1, "::1")
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expect(t, tid == newID, fmt.Sprintf("TID for the new topic should be %d, not %d", newID, tid))
|
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")
|
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?
|
// TODO: Use unixtime to remove this MySQLesque logic?
|
||||||
f := func(tbl string) {
|
f := func(tbl string) {
|
||||||
_, err := qgen.NewAcc().Update(tbl).Set("ipaddress='0'").DateOlderThan("createdAt", c.Config.PostIPCutoff, "day").Where("ipaddress!='0'").Exec()
|
_, err := qgen.NewAcc().Update(tbl).Set("ipaddress='0'").DateOlderThan("createdAt", c.Config.PostIPCutoff, "day").Where("ipaddress!='0'").Exec()
|
||||||
|
|
Loading…
Reference in New Issue