new
This commit is contained in:
@ -7,6 +7,7 @@ import dns.rdtypes.IN.A
|
||||
import dns.tsigkeyring
|
||||
import dns.rcode
|
||||
import threading
|
||||
import time
|
||||
from logger import Logger
|
||||
|
||||
class LocalDnsHandlerException(Exception):
|
||||
@ -14,14 +15,20 @@ class LocalDnsHandlerException(Exception):
|
||||
Exception.__init__(self, msg)
|
||||
|
||||
class DnsHandler(threading.Thread):
|
||||
def __init__(self, msgQueue, tsigKey, nsAddress, ttl):
|
||||
def __init__(self, msgQueue, dnsDummy, tsigKey, nsAddress, ttl, actionlogDir):
|
||||
threading.Thread.__init__(self)
|
||||
self.msgQueue = msgQueue
|
||||
self.dnsDummy = dnsDummy
|
||||
self.nsAddress = nsAddress
|
||||
self.ttl = ttl
|
||||
self.keyring = dns.tsigkeyring.from_text(tsigKey)
|
||||
self.actionlogDir = actionlogDir
|
||||
self.setDaemon(True)
|
||||
|
||||
def writeActionlog(self, dynid, name, zone, oldAddr, newAddr):
|
||||
f = open("%s/%s" % (self.actionlogDir, dynid), 'a')
|
||||
f.write("%d %s.%s %s %s\n" % (time.time(), name, zone, oldAddr, newAddr))
|
||||
f.close()
|
||||
|
||||
def run(self):
|
||||
while(True):
|
||||
@ -31,6 +38,7 @@ class DnsHandler(threading.Thread):
|
||||
try:
|
||||
self.deleteARR(msg.dynid, msg.name, msg.zone)
|
||||
self.insertARR(msg.dynid, msg.name, msg.zone, msg.address)
|
||||
self.writeActionlog(msg.dynid, msg.name, msg.zone, msg.addressInDns, msg.address)
|
||||
Logger.log("Update: %s, %s.%s, %s -> %s" %
|
||||
(msg.dynid, msg.name, msg.zone, msg.addressInDns, msg.address))
|
||||
msg.addressInDns = msg.address
|
||||
@ -39,6 +47,8 @@ class DnsHandler(threading.Thread):
|
||||
|
||||
|
||||
def insertARR(self, dynid, name, zone, address):
|
||||
if self.dnsDummy:
|
||||
return
|
||||
# send A-RR insertion for ip to DNS server
|
||||
rr = dns.rdtypes.IN.A.A(dns.rdataclass.IN, dns.rdatatype.A, address)
|
||||
u = dns.update.Update(zone, keyring=self.keyring)
|
||||
@ -51,6 +61,8 @@ class DnsHandler(threading.Thread):
|
||||
|
||||
|
||||
def deleteARR(self, dynid, name, zone):
|
||||
if self.dnsDummy:
|
||||
return
|
||||
# send A-RR deletion for ip to DNS server
|
||||
u = dns.update.Update(zone, keyring=self.keyring)
|
||||
u.delete(name)
|
||||
|
Reference in New Issue
Block a user