feat: first prototype, "works on my machine" edition
This commit is contained in:
parent
fedf572107
commit
f6d23e0f66
5 changed files with 132 additions and 0 deletions
46
main.py
Normal file
46
main.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import datetime
|
||||
import logging
|
||||
import MySQLdb as m
|
||||
import dns.resolver
|
||||
|
||||
def read_config():
|
||||
return (['example.com'],'localhost',3306,'test','testpass','pdns','wile')
|
||||
|
||||
|
||||
def main():
|
||||
(zones, host, port, username, password, database, myname) = read_config()
|
||||
db = m.connect(host, username, password, database)
|
||||
for zone in zones:
|
||||
logging.debug(f"checking zone {zone}")
|
||||
# try to resolve dnskey.{zone} on all nameservers
|
||||
# dammit, my testserver is running on a weird port
|
||||
r = dns.resolver.Resolver()
|
||||
nsarr = ['127.0.0.1:10053']
|
||||
expected = None
|
||||
for ns in nsarr:
|
||||
# r.nameservers = [ns]
|
||||
answer = r.resolve(qname=zone, rdtype='DNSKEY', tcp=False, search=ns)
|
||||
print(f"{answer=}")
|
||||
if not expected:
|
||||
expected = answer.rrset.to_text()
|
||||
print(f"set {expected=}")
|
||||
else:
|
||||
if answer.rrset.to_text() != expected:
|
||||
print(f"{answer.rrset.to_text()=} differs from {expected=}")
|
||||
# I'm very confident this is more complicated than it needs to be...
|
||||
db.query(f"""SELECT id,content FROM records WHERE type='SOA' AND name='{zone}'""")
|
||||
result = db.store_result()
|
||||
row = result.fetch_row()
|
||||
(id,content) = row[0]
|
||||
carr = content.split()
|
||||
newdatestr = datetime.datetime.today().strftime("%Y%m%d01")
|
||||
if newdatestr[:8] == carr[2][:8]:
|
||||
count = int(carr[2][8:])
|
||||
newcount = count + 1
|
||||
newdatestr = f"{newdatestr[:8]}{newcount:02d}"
|
||||
carr[2] = newdatestr
|
||||
db.query(f"""UPDATE records SET content = '{' '.join(carr)}' WHERE id={id}""")
|
||||
db.commit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue