fixed some bugs

This commit is contained in:
nd 2019-10-13 17:44:37 +02:00
parent 3f14417641
commit bab37262b3
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9

View file

@ -1,14 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys import sys
from sys import stdin, stdout from sys import stdin, stdout
import logging import socket
import sqlite3 import sqlite3
def setupdb(): def setupdb():
conn = sqlite3.connect('{{ powerdns.letsencrypthandler.dbpath }}') 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, q TEXT NOT NULL PRIMARY KEY,
value TEXT, value TEXT,
timestamp DEFAULT (strftime('%s','now')) timestamp DEFAULT (strftime('%s','now'))
) )
@ -23,11 +23,11 @@ def get_challenge(db, path):
if result: if result:
return result[0] return result[0]
else: else:
return 'NO DATA' return 'NO DATA - ' + socket.gethostname()
def add_challenge(db, path, value): def add_challenge(db, path, value):
c = db.cursor() c = db.cursor()
c.execute('INSERT INTO challenges (q, value) VALUES(?, ?)', (path,value,)) c.execute('REPLACE INTO challenges (q, value) VALUES(?, ?)', (path,value,))
db.commit() db.commit()
def main_query(): def main_query():
@ -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\t300\t" + id + "\t") stdout.write("DATA\t" + qname + "\t" + qclass + "\tTXT\t1\t" + id + "\t")
stdout.write('"' + get_challenge(db, qname) + '"\n') stdout.write('"' + get_challenge(db, qname.lower()) + '"\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()