1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-13 09:26:23 -07:00

Clean up some no longer used code

This commit is contained in:
Eggbertx 2024-08-25 17:30:18 -07:00
parent ec8ce785aa
commit 84c101e865
3 changed files with 6 additions and 174 deletions

View file

@ -170,97 +170,3 @@ func (ipb *IPBan) Deactivate(_ int) error {
}
return tx.Commit()
}
// NewNameBan is a wrapper around ApplyFilter for creating a name and/or tripcode ban.
// func NewNameBan(name string, nameIsRegex bool, tripcode string, tripcodeIsRegex bool, boardID int, staffID int, staffNote string) (*Filter, error) {
// const query = `INSERT INTO DBPREFIXusername_ban
// (board_id, staff_id, staff_note, username, is_regex)
// VALUES(?,?,?,?,?)`
// var ban UsernameBan
// if boardID > 0 {
// ban.BoardID = new(int)
// *ban.BoardID = boardID
// }
// tx, err := BeginTx()
// if err != nil {
// return nil, err
// }
// defer tx.Rollback()
// stmt, err := PrepareSQL(query, tx)
// if err != nil {
// return nil, err
// }
// defer stmt.Close()
// if _, err = stmt.Exec(ban.BoardID, staffID, staffNote, name, isRegex); err != nil {
// return nil, err
// }
// if ban.ID, err = getLatestID("DBPREFIXusername_ban", tx); err != nil {
// return nil, err
// }
// if err = tx.Commit(); err != nil {
// return nil, err
// }
// ban.StaffID = staffID
// ban.StaffNote = staffNote
// ban.Username = name
// ban.IsRegex = isRegex
// return &ban, stmt.Close()
// }
// func NewFilenameBan(filename string, isRegex bool, boardID int, staffID int, staffNote string) (*FilenameBan, error) {
// const query = `INSERT INTO DBPREFIXfilename_ban (board_id, staff_id, staff_note, filename, is_regex) VALUES(?,?,?,?,?)`
// var ban FilenameBan
// if boardID > 0 {
// ban.BoardID = new(int)
// *ban.BoardID = boardID
// }
// tx, err := BeginTx()
// if err != nil {
// return nil, err
// }
// defer tx.Rollback()
// stmt, err := PrepareSQL(query, tx)
// if err != nil {
// return nil, err
// }
// defer stmt.Close()
// if _, err = stmt.Exec(ban.BoardID, staffID, staffNote, filename, isRegex); err != nil {
// return nil, err
// }
// if ban.ID, err = getLatestID("DBPREFIXfilename_ban", tx); err != nil {
// return nil, err
// }
// if err = tx.Commit(); err != nil {
// return nil, err
// }
// ban.StaffID = staffID
// ban.StaffNote = staffNote
// ban.Filename = filename
// ban.IsRegex = isRegex
// return &ban, stmt.Close()
// }
// // CheckFileChecksumBan checks to see if the given checksum is banned on the given boardID, or on all boards.
// // It returns the ban info (or nil if it is not banned) and any errors
// func CheckFileChecksumBan(checksum string, boardID int) (*FileBan, error) {
// const query = `SELECT
// id, board_id, staff_id, staff_note, issued_at, checksum
// FROM DBPREFIXfile_ban
// WHERE checksum = ? AND (board_id IS NULL OR board_id = ?) ORDER BY id DESC LIMIT 1`
// var ban FileBan
// err := QueryRowSQL(query, []any{checksum, boardID}, []any{
// &ban.ID, &ban.BoardID, &ban.StaffID, &ban.StaffNote, &ban.IssuedAt, &ban.Checksum,
// })
// if err == sql.ErrNoRows {
// return nil, nil
// }
// if err != nil {
// return nil, err
// }
// return &ban, err
// }

View file

@ -53,54 +53,6 @@ type Board struct {
EnableCatalog bool // sql: enable_catalog
}
// // Deprecated, use PostFilter instead, with a condition field = "checksum" if Fingerprinter is nil
// // or "ahash" otherwise.
// // FileBan contains the information associated with a specific file ban.
// type FileBan struct {
// ID int // sql: id
// BoardID *int // sql: board_id
// StaffID int // sql: staff_id
// StaffNote string // sql: staff_note
// IssuedAt time.Time // sql: issued_at
// Checksum string // sql: checksum
// Fingerprinter *string // sql: fingerprinter
// BanIP bool // sql: ban_ip
// BanIPMessage *string // sql: ban_ip_message
// }
// // ApplyIPBan bans the given IP if it posted a banned image
// // If BanIP is false, it returns with no error
// func (fb *FileBan) ApplyIPBan(postIP string) error {
// if !fb.BanIP {
// return nil
// }
// now := time.Now()
// ipBan := &IPBan{
// RangeStart: postIP,
// RangeEnd: postIP,
// IssuedAt: now,
// }
// ipBan.IsActive = true
// ipBan.CanAppeal = true
// ipBan.AppealAt = now
// ipBan.StaffID = fb.StaffID
// ipBan.Permanent = true
// if fb.BoardID != nil {
// ipBan.BoardID = new(int)
// *ipBan.BoardID = *fb.BoardID
// }
// if fb.BanIPMessage == nil {
// ipBan.Message = "posting disallowed image, resulting in ban"
// } else {
// ipBan.Message = *fb.BanIPMessage
// }
// if fb.StaffNote == "" {
// ipBan.StaffNote = "fingerprint"
// }
// return NewIPBan(ipBan)
// }
// Filter represents an entry in gochan's new filter system which merges username bans, file bans, and filename bans,
// and will allow moderators to block posts based on the user's name, email, subject, message content, and other fields.
// table: DBPREFIXfilters

View file

@ -285,33 +285,9 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
return
}
// filters, err := gcsql.GetFiltersByBoardID(post.ID, true, gcsql.OnlyActiveFilters)
// if err != nil {
// errEv.Err(err).Caller().Msg("Unable to get filter list")
// server.ServeError(writer, "Unable to get post filter list", wantsJSON, nil)
// return
// }
// var match bool
// for _, filter := range filters {
// if match, err = filter.CheckIfMatch(post, request); err != nil {
// errEv.Err(err).Caller().
// Int("filterID", filter.ID).
// Msg("Unable to check filter for a match")
// server.ServeError(writer, "Unable to check post filters", wantsJSON, nil)
// return
// }
// if match {
// }
// }
if checkIpBan(post, postBoard, writer, request) {
return
}
// if checkUsernameBan(post, postBoard, writer, request) {
// return
// }
captchaSuccess, err := submitCaptchaResponse(request)
if err != nil {
@ -380,25 +356,23 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
return
}
if filter != nil && filter.MatchAction != "log" {
if filter.MatchAction != "ban" {
// if the filter bans the user, it will be logged
gcutil.LogWarning().
Str("ip", post.IP).
Str("userAgent", request.UserAgent()).
Int("filterID", filter.ID).
Msg("Post filtered")
}
os.Remove(filePath)
os.Remove(thumbPath)
os.Remove(catalogThumbPath)
switch filter.MatchAction {
case "reject":
gcutil.LogWarning().
Str("ip", post.IP).
Str("userAgent", request.UserAgent()).
Int("filterID", filter.ID).
Msg("Post rejected by filter")
rejectReason := filter.MatchDetail
if rejectReason == "" {
rejectReason = "Post rejected"
}
server.ServeError(writer, rejectReason, wantsJSON, nil)
case "ban":
// if the filter bans the user, it will be logged
checkIpBan(post, postBoard, writer, request)
}
return