corrige detecção de endereços

This commit is contained in:
2026-09-16 00:31:37 -03:00
parent 1a5a446b5c
commit 6c16f0da7a
4 changed files with 78 additions and 23 deletions
+27 -1
View File
@@ -5,16 +5,30 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/BurntSushi/toml"
)
const DefaultIntervalMinutes = 5
// RecordType identifies which DNS record family an entry updates. Hurricane
// Electric's dynamic DNS API cannot infer this from the submitted address
// alone, so it must be configured explicitly per entry.
type RecordType string
const (
RecordTypeA RecordType = "A"
RecordTypeAAAA RecordType = "AAAA"
)
// Entry describes a single Hurricane Electric dynamic DNS hostname to keep updated.
type Entry struct {
Hostname string `toml:"hostname"`
Token string `toml:"token"`
// RecordType selects whether this entry updates the A (IPv4) or AAAA
// (IPv6) record. Defaults to A when omitted.
RecordType RecordType `toml:"record_type"`
}
// Config is the top-level he-dydns configuration.
@@ -46,13 +60,25 @@ func Load(path string) (*Config, error) {
if len(cfg.Entries) == 0 {
return nil, fmt.Errorf("config %s: no entries defined", path)
}
for i, e := range cfg.Entries {
for i := range cfg.Entries {
e := &cfg.Entries[i]
if e.Hostname == "" {
return nil, fmt.Errorf("config %s: entries[%d] missing hostname", path, i)
}
if e.Token == "" {
return nil, fmt.Errorf("config %s: entries[%d] missing token", path, i)
}
switch RecordType(strings.ToUpper(string(e.RecordType))) {
case "":
e.RecordType = RecordTypeA
case RecordTypeA:
e.RecordType = RecordTypeA
case RecordTypeAAAA:
e.RecordType = RecordTypeAAAA
default:
return nil, fmt.Errorf("config %s: entries[%d] invalid record_type %q (must be \"A\" or \"AAAA\")", path, i, e.RecordType)
}
}
if cfg.IntervalMinutes <= 0 {