support multiple txt records at once

This commit is contained in:
nd 2019-11-01 16:00:13 +01:00
parent bab37262b3
commit ff7e2c1db8
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9

View file

@ -8,7 +8,7 @@ def setupdb():
conn = sqlite3.connect('{{ powerdns.letsencrypthandler.dbpath }}', isolation_level=None) conn = sqlite3.connect('{{ powerdns.letsencrypthandler.dbpath }}', isolation_level=None)
conn.executescript(""" conn.executescript("""
CREATE TABLE IF NOT EXISTS challenges ( CREATE TABLE IF NOT EXISTS challenges (
q TEXT NOT NULL PRIMARY KEY, q TEXT NOT NULL,
value TEXT, value TEXT,
timestamp DEFAULT (strftime('%s','now')) timestamp DEFAULT (strftime('%s','now'))
) )
@ -21,9 +21,9 @@ def get_challenge(db, path):
c.execute('SELECT value FROM challenges WHERE q = ?', (path,)) c.execute('SELECT value FROM challenges WHERE q = ?', (path,))
result = c.fetchone() result = c.fetchone()
if result: if result:
return result[0] return result
else: else:
return 'NO DATA - ' + socket.gethostname() return ['NO DATA - ' + socket.gethostname()]
def add_challenge(db, path, value): def add_challenge(db, path, value):
c = db.cursor() c = db.cursor()
@ -42,8 +42,8 @@ def main_query():
stdout.write("DATA\t" + qname + "\t" + qclass + "\t" + qtype + "\t300\t" + id + "\t") stdout.write("DATA\t" + qname + "\t" + qclass + "\t" + qtype + "\t300\t" + id + "\t")
stdout.write("example.com. example.example.com. 1 1d 2h 4w 1h\n") stdout.write("example.com. example.example.com. 1 1d 2h 4w 1h\n")
else: else:
stdout.write("DATA\t" + qname + "\t" + qclass + "\tTXT\t1\t" + id + "\t") for i in get_challenge(db, qname.lower()):
stdout.write('"' + get_challenge(db, qname.lower()) + '"\n') stdout.write("DATA\t" + qname + "\t" + qclass + "\tTXT\t1\t" + id + '\t"' + i + '"\n')
stdout.write("LOG\tletsencrypt pipe handler got query: '" + data + "'\n") stdout.write("LOG\tletsencrypt pipe handler got query: '" + data + "'\n")
stdout.write("END\n") stdout.write("END\n")
stdout.flush() stdout.flush()