zone rendering

This commit is contained in:
core 2023-10-02 10:21:08 -04:00
parent 173e3f6476
commit b41f622655
Signed by: core
GPG Key ID: FDBF740DADDCEECF
4 changed files with 170 additions and 15 deletions

View File

@ -0,0 +1,59 @@
package main
import (
"flag"
"git.e3t.cc/e3team/pancheri"
"net"
"os"
)
func main() {
//configPath := flag.String("zone", "", "Zone file to render")
printUsage := flag.Bool("help", false, "Print command line usage")
flag.Parse()
if *printUsage {
flag.Usage()
os.Exit(0)
}
var aRecords []pancheri.RecordA
aRecords = append(aRecords, pancheri.RecordA{
In: "test.xe.",
Ip: net.ParseIP("1.2.3.4"),
TTL: 600,
})
var aaaaRecords []pancheri.RecordAAAA
aaaaRecords = append(aaaaRecords, pancheri.RecordAAAA{
In: "testv6.xe.",
Ip: net.ParseIP("bd1f:f314:5398:0e3d:b3e0:f427:73ef:60fb"),
TTL: 600,
})
var cnameRecords []pancheri.RecordCNAME
cnameRecords = append(cnameRecords, pancheri.RecordCNAME{
In: "cname.xe.",
Target: "test.xe.",
TTL: 600,
})
var txtRecords []pancheri.RecordTXT
txtRecords = append(txtRecords, pancheri.RecordTXT{
In: "txt.xe.",
Content: []string{"WHY HELLO THERE MY FELLOW E3TEAMERS"},
TTL: 600,
})
zone := pancheri.Zone{
ReducedHash: "0433da05bf22d86c1886fca6e3e2c3239b86f1e6ebea9b94201483c8596c0468",
Root: "xe",
ARecords: aRecords,
AAAARecords: aaaaRecords,
CNAMERecords: cnameRecords,
TXTRecords: txtRecords,
Zonefile: "zone_example.yml",
}
println(zone.RenderZone())
}

23
rule.go
View File

@ -1,12 +1,31 @@
package pancheri
import "net"
const (
RuleTypeA = "A"
RuleTypeAAAA = "AAAA"
RuleTypeCNAME = "CNAME"
RuleTypeMX = "MX"
RuleTypeTXT = "TXT"
)
type Rule interface {
type RecordA struct {
In string
Ip net.IP
TTL uint
}
type RecordAAAA struct {
In string
Ip net.IP
TTL uint
}
type RecordCNAME struct {
In string
Target string
TTL uint
}
type RecordTXT struct {
In string
Content []string
TTL uint
}

85
zone.go Normal file
View File

@ -0,0 +1,85 @@
package pancheri
import (
"fmt"
"github.com/miekg/dns"
"time"
)
type Zone struct {
Root string
ReducedHash string
Zonefile string
ARecords []RecordA
AAAARecords []RecordAAAA
CNAMERecords []RecordCNAME
TXTRecords []RecordTXT
}
func (z *Zone) RenderZone() string {
outString := ""
outString += fmt.Sprintf(";; Rendered zonefile for %s (rsha %s) at %s\n", z.Zonefile, z.ReducedHash, time.Now().Format(time.RFC3339))
outString += ";; Generated by pancheri-render. Note: this will NOT work out of the box!\n"
outString += ";; At the very least, you'll need to change the SOA and NS values.\n"
outString += "\n"
outString += ";; SOA & NS records\n"
outString += ";; TODO\n"
outString += "\n"
outString += ";; A Records\n"
for _, record := range z.ARecords {
r := new(dns.A)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.A = record.Ip
outString += r.String() + "\n"
}
outString += ";; AAAA Records\n"
for _, record := range z.AAAARecords {
r := new(dns.AAAA)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeAAAA,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.AAAA = record.Ip
outString += r.String() + "\n"
}
outString += ";; CNAME Records\n"
for _, record := range z.CNAMERecords {
r := new(dns.CNAME)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeCNAME,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.Target = record.Target
outString += r.String() + "\n"
}
outString += ";; TXT Records\n"
for _, record := range z.TXTRecords {
r := new(dns.TXT)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeTXT,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.Txt = record.Content
outString += r.String() + "\n"
}
return outString
}

View File

@ -2,23 +2,15 @@ zone:
root: 'xe'
records:
- type: 'A'
domains: ['some_a']
domains: ['test']
ipv4: '1.2.3.4'
- type: 'AAAA'
domains: ['some_aaaa']
domains: ['testv6']
ipv6: 'bd1f:f314:5398:0e3d:b3e0:f427:73ef:60fb'
- type: 'CNAME'
domains: ['some_cname']
content: 'some_a'
- type: 'MX'
domains: ['some_mail_domain']
mailserver: 'mail.e3t.cc'
priority: 10
domains: ['cname']
content: 'test'
- type: 'TXT'
domains: ['some_txt']
domains: ['txt']
content: |
WHY HELLO THERE MY FELLOW E3TEAMERS