208 lines
6.7 KiB
Go
208 lines
6.7 KiB
Go
package easydns
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Pagination struct {
|
|
Page int `json:"page"`
|
|
PerPage int `json:"per_page"`
|
|
Total int `json:"total"`
|
|
}
|
|
type Page[T any] struct {
|
|
Items []T `json:"items"`
|
|
Pagination Pagination `json:"pagination"`
|
|
Serial uint32 `json:"serial"`
|
|
}
|
|
type Health struct {
|
|
Status string `json:"status"`
|
|
ExpiredZones []string `json:"expired_zones"`
|
|
}
|
|
type Roles struct {
|
|
Primary int `json:"primary"`
|
|
Secondary int `json:"secondary"`
|
|
Recursive bool `json:"recursive"`
|
|
Forwarder bool `json:"forwarder"`
|
|
ForwardZones int `json:"forward_zones"`
|
|
DefaultResolution string `json:"default_resolution"`
|
|
}
|
|
type Status struct {
|
|
Version string `json:"version"`
|
|
Mode string `json:"mode"`
|
|
UptimeSeconds uint64 `json:"uptime_seconds"`
|
|
Roles Roles `json:"roles"`
|
|
Listeners map[string]any `json:"listeners"`
|
|
Zones []Zone `json:"zones"`
|
|
DNSSECValidation any `json:"dnssec_validation"`
|
|
}
|
|
type Cache struct {
|
|
Entries uint64 `json:"entries"`
|
|
Capacity uint64 `json:"capacity"`
|
|
Hits uint64 `json:"hits"`
|
|
Misses uint64 `json:"misses"`
|
|
Inserts uint64 `json:"inserts"`
|
|
Evictions uint64 `json:"evictions"`
|
|
Expired uint64 `json:"expired"`
|
|
StaleServed uint64 `json:"stale_served"`
|
|
Prefetches uint64 `json:"prefetches"`
|
|
}
|
|
type Stats struct {
|
|
QueriesTotal uint64 `json:"queries_total"`
|
|
Responses map[string]uint64 `json:"responses"`
|
|
Sources map[string]uint64 `json:"sources"`
|
|
LatencyP50S float64 `json:"latency_p50_s"`
|
|
LatencyP95S float64 `json:"latency_p95_s"`
|
|
LatencyP99S float64 `json:"latency_p99_s"`
|
|
Cache Cache `json:"cache"`
|
|
CacheHitRate float64 `json:"cache_hit_rate"`
|
|
Blocked uint64 `json:"blocked"`
|
|
RateLimited uint64 `json:"rate_limited"`
|
|
UptimeSeconds uint64 `json:"uptime_seconds"`
|
|
}
|
|
type ZoneState struct {
|
|
Serial *uint32 `json:"serial"`
|
|
Loaded bool `json:"loaded"`
|
|
Expired bool `json:"expired"`
|
|
Records int `json:"records"`
|
|
Source *string `json:"source"`
|
|
LastRefreshUnix *int64 `json:"last_refresh_unix"`
|
|
LastSuccessUnix *int64 `json:"last_success_unix"`
|
|
NextRefreshUnix *int64 `json:"next_refresh_unix"`
|
|
ExpiresAtUnix *int64 `json:"expires_at_unix"`
|
|
LastError *string `json:"last_error"`
|
|
NotifiesSent uint64 `json:"notifies_sent"`
|
|
NotifiesFailed uint64 `json:"notifies_failed"`
|
|
}
|
|
type Zone struct {
|
|
Name string `json:"name"`
|
|
Kind string `json:"kind"`
|
|
Views []string `json:"views"`
|
|
Serial *uint32 `json:"serial"`
|
|
Loaded bool `json:"loaded"`
|
|
Expired bool `json:"expired"`
|
|
Records int `json:"records"`
|
|
Status ZoneState `json:"status"`
|
|
Config ZoneConfig `json:"config"`
|
|
JournalEntries int `json:"journal_entries"`
|
|
DNSSEC map[string]any `json:"dnssec"`
|
|
}
|
|
type ZoneConfig struct {
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Notify []string `json:"notify"`
|
|
TransferACL []string `json:"transfer_acl"`
|
|
Primaries []string `json:"primaries"`
|
|
File *string `json:"file"`
|
|
DNSSEC map[string]any `json:"dnssec"`
|
|
Transfer any `json:"transfer"`
|
|
Views []string `json:"views"`
|
|
}
|
|
|
|
func (z Zone) IsPrimary() bool { return strings.EqualFold(z.Kind, "primary") }
|
|
func (z Zone) IsSecondary() bool { return strings.EqualFold(z.Kind, "secondary") }
|
|
func (z Zone) StateText() string {
|
|
if z.Expired {
|
|
return "Expired"
|
|
}
|
|
if !z.Loaded {
|
|
return "Not loaded"
|
|
}
|
|
return "Loaded"
|
|
}
|
|
func (z Zone) SerialText() string {
|
|
if z.Serial == nil {
|
|
return "—"
|
|
}
|
|
return fmt.Sprint(*z.Serial)
|
|
}
|
|
func (z Zone) SyncText() string {
|
|
if z.IsPrimary() {
|
|
return "Not applicable"
|
|
}
|
|
if z.Expired {
|
|
return "Expired"
|
|
}
|
|
if z.Status.LastError != nil && *z.Status.LastError != "" {
|
|
return "Error"
|
|
}
|
|
if z.Status.LastSuccessUnix != nil {
|
|
return "Last sync OK"
|
|
}
|
|
return "Not yet synced"
|
|
}
|
|
func (z Zone) LastSync() string {
|
|
if z.Status.LastSuccessUnix == nil {
|
|
return "—"
|
|
}
|
|
return time.Unix(*z.Status.LastSuccessUnix, 0).UTC().Format("2006-01-02 15:04:05 UTC")
|
|
}
|
|
|
|
type Record struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
TTL uint32 `json:"ttl"`
|
|
Data string `json:"data"`
|
|
}
|
|
type Transfer struct {
|
|
TimeUnix int64 `json:"time_unix"`
|
|
Direction string `json:"direction"`
|
|
Kind string `json:"kind"`
|
|
Peer string `json:"peer"`
|
|
Serial *uint32 `json:"serial"`
|
|
Records int `json:"records"`
|
|
OK bool `json:"ok"`
|
|
Error *string `json:"error"`
|
|
DurationMS uint64 `json:"duration_ms"`
|
|
}
|
|
type UpstreamGroup struct {
|
|
Group string `json:"group"`
|
|
Strategy string `json:"strategy"`
|
|
Servers []Upstream `json:"servers"`
|
|
}
|
|
type Upstream struct {
|
|
Address string `json:"address"`
|
|
Stats UpstreamStats `json:"stats"`
|
|
}
|
|
type UpstreamStats struct {
|
|
Queries uint64 `json:"queries"`
|
|
Failures uint64 `json:"failures"`
|
|
ConsecutiveFailures uint32 `json:"consecutive_failures"`
|
|
EWMARTTMS *float64 `json:"ewma_rtt_ms"`
|
|
CircuitOpenForMS *uint64 `json:"circuit_open_for_ms"`
|
|
LastError *string `json:"last_error"`
|
|
Healthy bool `json:"healthy"`
|
|
}
|
|
type QueryResult struct {
|
|
RCode string `json:"rcode"`
|
|
AA bool `json:"aa"`
|
|
Answers []Record `json:"answers"`
|
|
Authority []Record `json:"authority"`
|
|
ElapsedMS float64 `json:"elapsed_ms"`
|
|
}
|
|
type AuditItem struct {
|
|
TimeUnix int64 `json:"time_unix"`
|
|
Actor string `json:"actor"`
|
|
Action string `json:"action"`
|
|
Target string `json:"target"`
|
|
Result string `json:"result"`
|
|
Detail string `json:"detail"`
|
|
}
|
|
type Blocklists struct {
|
|
Lists []map[string]any `json:"lists"`
|
|
Loaded []string `json:"loaded"`
|
|
Rules int `json:"rules"`
|
|
UpdateInterval string `json:"update_interval"`
|
|
State map[string]map[string]any `json:"state"`
|
|
}
|
|
type Policies struct {
|
|
RecursionAllowedClients []string `json:"recursion_allowed_clients"`
|
|
ACLs map[string]any `json:"acls"`
|
|
Views []map[string]any `json:"views"`
|
|
RateLimit map[string]any `json:"rate_limit"`
|
|
Policy map[string]any `json:"policy"`
|
|
APIAllowedClients []string `json:"api_allowed_clients"`
|
|
}
|