servers

package
v0.0.0-...-784cda0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2018 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphabetizeConstraints

func AlphabetizeConstraints(constraints map[string]*KeyConstraint) []string

AlphabetizeConstraints takes in a map of KeyData and returns the keys/names in alphabetical order.

func AlphabetizeKeyData

func AlphabetizeKeyData(keyData map[string]*KeyData) []string

AlphabetizeKeyData takes in a map of KeyData and returns the keys/names in alphabetical order.

func AlphabetizeSettings

func AlphabetizeSettings(settings map[string]*ServerSetting) []string

AlphabetizeSettings takes in a map of ServerSettings and returns the keys/names in alphabetical order.

func BuildKey

func BuildKey(s string) map[string]string

BuildKey takes the string data and generates all supported hashes A map with the hash type as key and hash as value is returned

func DnsKeyData

func DnsKeyData() map[string]*KeyData

func GenerateSHA256

func GenerateSHA256(s string) string

GenerateSHA256 takes a string, generates a SHA256 hash and sends back as hex string

func GenerateSHA512

func GenerateSHA512(s string) string

GenerateSHA512 takes a string, generates a SHA512 hash and sends back as hex string

func GetToday

func GetToday() string

func HttpKeyData

func HttpKeyData() map[string]*KeyData

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile returns the contents as a []byte

Types

type DnsServer

type DnsServer struct {
	State      map[string]*ServerSetting
	Server     *dns.Server
	Keys       map[string]*Key
	DefaultTTL uint
	Running    bool
	SendingKey bool
}

DnsServer struct, uses following map keys for modifiable settings "Listen": listening IP address "Domain": the root level domain name we're authoratative over "DefaultTTL": default Time To Live (TTL) for DNS responses

func GetDnsServer

func GetDnsServer() *DnsServer

GetDnsServer returns a starting point for the DnsServer and DnsState structs for use throughout keyserver

func (*DnsServer) AddKey

func (d *DnsServer) AddKey(k *Key, name string) error

AddKey does the fun stuff, takes in the data generates the hasehs and adds it to the end of the Keys slice within the HttpServer

func (*DnsServer) AppendResult

func (is *DnsServer) AppendResult(q dns.Question, m *dns.Msg, rr dns.RR, ttl uint)

AppendResult prepares response for ServeDNS Taken directly from OJ's code

func (*DnsServer) ServeDNS

func (d *DnsServer) ServeDNS(w dns.ResponseWriter, r *dns.Msg)

ServeDNS handles the DNS queries

func (*DnsServer) StartDNS

func (d *DnsServer) StartDNS()

StartDNS starts the DNS server in the background

type HttpServer

type HttpServer struct {
	Server  *http.Server
	State   map[string]*ServerSetting
	Keys    map[string]*Key
	Running bool
}

HttpServer struct, uses following map keys for modifiable settings "Listen": listening IP address "Port": listening port "DefaultPage": default page returned with no key matchings "ServerHeader": option HTTP response 'Server' header

func GetHttpServer

func GetHttpServer() *HttpServer

GetHttpServer returns a starting point for the HttpServer and HttpState structs for use throughout keyserver

func (*HttpServer) AddKey

func (h *HttpServer) AddKey(k *Key, name string) error

AddKey does the fun stuff, takes in the data generates the hasehs and adds it to the end of the Keys slice within the HttpServer

func (*HttpServer) ServeHTTP

func (h *HttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows SubHTTPServer to handle http requests The requested URL path needs to match a key's Data["URL"].Value to evaluate the Key

func (*HttpServer) StartHTTP

func (h *HttpServer) StartHTTP()

StartHTTP is the exported function to call and get the HTTP server running.

func (*HttpServer) StartHTTPS

func (h *HttpServer) StartHTTPS()

StartHTTPS is the exported function to call and get the HTTPS/TLS server running.

type Key

type Key struct {
	Type        string
	On          bool
	Disabled    bool
	SendAlerts  bool
	HitCounter  map[string]int
	LastHit     string
	Data        map[string]*KeyData
	Constraints map[string]*KeyConstraint
	Hashes      map[string]string
}

Key contains attributes that fit both Http and Dns keys

func (*Key) ClearHits

func (k *Key) ClearHits()

ClearHits sets the current day to 0 hits

func (*Key) GetDnsKeyConstraints

func (k *Key) GetDnsKeyConstraints() map[string]*KeyConstraint

func (*Key) GetHits

func (k *Key) GetHits() int

GetHits returns the hit counter but ensures theres an entry for the current day.

func (*Key) GetHttpKeyConstraints

func (k *Key) GetHttpKeyConstraints() map[string]*KeyConstraint

GetHttpKeyConstraints returns all possible key constraints for an HttpKey

func (*Key) HitLimitDnsConstraint

func (k *Key) HitLimitDnsConstraint(constraint string, q *dns.Question) bool

HitLimitDnsConstraint is a key constraint that returns true if the number of hits is below the supplied limit

func (*Key) HitLimitHttpConstraint

func (k *Key) HitLimitHttpConstraint(constraint string, r *http.Request) bool

HitLimitHttpConstraint is a key constraint that returns true if the number of hits is below the supplied limit

func (*Key) HitMaxDnsConstraint

func (k *Key) HitMaxDnsConstraint(constraint string, q *dns.Question) bool

HitMaxDnsConstraint is a key constraint that returns true if the number of hits is above the supplied value

func (*Key) HitMaxHttpConstraint

func (k *Key) HitMaxHttpConstraint(constraint string, r *http.Request) bool

HitMaxHttpConstraint is a key constraint that returns true if the number of hits is above the supplied value

func (*Key) IsActive

func (k *Key) IsActive(r *http.Request, q *dns.Question) (bool, string)

IsActive determines whether a key is active for the HttpServer The string returned is the "reason" the key is active or inactive, manually turned on or due to a constraint

func (*Key) TimeDnsConstraint

func (k *Key) TimeDnsConstraint(constraint string, q *dns.Question) bool

TimeConstraint is a key constraint that returns true if the current time falls within a specified timeframe. DNS request data not needed as we just want the current time.

func (*Key) TimeHttpConstraint

func (k *Key) TimeHttpConstraint(constraint string, r *http.Request) bool

TimeHttpConstraint is a key constraint that returns true if the current time falls within a specified timeframe. http.Request data not needed as we just want the current time.

func (*Key) UpdateHits

func (k *Key) UpdateHits()

UpdateHits updates the HitCounter for the current day

func (*Key) UserAgentHttpConstraint

func (k *Key) UserAgentHttpConstraint(constraint string, r *http.Request) bool

UserAgentConstraint is a key constraint that returns true if the current time falls within a specified timeframe. requestData is null as the data we want is the current time.

type KeyConstraint

type KeyConstraint struct {
	Description     string
	Constraint      string
	ConstraintRegex *regexp.Regexp
	HttpValidator   func(constraint string, r *http.Request) bool
	DnsValidator    func(constraint string, q *dns.Question) bool
}

type KeyData

type KeyData struct {
	Description string
	Value       string
}

type ServerSetting

type ServerSetting struct {
	Value    string
	Default  string
	Required bool
	Help     string
}

ServerSetting for various settings for DNS and HTTP servers

Jump to

Keyboard shortcuts

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