Merge branch 'main' into main

This commit is contained in:
unreality 2021-10-16 22:31:37 +08:00 committed by GitHub
commit afbfc1d370
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 621 additions and 99 deletions

15
app.go
View file

@ -16,12 +16,13 @@ import (
"github.com/rs/zerolog/log"
"github.com/gin-gonic/gin"
"github.com/zsais/go-gin-prometheus"
ginprometheus "github.com/zsais/go-gin-prometheus"
"golang.org/x/crypto/acme"
"golang.org/x/crypto/acme/autocert"
"gorm.io/gorm"
"inet.af/netaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/dnstype"
"tailscale.com/types/wgkey"
)
@ -33,6 +34,7 @@ type Config struct {
DerpMap *tailcfg.DERPMap
EphemeralNodeInactivityTimeout time.Duration
IPPrefix netaddr.IPPrefix
BaseDomain string
DBtype string
DBpath string
@ -125,6 +127,17 @@ func NewHeadscale(cfg Config) (*Headscale, error) {
if err != nil {
return nil, err
}
}
if h.cfg.DNSConfig != nil && h.cfg.DNSConfig.Proxied { // if MagicDNS
magicDNSDomains, err := generateMagicDNSRootDomains(h.cfg.IPPrefix, h.cfg.BaseDomain)
if err != nil {
return nil, err
}
h.cfg.DNSConfig.Routes = make(map[string][]dnstype.Resolver)
for _, d := range magicDNSDomains {
h.cfg.DNSConfig.Routes[d.WithoutTrailingDot()] = nil
}
}
return &h, nil