cooldns

package
v0.0.0-...-f123cf3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2014 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScryptN      int = 16384
	Scryptr      int = 8
	Scryptp      int = 1
	ScryptKeyLen int = 32
)

Variables

View Source
var (
	AuthConstraintsNotMet error = errors.New("Constraints do not apply")
)

Functions

func AuthHandler

func AuthHandler(db CoolDB, res http.ResponseWriter, req *http.Request)

func ReCaptcha

func ReCaptcha(remoteip, challenge, response, privKey string) (bool, error)

func Register

func Register(db CoolDB, r render.Render, reg Registration, errors binding.Errors)

func Run

func Run(config *Config)

The main Server Runner, specify a listen string in the form <net>:<port>, and a database filename.

func RunDns

func RunDns(config *DnsServerConfig, db CoolDB, metric MetricsHandle)

Run DNS Server with given config.

A configuration is sufficient if it contains a Domain name, a db mustbe supplied but the metricsHandle can be nil

func SetupWeb

func SetupWeb(config *WebConfig, db CoolDB, metric MetricsHandle) http.Handler

func ValidateDomain

func ValidateDomain(subdomain, domain string) (fqdn string, valid bool)

Validates a sub domain, if validation fails we try to make it a valid sub fqdn of the subdomain. The following things are checked and mitigated:

  • Sub-domain is actually a sub-domain if not we try to append the domain
  • multiple dots are deleted
  • if not an fqdn a dot is appended
  • Everything is lowercased

If the URL has one of the following features we just return false and do not recover

  • URL to short (below 2 characters)
  • contains illeageal characters.

Types

type Auth

type Auth struct {
	Name string
	Salt []byte
	Key  []byte
}

func NewAuth

func NewAuth(name, secret string) (*Auth, error)

New Auth takes a name and secret of type string and generated an Auth out of them. An 8 Byte salt is randomly generated and added to the Auth.

Some standard input constraints are applied:

*No Empty strings
*Minimum of 8 unicode Runes for the secret (more is recomended)

We use /dev/urandom as a rand source and if you wish to argue about this, argue with a knife because I am not intersted. Oh, and don't trust this on *BSD because they got it all wrong.

func (*Auth) CheckAuth

func (a *Auth) CheckAuth(name, secret string) (bool, error)

CheckAuth Checks if a name, secret touple is identical to the one used for the initial key. We return ok=true if the touple matches, else ok=false.

Well let's just hope this happens in constant time or something

type Config

type Config struct {
	DbFile       string
	Domain       string // fqdn of the full Domain name
	WebConfig    *WebConfig
	DnsConfig    *DnsServerConfig // Server Configuration
	InfluxConfig *InfluxConfig    // Influx DB configuration
}

Server Confiuration object holds instance specific variables

If all values for a specific feature are set, the corrensponding feature is activated, These shall not be changed during server Runtime.

func LoadConfig

func LoadConfig() *Config

func (*Config) SetDomain

func (c *Config) SetDomain(d string)

type CoolDB

type CoolDB interface {
	GetEntry(string) *Entry
	SaveEntry(*Entry) error
	GetAuth(string) *Auth
	SaveAuth(*Auth) error

	Close() error
}

Specifies the four methods that are needed from a DB All methods shall be callable from sevferal goroutines at a time.

type DnsDB

type DnsDB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCache

func NewCache() *DnsDB

func (*DnsDB) Get

func (d *DnsDB) Get(name string) *Entry

func (*DnsDB) GetUser

func (d *DnsDB) GetUser(name string) *Auth

func (*DnsDB) LoadCache

func (d *DnsDB) LoadCache(m map[string]*Entry, u map[string]*Auth)

func (*DnsDB) Put

func (d *DnsDB) Put(e *Entry)

func (*DnsDB) PutUser

func (d *DnsDB) PutUser(a *Auth)

type DnsServerConfig

type DnsServerConfig struct {
	Domain string // fqdn of the full Domain name
	Listen string // Dns server listener Interface <interface>:<port>. default is ":8053"
	// Tsig Key according to the tsig spec (base64 string)
	// If not set, tsig will not be activated.
	TsigKey string
}

Configuration for the DNS server

type DummyMHandle

type DummyMHandle struct {
}

func NewDummyMetrics

func NewDummyMetrics() *DummyMHandle

func (*DummyMHandle) DatabaseEvent

func (m *DummyMHandle) DatabaseEvent()

func (*DummyMHandle) DnsEvent

func (m *DummyMHandle) DnsEvent()

func (*DummyMHandle) HttpEvent

func (m *DummyMHandle) HttpEvent()

