This commit is contained in:
Wolfgang Hottgenroth 2007-11-16 17:45:39 +01:00
parent 825276e9b2
commit 3f3db5fcf7
3 changed files with 52 additions and 7 deletions

View File

@ -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)

33
server/XmlRpcReceiver.py Normal file
View File

@ -0,0 +1,33 @@
import threading
import time
import Event
from logger import Logger
class MathServer(SimpleXMLRPCServer):
def _dispatch(self, method, params):
try:
# We are forcing the 'export_' prefix on methods that are
# callable through XML-RPC to prevent potential security
# problems
func = getattr(self, 'export_' + method)
except AttributeError:
raise Exception('method "%s" is not supported' % method)
else:
return func(*params)
def export_add(self, x, y):
return x + y
class XmlRpcReceiver(threading.Thread):
def __init__(self, xmlRpcRecvAddr):
threading.Thread.__init__(self)
self.xmlRpcRecvAddr = xmlRpcRecvAddr
self.setDaemon(True)
def run(self):
server = MathServer(self.xmlRpcAddr)
server.serve_forever()

View File

@ -18,17 +18,18 @@ import Event
MSG_TIME_CORRIDOR = 120
EVENT_LIFE_TIME = 300
EVENT_LIFE_TIME = 5
NULL_ADDRESS = '0.0.0.0'
TTL = 120
EXPIRY_PERIOD = 300
EXPIRY_PERIOD = 10
NAMESERVER = '88.198.170.2'
TSIGKEY = { "monitoring." : "+xLH8GuZnEgBljuIEM/iDA==" }
PID_FILE = "/var/db/yadyn/yadyn.pid"
ENTRIES_FILE = "/var/db/yadyn/entries"
STATUSMAP_FILE = "/var/db/yadyn/statusMap"
ACTIONLOG_DIR = "/var/db/yadyn/actionlog"
ADMIN_PWD = 'test123'
DEBUG = False
DNS_DUMMY = True
DEBUG = True
@ -65,7 +66,7 @@ try:
dynHandler.start()
Logger.debug("DynHandler started")
dnsHandler = DnsHandler.DnsHandler(dnsq, TSIGKEY, NAMESERVER, TTL)
dnsHandler = DnsHandler.DnsHandler(dnsq, DNS_DUMMY, TSIGKEY, NAMESERVER, TTL, ACTIONLOG_DIR)
dnsHandler.start()
Logger.debug("DnsHandler started")
@ -87,6 +88,5 @@ try:
time.sleep(10)
finally:
entries.close()
statusMap.close()
Logger.debug("Shelves closed")
Logger.log("yadyn terminating")