added funktion to add values
This commit is contained in:
parent
c2a6dfb887
commit
3f14417641
1 changed files with 15 additions and 13 deletions
|
|
@ -1,15 +1,9 @@
|
|||
#!/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("""
|
||||
|
|
@ -22,15 +16,20 @@ def setupdb():
|
|||
conn.commit()
|
||||
return conn
|
||||
|
||||
def get_secret(db, path):
|
||||
def get_challenge(db, path):
|
||||
c = db.cursor()
|
||||
c.execute('SELECT * FROM challenges WHERE q = ?', (path,))
|
||||
c.execute('SELECT value FROM challenges WHERE q = ?', (path,))
|
||||
result = c.fetchone()
|
||||
if result:
|
||||
return result
|
||||
return result[0]
|
||||
else:
|
||||
return 'NO DATA'
|
||||
|
||||
def add_challenge(db, path, value):
|
||||
c = db.cursor()
|
||||
c.execute('INSERT INTO challenges (q, value) VALUES(?, ?)', (path,value,))
|
||||
db.commit()
|
||||
|
||||
def main_query():
|
||||
db = setupdb()
|
||||
data = stdin.readline()
|
||||
|
|
@ -44,16 +43,19 @@ def main_query():
|
|||
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('"' + get_challenge(db, qname) + '"\n')
|
||||
stdout.write("LOG\tletsencrypt pipe handler got query: '" + data + "'\n")
|
||||
stdout.write("END\n")
|
||||
stdout.flush()
|
||||
|
||||
def main_add_challange(db):
|
||||
def main_add_challenge():
|
||||
db = setupdb()
|
||||
pass
|
||||
add_challenge(db ,sys.argv[1], sys.argv[2])
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 3:
|
||||
main_add_challenge()
|
||||
else:
|
||||
main_query()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue