auth

package
v4.4.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2017 License: AGPL-3.0, AGPL-3.0-or-later Imports: 12 Imported by: 0

Documentation

Overview

Package auth determines and asserts client permissions to access and modify server resources.

Index

Constants

View Source
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

View Source
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
)
View Source
var (
	// The poster is almost certainly spamming
	ErrSpamDected = errors.New("spam detected")
)

Functions

func AuthenticateCaptcha

func AuthenticateCaptcha(req Captcha) bool

AuthenticateCaptcha posts a request to the SolveMedia API to authenticate a captcha

func BcryptCompare

func BcryptCompare(password string, hash []byte) error

BcryptCompare compares a bcrypt hash with a user-supplied string

func BcryptHash

func BcryptHash(password string, rounds int) ([]byte, error)

BcryptHash generates a bcrypt hash from the passed string

func CanPost

func CanPost(ip string) bool

Returns, if the user does not trigger antispam

func ClearSpamCounters

func ClearSpamCounters()

Clear all spam detection data. Only use for tests.

func GetBannedLevels

func GetBannedLevels(board, ip string) (globally, locally bool)

GetBannedLevels is like IsBanned, but returns, if the IP is banned globally or only from the specific board.

func GetIP

func GetIP(r *http.Request) (string, error)

GetIP extracts the IP of a request, honouring reverse proxies, if set

func GetNoscriptCaptcha

func GetNoscriptCaptcha(ip string) string

GetNoscriptCaptcha returns a captcha id by IP. Use only for clients with scripts disabled.

func IncrementSpamScore

func IncrementSpamScore(ip string, score time.Duration) (bool, error)

Increment spam detection score to an IP, after performing an action. Returns, if the limit was exceeded.

func IsBanned

func IsBanned(board, ip string) (banned bool)

IsBanned returns if the IP is banned on the target board

func IsBoard

func IsBoard(board string) bool

IsBoard confirms the string is a valid board

func IsNonMetaBoard

func IsNonMetaBoard(b string) bool

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 RandomID

func RandomID(length int) (string, error)

RandomID generates a randomID of base64 characters of desired byte length

func ResetSpamScore

func ResetSpamScore(ip string)

Reset a spam score to zero by IP

func ServeCaptcha

func ServeCaptcha(w http.ResponseWriter, r *http.Request)

ServeCaptcha serves captcha images and audio

func SetBans

func SetBans(b ...Ban)

SetBans replaces the ban cache with the new set

Types

type Ban

type Ban struct {
	IP, Board string
}

Ban holdsan entry of an IP being banned from a board

type BanRecord

type BanRecord struct {
	Ban
	ForPost    uint64
	Reason, By string
	Expires    time.Time
}

BanRecord stores information about a specific ban

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 Report

type Report struct {
	ID, Target    uint64
	Created       time.Time
	Board, Reason string
}

Contains data of a reported post

type SessionCreds

type SessionCreds struct {
	UserID, Session string
}

SessionCreds is embed in every request that needs logged in authentication

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL