Compare commits
5 Commits
00a82aca87
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| adcb67e9c2 | |||
| afdea7e64f | |||
| 4394d6078d | |||
| ebce605863 | |||
| 7255fc02c8 |
@@ -121,10 +121,16 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg, zone zoneView) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(m.Answer) == 0 {
|
if len(m.Answer) == 0 {
|
||||||
m.SetRcode(m, dns.RcodeNameError)
|
var soa dns.RR
|
||||||
|
for _, v := range zone.rr[dns.TypeSOA] {
|
||||||
|
if len(v) == 1 {
|
||||||
|
soa = v[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if soa != nil {
|
||||||
|
m.Extra = append(m.Extra, soa)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debugResponse(m)
|
|
||||||
|
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
const blockTTL uint32 = 300
|
const blockTTL uint32 = 604800
|
||||||
|
|
||||||
var nullIPv4 = net.IPv4(0, 0, 0, 0)
|
var nullIPv4 = net.IPv4(0, 0, 0, 0)
|
||||||
var nullIPv6 = net.ParseIP("::/0")
|
var nullIPv6 = net.ParseIP("::/0")
|
||||||
@@ -86,12 +86,10 @@ func parseRawBlacklist(blacklist configBlacklist, raw string) []string {
|
|||||||
// parseHostFormat parse the string in the format of a hostfile
|
// parseHostFormat parse the string in the format of a hostfile
|
||||||
func parseHostFormat(raw string) []string {
|
func parseHostFormat(raw string) []string {
|
||||||
finalList := make([]string, 0)
|
finalList := make([]string, 0)
|
||||||
reg := regexp.MustCompile(`(?mi)^\s*(#*)\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-zA-Z0-9\.\- ]+)$`)
|
reg := regexp.MustCompile(`(?m)^\s*(0\.0\.0\.0) ([a-zA-Z0-9-.]*)`)
|
||||||
matches := reg.FindAllStringSubmatch(raw, -1)
|
matches := reg.FindAllStringSubmatch(raw, -1)
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
if match[1] != "#" {
|
finalList = append(finalList, dns.Fqdn(match[2]))
|
||||||
finalList = append(finalList, dns.Fqdn(match[3]))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalList
|
return finalList
|
||||||
|
|||||||
@@ -18,13 +18,6 @@ type zoneMap map[string][]zoneView
|
|||||||
|
|
||||||
// Start starts cooldns
|
// Start starts cooldns
|
||||||
func Start(configPath string) {
|
func Start(configPath string) {
|
||||||
|
|
||||||
debug := os.Getenv("COOLDNS_DEBUG")
|
|
||||||
if len(debug) != 0 {
|
|
||||||
debugFlag = true
|
|
||||||
debugLog("Enabled debug")
|
|
||||||
}
|
|
||||||
|
|
||||||
config, err := loadConfig(configPath)
|
config, err := loadConfig(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load config: %s\n", err.Error())
|
log.Fatalf("Failed to load config: %s\n", err.Error())
|
||||||
@@ -87,8 +80,6 @@ func createServer(zones zoneMap, config config, aclList map[string]*net.IPNet, b
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
debugRequest(r, ip)
|
|
||||||
|
|
||||||
// Check if it is a ACME DNS-01 challange
|
// Check if it is a ACME DNS-01 challange
|
||||||
if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
|
if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
|
||||||
return
|
return
|
||||||
@@ -105,7 +96,6 @@ func createServer(zones zoneMap, config config, aclList map[string]*net.IPNet, b
|
|||||||
handleBlockedDomain(w, r)
|
handleBlockedDomain(w, r)
|
||||||
} else {
|
} else {
|
||||||
// Forward request
|
// Forward request
|
||||||
debugLog("Forwarded request")
|
|
||||||
in, _, err := c.Exchange(r, config.Forward.Server)
|
in, _, err := c.Exchange(r, config.Forward.Server)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -177,8 +167,6 @@ func createHandler(zones []zoneView, config config, aclList map[string]*net.IPNe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
debugRequest(r, ip)
|
|
||||||
|
|
||||||
// Check if it is a ACME DNS-01 challange
|
// Check if it is a ACME DNS-01 challange
|
||||||
if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
|
if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package cooldns
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net"
|
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
|
||||||
)
|
|
||||||
|
|
||||||
var debugFlag = false
|
|
||||||
|
|
||||||
func debugLog(msg string) {
|
|
||||||
if !debugFlag {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("DEBUG: %s", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func debugRequest(r *dns.Msg, ip net.IP) {
|
|
||||||
if !debugFlag {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
debugLog(fmt.Sprintf("Request from %s: %s", ip, r.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func debugResponse(m *dns.Msg) {
|
|
||||||
if !debugFlag {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
debugLog(fmt.Sprintf("Response send: %s", m.String()))
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user