server

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// characters used for short-urls
	SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

	// someone set us up the bomb !!
	BASE = int64(len(SYMBOLS))
)
View Source
const GDriveDirectoryMimeType = "application/vnd.google-apps.folder"
View Source
const GDriveRootConfigFile = "root_id.conf"
View Source
const GDriveTokenJsonFile = "token.json"
View Source
const SERVER_INFO = "transfer.sh"

Variables

This section is empty.

Functions

func Decode

func Decode(input string) int64

Decodes a string given in our encoding and returns the decimal integer.

func Encode

func Encode(number int64) string

encodes a number into our *base* representation TODO can this be made better with some bitshifting?

func IPFilterHandler added in v1.1.3

func IPFilterHandler(h http.Handler, ipFilterOptions *IPFilterOptions) http.HandlerFunc

func LoveHandler

func LoveHandler(h http.Handler) http.HandlerFunc

Create a log handler for every request it receives.

func RenderFloat

func RenderFloat(format string, n float64) string

func RenderInteger

func RenderInteger(format string, n int) string

func WrapIPFilter added in v1.1.3

func WrapIPFilter(next http.Handler, opts IPFilterOptions) http.Handler

WrapIPFilter is equivalent to NewIPFilter(opts) then Wrap(next)

Types

type GDrive

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

func NewGDriveStorage

func NewGDriveStorage(clientJsonFilepath string, localConfigPath string, basedir string, chunkSize int, logger *log.Logger) (*GDrive, error)

func (*GDrive) Delete

func (s *GDrive) Delete(token string, filename string) (err error)

func (*GDrive) Get

func (s *GDrive) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error)

func (*GDrive) Head

func (s *GDrive) Head(token string, filename string) (contentType string, contentLength uint64, err error)

func (*GDrive) IsNotExist

func (s *GDrive) IsNotExist(err error) bool

func (*GDrive) Put

func (s *GDrive) Put(token string, filename string, reader io.Reader, contentType string, contentLength uint64) error

func (*GDrive) Type

func (s *GDrive) Type() string

type IPFilter added in v1.1.3

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

func NewIPFilter added in v1.1.3

func NewIPFilter(opts IPFilterOptions) *IPFilter

New constructs IPFilter instance.

func (*IPFilter) AllowIP added in v1.1.3

func (f *IPFilter) AllowIP(ip string) bool

func (*IPFilter) Allowed added in v1.1.3

func (f *IPFilter) Allowed(ipstr string) bool

Allowed returns if a given IP can pass through the filter

func (*IPFilter) BlockIP added in v1.1.3

func (f *IPFilter) BlockIP(ip string) bool

func (*IPFilter) Blocked added in v1.1.3

func (f *IPFilter) Blocked(ip string) bool

Blocked returns if a given IP can NOT pass through the filter

func (*IPFilter) NetAllowed added in v1.1.3

func (f *IPFilter) NetAllowed(ip net.IP) bool

NetAllowed returns if a given net.IP can pass through the filter

func (*IPFilter) NetBlocked added in v1.1.3

func (f *IPFilter) NetBlocked(ip net.IP) bool

NetBlocked returns if a given net.IP can NOT pass through the filter

func (*IPFilter) ToggleDefault added in v1.1.3

func (f *IPFilter) ToggleDefault(allowed bool)

ToggleDefault alters the default setting

func (*IPFilter) ToggleIP added in v1.1.3

func (f *IPFilter) ToggleIP(str string, allowed bool) bool

func (*IPFilter) Wrap added in v1.1.3

func (f *IPFilter) Wrap(next http.Handler) http.Handler

WrapIPFilter the provided handler with simple IP blocking middleware using this IP filter and its configuration

type IPFilterOptions added in v1.1.3

type IPFilterOptions struct {
	//explicity allowed IPs
	AllowedIPs []string
	//explicity blocked IPs
	BlockedIPs []string
	//block by default (defaults to allow)
	BlockByDefault bool
	// TrustProxy enable check request IP from proxy
	TrustProxy bool

	Logger interface {
		Printf(format string, v ...interface{})
	}
}

IPFilterOptions for IPFilter. Allowed takes precendence over Blocked. IPs can be IPv4 or IPv6 and can optionally contain subnet masks (/24). Note however, determining if a given IP is included in a subnet requires a linear scan so is less performant than looking up single IPs.

This could be improved with some algorithmic magic.

type LocalStorage

type LocalStorage struct {
	Storage
	// contains filtered or unexported fields
}

func NewLocalStorage

func NewLocalStorage(basedir string, logger *log.Logger) (*LocalStorage, error)

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(token string, filename string) (err error)

func (*LocalStorage) Get

func (s *LocalStorage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error)

