ddns

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ddns publishes a node's public IP to DNS when it changes. It is dependency-free: the Cloudflare provider talks to the Cloudflare API v4 over the standard library and the webhook provider posts a templated request, so the server keeps its zero-dependency footprint (no libdns).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, p Provider, profile model.DDNSProfile, ipv4, ipv6 string) error

Apply pushes the node's current IPs to every domain in the profile, honoring EnableIPv4/EnableIPv6 and retrying each record up to MaxRetries times. It returns the joined error of all failed records (nil if all succeeded).

func GuardOutbound

func GuardOutbound(raw string) error

GuardOutbound rejects URLs that resolve to loopback, private, link-local, unspecified, or cloud-metadata addresses. This blunts SSRF via an admin-configured webhook URL. It performs a real DNS lookup; callers that must reach loopback (tests) construct the provider without this guard.

Types

type Cloudflare

type Cloudflare struct {
	Token   string
	BaseURL string // defaults to cloudflareDefaultBase
	Client  *http.Client
	// contains filtered or unexported fields
}

Cloudflare sets A/AAAA records through the Cloudflare API v4 using an API token. The token needs Zone:Read + DNS:Edit on the target zones.

func (*Cloudflare) Kind

func (c *Cloudflare) Kind() string

func (*Cloudflare) SetRecord

func (c *Cloudflare) SetRecord(ctx context.Context, r Record) error

type Provider

type Provider interface {
	Kind() string
	SetRecord(ctx context.Context, r Record) error
}

Provider sets DNS records for one backend (Cloudflare, webhook, ...).

func NewProvider

func NewProvider(p model.DDNSProfile, client *http.Client) (Provider, error)

NewProvider builds the Provider described by a profile. The webhook provider is given the production SSRF guard; the Cloudflare provider targets the real API. Tests construct providers directly to bypass the guard / point at a mock.

type Record

type Record struct {
	Type string // "A" or "AAAA"
	Name string // fully-qualified record name, e.g. node.example.com
	IP   string
	TTL  int
}

Record is a single DNS record to set.

type Webhook

type Webhook struct {
	URL     string
	Method  string
	Body    string
	Headers string // "Key: Value" per line
	Client  *http.Client
	Guard   func(rawURL string) error
}

Webhook delivers DNS updates to an arbitrary HTTP endpoint. The URL and body support the templates #ip#, #domain#, and #type#. Because the URL is operator-supplied, Guard (when set) is consulted before each request to block SSRF to internal addresses.

func (*Webhook) Kind

func (w *Webhook) Kind() string

func (*Webhook) SetRecord

func (w *Webhook) SetRecord(ctx context.Context, r Record) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL