Fix DNS issues with CNAME resolution

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