Skip to content

Commit

Permalink
case insensitive match
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobg committed Aug 29, 2021
1 parent 5e1d17d commit 96b8cd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions dnsserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
'SOA': (dns.SOA, QTYPE.SOA),
'SRV': (dns.SRV, QTYPE.SRV),
'TXT': (dns.TXT, QTYPE.TXT),
'SPF': (dns.SPF, QTYPE.SPF),
}

TXT_RECORDS = {}
Expand Down Expand Up @@ -95,10 +94,17 @@ def __init__(self, upstream):
else:
self.NS = []

def match_suffix_insensitive(self, request):
name = request.q.qname
# skip the last dot
suffixLower = str(name)[-len(confs.BASE_DOMAIN)-1:-1].lower()
return suffixLower == confs.BASE_DOMAIN

def resolve(self, request, handler):
global TXT_RECORDS
reply = request.reply()
name = request.q.qname

logger.info("query %s", request.q.qname)

# handle the main domain
Expand Down Expand Up @@ -150,7 +156,7 @@ def resolve(self, request, handler):
reply.add_answer(r)
return reply
# handle subdomains
elif name.matchSuffix(confs.BASE_DOMAIN): # fnmatch
elif self.match_suffix_insensitive(request):
labelstr = str(request.q.qname)
logger.info("requestx: %s, %s", labelstr, confs.ONLY_PRIVATE_IPS)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dnslib==0.9.13
dnslib==0.9.16
cherrypy==18.1.2

0 comments on commit 96b8cd2

Please sign in to comment.