Skip to content

Commit

Permalink
fixed Relay Config
Browse files Browse the repository at this point in the history
  • Loading branch information
mguptahub committed Oct 28, 2024
1 parent 0632011 commit 0345800
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
51 changes: 51 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# DNS Server Configuration
DNS_PORT=10053

# Relay Configuration
DNS_RELAY_SERVERS=8.8.8.8,1.1.1.1

# API Configuration
DNS_API_PORT=8080 # Port for ACME HTTP API
DNS_API_TOKEN=1234

# TTL Configuration (in seconds)
DNS_DEFAULT_TTL=60

# A Records
# Format: domain|ip|ttl or domain|service:servicename|ttl
A_REC1=app1.example.com|10.10.0.1|300
A_REC2=app2.example.com|10.10.0.2|300
# A_REC3=static.example.com|10.0.0.50
# A_REC4=*.example.com|192.168.1.100|300

# CNAME Records
# Format: domain|target|ttl
# CNAME_REC1=www.example.com|app.example.com|3600
# CNAME_REC2=docs.example.com|documentation.service.local
# CNAME_REC3=blog.example.com|app.example.com|600

# MX Records
# Format: domain|priority|mailserver|ttl
# MX_REC1=example.com|10|mail1.example.com|3600
# MX_REC2=example.com|20|mail2.example.com|3600
# MX_REC3=example.com|30|mail-backup.example.com|3600

# TXT Records
# Format: domain|"text value"|ttl
# TXT_REC1=example.com|v=spf1 include:_spf.example.com ~all|3600
# TXT_REC2=_dmarc.example.com|v=DMARC1; p=reject; rua=mailto:dmarc@example.com
# TXT_REC3=_acme-challenge.example.com|validation-token-here|60
# TXT_REC4=mail._domainkey.example.com|v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4|3600

# Service Discovery Examples
# A_REC5=db.local|service:postgres.default.svc.cluster.local|60
# A_REC6=redis.local|service:redis.default.svc.cluster.local|60
# A_REC7=kafka.local|service:kafka.kafka.svc.cluster.local|60

# Load Balancing Examples
# A_REC8=api.local|192.168.1.10|60
# A_REC9=api.local|192.168.1.11|60
# A_REC10=api.local|192.168.1.12|60

# Note: All TTL values are optional and will default to DNS_DEFAULT_TTL if not specified
# Note: Service references will be automatically resolved in Docker/Kubernetes environments
15 changes: 8 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,29 @@ func GetRelayConfig() RelayConfig {
// Split and clean nameserver addresses
rawServers := strings.Split(servers, ",")
validServers := make([]string, 0, len(rawServers))
hasInvalid := false

for _, server := range rawServers {
server = strings.TrimSpace(server)

// Skip empty entries
if server == "" {
continue
}

// Basic validation of nameserver address
if !isValidNameserver(server) {
} else if !isValidNameserver(server) {
log.Printf("Warning: Invalid nameserver address: %s", server)
hasInvalid = true
continue
}

validServers = append(validServers, server)
}

// Only enable if we have valid servers
if len(validServers) > 0 {
// Enable only if all provided servers are valid
if len(validServers) > 0 && !hasInvalid {
config.Enabled = true
config.Nameservers = validServers
} else {
log.Print("Warning: DNS relay disabled due to no valid nameservers")
log.Print("Warning: DNS relay disabled due to invalid nameserver entries")
}
}

Expand Down

0 comments on commit 0345800

Please sign in to comment.