summaryrefslogtreecommitdiff
path: root/web/config.go
blob: b30742531d079bbe23f4ca556c4dd1b325139faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package web

import (
	"strings"

	"code.crute.me/mcrute/go_ddns_manager/bind"
	"code.crute.me/mcrute/go_ddns_manager/dns"
)

type ServerConfig struct {
	BindConfig     *bind.BINDConfig
	DNSClient      *dns.DNSClient
	AcmeView       string
	DynamicDnsView string
	DDNSSecrets    map[string]string         `json:"DDNS"`
	AcmeSecrets    map[string]map[string]int `json:"ACME"`
}

func (s *ServerConfig) GetDDNSZoneName(k string) string {
	v, _ := s.DDNSSecrets[k]
	return v
}

func (s *ServerConfig) AcmeSecretExists(k string) bool {
	_, ok := s.AcmeSecrets[k]
	return ok
}

func (s *ServerConfig) IsAcmeClientAllowed(key, zone string) bool {
	u, ok := s.AcmeSecrets[key]
	if !ok {
		return false
	}

	p, ok := u[zone]
	if ok && p == 1 {
		return true
	}

	p, ok = u[strings.TrimRight(zone, ".")]
	if ok && p == 1 {
		return true
	}

	return false
}