s/records/hardcodedrecords
This commit is contained in:
parent
26a0d968a7
commit
8ee3d3ce75
@ -15,7 +15,7 @@ type hardcodedRecord struct {
|
|||||||
SRV *dns.SRV
|
SRV *dns.SRV
|
||||||
}
|
}
|
||||||
|
|
||||||
var records = map[string]hardcodedRecord{
|
var hardcodedRecords = map[string]hardcodedRecord{
|
||||||
// additional records I set up to host emails, feel free to change or remove them for your own needs
|
// additional records I set up to host emails, feel free to change or remove them for your own needs
|
||||||
"local-ip.sh.": {
|
"local-ip.sh.": {
|
||||||
TXT: []string{"v=spf1 include:capsulecorp.dev ~all"},
|
TXT: []string{"v=spf1 include:capsulecorp.dev ~all"},
|
||||||
|
48
xip/xip.go
48
xip/xip.go
@ -31,9 +31,9 @@ func (xip *Xip) SetTXTRecord(fqdn string, value string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if rootRecords, ok := records[fqdn]; ok {
|
if rootRecords, ok := hardcodedRecords[fqdn]; ok {
|
||||||
rootRecords.TXT = []string{value}
|
rootRecords.TXT = []string{value}
|
||||||
records[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
|
hardcodedRecords[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,18 +45,18 @@ func (xip *Xip) UnsetTXTRecord(fqdn string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if rootRecords, ok := records[fqdn]; ok {
|
if rootRecords, ok := hardcodedRecords[fqdn]; ok {
|
||||||
rootRecords.TXT = []string{}
|
rootRecords.TXT = []string{}
|
||||||
records[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
|
hardcodedRecords[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
|
func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
|
||||||
normalizedFqdn := strings.ToLower(fqdn)
|
normalizedFqdn := strings.ToLower(fqdn)
|
||||||
if records[normalizedFqdn].A != nil {
|
if hardcodedRecords[normalizedFqdn].A != nil {
|
||||||
var aRecords []*dns.A
|
var aRecords []*dns.A
|
||||||
|
|
||||||
for _, record := range records[normalizedFqdn].A {
|
for _, record := range hardcodedRecords[normalizedFqdn].A {
|
||||||
aRecords = append(aRecords, &dns.A{
|
aRecords = append(aRecords, &dns.A{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Ttl: uint32((time.Minute * 5).Seconds()),
|
Ttl: uint32((time.Minute * 5).Seconds()),
|
||||||
@ -117,12 +117,12 @@ func (xip *Xip) handleA(question dns.Question, message *dns.Msg) {
|
|||||||
func (xip *Xip) handleAAAA(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) handleAAAA(question dns.Question, message *dns.Msg) {
|
||||||
fqdn := question.Name
|
fqdn := question.Name
|
||||||
normalizedFqdn := strings.ToLower(fqdn)
|
normalizedFqdn := strings.ToLower(fqdn)
|
||||||
if records[normalizedFqdn].AAAA == nil {
|
if hardcodedRecords[normalizedFqdn].AAAA == nil {
|
||||||
xip.answerWithAuthority(question, message)
|
xip.answerWithAuthority(question, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, record := range records[normalizedFqdn].AAAA {
|
for _, record := range hardcodedRecords[normalizedFqdn].AAAA {
|
||||||
message.Answer = append(message.Answer, &dns.AAAA{
|
message.Answer = append(message.Answer, &dns.AAAA{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Ttl: uint32((time.Minute * 5).Seconds()),
|
Ttl: uint32((time.Minute * 5).Seconds()),
|
||||||
@ -172,12 +172,12 @@ func chunkBy(str string, chunkSize int) (chunks []string) {
|
|||||||
func (xip *Xip) handleTXT(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) handleTXT(question dns.Question, message *dns.Msg) {
|
||||||
fqdn := question.Name
|
fqdn := question.Name
|
||||||
normalizedFqdn := strings.ToLower(fqdn)
|
normalizedFqdn := strings.ToLower(fqdn)
|
||||||
if records[normalizedFqdn].TXT == nil {
|
if hardcodedRecords[normalizedFqdn].TXT == nil {
|
||||||
xip.answerWithAuthority(question, message)
|
xip.answerWithAuthority(question, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, record := range records[normalizedFqdn].TXT {
|
for _, record := range hardcodedRecords[normalizedFqdn].TXT {
|
||||||
message.Answer = append(message.Answer, &dns.TXT{
|
message.Answer = append(message.Answer, &dns.TXT{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Ttl: uint32((time.Minute * 5).Seconds()),
|
Ttl: uint32((time.Minute * 5).Seconds()),
|
||||||
@ -193,12 +193,12 @@ func (xip *Xip) handleTXT(question dns.Question, message *dns.Msg) {
|
|||||||
func (xip *Xip) handleMX(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) handleMX(question dns.Question, message *dns.Msg) {
|
||||||
fqdn := question.Name
|
fqdn := question.Name
|
||||||
normalizedFqdn := strings.ToLower(fqdn)
|
normalizedFqdn := strings.ToLower(fqdn)
|
||||||
if records[normalizedFqdn].MX == nil {
|
if hardcodedRecords[normalizedFqdn].MX == nil {
|
||||||
xip.answerWithAuthority(question, message)
|
xip.answerWithAuthority(question, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, record := range records[normalizedFqdn].MX {
|
for _, record := range hardcodedRecords[normalizedFqdn].MX {
|
||||||
message.Answer = append(message.Answer, &dns.MX{
|
message.Answer = append(message.Answer, &dns.MX{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Ttl: uint32((time.Minute * 5).Seconds()),
|
Ttl: uint32((time.Minute * 5).Seconds()),
|
||||||
@ -215,12 +215,12 @@ func (xip *Xip) handleMX(question dns.Question, message *dns.Msg) {
|
|||||||
func (xip *Xip) handleCNAME(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) handleCNAME(question dns.Question, message *dns.Msg) {
|
||||||
fqdn := question.Name
|
fqdn := question.Name
|
||||||
normalizedFqdn := strings.ToLower(fqdn)
|
normalizedFqdn := strings.ToLower(fqdn)
|
||||||
if records[normalizedFqdn].CNAME == nil {
|
if hardcodedRecords[normalizedFqdn].CNAME == nil {
|
||||||
xip.answerWithAuthority(question, message)
|
xip.answerWithAuthority(question, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, record := range records[normalizedFqdn].CNAME {
|
for _, record := range hardcodedRecords[normalizedFqdn].CNAME {
|
||||||
message.Answer = append(message.Answer, &dns.CNAME{
|
message.Answer = append(message.Answer, &dns.CNAME{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Ttl: uint32((time.Minute * 5).Seconds()),
|
Ttl: uint32((time.Minute * 5).Seconds()),
|
||||||
@ -236,7 +236,7 @@ func (xip *Xip) handleCNAME(question dns.Question, message *dns.Msg) {
|
|||||||
func (xip *Xip) handleSRV(question dns.Question, message *dns.Msg) {
|
func (xip *Xip) handleSRV(question dns.Question, message *dns.Msg) {
|
||||||
fqdn := question.Name
|
fqdn := question.Name
|
||||||
normalizedFqdn := strings.ToLower(fqdn)
|
normalizedFqdn := strings.ToLower(fqdn)
|
||||||
if records[normalizedFqdn].SRV == nil {
|
if hardcodedRecords[normalizedFqdn].SRV == nil {
|
||||||
xip.answerWithAuthority(question, message)
|
xip.answerWithAuthority(question, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -248,10 +248,10 @@ func (xip *Xip) handleSRV(question dns.Question, message *dns.Msg) {
|
|||||||
Rrtype: dns.TypeSRV,
|
Rrtype: dns.TypeSRV,
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
},
|
},
|
||||||
Priority: records[normalizedFqdn].SRV.Priority,
|
Priority: hardcodedRecords[normalizedFqdn].SRV.Priority,
|
||||||
Weight: records[normalizedFqdn].SRV.Weight,
|
Weight: hardcodedRecords[normalizedFqdn].SRV.Weight,
|
||||||
Port: records[normalizedFqdn].SRV.Port,
|
Port: hardcodedRecords[normalizedFqdn].SRV.Port,
|
||||||
Target: records[normalizedFqdn].SRV.Target,
|
Target: hardcodedRecords[normalizedFqdn].SRV.Target,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,17 +373,17 @@ func (xip *Xip) initHardcodedRecords() {
|
|||||||
ip := net.ParseIP(ns)
|
ip := net.ParseIP(ns)
|
||||||
|
|
||||||
rootDomainARecords = append(rootDomainARecords, ip)
|
rootDomainARecords = append(rootDomainARecords, ip)
|
||||||
entry := records[name]
|
entry := hardcodedRecords[name]
|
||||||
entry.A = append(records[name].A, ip)
|
entry.A = append(hardcodedRecords[name].A, ip)
|
||||||
records[name] = entry
|
hardcodedRecords[name] = entry
|
||||||
|
|
||||||
xip.nameServers = append(xip.nameServers, name)
|
xip.nameServers = append(xip.nameServers, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
records[fmt.Sprintf("%s.", config.Domain)] = hardcodedRecord{A: rootDomainARecords}
|
hardcodedRecords[fmt.Sprintf("%s.", config.Domain)] = hardcodedRecord{A: rootDomainARecords}
|
||||||
|
|
||||||
// will be filled in later when requesting the wildcard certificate
|
// will be filled in later when requesting the wildcard certificate
|
||||||
records[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = hardcodedRecord{TXT: []string{}}
|
hardcodedRecords[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = hardcodedRecord{TXT: []string{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewXip() (xip *Xip) {
|
func NewXip() (xip *Xip) {
|
||||||
|
Loading…
Reference in New Issue
Block a user