magicgate

package module
v0.0.0-...-00f1f04 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: MIT Imports: 17 Imported by: 0

README

magicgate

A multiple function gateway include http/https/dns server

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HTTPContentType is HTTP Content-Type header key
	HTTPContentType = []byte("Content-Type")

	// ApplicationJSON is HTTP Content-Type header value
	ApplicationJSON = []byte("application/json")
)

Functions

func NewAliasHandler

func NewAliasHandler(pathMap string, docRoot string, vhost, generateIndexPages, compress, byteRange bool, pathNotFound fasthttp.RequestHandler) fasthttp.RequestHandler

NewAliasHandler return a RequestHandler which will handle file access

Types

type BackendList

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

BackendList for reverse proxy <*|*.example.com|example.com>@10.0.0.2:9080:tls/be1.example.com:9080^iphash, target@backendlist^load‑balancing methods,[more target section], tls mark in backend list means connect to backend by tls

func NewBackendList

func NewBackendList() *BackendList

NewBackendList return an initialed *backendList

func NewBackendListFromArgs

func NewBackendListFromArgs(backendArgs string) *BackendList

NewBackendListFromArgs parse input args and return *backendList

func (*BackendList) AddBackendArgs

func (be *BackendList) AddBackendArgs(backendArgs string) error

AddBackendArgs add more backend to backendList

type DataCache

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

DataCache implements internal data/cache management

func LoadDataCache

func LoadDataCache(cacheDir string, createOnFatal bool, size int) (dc *DataCache, err error)

LoadDataCache load DataCache from saved fastcache dir, or create new on fatal. size counted in bytes.

func (*DataCache) DataCacheGetKVHandler

func (dc *DataCache) DataCacheGetKVHandler() fasthttp.RequestHandler

DataCacheGetKVHandler return a fasthttp.RequestHandler which can update dataCache by token/key/value, tlsRouter.GET("/api/db/set/:token/:key/:value", dc.DataCacheGetKVHandler())

func (*DataCache) DataCacheJSONHandler

func (dc *DataCache) DataCacheJSONHandler() fasthttp.RequestHandler

DataCacheJSONHandler return a fasthttp.RequestHandler which can update dataCache by token/key/JSON

func (*DataCache) DataCacheListKVHandler

func (dc *DataCache) DataCacheListKVHandler() fasthttp.RequestHandler

DataCacheListKVHandler return a fasthttp.RequestHandler which can list dataCache by token/key in JSON text, tlsRouter.GET("/api/db/list/:token/:key", dc.DataCacheListKVHandler())

func (*DataCache) DataCacheSetKVHandler

func (dc *DataCache) DataCacheSetKVHandler() fasthttp.RequestHandler

DataCacheSetKVHandler return a fasthttp.RequestHandler which can update dataCache by token/key/value, tlsRouter.GET("/api/db/set/:token/:key/:value", dc.DataCacheSetKVHandler())

func (*DataCache) DataCacheSetProxyHandler

func (dc *DataCache) DataCacheSetProxyHandler() fasthttp.RequestHandler

DataCacheSetProxyHandler return a fasthttp.RequestHandler which can update proxy setting by token/key/value, tlsRouter.GET("/api/db/setproxy/:token/:key/:value", dc.DataCacheSetKVHandler())

func (*DataCache) GetUIDByToken

func (dc *DataCache) GetUIDByToken(tk string) (uid uint64, ok bool)

GetUIDByToken get uid from tokens, return ok == true when hit

func (*DataCache) GetValue

func (dc *DataCache) GetValue(uid uint64, key string) (value string, ok bool)

GetValue get value from tokens by uid, key, return ok == true when hit

func (*DataCache) JSONContentHandler

func (dc *DataCache) JSONContentHandler() fasthttp.RequestHandler

JSONContentHandler return a fasthttp.RequestHandler which show current contents to client in JSON

func (*DataCache) MergeTokens

func (dc *DataCache) MergeTokens(tokens map[string]uint64, overwrite bool) (replaced map[string]uint64)

MergeTokens DataCache with input token list, duplicated tokens will be ignored if overwrite flag is false. return replaced tokens

func (*DataCache) ProxyAuthHandler

func (dc *DataCache) ProxyAuthHandler() multiproxy.ProxyAuthHandler

