internal

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirDatabase = "db"
	DirStorage  = "data"
)
View Source
const MimeDrop = "DROP"

Variables

View Source
var (
	ErrLifetimeTooLong = errors.New("Lifetime is greater than maximum lifetime")

	ErrFileTooBig = errors.New("File size is greater than maxium filesize")
)
View Source
var ErrMimeDrop = errors.New("MIME must be dropped")
View Source
var (
	ErrNoMatch = errors.New("Input does not match pattern")
)
View Source
var ErrNotFound = errors.New("No Item found for this ID")

ErrNotFound is returned by the `Store.Get` method if there is no Item for the requested ID.

Functions

func NewOwnerTypes

func NewOwnerTypes(r *http.Request) (owners map[OwnerType]net.IP, err error)

NewOwnerTypes creates a map of OwnerTypes to IP addresses based on a Request.

func ParseBytesize

func ParseBytesize(s string) (size int64, err error)

ParseBytesize parses a positive, human readable and whole byte amount in the binary prefix notation. Legit values might be "1B", "23KiB"/"23KB" etc.

func ParseDuration

func ParseDuration(s string) (d time.Duration, err error)

ParseDuration parses a (positive) duration string, similar to the `time.ParseDuration` method. A duration string is sequence of decimal numbers and a unit suffix. Valid time units are "s", "m", "h", "d", "w", "mo", "y".

func PrettyBytesize

func PrettyBytesize(bs int64) string

PrettyBytesize returns a human readable representation of a byte size.

func PrettyDuration

func PrettyDuration(d time.Duration) string

PrettyDuration returns a human readable representation of a time.Duration.

func WebProtocol

func WebProtocol(r *http.Request) string

WebProtocol returns "http" or "https", based either on the X-Forwarded-Proto header or FastCGI's SERVER_PORT variable.

Types

type HardeningOpts added in v0.6.0

type HardeningOpts struct {
	// StoreDir is the path to the store; MUST be set.
	StoreDir *string
	// ListenTcpAddr is a listen address for a TCP socket; MIGHT be set.
	ListenTcpAddr *string
	// ListenUnixAddr is the path for a Unix domain socket; MIGHT be set.
	ListenUnixAddr *string
	// MimeMapFile is the path to an existing MimeMap file; MIGHT be set.
	MimeMapFile *string
	// ChangeUser is a system user which identity should be used; MIGHT be set.
	ChangeUser *string

	// ListenSocket is a file descriptor to a socket if either ListenTcpAddr or
	// ListenUnixAddr is set.
	ListenSocket *os.File
}

HardeningOpts are being altered by platform specific functions to allow establishing a state of least privilege.

The topper variables are treated as inputs and might get altered, e.g., after entering a chroot. The bottom variables are output variables, being populated by platform specific code.

Use the Apply method on a *HardeningOpts.

func (*HardeningOpts) Apply added in v0.6.0

func (opts *HardeningOpts) Apply()

Apply both Unix and Linux specific hardening.

type Item

type Item struct {
	ID string `badgerhold:"key"`

	DeletionKey string

	BurnAfterReading bool

	Filename    string
	ContentType string

	Created time.Time
	Expires time.Time `badgerholdIndex:"Expires"`

	Owner map[OwnerType]net.IP
}

Item describes an uploaded file.

func NewItem

func NewItem(r *http.Request, maxSize int64, maxLifetime time.Duration) (item Item, file io.ReadCloser, err error)

NewItem creates a new Item based on a Request. The ID will be left empty. Furthermore, if no error has occurred, a file is returned from which the file content should be read. This file must be closed afterwards.

func (Item) DeleteFile

func (i Item) DeleteFile(directory string) error

DeleteFile removes the file of an Item from the given directory.

func (Item) ReadFile

func (i Item) ReadFile(directory string) (io.ReadCloser, error)

ReadFile deserializes the file of an Item from the given directory into a ReadCloser.

func (Item) WriteFile

func (i Item) WriteFile(file io.ReadCloser, directory string) error

WriteFile serializes the file of an Item in the given directory. The file name will be the ID of the Item.

type MimeMap

type MimeMap map[string]string

MimeMap replaces predefined MIME types with others or requires them to be dropped.

# An example MimeMap could look like this, comment included:
text/html        text/plain
text/javascript  text/plain
text/mp4         DROP

func NewMimeMap

func NewMimeMap(file io.Reader) (mm MimeMap, err error)

NewMimeMap creates a new MimeMap based on the Reader's data.

func (MimeMap) MustDrop

func (mm MimeMap) MustDrop(mime string) bool

MustDrop indicates if a MIME type must be dropped.

func (MimeMap) Substitute

func (mm MimeMap) Substitute(mime string) (mimeOut string, err error)

Substitute returns the replaced MIME type and indicates with an error, if the input MIME type must be dropped.

type OwnerType

type OwnerType string

OwnerType describes a possible type of an owner, as an IP address. This can be the remote address as well as some header field.

const (
	RemoteAddr    OwnerType = "RemoteAddr"
	Forwarded     OwnerType = "Forwarded"
	XForwardedFor OwnerType = "X-Forwarded-For"
)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements an http.Handler for up- and download.

func NewServer

func NewServer(storeDirectory string, maxSize int64, maxLifetime time.Duration,
	contactMail string, mimeMap MimeMap) (s *Server, err error)

NewServer creates a new Server with a given database directory, and configuration values. The Server must be started as an http.Handler.

func (*Server) Close

func (serv *Server) Close() error

Close the Server and its components.

func (*Server) ServeHTTP

func (serv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store stores an index of all Items as well as the pure files.

func NewStore

func NewStore(baseDir string, backgroundCleanup bool) (s *Store, err error)

NewStore opens or initializes a Store in the given directory. A background task for continuous cleaning can be activated.

func (*Store) BadgerHold

func (s *Store) BadgerHold() *badgerhold.Store

BadgerHold returns a reference to the underlying BadgerHold instance.

func (*Store) Close

func (s *Store) Close() error

Close the Store and its database.

func (*Store) Delete

func (s *Store) Delete(i Item) (err error)

Delte an Item. Both the database entry and the file will be removed.

func (*Store) DeleteExpired

func (s *Store) DeleteExpired() error

DeleteExpired checks the Store for expired Items and deletes them.

func (*Store) Get

func (s *Store) Get(id string, delExpired bool) (i Item, err error)

Get an Item by its ID. The Item's file can be accessed with GetFile.

func (*Store) GetFile

func (s *Store) GetFile(i Item) (io.ReadCloser, error)

GetFile creates a ReadCloser to the Item's file.

func (*Store) Put

func (s *Store) Put(i Item, file io.ReadCloser) (id string, err error)

Put a new Item inside the Store. Both a database entry and a file will be created.

Jump to

Keyboard shortcuts

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