Initial commit
This commit is contained in:
commit
c2a6dfb887
5 changed files with 96 additions and 0 deletions
60
templates/pdns-letsencrypt.py.j2
Normal file
60
templates/pdns-letsencrypt.py.j2
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
from sys import stdin, stdout
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
def parse_args(args):
|
||||
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('--debug', action='store_true', default=False, help='Enable debugging output')
|
||||
return parser.parse_args(args)
|
||||
|
||||
def setupdb():
|
||||
conn = sqlite3.connect('{{ powerdns.letsencrypthandler.dbpath }}')
|
||||
conn.executescript("""
|
||||
CREATE TABLE IF NOT EXISTS challenges (
|
||||
q TEXT,
|
||||
value TEXT,
|
||||
timestamp DEFAULT (strftime('%s','now'))
|
||||
)
|
||||
""")
|
||||
conn.commit()
|
||||
return conn
|
||||
|
||||
def get_secret(db, path):
|
||||
c = db.cursor()
|
||||
c.execute('SELECT * FROM challenges WHERE q = ?', (path,))
|
||||
result = c.fetchone()
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
return 'NO DATA'
|
||||
|
||||
def main_query():
|
||||
db = setupdb()
|
||||
data = stdin.readline()
|
||||
stdout.write("OK\tpdns letsencrypt handler\n")
|
||||
stdout.flush()
|
||||
while True:
|
||||
data = stdin.readline().strip()
|
||||
kind, qname, qclass, qtype, id, ip = data.split("\t")
|
||||
if qtype == "SOA":
|
||||
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")
|
||||
else:
|
||||
stdout.write("DATA\t" + qname + "\t" + qclass + "\tTXT\t300\t" + id + "\t")
|
||||
stdout.write('"' + get_secret(db, qname) + '"\n')
|
||||
stdout.write("LOG\tletsencrypt pipe handler got query: '" + data + "'\n")
|
||||
stdout.write("END\n")
|
||||
stdout.flush()
|
||||
|
||||
def main_add_challange(db):
|
||||
db = setupdb()
|
||||
pass
|
||||
|
||||
def main():
|
||||
main_query()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue