Skip to content
Browse files

Display of CNAME records

  • Loading branch information...
1 parent e2072b4 commit 11339949cffa7c2a02d7d2ffd42e8d457895fa9d Stephane Bortzmeyer committed Dec 23, 2012
Showing with 30 additions and 2 deletions.
  1. +27 −2 DNSLG/Formatter.py
  2. +3 −0 JSON.txt
View
29 DNSLG/Formatter.py
@@ -8,8 +8,7 @@
import time
import struct
-# TODO: Accept explicit requests for CNAME and DNAME?
-# TODO CRIT: handle CNAME better
+# TODO: Accept explicit requests for DNAME?
# TODO: DANE/TLSA record type. Not yet in DNS Python so not easy...
import Answer
@@ -117,6 +116,8 @@ def format(self, answer, qtype, flags, querier):
(rdata.target, rdata.port, rdata.priority, rdata.weight)
elif rdata.rdtype == dns.rdatatype.PTR:
self.output += "Target: %s\n" % rdata.target
+ elif rdata.rdtype == dns.rdatatype.CNAME:
+ self.output += "Canonical name: %s\n" % rdata.target
elif rdata.rdtype == dns.rdatatype.DNSKEY:
self.output += "DNSSEC key: "
try:
@@ -202,6 +203,8 @@ def format(self, answer, qtype, flags, querier):
self.output += "NS\t%s\n" % rdata.to_text()
elif rdata.rdtype == dns.rdatatype.PTR:
self.output += "PTR\t%s\n" % rdata.to_text()
+ elif rdata.rdtype == dns.rdatatype.CNAME:
+ self.output += "CNAME\t%s\n" % rdata.to_text()
elif rdata.rdtype == dns.rdatatype.LOC:
self.output += "LOC\t%s\n" % rdata.to_text()
elif rdata.rdtype == dns.rdatatype.DNSKEY:
@@ -278,6 +281,9 @@ def format(self, answer, qtype, flags, querier):
elif rdata.rdtype == dns.rdatatype.PTR:
self.object['AnswerSection'].append({'Type': 'PTR',
'Target': str(rdata.target)})
+ elif rdata.rdtype == dns.rdatatype.CNAME:
+ self.object['AnswerSection'].append({'Type': 'CNAME',
+ 'Target': str(rdata.target)})
elif rdata.rdtype == dns.rdatatype.MX:
self.object['AnswerSection'].append({'Type': 'MX',
'MailExchanger': str(rdata.exchange),
@@ -412,6 +418,9 @@ def result(self, querier):
ptr_xml_template = """
<PTR tal:attributes="ptrdname name"/>
"""
+cname_xml_template = """
+<CNAME tal:attributes="host target"/>
+"""
# TODO: NSEC3PARAM not in draft-daley-dns-schema-00
nsec3param_xml_template = """
<NSEC3PARAM tal:attributes="algorithm algorithm; flags flags; iterations iterations"/>
@@ -455,6 +464,7 @@ def format(self, answer, qtype, flags, querier):
self.loc_template = simpleTAL.compileXMLTemplate (loc_xml_template)
self.ns_template = simpleTAL.compileXMLTemplate (ns_xml_template)
self.ptr_template = simpleTAL.compileXMLTemplate (ptr_xml_template)
+ self.cname_template = simpleTAL.compileXMLTemplate (cname_xml_template)
self.soa_template = simpleTAL.compileXMLTemplate (soa_xml_template)
self.ds_template = simpleTAL.compileXMLTemplate (ds_xml_template)
self.nsec3param_template = simpleTAL.compileXMLTemplate (nsec3param_xml_template)
@@ -608,6 +618,11 @@ def format(self, answer, qtype, flags, querier):
self.ptr_template.expand (icontext, iresult,
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
+ elif rdata.rdtype == dns.rdatatype.CNAME:
+ icontext.addGlobal ("target", rdata.target)
+ self.cname_template.expand (icontext, iresult,
+ suppressXMLDeclaration=True,
+ outputEncoding=querier.encoding)
elif rdata.rdtype == dns.rdatatype.LOC:
icontext.addGlobal ("longitude", rdata.float_longitude)
icontext.addGlobal ("latitude", rdata.float_latitude)
@@ -715,6 +730,9 @@ def result(self, querier):
ptr_html_template = """
<span><a class="hostname" tal:attributes="href path" tal:content="hostname"/></span>
"""
+cname_html_template = """
+<span><a class="hostname" tal:attributes="href path" tal:content="target"/></span>
+"""
srv_html_template = """
<span>Priority <span tal:content="priority"/>, weight <span tal:content="weight"/>, host <a class="hostname" tal:attributes="href path" tal:content="hostname"/>, port <span tal:content="port"/>,</span>
"""
@@ -824,6 +842,7 @@ def format(self, answer, qtype, flags, querier):
self.soa_template = simpleTAL.compileXMLTemplate (soa_html_template)
self.ns_template = simpleTAL.compileXMLTemplate (ns_html_template)
self.ptr_template = simpleTAL.compileXMLTemplate (ptr_html_template)
+ self.cname_template = simpleTAL.compileXMLTemplate (cname_html_template)
self.srv_template = simpleTAL.compileXMLTemplate (srv_html_template)
self.txt_template = simpleTAL.compileXMLTemplate (txt_html_template)
self.spf_template = simpleTAL.compileXMLTemplate (spf_html_template)
@@ -920,6 +939,12 @@ def format(self, answer, qtype, flags, querier):
self.ptr_template.expand (icontext, iresult,
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
+ elif rdata.rdtype == dns.rdatatype.CNAME:
+ icontext.addGlobal ("target", rdata.target)
+ icontext.addGlobal ("path", self.link_of(rdata.target, querier))
+ self.cname_template.expand (icontext, iresult,
+ suppressXMLDeclaration=True,
+ outputEncoding=querier.encoding)
elif rdata.rdtype == dns.rdatatype.SRV:
icontext.addGlobal ("hostname", rdata.target)
icontext.addGlobal ("path", self.link_of(rdata.target, querier))
View
3 JSON.txt
@@ -53,6 +53,9 @@ NS:
PTR:
* Target
+CNAME:
+ * Target
+
SOA:
* MaintainerName
* MasterServerName

0 comments on commit 1133994

Please sign in to comment.
Something went wrong with that request. Please try again.