Documentation ¶
Overview ¶
Package auth determines and asserts client permissions to access and modify server resources.
Index ¶
- Constants
- Variables
- func AuthenticateCaptcha(req Captcha) bool
- func BcryptCompare(password string, hash []byte) error
- func BcryptHash(password string, rounds int) ([]byte, error)
- func CanPost(ip string) bool
- func ClearSpamCounters()
- func GetBannedLevels(board, ip string) (globally, locally bool)
- func GetIP(r *http.Request) (string, error)
- func GetNoscriptCaptcha(ip string) string
- func IncrementSpamScore(ip string, score time.Duration) (bool, error)
- func IsBanned(board, ip string) (banned bool)
- func IsBoard(board string) bool
- func IsNonMetaBoard(b string) bool
- func NewCaptchaID(w http.ResponseWriter, _ *http.Request)
- func RandomID(length int) (string, error)
- func ResetSpamScore(ip string)
- func ServeCaptcha(w http.ResponseWriter, r *http.Request)
- func SetBans(b ...Ban)
- type Ban
- type BanRecord
- type Captcha
- type ModLogEntry
- type ModerationAction
- type ModerationLevel
- type Report
- type SessionCreds
Constants ¶
const ( // Single character update CharScore = time.Minute / 350 // Post creation PostCreationScore = time.Second * 10 // Image insertion score ImageScore = time.Second * 20 )
Score values of various actions
Variables ¶
var ( // IsReverseProxied specifies, if the server is deployed behind a reverse // proxy. IsReverseProxied bool // ReverseProxyIP specifies the IP of a non-localhost reverse proxy. Used // for filtering in XFF IP determination. ReverseProxyIP string )
var ( // The poster is almost certainly spamming ErrSpamDected = errors.New("spam detected") )
Functions ¶
func AuthenticateCaptcha ¶
AuthenticateCaptcha posts a request to the SolveMedia API to authenticate a captcha
func BcryptCompare ¶
BcryptCompare compares a bcrypt hash with a user-supplied string
func BcryptHash ¶
BcryptHash generates a bcrypt hash from the passed string
func ClearSpamCounters ¶
func ClearSpamCounters()
Clear all spam detection data. Only use for tests.
func GetBannedLevels ¶
GetBannedLevels is like IsBanned, but returns, if the IP is banned globally or only from the specific board.
func GetNoscriptCaptcha ¶
GetNoscriptCaptcha returns a captcha id by IP. Use only for clients with scripts disabled.
func IncrementSpamScore ¶
Increment spam detection score to an IP, after performing an action. Returns, if the limit was exceeded.
func IsNonMetaBoard ¶
IsNonMetaBoard returns whether a valid board is a classic board and not some other path that emulates a board
func NewCaptchaID ¶
func NewCaptchaID(w http.ResponseWriter, _ *http.Request)
NewCaptchaID creates a new captcha and write its ID to the client
func ServeCaptcha ¶
func ServeCaptcha(w http.ResponseWriter, r *http.Request)
ServeCaptcha serves captcha images and audio
Types ¶
type Ban ¶
type Ban struct {
IP, Board string
}
Ban holdsan entry of an IP being banned from a board
type Captcha ¶
type Captcha struct {
CaptchaID, Solution string
}
Captcha contains the ID and solution of a captcha-protected request
type ModLogEntry ¶
type ModLogEntry struct { Type ModerationAction ID uint64 By string Created time.Time }
Single entry in the moderation log
type ModerationAction ¶
type ModerationAction uint8
An action performable by moderation staff
const ( BanPost ModerationAction = iota UnbanPost DeletePost DeleteImage SpoilerImage )
All supported moderation actions
type ModerationLevel ¶
type ModerationLevel int8
ModerationLevel defines the level required to perform an action
const ( NotLoggedIn ModerationLevel = iota - 1 NotStaff Janitor Moderator BoardOwner Admin )
All available moderation levels
func (*ModerationLevel) FromString ¶
func (l *ModerationLevel) FromString(s string)
Reads moderation level from string representation
func (ModerationLevel) String ¶
func (l ModerationLevel) String() string
Returns string representation of moderation level
type SessionCreds ¶
type SessionCreds struct {
UserID, Session string
}
SessionCreds is embed in every request that needs logged in authentication