Skip to content

Commit

Permalink
Namecoin: Add support for CNAME DNS records
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Dec 12, 2019
1 parent 94c0fdc commit 50bb947
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
29 changes: 29 additions & 0 deletions electrum_nmc/electrum/gui/qt/configure_dns_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __init__(self, value, parent):
self.insert_record(idx, record)

self.ui.btnACreate.clicked.connect(self.create_address_record)
self.ui.btnCNAMECreate.clicked.connect(self.create_cname_record)
self.ui.btnTXTCreate.clicked.connect(self.create_txt_record)

self.ui.dialogButtons.accepted.connect(self.accept)
Expand Down Expand Up @@ -147,6 +148,22 @@ def create_address_record(self):

self.insert_record(idx, record)

def create_cname_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()

domain = self.get_selected_domain()

if self.has_cname_record(domain):
self.show_error(domain + _(" already has a CNAME record."))
return

data = self.ui.editCNAMEAlias.text()

record = [domain, "cname", data]

self.insert_record(idx, record)

def create_txt_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()
Expand Down Expand Up @@ -176,6 +193,15 @@ def has_zeronet_record(self, domain):

return False

def has_cname_record(self, domain):
for record in self.get_records():
record_domain, record_type, data = record

if record_domain == domain and record_type == "cname":
return True

return False

def insert_record(self, idx, record):
domain, record_type, data = record

Expand All @@ -197,6 +223,9 @@ def insert_record(self, idx, record):
formatted_data = "ZeroNet: " + data[1]
else:
raise Exception("Unknown address type")
elif record_type == "cname":
formatted_record_type = "CNAME"
formatted_data = data
elif record_type == "txt":
formatted_record_type = "TXT"
formatted_data = json.dumps(data)
Expand Down
28 changes: 28 additions & 0 deletions electrum_nmc/electrum/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ def get_domain_records(domain, value):
new_records, value = get_domain_records_address(domain, value)
records.extend(new_records)

if "alias" in value:
new_records, value["alias"] = get_domain_records_cname(domain, value["alias"])
records.extend(new_records)
if value["alias"] == None:
del value["alias"]

if "txt" in value:
new_records, value["txt"] = get_domain_records_txt(domain, value["txt"])
records.extend(new_records)
Expand Down Expand Up @@ -668,6 +674,18 @@ def get_domain_records_address_zeronet(domain, value):

return records, remaining

def get_domain_records_cname(domain, value):
records = []
remaining = None

# Must be string
if type(value) != str:
return [], value

records.append([domain, "cname", value])

return records, remaining

def get_domain_records_txt(domain, value):
# Process Tor specially
if domain.startswith("_tor."):
Expand Down Expand Up @@ -762,6 +780,8 @@ def add_domain_record(base_domain, value, record):

if record_type == "address":
add_domain_record_address(subdomain_value, data)
elif record_type == "cname":
add_domain_record_cname(subdomain_value, data)
elif record_type == "txt":
add_domain_record_txt(subdomain_value, data)

Expand Down Expand Up @@ -835,6 +855,14 @@ def add_domain_record_address_zeronet(value, data):
# Add the record
value["zeronet"] = data

def add_domain_record_cname(value, data):
# Make sure the field doesn't already exist
if "alias" in value:
raise Exception("Multiple CNAME records for one domain")

# Add the record
value["alias"] = data

def add_domain_record_txt(value, data):
# Make sure the field exists
if "txt" not in value:
Expand Down

0 comments on commit 50bb947

Please sign in to comment.