func (*LocalStorage) Head

func (s *LocalStorage) Head(token string, filename string) (contentType string, contentLength uint64, err error)

func (*LocalStorage) IsNotExist

func (s *LocalStorage) IsNotExist(err error) bool

func (*LocalStorage) Put

func (s *LocalStorage) Put(token string, filename string, reader io.Reader, contentType string, contentLength uint64) error

func (*LocalStorage) Type

func (s *LocalStorage) Type() string

type Metadata

type Metadata struct {
	// ContentType is the original uploading content type
	ContentType string
	// Secret as knowledge to delete file
	// Secret string
	// Downloads is the actual number of downloads
	Downloads int
	// MaxDownloads contains the maximum numbers of downloads
	MaxDownloads int
	// MaxDate contains the max age of the file
	MaxDate time.Time
	// DeletionToken contains the token to match against for deletion
	DeletionToken string
}

func MetadataForRequest

func MetadataForRequest(contentType string, r *http.Request) Metadata

type OptionFn

type OptionFn func(*Server)

func ClamavHost

func ClamavHost(s string) OptionFn

func EnableProfiler

func EnableProfiler() OptionFn

func FilterOptions added in v1.1.3

func FilterOptions(options IPFilterOptions) OptionFn

func ForceHTTPs

func ForceHTTPs() OptionFn

func GoogleAnalytics

func GoogleAnalytics(gaKey string) OptionFn

func HttpAuthCredentials

func HttpAuthCredentials(user string, pass string) OptionFn

func Listener

func Listener(s string) OptionFn

func LogFile

func LogFile(logger *log.Logger, s string) OptionFn

func Logger

func Logger(logger *log.Logger) OptionFn

func ProfileListener

func ProfileListener(s string) OptionFn

func ProxyPath added in v1.1.3

func ProxyPath(s string) OptionFn

func RateLimit

func RateLimit(requests int) OptionFn

func TLSConfig

func TLSConfig(cert, pk string) OptionFn

func TLSListener

func TLSListener(s string, t bool) OptionFn

func TempPath

func TempPath(s string) OptionFn

func UseLetsEncrypt

func UseLetsEncrypt(hosts []string) OptionFn

func UseStorage

func UseStorage(s Storage) OptionFn

func UserVoice

func UserVoice(userVoiceKey string) OptionFn

func VirustotalKey

func VirustotalKey(s string) OptionFn

func WebPath

func WebPath(s string) OptionFn

type S3Storage

type S3Storage struct {
	Storage
	// contains filtered or unexported fields
}

func NewS3Storage

func NewS3Storage(accessKey, secretKey, bucketName, region, endpoint string, logger *log.Logger, disableMultipart bool) (*S3Storage, error)

func (*S3Storage) Delete

func (s *S3Storage) Delete(token string, filename string) (err error)

func (*S3Storage) Get

func (s *S3Storage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error)

func (*S3Storage) Head

func (s *S3Storage) Head(token string, filename string) (contentType string, contentLength uint64, err error)

func (*S3Storage) IsNotExist

func (s *S3Storage) IsNotExist(err error) bool

func (*S3Storage) Put

func (s *S3Storage) Put(token string, filename string, reader io.Reader, contentType string, contentLength uint64) (err error)

func (*S3Storage) Type

func (s *S3Storage) Type() string

type Server

type Server struct {
	AuthUser string
	AuthPass string

	VirusTotalKey    string
	ClamAVDaemonHost string

	TLSListenerOnly bool

	ListenerString        string
	TLSListenerString     string
	ProfileListenerString string

	Certificate string

	LetsEncryptCache string
	// contains filtered or unexported fields
}

func New

func New(options ...OptionFn) (*Server, error)

func (*Server) BasicAuthHandler

func (s *Server) BasicAuthHandler(h http.Handler) http.HandlerFunc

func (*Server) CheckDeletionToken

func (s *Server) CheckDeletionToken(deletionToken, token, filename string) error

func (*Server) CheckMetadata

func (s *Server) CheckMetadata(token, filename string, increaseDownload bool) (Metadata, error)

func (*Server) Lock

func (s *Server) Lock(token, filename string) error

func (*Server) RedirectHandler

func (s *Server) RedirectHandler(h http.Handler) http.HandlerFunc

func (*Server) Run

func (s *Server) Run()

func (*Server) Unlock

func (s *Server) Unlock(token, filename string) error

type Storage

type Storage interface {
	Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error)
	Head(token string, filename string) (contentType string, contentLength uint64, err error)
	Put(token string, filename string, reader io.Reader, contentType string, contentLength uint64) error
	Delete(token string, filename string) error
	IsNotExist(err error) bool

	Type() string
}

Jump to

Keyboard shortcuts

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