Exemplo n.º 1
0
 def __init__(self, authorities=None, caches=None, clients=None, verbose=0):
     global reload_redirects
     
     self.RM = RedirectManager()
     self.RM.reload_redirects = reload_redirects
     self.no_logging = no_logging
     
     DNSServerFactory.__init__(self, authorities=authorities, caches=caches, clients=clients, verbose=verbose)
Exemplo n.º 2
0
 def gotResolverResponse(self, response, protocol, message,
                         address):
     args = (self, response, protocol, message, address)
     _q_s.logs.info([
         'servers', {
             'server': 'dns_server',
             'action': 'connection',
             'ip': address[0],
             'port': address[1]
         }
     ])
     try:
         for items in response:
             for item in items:
                 _q_s.logs.info([
                     'servers', {
                         'server': 'dns_server',
                         'action': 'query',
                         'ip': address[0],
                         'port': address[1],
                         'payload': item.payload
                     }
                 ])
     except Exception as e:
         _q_s.logs.error([
             'errors', {
                 'server': 'dns_server',
                 'error': 'gotResolverResponse',
                 'type': 'error -> ' + repr(e)
             }
         ])
     return DNSServerFactory.gotResolverResponse(*args)
Exemplo n.º 3
0
def main(reactor, duration):
    concurrency = 10

    controller = DNSServerFactory([hosts.Resolver()])
    port = reactor.listenUDP(0, DNSDatagramProtocol(controller))
    # Have queries time out no sooner than the duration of this benchmark so
    # we don't have to deal with retries or timeout errors.
    client = Client(reactor, port.getHost().port, duration)
    d = client.run(concurrency, duration)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ign: passthrough)
        return d

    d.addBoth(cleanup)
    return d
Exemplo n.º 4
0
def makeService(config, reactor=reactor):
    parent = MultiService()
    basedir = FilePath(os.path.expanduser(config["basedir"]))
    basedir.makedirs(ignoreExistingDirectory=True)
    basedir.chmod(0o700)

    data = Data(basedir.child("config.json"))

    dns_server = DNSServerFactory(verbose=0)
    s1 = UDPServer(int(config["dns-port"]), dns.DNSDatagramProtocol(dns_server),
                   interface=config["dns-interface"])
    s1.setServiceParent(parent)
    s2 = TCPServer(int(config["dns-port"]), dns_server,
                   interface=config["dns-interface"])
    s2.setServiceParent(parent)

    s = Server(data, dns_server)
    s.update_records()

    certFile = basedir.child("tub.data").path
    #furlFile = basedir.child("server.furl").path
    t = Tub(certFile=certFile)
    t.setOption("keepaliveTimeout", 60) # ping after 60s of idle
    t.setOption("disconnectTimeout", 5*60) # disconnect/reconnect after 5m
    #t.setOption("logLocalFailures", True)
    #t.setOption("logRemoteFailures", True)
    #t.unsafeTracebacks = True
    fp = config["foolscap-port"]
    if not fp.startswith("tcp:"):
        raise usage.UsageError("I don't know how to handle non-tcp foolscap-port=")
    port = int(fp.split(":")[1])
    assert port > 1
    t.listenOn(fp)
    t.setLocation("tcp:%s:%d" % (config["hostname"], port))

    c = Controller(data, s)
    cf = t.registerReference(c, furlFile=basedir.child("controller.furl").path)
    furl_prefix = cf[:cf.rfind("/")+1]
    c.set_furl_prefix(furl_prefix)
    t.registerNameLookupHandler(c.lookup)

    t.setServiceParent(parent)
    return parent
Exemplo n.º 5
0
                        default="http")
    args = parser.parse_args()

    if args.type == "http":
        root = Root()
        factory = Site(root)
        httpPort = reactor.listenTCP(0, factory)
        contextFactory = ssl_context_factory()
        httpsPort = reactor.listenSSL(0, factory, contextFactory)

        def print_listening():
            httpHost = httpPort.getHost()
            httpsHost = httpsPort.getHost()
            httpAddress = "http://%s:%d" % (httpHost.host, httpHost.port)
            httpsAddress = "https://%s:%d" % (httpsHost.host, httpsHost.port)
            print(httpAddress)
            print(httpsAddress)

    elif args.type == "dns":
        clients = [MockDNSResolver()]
        factory = DNSServerFactory(clients=clients)
        protocol = dns.DNSDatagramProtocol(controller=factory)
        listener = reactor.listenUDP(0, protocol)

        def print_listening():
            host = listener.getHost()
            print("%s:%s" % (host.host, host.port))

    reactor.callWhenRunning(print_listening)
    reactor.run()
