Compare commits
4 Commits
00a82aca87
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| afdea7e64f | |||
| 4394d6078d | |||
| ebce605863 | |||
| 7255fc02c8 |
@@ -121,10 +121,16 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg, zone zoneView) {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
const blockTTL uint32 = 300
|
||||
const blockTTL uint32 = 604800
|
||||
|
||||
var nullIPv4 = net.IPv4(0, 0, 0, 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
|
||||
func parseHostFormat(raw string) []string {
|
||||
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)
|
||||
for _, match := range matches {
|
||||
if match[1] != "#" {
|
||||
finalList = append(finalList, dns.Fqdn(match[3]))
|
||||
}
|
||||
finalList = append(finalList, dns.Fqdn(match[2]))
|
||||
}
|
||||
|
||||
return finalList
|
||||
|
||||
@@ -18,13 +18,6 @@ type zoneMap map[string][]zoneView
|
||||
|
||||
// Start starts cooldns
|
||||
func Start(configPath string) {
|
||||
|
||||
debug := os.Getenv("COOLDNS_DEBUG")
|
||||
if len(debug) != 0 {
|
||||
debugFlag = true
|
||||
debugLog("Enabled debug")
|
||||
}
|
||||
|
||||
config, err := loadConfig(configPath)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
debugRequest(r, ip)
|
||||
|
||||
// Check if it is a ACME DNS-01 challange
|
||||
if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
|
||||
return
|
||||
@@ -105,7 +96,6 @@ func createServer(zones zoneMap, config config, aclList map[string]*net.IPNet, b
|
||||
handleBlockedDomain(w, r)
|
||||
} else {
|
||||
// Forward request
|
||||
debugLog("Forwarded request")
|
||||
in, _, err := c.Exchange(r, config.Forward.Server)
|
||||
|
||||
if err != nil {
|
||||
@@ -177,8 +167,6 @@ func createHandler(zones []zoneView, config config, aclList map[string]*net.IPNe
|
||||
return
|
||||
}
|
||||
|
||||
debugRequest(r, ip)
|
||||
|
||||
// Check if it is a ACME DNS-01 challange
|
||||
if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
|
||||
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