remove unused code and use proper TTLs

This commit is contained in:
m5r 2023-12-13 22:13:35 +01:00
parent 18e4091bdf
commit da1b496653
No known key found for this signature in database
GPG Key ID: 5BC847276DD5DDEA

View File

@ -87,11 +87,11 @@ var (
}, },
}, },
"_acme-challenge.local-ip.sh.": { "_acme-challenge.local-ip.sh.": {
// if fly // required for fly.io to obtain a certificate for the website
CNAME: []*dns.CNAME{ CNAME: []*dns.CNAME{
{Target: "local-ip.sh.zzkxm3.flydns.net."}, {Target: "local-ip.sh.zzkxm3.flydns.net."},
}, },
// if manual // will be filled in later when requesting the wildcard certificate
TXT: &dns.TXT{}, TXT: &dns.TXT{},
}, },
} }
@ -132,8 +132,7 @@ func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
for _, record := range hardcodedRecords[strings.ToLower(fqdn)].A { for _, record := range hardcodedRecords[strings.ToLower(fqdn)].A {
records = append(records, &dns.A{ records = append(records, &dns.A{
Hdr: dns.RR_Header{ Hdr: dns.RR_Header{
// Ttl: uint32((time.Hour * 24 * 7).Seconds()), Ttl: uint32((time.Hour * 24 * 7).Seconds()),
Ttl: uint32((time.Second * 10).Seconds()),
Name: fqdn, Name: fqdn,
Rrtype: dns.TypeA, Rrtype: dns.TypeA,
Class: dns.ClassINET, Class: dns.ClassINET,
@ -156,8 +155,7 @@ func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
return []*dns.A{{ return []*dns.A{{
Hdr: dns.RR_Header{ Hdr: dns.RR_Header{
// Ttl: uint32((time.Hour * 24 * 7).Seconds()), Ttl: uint32((time.Hour * 24 * 7).Seconds()),
Ttl: uint32((time.Second * 10).Seconds()),
Name: fqdn, Name: fqdn,
Rrtype: dns.TypeA, Rrtype: dns.TypeA,
Class: dns.ClassINET, Class: dns.ClassINET,
@ -200,8 +198,7 @@ func (xip *Xip) handleAAAA(question dns.Question, message *dns.Msg) {
for _, record := range hardcodedRecords[strings.ToLower(fqdn)].AAAA { for _, record := range hardcodedRecords[strings.ToLower(fqdn)].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.Hour * 24 * 7).Seconds()), Ttl: uint32((time.Hour * 24 * 7).Seconds()),
Ttl: uint32((time.Second * 10).Seconds()),
Name: fqdn, Name: fqdn,
Rrtype: dns.TypeAAAA, Rrtype: dns.TypeAAAA,
Class: dns.ClassINET, Class: dns.ClassINET,
@ -218,8 +215,7 @@ func (xip *Xip) handleNS(question dns.Question, message *dns.Msg) {
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()),
Ttl: uint32((time.Second * 10).Seconds()),
Name: fqdn, Name: fqdn,
Rrtype: dns.TypeNS, Rrtype: dns.TypeNS,
Class: dns.ClassINET, Class: dns.ClassINET,
@ -248,8 +244,7 @@ func (xip *Xip) handleTXT(question dns.Question, message *dns.Msg) {
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.Hour * 24 * 7).Seconds()), Ttl: uint32((time.Hour * 24 * 7).Seconds()),
Ttl: uint32((time.Second * 120).Seconds()),
Name: fqdn, Name: fqdn,
Rrtype: dns.TypeTXT, Rrtype: dns.TypeTXT,
Class: dns.ClassINET, Class: dns.ClassINET,
@ -268,8 +263,7 @@ func (xip *Xip) handleMX(question dns.Question, message *dns.Msg) {
for _, record := range hardcodedRecords[strings.ToLower(fqdn)].MX { for _, record := range hardcodedRecords[strings.ToLower(fqdn)].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.Hour * 24 * 7).Seconds()), Ttl: uint32((time.Hour * 24 * 7).Seconds()),
Ttl: uint32((time.Second * 10).Seconds()),
Name: fqdn, Name: fqdn,
Rrtype: dns.TypeMX, Rrtype: dns.TypeMX,
Class: dns.ClassINET, Class: dns.ClassINET,
@ -290,8 +284,7 @@ func (xip *Xip) handleCNAME(question dns.Question, message *dns.Msg) {
for _, record := range hardcodedRecords[strings.ToLower(fqdn)].CNAME { for _, record := range hardcodedRecords[strings.ToLower(fqdn)].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.Hour * 24 * 7).Seconds()), Ttl: uint32((time.Hour * 24 * 7).Seconds()),
Ttl: uint32((time.Second * 10).Seconds()),
Name: fqdn, Name: fqdn,
Rrtype: dns.TypeCNAME, Rrtype: dns.TypeCNAME,
Class: dns.ClassINET, Class: dns.ClassINET,
@ -308,38 +301,25 @@ func (xip *Xip) handleSOA(question dns.Question, message *dns.Msg) {
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,
Rrtype: dns.TypeSOA, Rrtype: dns.TypeSOA,
Class: dns.ClassINET, Class: dns.ClassINET,
// Ttl: uint32((time.Hour * 24 * 7).Seconds()), Ttl: uint32((time.Hour * 24 * 7).Seconds()),
Ttl: uint32((time.Second * 10).Seconds()),
Rdlength: 0, Rdlength: 0,
} }
soa.Ns = "ns1.local-ip.sh." soa.Ns = "ns1.local-ip.sh."
soa.Mbox = "admin.local-ip.sh." soa.Mbox = "admin.local-ip.sh."
soa.Serial = 2022102800 soa.Serial = 2022102800
// soa.Refresh = uint32((time.Minute * 15).Seconds()) soa.Refresh = uint32((time.Minute * 15).Seconds())
soa.Refresh = uint32((time.Second * 10).Seconds()) soa.Retry = uint32((time.Minute * 15).Seconds())
// soa.Retry = uint32((time.Minute * 15).Seconds()) soa.Expire = uint32((time.Minute * 30).Seconds())
soa.Retry = uint32((time.Second * 10).Seconds()) soa.Minttl = uint32((time.Minute * 5).Seconds())
// soa.Expire = uint32((time.Minute * 30).Seconds())
soa.Expire = uint32((time.Second * 10).Seconds())
// soa.Minttl = uint32((time.Minute * 5).Seconds())
soa.Minttl = uint32((time.Second * 10).Seconds())
return soa return soa
} }
func (xip *Xip) handleQuery(message *dns.Msg) { func (xip *Xip) handleQuery(message *dns.Msg) {
for _, question := range message.Question { for _, question := range message.Question {
// log.Printf("name: %s\n", question.Name)
// log.Printf("class: %d\n", question.Qclass)
// log.Printf("type: %d\n", question.Qtype)
/* if strings.HasPrefix(strings.ToLower(question.Name), "_acme-challenge.") {
message.Authoritative = false
} */
switch question.Qtype { switch question.Qtype {
case dns.TypeA: case dns.TypeA:
xip.handleA(question, message) xip.handleA(question, message)