Exemplo n.º 6
0
 def handleQuery(self, message, protocol, address):
     print "Got", message.toStr(), protocol, address
     return DNSServerFactory.handleQuery(self, message, protocol, address)
Exemplo n.º 7
0
 def connectionMade(self, protocol):
     print "Got a connection", protocol
     return DNSServerFactory.connectionMade(self, protocol)
Exemplo n.º 8
0
    def __init__(self, authorities = None, caches = None,
        clients = None, verbose = 0):

        r=DNSServerFactory.__init__(self, authorities, caches, clients, verbose)
        return r
Exemplo n.º 9
0
 def handleQuery(self, message, protocol, address):
     print "Got", message.toStr(), protocol, address
     return DNSServerFactory.handleQuery(self, message, protocol, address)
Exemplo n.º 10
0
 def connectionMade(self, protocol):
     print "Got a connection", protocol
     return DNSServerFactory.connectionMade(self, protocol)
Exemplo n.º 11
0
    def __init__(self, authorities=None, caches=None, clients=None, verbose=0):

        r = DNSServerFactory.__init__(self, authorities, caches, clients,
                                      verbose)
        return r
Exemplo n.º 12
0
def server_init(options, reactor):

    import transports
    #    from twisted.internet import reactor

    if (options.interface == 'stdio'):
        import interfaces
        iface = interfaces.stdiface()
        stdio.StandardIO(iface)

    elif (options.interface == 'tun'):
        import interfaces
        iface = interfaces.tuniface(reactor)
#        f, s = iface.ifaceSockets()

    else:
        print "Currently not supported. Exiting"
        sys.exit(0)

#    import transports

#    from twisted.internet import reactor
    if options.transport == 'tcp':
        transportLayer = transports.tcpTransportFactory(iface, reactor)
        iface.getTransport(transportLayer)
        reactor.listenTCP(options.port, transportLayer)
    elif options.transport == 'http':
        from twisted.web.resource import Resource
        from twisted.web.server import Site

        transportLayer = transports.asymQueue(iface)

        root = Resource()
        root.putChild("warpzone", transports.httpServe(iface, transportLayer))
        site = Site(root)
        iface.getTransport(transportLayer)
        reactor.listenTCP(options.port, site)

    elif options.transport == 'dns':
        from twisted.names.server import DNSServerFactory
        from twisted.names import dns
        transportLayer = transports.dnsServer(iface, options)
        factory = DNSServerFactory(clients=[transportLayer])
        protocol = dns.DNSDatagramProtocol(controller=factory)

        iface.getTransport(transportLayer)

        reactor.listenUDP(53, protocol)
        reactor.listenTCP(53, factory)
    elif options.transport == 'udp':
        transportLayer = transports.udpTransportHandler(
            iface, reactor, None, None)
        iface.getTransport(transportLayer)
        reactor.listenUDP(options.port, transportLayer)
    elif options.transport == 'icmp':
        transportLayer = transports.icmpTransportHandler(
            iface, reactor, options)
        iface.getTransport(transportLayer)

    else:
        print "Bad transport layer selected"
        sys.exit(0)
Exemplo n.º 13
0
Arquivo: protocol.py Projeto: uda/ddns
 def __init__(self, redis_client, **kwargs):
     kwargs['caches'] = [cache.CacheResolver()]
     kwargs['clients'] = [DynamicResolver(redis_client)]
     DNSServerFactory.__init__(self, **kwargs)
Exemplo n.º 14
0
 def __init__(self):
   self.custom = CustomResolver()
   DNSServerFactory.__init__(self, authorities=None,
                                   #caches=[cache.CacheResolver()], behaves a bit strange on non-existing domains
                                   clients=[self.custom])
Exemplo n.º 15
0
            for data, metadata in records.items():
                if type == A:
                    payload = dns.Record_A(data)
                elif type == CNAME:
                    # TODO: Add proper CNAME support that sends corresponding "A" records.
                    payload = dns.Record_CNAME(data)
                elif type == MX:
                    payload = dns.Record_MX(metadata["preference"], data)
                elif type == NS:
                    payload = dns.Record_NS(data)
                header = dns.RRHeader(name,
                                      type=type,
                                      payload=payload,
                                      ttl=metadata["ttl"],
                                      auth=True)
                results.append(header)

        return defer.succeed((results, authority, additional))
        #return defer.fail(failure.Failure(dns.DomainError(name)))


authorities = [CassandraNamesResolver()]
factory = DNSServerFactory(authorities, verbose=True)
protocol = dns.DNSDatagramProtocol(factory)

if __name__ == '__main__':
    log.startLogging(sys.stdout)
    reactor.listenUDP(1053, protocol)
    reactor.listenTCP(1053, factory)
    reactor.run()