mirror of
https://github.com/adulau/pdns-qof-server.git
synced 2024-11-22 18:17:06 +00:00
Using CherryPy as backend instead of Tornado
This commit is contained in:
parent
a7e3cdc77c
commit
039c4bd45d
1 changed files with 21 additions and 23 deletions
|
@ -15,9 +15,7 @@
|
||||||
# Copyright (c) 2013 Alexandre Dulaunoy - a@foo.be
|
# Copyright (c) 2013 Alexandre Dulaunoy - a@foo.be
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import tornado.escape
|
import cherrypy
|
||||||
import tornado.ioloop
|
|
||||||
import tornado.web
|
|
||||||
|
|
||||||
import iptools
|
import iptools
|
||||||
import redis
|
import redis
|
||||||
|
@ -105,36 +103,35 @@ def JsonQOF(rrfound = None, RemoveDuplicate=True):
|
||||||
rrqof = rrqof + json.dumps(rr) + "\n"
|
rrqof = rrqof + json.dumps(rr) + "\n"
|
||||||
return rrqof
|
return rrqof
|
||||||
|
|
||||||
class InfoHandler(tornado.web.RequestHandler):
|
class Root:
|
||||||
def get(self):
|
def info(self):
|
||||||
response = { 'version': 'git',
|
response = { 'version': 'git','software': 'pdns-qof-server' }
|
||||||
'software': 'pdns-qof-server' }
|
return json.dumps(response)
|
||||||
self.write(response)
|
|
||||||
|
|
||||||
class QueryHandler(tornado.web.RequestHandler):
|
def query(self, q):
|
||||||
def get(self, q):
|
|
||||||
print ("query: "+q)
|
print ("query: "+q)
|
||||||
|
o=""
|
||||||
if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q):
|
if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q):
|
||||||
for x in getAssociatedRecords(q):
|
for x in getAssociatedRecords(q):
|
||||||
self.write(JsonQOF(getRecord(x)))
|
o = o + JsonQOF(getRecord(x))
|
||||||
else:
|
else:
|
||||||
self.write(JsonQOF(getRecord(t = q.strip())))
|
o = o + JsonQOF(getRecord(t = q.strip()))
|
||||||
|
return o
|
||||||
|
|
||||||
class FullQueryHandler(tornado.web.RequestHandler):
|
def fquery(self, q):
|
||||||
def get(self, q):
|
|
||||||
print ("fquery: "+q)
|
print ("fquery: "+q)
|
||||||
|
o=""
|
||||||
if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q):
|
if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q):
|
||||||
for x in getAssociatedRecords(q):
|
for x in getAssociatedRecords(q):
|
||||||
self.write(JsonQOF(getRecord(x)))
|
o = o + JsonQOF(getRecord(x))
|
||||||
else:
|
else:
|
||||||
for x in getAssociatedRecords(q):
|
for x in getAssociatedRecords(q):
|
||||||
self.write(JsonQOF(getRecord(t = x.strip())))
|
o = o + JsonQOF(getRecord(t = x.strip()))
|
||||||
|
return o
|
||||||
|
|
||||||
application = tornado.web.Application([
|
info.exposed = True
|
||||||
(r"/query/(.*)",QueryHandler),
|
query.exposed = True
|
||||||
(r"/fquery/(.*)",FullQueryHandler),
|
fquery.exposed = True
|
||||||
(r"/info", InfoHandler)
|
|
||||||
])
|
|
||||||
|
|
||||||
if __name__ == "test":
|
if __name__ == "test":
|
||||||
|
|
||||||
|
@ -147,6 +144,7 @@ if __name__ == "test":
|
||||||
else:
|
else:
|
||||||
print (JsonQOF(getRecord(t = q)))
|
print (JsonQOF(getRecord(t = q)))
|
||||||
else:
|
else:
|
||||||
application.listen(8888)
|
root = Root()
|
||||||
tornado.ioloop.IOLoop.instance().start()
|
cherrypy.config.update({ 'server.socket_port': 8887, 'request.show_tracebacks': False, 'server.thread_pool': 30, 'server.socket_host': '::'})
|
||||||
|
cherrypy.quickstart(root)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue