-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
666 lines (578 loc) Β· 28.1 KB
/
Copy pathindex.html
File metadata and controls
666 lines (578 loc) Β· 28.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>DNS Resource Record Builder β NicTool</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css"
integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous" />
<link rel="stylesheet" href="../css/nictool.css" />
<style>
/* Monospace output */
textarea.mono, input.mono {
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
font-size: .82rem;
}
/* Field hints */
.field-hint { font-size: .72rem; opacity: .55; font-weight: 400; }
/* Format output blocks */
.fmt-label { font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
.fmt-sublabel { font-size: .72rem; opacity: .5; margin-left: .4rem; font-weight: 400; }
.fmt-textarea { resize: vertical; min-height: 2.6rem; }
/* Copy button */
.copy-btn { min-width: 4.8rem; font-size: .78rem; transition: all .18s; }
.copy-btn.ok { background: var(--bs-success); border-color: var(--bs-success); color: #fff; }
/* Error area */
#rrError { white-space: pre-wrap; font-family: monospace; font-size: .8rem; }
/* Type selector */
#rrType { font-weight: 500; }
/* Loading overlay */
#loadingOverlay {
position: fixed; inset: 0; background: rgba(17,24,39,.85);
display: flex; align-items: center; justify-content: center;
z-index: 9999; transition: opacity .3s;
}
#loadingOverlay.hidden { opacity: 0; pointer-events: none; }
/* Rdata field rows */
#rrRdataFields .col-rr { margin-bottom: .1rem; }
/* RFC badge */
.rfc-badge {
font-size: .7rem; padding: .15rem .45rem;
border-radius: 3px; background: rgba(99,179,237,.15);
color: #63b3ed; border: 1px solid rgba(99,179,237,.25);
}
</style>
</head>
<body>
<!-- Loading overlay -->
<div id="loadingOverlay">
<div class="text-center text-light">
<div class="spinner-border mb-3" style="width:2.5rem;height:2.5rem" role="status"></div>
<div class="small">Loading dns-resource-recordβ¦</div>
</div>
</div>
<nav class="navbar navbar-expand-sm py-2 nt-navbar">
<div class="container px-4">
<a class="navbar-brand" href="../index.html">NicTool</a>
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navMain">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navMain">
<ul class="navbar-nav ms-auto gap-1">
<li class="nav-item">
<a class="nav-link" href="../index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="index.html">Builder</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../dictionary.html">Dictionary</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/orgs/NicTool/discussions" target="_blank" rel="noopener">Discussions</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="container-xl py-4 px-3 px-md-4">
<!-- Page header -->
<div class="mb-4">
<h1 class="h4 mb-1 fw-bold">DNS Resource Record Builder</h1>
<p class="text-muted small mb-0">
Generate DNS RRs in <strong>BIND / RFC 1035</strong>, <strong>tinydns</strong>,
<strong>MaraDNS</strong>, and <strong>wire</strong> formats β powered by
<a href="https://github.com/NicTool/dns-resource-record" target="_blank"
rel="noopener" class="link-info">@nictool/dns-resource-record</a>.
</p>
</div>
<!-- ββ Record type selector βββββββββββββββββββββββββββββββββββββββββ -->
<div class="card mb-3">
<div class="card-body py-3">
<div class="row g-3 align-items-center">
<div class="col-sm-4 col-lg-3">
<label for="rrType" class="form-label small text-uppercase text-secondary fw-semibold mb-1">
Record Type
</label>
<select id="rrType" class="form-select">
<option value="">Loadingβ¦</option>
</select>
</div>
<div class="col-sm-8 col-lg-9">
<div id="rrDescription" class="fs-5 fw-semibold text-info mb-1">β</div>
<div id="rrRfcBadges" class="d-flex flex-wrap gap-1"></div>
</div>
</div>
</div>
</div>
<!-- ββ Record fields ββββββββββββββββββββββββββββββββββββββββββββββββ -->
<div class="card mb-3">
<div class="card-header py-2 d-flex align-items-center justify-content-between">
<span class="fw-semibold small">Record Fields</span>
<button id="loadExampleBtn" class="btn btn-sm btn-outline-secondary py-0" style="font-size:.75rem">
Load example
</button>
</div>
<div class="card-body pb-3 pt-3">
<!-- Common fields: owner / TTL / class -->
<div class="row g-3 mb-3">
<div class="col-md-7">
<label for="field-owner" class="form-label small fw-semibold mb-1">
Owner
<span class="field-hint">fully qualified β must end with .</span>
</label>
<input type="text" id="field-owner" class="form-control form-control-sm mono"
placeholder="host.example.com."
autocorrect="off" autocapitalize="none" spellcheck="false" />
</div>
<div class="col-md-3">
<label for="field-ttl" class="form-label small fw-semibold mb-1">
TTL
<span class="field-hint js-ttl-human"></span>
</label>
<input type="number" id="field-ttl" class="form-control form-control-sm"
value="3600" min="0" max="2147483647" />
</div>
<div class="col-md-2">
<label for="field-class" class="form-label small fw-semibold mb-1">Class</label>
<select id="field-class" class="form-select form-select-sm">
<option value="IN" selected>IN</option>
<option value="CH">CH</option>
<option value="HS">HS</option>
</select>
</div>
</div>
<!-- Dynamic rdata fields injected here -->
<div id="rrRdataFields" class="row g-3"></div>
</div>
</div>
<!-- ββ Validation error βββββββββββββββββββββββββββββββββββββββββββββ -->
<div id="rrError" class="alert alert-danger mb-3 d-none py-2" role="alert"></div>
<!-- ββ Output formats ββββββββββββββββββββββββββββββββββββββββββββββ -->
<div class="card">
<div class="card-header py-2 fw-semibold small">Output Formats</div>
<div class="card-body py-3">
<div class="row g-4">
<!-- BIND / RFC 1035 -->
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-1">
<div class="fmt-label">
BIND / RFC 1035
<span class="fmt-sublabel">ISC BIND, Knot, NSD, PowerDNS…</span>
</div>
<button class="btn btn-sm btn-outline-secondary copy-btn" data-target="out-bind">Copy</button>
</div>
<textarea id="out-bind" class="form-control mono fmt-textarea" rows="2" readonly
placeholder="Fill in the fields aboveβ¦"></textarea>
</div>
<!-- tinydns -->
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-1">
<div class="fmt-label">
tinydns
<span class="fmt-sublabel">djbdns / tinydns data file</span>
</div>
<button class="btn btn-sm btn-outline-secondary copy-btn" data-target="out-tinydns">Copy</button>
</div>
<textarea id="out-tinydns" class="form-control mono fmt-textarea" rows="2" readonly></textarea>
</div>
<!-- MaraDNS -->
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-1">
<div class="fmt-label">
MaraDNS
<span class="fmt-sublabel">MaraDNS zone file</span>
</div>
<button class="btn btn-sm btn-outline-secondary copy-btn" data-target="out-maradns">Copy</button>
</div>
<textarea id="out-maradns" class="form-control mono fmt-textarea" rows="2" readonly></textarea>
</div>
<!-- Wire -->
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-1">
<div class="fmt-label">
Wire
<span class="fmt-sublabel">binary wire format, hex encoded</span>
</div>
<button class="btn btn-sm btn-outline-secondary copy-btn" data-target="out-wire">Copy</button>
</div>
<textarea id="out-wire" class="form-control mono fmt-textarea" rows="3" readonly></textarea>
</div>
</div>
</div>
</div>
<p class="text-muted small mt-4 text-center">
Powered by
<a href="https://github.com/NicTool/dns-resource-record" target="_blank" rel="noopener"
class="link-secondary">@nictool/dns-resource-record</a>
·
Inspired by
<a href="https://andersbrownworth.com/projects/sysadmin/djbdnsRecordBuilder/" target="_blank"
rel="noopener" class="link-secondary">andersbrownworth.com</a>
</p>
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"
integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI"
crossorigin="anonymous"></script>
<script type="module">
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 1. Import dns-resource-record. v1.7.0+ uses Uint8Array/DataView natively β
// no Buffer polyfill needed.
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const RR = await import('https://cdn.jsdelivr.net/npm/@nictool/dns-resource-record@1.7.0/dist/dns-rr.min.js')
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 2. Constants
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const TAG_TO_GROUP = {
common: 'Common',
security: 'Security',
dnssec: 'DNSSEC',
deprecated: 'Deprecated',
obsolete: 'Obsolete',
}
const GROUP_ORDER = ['Common', 'Less Common', 'Security', 'DNSSEC', 'Deprecated', 'Obsolete']
// Fields that get a <textarea> instead of a single-line <input>
const LARGE_FIELDS = new Set([
'data', 'certificate association data', 'fingerprint', 'public key',
'key tag', 'public key', 'digest', 'hit', 'public key', 'rendezvous servers',
'signature', 'key data', 'next domain name', 'type bit maps',
])
// Fields that are FQDN domain names (hint about trailing dot)
const FQDN_FIELDS = new Set([
'exchange', 'target', 'nsdname', 'dname', 'cname', 'mname', 'rname',
'replacement', 'signer name', 'next',
])
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 3. Helpers
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function ucFirst(str) {
return str.split(/\s+/).map(w => w.charAt(0).toUpperCase() + w.slice(1)).join('')
}
function titleCase(str) {
return str.split(/\s+/).map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ')
}
function htmlEsc(s) {
return String(s ?? '')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
}
function humanTtl(secs) {
if (!secs && secs !== 0) return ''
if (secs < 60) return `${secs}s`
if (secs < 3600) return `${secs / 60}m`
if (secs % 3600 === 0 && secs < 86400) return `${secs / 3600}h`
if (secs % 86400 === 0 && secs < 604800) return `${secs / 86400}d`
if (secs % 604800 === 0) return `${secs / 604800}w`
const h = Math.floor(secs / 3600)
const m = Math.floor((secs % 3600) / 60)
return h ? `${h}h ${m}m` : `${m}m`
}
function getGroupForInstance(inst) {
const tags = inst.getTags?.() ?? []
for (const [tag, group] of Object.entries(TAG_TO_GROUP)) {
if (tags.includes(tag)) return group
}
return 'Less Common'
}
// Collect all exported RR classes (skip 'default' base class and 'typeMap')
const SKIP = new Set(['default', 'typeMap'])
const ALL_TYPES = {}
for (const [name, val] of Object.entries(RR)) {
if (!SKIP.has(name) && typeof val === 'function') {
ALL_TYPES[name] = val
}
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 4. Build the <select> type selector grouped by category
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function buildTypeSelector() {
const grouped = {}
for (const name of GROUP_ORDER) grouped[name] = []
for (const [name, cls] of Object.entries(ALL_TYPES)) {
try {
const inst = new cls(null)
grouped[getGroupForInstance(inst)].push(name)
} catch { /* skip broken entries */ }
}
const sel = document.getElementById('rrType')
sel.innerHTML = ''
for (const groupName of GROUP_ORDER) {
const names = (grouped[groupName] ?? []).sort()
if (!names.length) continue
const og = document.createElement('optgroup')
og.label = groupName
for (const name of names) {
const opt = document.createElement('option')
opt.value = name
opt.textContent = name
og.appendChild(opt)
}
sel.appendChild(og)
}
sel.value = 'A'
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 5. Render rdata field inputs for the chosen type
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function renderRdataFields(typeName) {
const cls = ALL_TYPES[typeName]
if (!cls) return
const inst = new cls(null)
const canonical = inst.getCanonical?.() ?? {}
const rdataFlds = inst.getRdataFields?.() ?? []
// Update description
document.getElementById('rrDescription').textContent = inst.getDescription?.() || typeName
// RFC badges
const badgesEl = document.getElementById('rrRfcBadges')
badgesEl.innerHTML = ''
for (const rfc of (inst.getRFCs?.() ?? [])) {
const a = document.createElement('a')
a.href = `https://www.rfc-editor.org/rfc/rfc${rfc}`
a.target = '_blank'; a.rel = 'noopener'
a.className = 'rfc-badge text-decoration-none'
a.textContent = `RFC ${rfc}`
badgesEl.appendChild(a)
}
// Set canonical owner/ttl defaults (only when switching type)
if (canonical.owner) document.getElementById('field-owner').value = canonical.owner
if (canonical.ttl) document.getElementById('field-ttl').value = canonical.ttl
// Build dynamic rdata field elements
const container = document.getElementById('rrRdataFields')
container.innerHTML = ''
for (const fieldName of rdataFlds) {
const optionsMethod = `get${ucFirst(fieldName)}Options`
const options = typeof inst[optionsMethod] === 'function' ? inst[optionsMethod]() : null
const canonVal = canonical[fieldName]
const isNumeric = typeof canonVal === 'number'
const safeId = `rdf-${fieldName.replace(/\s+/g, '-')}`
const labelText = titleCase(fieldName)
const isFqdn = FQDN_FIELDS.has(fieldName)
const isLarge = LARGE_FIELDS.has(fieldName)
const col = document.createElement('div')
if (options) {
// ββ Select (enumerated options) ββββββββββββββββββββββββββββββββββ
const firstKey = options.keys().next().value
const keysNumeric = typeof firstKey === 'number'
col.className = 'col-md-6'
const optionsHtml = [...options.entries()].map(([k, v]) => {
const display = v != null ? `${k} β ${v}` : (k === '' ? '(empty)' : String(k))
const sel = String(k) === String(canonVal) ? ' selected' : ''
return `<option value="${htmlEsc(k)}"${sel}>${htmlEsc(display)}</option>`
}).join('')
col.innerHTML = `
<label for="${safeId}" class="form-label small fw-semibold mb-1">${htmlEsc(labelText)}</label>
<select id="${safeId}" data-field="${htmlEsc(fieldName)}"
data-numeric="${keysNumeric}" class="form-select form-select-sm rr-field">
${optionsHtml}
</select>`
} else if (isLarge) {
// ββ Textarea (long text fields) ββββββββββββββββββββββββββββββββββ
col.className = 'col-12'
col.innerHTML = `
<label for="${safeId}" class="form-label small fw-semibold mb-1">${htmlEsc(labelText)}</label>
<textarea id="${safeId}" data-field="${htmlEsc(fieldName)}"
class="form-control form-control-sm mono rr-field fmt-textarea"
rows="3" autocorrect="off" autocapitalize="none"
spellcheck="false"></textarea>`
// Set value via DOM to avoid HTML encoding issues
col.querySelector('textarea').value = String(canonVal ?? '')
} else if (isNumeric) {
// ββ Number input βββββββββββββββββββββββββββββββββββββββββββββββββ
col.className = 'col-md-4 col-sm-6'
col.innerHTML = `
<label for="${safeId}" class="form-label small fw-semibold mb-1">${htmlEsc(labelText)}</label>
<input type="number" id="${safeId}" data-field="${htmlEsc(fieldName)}"
data-numeric="true" class="form-control form-control-sm rr-field"
value="${canonVal ?? 0}" min="0" />`
} else {
// ββ Text input βββββββββββββββββββββββββββββββββββββββββββββββββββ
col.className = 'col-md-6'
const hint = isFqdn ? '<span class="field-hint ms-1">FQDN, ends with .</span>' : ''
col.innerHTML = `
<label for="${safeId}" class="form-label small fw-semibold mb-1">${htmlEsc(labelText)}${hint}</label>
<input type="text" id="${safeId}" data-field="${htmlEsc(fieldName)}"
class="form-control form-control-sm mono rr-field"
autocorrect="off" autocapitalize="none" spellcheck="false" />`
col.querySelector('input').value = String(canonVal ?? '')
}
container.appendChild(col)
}
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 6. Collect form values β build RR β render all output formats
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function updateOutput() {
const typeName = document.getElementById('rrType').value
if (!typeName) return
const cls = ALL_TYPES[typeName]
if (!cls) return
const errorEl = document.getElementById('rrError')
// Collect common fields
const opts = {
owner : document.getElementById('field-owner').value.trim(),
ttl : parseInt(document.getElementById('field-ttl').value, 10) || 3600,
class : document.getElementById('field-class').value,
type : typeName,
}
// Collect rdata fields
for (const el of document.querySelectorAll('.rr-field')) {
const field = el.dataset.field
if (!field) continue
if (el.dataset.numeric === 'true') {
opts[field] = parseInt(el.value, 10)
if (isNaN(opts[field])) opts[field] = 0
} else {
opts[field] = el.tagName === 'TEXTAREA' ? el.value : el.value
}
}
try {
const rr = new cls(opts)
setOut('out-bind', tryCall(() => rr.toBind?.().trim()))
setOut('out-tinydns', tryCall(() => rr.toTinydns?.().trim()))
setOut('out-maradns', tryCall(() => rr.toMaraDNS?.().trim()))
// Wire: toWire() returns a Buffer; display as spaced hex
setOut('out-wire', tryCall(() => {
const bytes = rr.toWire()
const hex = Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join(' ')
return `${hex}\n; ${bytes.length} bytes`
}))
errorEl.classList.add('d-none')
errorEl.textContent = ''
} catch (e) {
errorEl.textContent = e.message
errorEl.classList.remove('d-none')
for (const id of ['out-bind', 'out-tinydns', 'out-maradns', 'out-wire']) {
document.getElementById(id).value = ''
}
}
}
function setOut(id, value) {
const el = document.getElementById(id)
if (el) el.value = value ?? ''
}
function tryCall(fn) {
try {
return fn()
} catch (e) {
return `; Error: ${e.message}`
}
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 7. Load example values from getCanonical()
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function loadExample() {
const typeName = document.getElementById('rrType').value
const cls = ALL_TYPES[typeName]
if (!cls) return
const inst = new cls(null)
const canonical = inst.getCanonical?.() ?? {}
if (canonical.owner) document.getElementById('field-owner').value = canonical.owner
if (canonical.ttl) document.getElementById('field-ttl').value = canonical.ttl
for (const el of document.querySelectorAll('.rr-field')) {
const field = el.dataset.field
if (field === undefined || !(field in canonical)) continue
if (el.tagName === 'SELECT') {
el.value = String(canonical[field])
} else {
el.value = String(canonical[field] ?? '')
}
}
updateTtlDisplay()
updateOutput()
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 8. Copy-to-clipboard buttons
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function setupCopyButtons() {
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', () => {
const ta = document.getElementById(btn.dataset.target)
if (!ta?.value) return
const reset = () => {
btn.textContent = 'Copy'
btn.classList.remove('ok', 'btn-success')
btn.classList.add('btn-outline-secondary')
}
const markCopied = () => {
btn.textContent = 'β Copied'
btn.classList.add('ok', 'btn-success')
btn.classList.remove('btn-outline-secondary')
setTimeout(reset, 1800)
}
if (navigator.clipboard?.writeText) {
navigator.clipboard.writeText(ta.value).then(markCopied).catch(() => {
ta.select(); document.execCommand('copy'); markCopied()
})
} else {
ta.select(); document.execCommand('copy'); markCopied()
}
})
})
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 9. TTL human-readable display
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function updateTtlDisplay() {
const ttl = parseInt(document.getElementById('field-ttl').value, 10)
for (const s of document.querySelectorAll('.js-ttl-human')) {
s.textContent = isNaN(ttl) ? '' : `(${humanTtl(ttl)})`
}
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 10. Wire up all events
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function attachEvents() {
document.getElementById('rrType').addEventListener('change', e => {
renderRdataFields(e.target.value)
updateTtlDisplay()
updateOutput()
})
document.getElementById('field-owner').addEventListener('input', updateOutput)
document.getElementById('field-ttl').addEventListener('input', () => {
updateTtlDisplay(); updateOutput()
})
document.getElementById('field-class').addEventListener('change', updateOutput)
// FQDN auto-dot on blur for owner
document.getElementById('field-owner').addEventListener('blur', e => {
const v = e.target.value.trim()
if (v && !v.endsWith('.')) {
e.target.value = v + '.'
updateOutput()
}
})
// Delegate rdata field changes
const rdataContainer = document.getElementById('rrRdataFields')
rdataContainer.addEventListener('input', updateOutput)
rdataContainer.addEventListener('change', updateOutput)
// Auto-dot for FQDN rdata fields on blur
rdataContainer.addEventListener('focusout', e => {
const el = e.target
if (!el.classList.contains('rr-field')) return
if (el.type !== 'text') return
if (!FQDN_FIELDS.has(el.dataset.field)) return
const v = el.value.trim()
if (v && !v.endsWith('.')) {
el.value = v + '.'
updateOutput()
}
})
document.getElementById('loadExampleBtn').addEventListener('click', loadExample)
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// 11. Init
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
buildTypeSelector()
attachEvents()
setupCopyButtons()
renderRdataFields('A')
updateTtlDisplay()
updateOutput()
// Hide loading overlay
const overlay = document.getElementById('loadingOverlay')
overlay.classList.add('hidden')
setTimeout(() => overlay.remove(), 350)
</script>
</body>
</html>