ProxyAuthHandler return a fasthttp.RequestHandler which can update proxy setting by token/key/value, tlsRouter.GET("/api/db/setproxy/:token/:key/:value", dc.DataCacheSetKVHandler())

func (*DataCache) SaveToDir

func (dc *DataCache) SaveToDir(cacheDir string) (err error)

SaveToDir flush current DataCache data into disk cacheDir, if cacheDir is empty, will save to the dir which used on loading.

func (*DataCache) SetKeyValue

func (dc *DataCache) SetKeyValue(uid uint64, key, value string)

SetKeyValue set uid,key,value into contents

func (*DataCache) SetToken

func (dc *DataCache) SetToken(tk string, uid uint64)

SetToken set token:uid into tokens

type HostStat

type HostStat struct {
}

HostStat record stat of a backend host

type PathMapEntry

type PathMapEntry struct {
	Domain   string
	URL      []byte
	Path     []byte
	OrigPath []byte
	FS       *fasthttp.FS
}

PathMapEntry record a path to URL mapping

type ServerImp

type ServerImp struct {
	LastURI string
	Counter int64

	CtrlToken []byte

	NormalHostSwitch   map[string]fasthttp.RequestHandler
	WildcardHostSwitch map[string]fasthttp.RequestHandler

	Domains           []string
	WildcardDomains   []string
	DefaultServerName string
	TrimList          [][]byte
	Backends          *BackendList
	// contains filtered or unexported fields
}

ServerImp redirect HTTP requests to HTTPS

func (*ServerImp) DomainACL

func (h *ServerImp) DomainACL(name string) error

DomainACL do ACL on access host

func (*ServerImp) DomainACLNoIP

func (h *ServerImp) DomainACLNoIP(name string) error

DomainACLNoIP do ACL on access host, IP not allowed

func (*ServerImp) FastHTTPChallengeHandler

func (h *ServerImp) FastHTTPChallengeHandler(am *certmagic.ACMEManager, next fasthttp.RequestHandler) fasthttp.RequestHandler

FastHTTPChallengeHandler return a fasthttp.RequestHandler which use for handle ACME HTTP challenge, only requests to "/.well-known/acme-challenge/" should be route to this handler.

func (*ServerImp) MagicServerImp

func (h *ServerImp) MagicServerImp(redirect, next fasthttp.RequestHandler) fasthttp.RequestHandler

MagicServerImp return a fasthttp.RequestHandler which call redirect handler and return on redirected, otherwise call next

func (*ServerImp) MatchHostHandler

func (h *ServerImp) MatchHostHandler(name string) fasthttp.RequestHandler

MatchHostHandler do handler matching on access host, will return nil for mismatch.

func (*ServerImp) PrefixRedirectHandler

func (h *ServerImp) PrefixRedirectHandler(next fasthttp.RequestHandler) fasthttp.RequestHandler

PrefixRedirectHandler return a fasthttp.RequestHandler which trim the prefix from request host and redirect to new host, if prefix not found, will pass request to next handler.

func (*ServerImp) PrefixTLSRedirectHandler

func (h *ServerImp) PrefixTLSRedirectHandler() fasthttp.RequestHandler

PrefixTLSRedirectHandler return a fasthttp.RequestHandler which redirect a http request to https, and trim the prefix from request host and redirect to new host, if prefix not found, will pass request to next handler.

func (*ServerImp) RedirectToTLSHandler

func (h *ServerImp) RedirectToTLSHandler() fasthttp.RequestHandler

RedirectToTLSHandler return a fasthttp.RequestHandler which redirect a http request to https

func (*ServerImp) ServerControlHandler

func (h *ServerImp) ServerControlHandler(ctx *fasthttp.RequestCtx)

ServerControlHandler process shutdown command from remote

func (*ServerImp) ServerHandler

func (h *ServerImp) ServerHandler(next fasthttp.RequestHandler) fasthttp.RequestHandler

ServerHandler return a fasthttp.RequestHandler which redirect a http request to https

func (*ServerImp) ServerHostSwitchHandler

func (h *ServerImp) ServerHostSwitchHandler(next fasthttp.RequestHandler) fasthttp.RequestHandler

ServerHostSwitchHandler return a fasthttp.RequestHandler which select handler by request host

Directories

Path Synopsis
acmez module
certmagic module
cmd
dnsmagic

Jump to

Keyboard shortcuts

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