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 GetByteIP(r *http.Request) (net.IP, error)
- func GetIP(r *http.Request) (string, error)
- func GetLogIP(r *http.Request) (ip string)
- func GetNoscriptCaptcha(ip string) string
- func IncrementSpamScore(ip string, score time.Duration) (bool, error)
- func IsBanned(board, ip string) (banned 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 AccountSettings
- type Ban
- type BanRecord
- type BanRecords
- type Captcha
- type IgnoreMode
- type ModLogRecord
- type ModLogRecords
- type ModerationAction
- type ModerationLevel
- type Positions
- type Session
- type Staff
- type StaffRecord
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 NullPositions = Positions{CurBoard: NotLoggedIn, AnyBoard: NotLoggedIn} )
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 GetLogIP ¶
Get IP for logging, replace with placeholder on error. TODO(Kagami): Migrate boilerplate to use this helper.
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 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 AccountSettings ¶
type AccountSettings struct { Name string `json:"name,omitempty"` ShowName bool `json:"showName,omitempty"` IgnoreMode IgnoreMode `json:"ignoreMode,omitempty"` IncludeAnon bool `json:"includeAnon,omitempty"` Whitelist []string `json:"whitelist,omitempty"` Blacklist []string `json:"blacklist,omitempty"` }
type BanRecord ¶
type BanRecord struct { Ban ID uint64 `json:"id"` By string `json:"by"` Expires int64 `json:"expires"` Reason string `json:"reason"` }
BanRecord stores information about a specific ban
type BanRecords ¶
type BanRecords []BanRecord
func (*BanRecords) TryMarshal ¶
func (bans *BanRecords) TryMarshal() []byte
type Captcha ¶
type Captcha struct {
CaptchaID, Solution string
}
Captcha contains the ID and solution of a captcha-protected request
type IgnoreMode ¶
type IgnoreMode int
const ( IgnoreDisabled IgnoreMode = iota - 1 IgnoreByBlacklist IgnoreByWhitelist )
type ModLogRecord ¶
type ModLogRecord struct { Board string `json:"board"` ID uint64 `json:"id"` Type ModerationAction `json:"type"` By string `json:"by"` Created int64 `json:"created"` }
Single entry in the moderation log
type ModLogRecords ¶
type ModLogRecords []ModLogRecord
func (*ModLogRecords) TryMarshal ¶
func (log *ModLogRecords) TryMarshal() []byte
type ModerationAction ¶
type ModerationAction uint8
An action performable by moderation staff
const ( BanPost ModerationAction = iota UnbanPost DeletePost DeleteImage SpoilerImage DeleteThread UpdateBoard )
All supported moderation actions NOTE(Kagami): This is represented as number is DB, so add new items to the end, don't remove!
type ModerationLevel ¶
type ModerationLevel int8
ModerationLevel defines the level required to perform an action
const ( NotLoggedIn ModerationLevel = iota - 1 NotStaff Blacklisted Whitelisted 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 Positions ¶
type Positions struct { CurBoard ModerationLevel `json:"curBoard"` AnyBoard ModerationLevel `json:"anyBoard"` }
func (Positions) IsPowerUser ¶
type Session ¶
type Session struct { UserID string `json:"userID"` Positions Positions `json:"positions"` Settings AccountSettings `json:"settings"` }
Contains user data and settings of the request's session.
func (*Session) GetPositions ¶
func (*Session) GetSettings ¶
func (ss *Session) GetSettings() AccountSettings
func (*Session) TryMarshal ¶
type StaffRecord ¶
type StaffRecord struct { Board string `json:"board"` UserID string `json:"userID"` Position ModerationLevel `json:"position"` }