Somewhat working

This commit is contained in:
Magnus Åhall 2026-02-23 07:59:45 +01:00
parent ad638acaf3
commit 4637689db4
6 changed files with 52 additions and 12 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
routeros_dns

28
dns.go
View file

@ -107,6 +107,13 @@ func BuildRecordsTree(records []DNSRecord) *DomainPart {
func (dp *DomainPart) ToHTML(parts []string) string { func (dp *DomainPart) ToHTML(parts []string) string {
html := "" html := ""
/*
var lines []struct {
Header bool
HTML string
}
*/
sortedParts := slices.Sorted(maps.Keys(dp.Subparts)) sortedParts := slices.Sorted(maps.Keys(dp.Subparts))
for _, part := range sortedParts { for _, part := range sortedParts {
@ -118,18 +125,33 @@ func (dp *DomainPart) ToHTML(parts []string) string {
slices.Reverse(reversedParts) slices.Reverse(reversedParts)
fqdn := strings.Join(reversedParts, ".") fqdn := strings.Join(reversedParts, ".")
mostSpecificPart := reversedParts[0]
restPart := ""
if len(reversedParts) > 1 {
restPart = strings.Join(reversedParts[1:], ".")
mostSpecificPart += "."
}
var subHTML string var subHTML string
if len(subpart.Subparts) == 0 { if len(subpart.Subparts) == 0 {
html += fmt.Sprintf(`<div class="record" data-record="%s">%s</div>`, fqdn, fqdn) html += fmt.Sprintf(
`<div class="record" style="margin-left: %dpx" data-top="%s"><span>%s</span><span>%s</span></div>`,
len(newParts)*16,
restPart,
mostSpecificPart,
restPart,
)
} else { } else {
subHTML = subpart.ToHTML(newParts) subHTML = subpart.ToHTML(newParts)
html += fmt.Sprintf(` html += fmt.Sprintf(`
<div class="top" data-top="%s"> <div class="top" data-top="%s" style="margin-left: %dpx">
<div class="fqdn">%s</div> <div class="fqdn">%s</div>
<div class="records">%s</div>
</div> </div>
<div data-top="%s" class="records">%s</div>
`, `,
fqdn, fqdn,
len(newParts)*16,
fqdn,
fqdn, fqdn,
subHTML, subHTML,
) )

2
go.sum
View file

@ -1,6 +1,6 @@
git.gibonuddevalla.se/go/html_template v1.0.0 h1:0YoqKiWMxYUsYZomqFlXLR/h0UNBicqw+VOsPyotcD4= git.gibonuddevalla.se/go/html_template v1.0.0 h1:0YoqKiWMxYUsYZomqFlXLR/h0UNBicqw+VOsPyotcD4=
git.gibonuddevalla.se/go/html_template v1.0.0/go.mod h1:DGqGMulbZyGoRqWXInXISb6GQLswuUrTaX1WhH7jx/w= git.gibonuddevalla.se/go/html_template v1.0.0/go.mod h1:DGqGMulbZyGoRqWXInXISb6GQLswuUrTaX1WhH7jx/w=
git.gibonuddevalla.se/go/vlog v1.0.0 h1:AlArMDt1Aw6poI8yDtU22d4NyFl3iQocZSswvlzy48o= git.gibonuddevalla.se/go/vlog v1.0.0 h1:6iu7Wy3V3vTSg1usLSZWX9ipA+SY3FV4pi7HrHqagyc=
git.gibonuddevalla.se/go/vlog v1.0.0/go.mod h1:rjS9ZINhZF+Bhrb+fdD4aEKOnLxFYU3PJFMx7nOi4c0= git.gibonuddevalla.se/go/vlog v1.0.0/go.mod h1:rjS9ZINhZF+Bhrb+fdD4aEKOnLxFYU3PJFMx7nOi4c0=
git.gibonuddevalla.se/go/wrappederror v0.3.5 h1:/EzrdXETlZfNpS6TcK1Ix6BaV+Fl7qcGoxUM0GkrIN8= git.gibonuddevalla.se/go/wrappederror v0.3.5 h1:/EzrdXETlZfNpS6TcK1Ix6BaV+Fl7qcGoxUM0GkrIN8=
git.gibonuddevalla.se/go/wrappederror v0.3.5/go.mod h1:j4w320Hk1wvhOPjUaK4GgLvmtnjUUM5yVu6JFO1OCSc= git.gibonuddevalla.se/go/wrappederror v0.3.5/go.mod h1:j4w320Hk1wvhOPjUaK4GgLvmtnjUUM5yVu6JFO1OCSc=

View file

@ -17,18 +17,35 @@ body {
} }
.records-tree { .records-tree {
display: grid;
.fqdn, .record {
border-bottom: 1px solid #aaa;
padding: 4px 0px;
}
.top { .top {
font-weight: bold; font-weight: bold;
margin-left: 16px;
} }
&>.top { &>.top {
margin-left: 0px;
} }
.record { .record {
display: none; display: none;
font-weight: normal;
color: #444; color: #444;
&.show {
display: block;
}
span:first-child {
color: #800033;
}
span:last-child {
color: #888;
}
} }
} }

View file

@ -10,8 +10,11 @@ export class Application {
handlerTop(event) { handlerTop(event) {
const fqdn = event.target const fqdn = event.target
const top = fqdn.closest('.top') const topEl = fqdn.closest('.top')
const records = top.querySelector('.records') const records = document.querySelectorAll(`.record[data-top="${topEl.dataset.top}"]`)
console.log(fqdn, top, records) console.log(`.record[data-top="${topEl.dataset.top}"]`)
console.log(topEl.dataset.top, records)
for (const r of records)
r.classList.toggle('show')
} }
} }

View file

@ -66,13 +66,10 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
slices.SortFunc(entries, SortDNSRecord) slices.SortFunc(entries, SortDNSRecord)
data["DNSRecords"] = entries data["DNSRecords"] = entries
fmt.Printf("\n\x1b[32;1mSTART\x1b[0m\n")
tree := BuildRecordsTree(entries) tree := BuildRecordsTree(entries)
htmlTree := tree.ToHTML([]string{}) htmlTree := tree.ToHTML([]string{})
data["Tree"] = template.HTML(htmlTree) data["Tree"] = template.HTML(htmlTree)
fmt.Printf("\n\x1b[32;1mDONE\x1b[0m\n")
j, _ := json.Marshal(tree) j, _ := json.Marshal(tree)
os.WriteFile("/tmp/tree.json", j, 0644) os.WriteFile("/tmp/tree.json", j, 0644)