shimmie

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: BSD-3-Clause Imports: 10 Imported by: 3

README

shimmie

A package with operations that can be performed on a Shimmie2 deployment.

The purpose of the package is to hold Shimmie related code so that it can be used by other projects.

It is assuming Shimmie v2.5.1 authentication system and database schema with MySQL driver.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongCredentials = errors.New("wrong username or password")
	ErrNotFound         = errors.New("entry not found")
)

Errors returned by Verify.

Functions

func CookieValue

func CookieValue(passwordHash, userIP string) string

CookieValue recreates the Shimmie session cookie value based on the user password hash and the user IP.

Shimmie creates a cookie "shm_session" containing an md5 digest value of the user password hash concatenated with the user IP masked with the 255.255.0.0 mask. That's essentially:

md5(password_hash + masked_ip)

func GetOriginalIP

func GetOriginalIP(r *http.Request) string

GetOriginalIP gets the original IP of the HTTP for the case of being behind a proxy. It searches for the X-Forwarded-For header.

func Hash

func Hash(s string) string

Hash returns the MD5 checksum of a string s as type string.

func ImageRating

func ImageRating(rating string) string

ImageRating converts rating letters to full words.

s -> Safe
q -> Questionable
e -> Explicit

If another value except (s, q, e) is given, then it returns that value as it is.

func NewContextWithUser

func NewContextWithUser(ctx context.Context, user *User) context.Context

NewContextWithUser adds user to context.

func PasswordHash

func PasswordHash(username, password string) string

PasswordHash returns the password hash of a username and password the same way that shimmie2 does it.

func SetCookie

func SetCookie(w http.ResponseWriter, name, value string)

SetCookie creates a cookie on path "/" with 1 year expiration and other flags set to false mimicking the cookies that Shimmie creates.

Types

type Alias

type Alias struct {
	OldTag string
	NewTag string
}

Alias is an alias of an old tag to a new tag.

type Autocomplete

type Autocomplete struct {
	Old   string `json:"old"`
	Name  string `json:"name"`
	Count int    `json:"count"`
}

Autocomplete is the result of searching into tags and tag alias to give autocomplete suggestions.

type Common

type Common struct {
	Title       string
	AnalyticsID string
	Description string
	Keywords    string
}

Common holds common configuration values.

func (Common) SiteTitle

func (c Common) SiteTitle() string

SiteTitle returns the Title capitalized.

type ContributedTagHistory

type ContributedTagHistory struct {
	ID         int
	ImageID    int
	OwnerID    int
	OwnerName  string
	TaggerID   int
	TaggerName string
	TaggerIP   string
	Tags       string
	DateSet    *time.Time
}

ContributedTagHistory holds previous tags for an image that were set by contributors.

type Image

type Image struct {
	ID           int64
	OwnerID      int64
	OwnerIP      string
	Filename     string
	Filesize     int
	Hash         string
	Ext          string
	Source       string
	Width        int
	Height       int
	Posted       *time.Time
	Locked       string
	NumericScore int
	Rating       string
	Favorites    int
	ParentID     int64
	HasChildren  bool
	Author       string
	Notes        int
}

Image represents a shimmie image.

type PM added in v0.2.0

type PM struct {
	FromUser string    `json:"from_user"`
	ToUser   string    `json:"to_user"`
	ID       int64     `json:"id"`
	FromID   int64     `json:"from_id"`
	FromIP   string    `json:"from_ip"`
	ToID     int64     `json:"to_id"`
	SentDate time.Time `json:"sent_date"`
	Subject  string    `json:"subject"`
	Message  string    `json:"message"`
	IsRead   bool      `json:"is_read"`
}

PM is a private message exchanged between users.

type PMChoice added in v0.2.0

type PMChoice int

PMChoice allows to choose between read and unread private messages.

const (
	PMAny PMChoice = iota
	PMRead
	PMUnread
)

Possible private message choices.

type RatedImage

type RatedImage struct {
	Image
	Rater    string
	RaterIP  string
	RateDate *time.Time
}

RatedImage represents a shimmie image that also carries information about who rated it and when.

func (RatedImage) RateDateFormat

func (ri RatedImage) RateDateFormat() string

RateDateFormat returns the RateDate as UTC with Mon 02 Jan 2006 15:04:05 MST format.

type SCoreLog

type SCoreLog struct {
	ID       int64
	DateSent *time.Time
	Section  string
	Username string
	Address  string
	Priority int
	Message  string
}

SCoreLog represents a log message in the shimmie log that is stored in the table "score_log".

type Schemer

type Schemer interface {
	Create(dbName string) error
	Drop(dbName string) error
	Close() error
}

Schemer describes operations that can be done on the database schema. Those operations include creating and dropping the schema for a specific database name.

type Shimmie

type Shimmie struct {
	ImagePath string
	ThumbPath string
	User      UserGetter
}

Shimmie represents an installed shimmie2 project.

func (*Shimmie) Auth

func (shim *Shimmie) Auth(h http.Handler, redirectURL string) http.Handler

Auth is a handler wrapper that checks if a user is authenticated to Shimmie. It checks for two cookies "shm_user" and "shm_session". The first contains the username which is used to query the database and the get user's password hash. Then it attempts to recreate the "shm_session" cookie value by using the username, user IP and password hash. If the recreated value does not match the "shm_session" cookie value then it redirects to redirectPath. If redirectURL is empty then "/user_admin/login" is used instead which is the default login URL for Shimmie.

func (*Shimmie) AuthFunc

func (shim *Shimmie) AuthFunc(fn http.HandlerFunc, redirectURL string) http.Handler

type Tag

type Tag struct {
	ID    int
	Tag   string
	Count int
}

Tag is an image's tag.

type TagHistory

type TagHistory struct {
	ID      int64
	ImageID int64
	UserID  int64
	UserIP  string
	Tags    string
	DateSet *time.Time
	// Name of the user who did the edit.
	Name string
}

TagHistory holds previous tags for an image.

type User

type User struct {
	ID       int64
	Name     string
	Pass     string
	JoinDate *time.Time
	Admin    string
	Email    string
	Class    string
}

User represents a shimmie user.

func FromContextGetUser

func FromContextGetUser(ctx context.Context) (*User, bool)

FromContextGetUser gets User from context. If User does not exist in context, nil and false are returned instead.

type UserGetter added in v0.4.0

type UserGetter interface {
	GetUserByName(username string) (*User, error)
}

UserGetter represents a type that can get users from the db.

type UserScore added in v0.3.0

type UserScore struct {
	Score    int        `json:"score"`
	ID       int64      `json:"id"`
	Name     string     `json:"name"`
	JoinDate *time.Time `json:"join_date"`
	Email    string     `json:"email"`
	Class    string     `json:"class"`
}

UserScore can be used to hold user scores like who has uploaded the most images and who has edited the most tags.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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