func (*DummyMHandle) HttpTime

func (m *DummyMHandle) HttpTime(f func())

type Entry

type Entry struct {
	Hostname string
	Ip6s     []net.IP
	Ip4s     []net.IP
	Offline  bool
	Txts     []string
	Mxs      []MxEntry
	Cname    string
}

func (*Entry) String

func (e *Entry) String() string

type InfluxConfig

type InfluxConfig struct {
	Host     string // Hostname:port of the Database
	Database string // Database name
	Username string
	Password string
}

Configuration of the InfluxDB host where all metrics are stored in

type InfluxMHandle

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

func NewInfluxMetrics

func NewInfluxMetrics(config *InfluxConfig) *InfluxMHandle

func (*InfluxMHandle) DatabaseEvent

func (m *InfluxMHandle) DatabaseEvent()

func (*InfluxMHandle) DnsEvent

func (m *InfluxMHandle) DnsEvent()

func (*InfluxMHandle) HttpEvent

func (m *InfluxMHandle) HttpEvent()

func (*InfluxMHandle) HttpTime

func (m *InfluxMHandle) HttpTime(f func())

type MetricsHandle

type MetricsHandle interface {
	DnsEvent()
	DatabaseEvent()
	HttpEvent()
	HttpTime(func())
}

type MxEntry

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

type Registration

type Registration struct {
	Hostname string `form:"hostname"`
	MyIp     string `form:"myip"`
	Offline  string `form:"offline"`
	Txt      string `form:"txt"`
}

func (*Registration) Validate

func (r *Registration) Validate(errors binding.Errors, req *http.Request) binding.Errors

type SqliteCoolDB

type SqliteCoolDB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSqliteCoolDB

func NewSqliteCoolDB(filename string) (*SqliteCoolDB, error)

func (*SqliteCoolDB) Close

func (db *SqliteCoolDB) Close() error

func (*SqliteCoolDB) GetAuth

func (db *SqliteCoolDB) GetAuth(name string) *Auth

func (*SqliteCoolDB) GetEntry

func (db *SqliteCoolDB) GetEntry(name string) *Entry

func (*SqliteCoolDB) SaveAuth

func (db *SqliteCoolDB) SaveAuth(auth *Auth) error

func (*SqliteCoolDB) SaveEntry

func (db *SqliteCoolDB) SaveEntry(e *Entry) error

type Web

type Web struct {
	Domain    string
	RcPubKey  string
	RcPrivKey string
}

func NewWeb

func NewWeb(c *WebConfig) *Web

func (*Web) FormApiDomainNew

func (w *Web) FormApiDomainNew(db CoolDB,
	r render.Render,
	n WebNewDomain,
	errors binding.Errors,
	req *http.Request)

func (*Web) FormApiDomainUpdate

func (w *Web) FormApiDomainUpdate(db CoolDB,
	r render.Render,
	n WebUpdateDomain,
	errors binding.Errors,
	req *http.Request)

func (*Web) Index

func (w *Web) Index(db CoolDB, r render.Render)

func (*Web) Update

func (w *Web) Update(db CoolDB, r render.Render)

func (*Web) UpdateDomain

func (w *Web) UpdateDomain(db CoolDB,
	r render.Render,
	n WebUpdateDomain,
	errors binding.Errors,
	req *http.Request,
	errHandler WebErrorHandler,
	successHandler WebSuccessHandler)

type WebConfig

type WebConfig struct {
	Domain    string // fqdn of the full Domain name
	Resources string // Directory where all resources can be found. Default "./"
	Listen    string // Listener <interface>:<port>. Default ":3000"
	RcPubKey  string // reCaptcha public key
	RcPrivKey string // reCaptcha private key
}

type WebErrorHandler

type WebErrorHandler func(int, []string, interface{})

Web Error Handler function signature. Helps you interface with errors

type WebNewDomain

type WebNewDomain struct {
	Hostname string `json:"hostname" form:"domain"`
	Secret   string `json:"secret" form:"secret"`
	RcChal   string `json:"rcchal" form:"recaptcha_challenge_field"`
	RcResp   string `json:"rcresp" form:"recaptcha_response_field"`
}

type WebSuccessHandler

type WebSuccessHandler func([]string, interface{})

Web Success Handler function signature. Helps interface with success messages

type WebUpdateDomain

type WebUpdateDomain struct {
	Hostname string `form:"domain"`
	Secret   string `form:"secret"`
	CName    string `form:"cname"`
	Ips      string `form:"ip"`
	Mxs      string `form:"mx"`
	TXTs     string `form:"txt"`
}

Jump to

Keyboard shortcuts

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