export only necessary things from xip.go
This commit is contained in:
parent
937e2415ea
commit
e25db3094f
30
xip/xip.go
30
xip/xip.go
@ -13,9 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Xip struct {
|
type Xip struct {
|
||||||
Server dns.Server
|
server dns.Server
|
||||||
NameServers []*dns.NS
|
nameServers []*dns.NS
|
||||||
Zone string
|
zone string
|
||||||
}
|
}
|
||||||
|
|
||||||
type HardcodedRecord struct {
|
type HardcodedRecord struct {
|
||||||
@ -93,17 +93,13 @@ var (
|
|||||||
}, */
|
}, */
|
||||||
// if manual
|
// if manual
|
||||||
TXT: &dns.TXT{
|
TXT: &dns.TXT{
|
||||||
Txt: []string{"YOnjnzc3vnp67aLT22CXGEeOpEV0OiZ5ixRAWCPW18Y"},
|
Txt: []string{"FRMKrfS9tGP5Gap6ruCG7qRprBlMrsBnQPtMD-dmOGk"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
|
func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
|
||||||
/* hardcodedRecords["_acme-challenge.local-ip.sh."].TXT = &dns.TXT{
|
|
||||||
Txt: []string{"YOnjnzc3vnp67aLT22CXGEeOpEV0OiZ5ixRAWCPW18Y"},
|
|
||||||
} */
|
|
||||||
|
|
||||||
if hardcodedRecords[strings.ToLower(fqdn)].A != nil {
|
if hardcodedRecords[strings.ToLower(fqdn)].A != nil {
|
||||||
var records []*dns.A
|
var records []*dns.A
|
||||||
|
|
||||||
@ -149,7 +145,7 @@ func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (xip *Xip) answerWithAuthority(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) answerWithAuthority(question dns.Question, message *dns.Msg) {
|
||||||
message.Ns = append(message.Ns, xip.SOARecord(question))
|
message.Ns = append(message.Ns, xip.soaRecord(question))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (xip *Xip) handleA(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) handleA(question dns.Question, message *dns.Msg) {
|
||||||
@ -193,7 +189,7 @@ func (xip *Xip) handleNS(question dns.Question, message *dns.Msg) {
|
|||||||
fqdn := question.Name
|
fqdn := question.Name
|
||||||
nameServers := []*dns.NS{}
|
nameServers := []*dns.NS{}
|
||||||
additionals := []*dns.A{}
|
additionals := []*dns.A{}
|
||||||
for _, ns := range xip.NameServers {
|
for _, ns := range xip.nameServers {
|
||||||
nameServers = append(nameServers, &dns.NS{
|
nameServers = append(nameServers, &dns.NS{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
// Ttl: uint32((time.Hour * 24 * 7).Seconds()),
|
// Ttl: uint32((time.Hour * 24 * 7).Seconds()),
|
||||||
@ -280,10 +276,10 @@ func (xip *Xip) handleCNAME(question dns.Question, message *dns.Msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (xip *Xip) handleSOA(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) handleSOA(question dns.Question, message *dns.Msg) {
|
||||||
message.Answer = append(message.Answer, xip.SOARecord(question))
|
message.Answer = append(message.Answer, xip.soaRecord(question))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (xip *Xip) SOARecord(question dns.Question) *dns.SOA {
|
func (xip *Xip) soaRecord(question dns.Question) *dns.SOA {
|
||||||
soa := new(dns.SOA)
|
soa := new(dns.SOA)
|
||||||
soa.Hdr = dns.RR_Header{
|
soa.Hdr = dns.RR_Header{
|
||||||
Name: question.Name,
|
Name: question.Name,
|
||||||
@ -360,9 +356,9 @@ func (xip *Xip) handleDnsRequest(response dns.ResponseWriter, request *dns.Msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (xip *Xip) StartServer() {
|
func (xip *Xip) StartServer() {
|
||||||
log.Printf("Listening on %s\n", xip.Server.Addr)
|
log.Printf("Listening on %s\n", xip.server.Addr)
|
||||||
err := xip.Server.ListenAndServe()
|
err := xip.server.ListenAndServe()
|
||||||
defer xip.Server.Shutdown()
|
defer xip.server.Shutdown()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to start server: %s\n ", err.Error())
|
log.Fatalf("Failed to start server: %s\n ", err.Error())
|
||||||
}
|
}
|
||||||
@ -372,10 +368,10 @@ func NewXip(zone string, nameservers []string, port int) (xip *Xip) {
|
|||||||
xip = &Xip{}
|
xip = &Xip{}
|
||||||
|
|
||||||
for _, ns := range nameservers {
|
for _, ns := range nameservers {
|
||||||
xip.NameServers = append(xip.NameServers, &dns.NS{Ns: ns})
|
xip.nameServers = append(xip.nameServers, &dns.NS{Ns: ns})
|
||||||
}
|
}
|
||||||
|
|
||||||
xip.Server = dns.Server{
|
xip.server = dns.Server{
|
||||||
Addr: ":" + strconv.Itoa(port),
|
Addr: ":" + strconv.Itoa(port),
|
||||||
Net: "udp",
|
Net: "udp",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user