Fix DNS issues with CNAME resolution

parent c11570b3
......@@ -120,6 +120,7 @@ class domotikaService(service.Service):
dmdb.initialize(self.config)
def isStarted(self):
log.debug("isStarted() called")
self.isConfigured()
def isConfigured(self):
......@@ -141,7 +142,6 @@ class domotikaService(service.Service):
self.thermoprgloop=txcron.ScheduledCall(self.thermoProgramLoop)
self.thermoprgloop.start(CronSchedule('00 * * * *'))
self.actiontimer.start(int(self.config.get("general", "action_status_timer")))
self.timer.start(int(self.config.get("ikapserver", "timeupdates")))
if self.config.get("general", "timeserver").lower() in ['yes','y','1','true', 'on']:
......@@ -155,7 +155,6 @@ class domotikaService(service.Service):
flags=task.LoopingCall(self.cleanFlags)
flags.start(1)
self.startUPNPService()
self.startAsteriskServices()
self.initializeCrontab()
......@@ -168,6 +167,7 @@ class domotikaService(service.Service):
self.startVLC()
self.startOpenWeatherMap()
self.initialized=True
log.debug("isConfigured() called")
def startOpenWeatherMap(self):
weather.OWMWeather(self.config.get("geo", "latitude"),
......
......@@ -35,13 +35,15 @@ TO = '127.0.0.1'
TTL = 60
class DNSServerFactory(server.DNSServerFactory):
def gotResolverResponse(self, (ans, auth, add), protocol, message, address):
def gotResolverResponse(self, records, protocol, message, address):
ans, auth, add = records
ans2=[]
qname = message.queries[0].name.name
if self.dmhost in qname:
for answer in ans:
if answer.type != dns.A:
continue
if not answer.name.name.endswith(self.dmhost):
if (answer.type != dns.A and answer.type != dns.CNAME) or not answer.name.name.endswith(self.dmhost):
if answer.type != dns.CNAME and answer.type != dns.A:
ans2.append(answer)
continue
to=self.dmip
......@@ -53,14 +55,18 @@ class DNSServerFactory(server.DNSServerFactory):
to=netifaces.ifaddresses(self.dmiface+':0')[2][0]['addr']
except:
to='10.224.207.1'
answer.payload.address = socket.inet_aton(to)
answer.payload.ttl = TTL
answer.type = dns.A
answer.payload = dns.Record_A(to, TTL)
#answer.payload.address = socket.inet_aton(to)
#answer.payload.ttl = TTL
ans2.append(answer)
if len(ans2) > 0:
ans = ans2
args = (self, (ans, auth, add), protocol, message, address)
return server.DNSServerFactory.gotResolverResponse(*args)
def startDNS(host="q.unixmedia.net", ip="auto", iface="eth0", servers=[('8.8.8.8', 53)]):
def startDNS(host="q.nexlab.net", ip="auto", iface="eth0", servers=[('8.8.8.8', 53)]):
verbosity = 0
resolver = client.Resolver(servers=servers)
factory = DNSServerFactory(clients=[resolver], verbose=verbosity)
......@@ -75,5 +81,5 @@ def startDNS(host="q.unixmedia.net", ip="auto", iface="eth0", servers=[('8.8.8.8
if __name__ == '__main__':
startDNS('q.unixmedia.net', 'auto')
startDNS('q.nexlab.net', 'auto')
reactor.run()
......@@ -26,7 +26,7 @@ from twisted.internet import epollreactor
epollreactor.install()
from twisted.internet import reactor, ssl, protocol
from twisted.internet import reactor, ssl, protocol, endpoints
from twisted.application import service, internet, app, reactors
from twisted.web import server #, soap
import logging, time, sys, os
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment