File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/names.zip
Back
PK y�Z.{sa�# �# srvconnect.pynu �[��� # -*- test-case-name: twisted.names.test.test_srvconnect -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. import random from zope.interface import implementer from twisted.internet import error, interfaces from twisted.names import client, dns from twisted.names.error import DNSNameError from twisted.python.compat import nativeString class _SRVConnector_ClientFactoryWrapper: def __init__(self, connector, wrappedFactory): self.__connector = connector self.__wrappedFactory = wrappedFactory def startedConnecting(self, connector): self.__wrappedFactory.startedConnecting(self.__connector) def clientConnectionFailed(self, connector, reason): self.__connector.connectionFailed(reason) def clientConnectionLost(self, connector, reason): self.__connector.connectionLost(reason) def __getattr__(self, key): return getattr(self.__wrappedFactory, key) @implementer(interfaces.IConnector) class SRVConnector: """ A connector that looks up DNS SRV records. RFC 2782 details how SRV records should be interpreted and selected for subsequent connection attempts. The algorithm for using the records' priority and weight is implemented in L{pickServer}. @ivar servers: List of candidate server records for future connection attempts. @type servers: L{list} of L{dns.Record_SRV} @ivar orderedServers: List of server records that have already been tried in this round of connection attempts. @type orderedServers: L{list} of L{dns.Record_SRV} """ stopAfterDNS = 0 def __init__( self, reactor, service, domain, factory, protocol="tcp", connectFuncName="connectTCP", connectFuncArgs=(), connectFuncKwArgs={}, defaultPort=None, ): """ @param domain: The domain to connect to. If passed as a text string, it will be encoded using C{idna} encoding. @type domain: L{bytes} or L{str} @param defaultPort: Optional default port number to be used when SRV lookup fails and the service name is unknown. This should be the port number associated with the service name as defined by the IANA registry. @type defaultPort: L{int} """ self.reactor = reactor self.service = service self.domain = None if domain is None else dns.domainString(domain) self.factory = factory self.protocol = protocol self.connectFuncName = connectFuncName self.connectFuncArgs = connectFuncArgs self.connectFuncKwArgs = connectFuncKwArgs self._defaultPort = defaultPort self.connector = None self.servers = None # list of servers already used in this round: self.orderedServers = None def connect(self): """Start connection to remote server.""" self.factory.doStart() self.factory.startedConnecting(self) if not self.servers: if self.domain is None: self.connectionFailed( error.DNSLookupError("Domain is not defined."), ) return d = client.lookupService( "_%s._%s.%s" % ( nativeString(self.service), nativeString(self.protocol), nativeString(self.domain), ), ) d.addCallbacks(self._cbGotServers, self._ebGotServers) d.addCallback(lambda x, self=self: self._reallyConnect()) if self._defaultPort: d.addErrback(self._ebServiceUnknown) d.addErrback(self.connectionFailed) elif self.connector is None: self._reallyConnect() else: self.connector.connect() def _ebGotServers(self, failure): failure.trap(DNSNameError) # Some DNS servers reply with NXDOMAIN when in fact there are # just no SRV records for that domain. Act as if we just got an # empty response and use fallback. self.servers = [] self.orderedServers = [] def _cbGotServers(self, result): answers, auth, add = result if ( len(answers) == 1 and answers[0].type == dns.SRV and answers[0].payload and answers[0].payload.target == dns.Name(b".") ): # decidedly not available raise error.DNSLookupError( "Service %s not available for domain %s." % (repr(self.service), repr(self.domain)) ) self.servers = [] self.orderedServers = [] for a in answers: if a.type != dns.SRV or not a.payload: continue self.orderedServers.append(a.payload) def _ebServiceUnknown(self, failure): """ Connect to the default port when the service name is unknown. If no SRV records were found, the service name will be passed as the port. If resolving the name fails with L{error.ServiceNameUnknownError}, a final attempt is done using the default port. """ failure.trap(error.ServiceNameUnknownError) self.servers = [dns.Record_SRV(0, 0, self._defaultPort, self.domain)] self.orderedServers = [] self.connect() def pickServer(self): """ Pick the next server. This selects the next server from the list of SRV records according to their priority and weight values, as set out by the default algorithm specified in RFC 2782. At the beginning of a round, L{servers} is populated with L{orderedServers}, and the latter is made empty. L{servers} is the list of candidates, and L{orderedServers} is the list of servers that have already been tried. First, all records are ordered by priority and weight in ascending order. Then for each priority level, a running sum is calculated over the sorted list of records for that priority. Then a random value between 0 and the final sum is compared to each record in order. The first record that is greater than or equal to that random value is chosen and removed from the list of candidates for this round. @return: A tuple of target hostname and port from the chosen DNS SRV record. @rtype: L{tuple} of native L{str} and L{int} """ assert self.servers is not None assert self.orderedServers is not None if not self.servers and not self.orderedServers: # no SRV record, fall back.. return nativeString(self.domain), self.service if not self.servers and self.orderedServers: # start new round self.servers = self.orderedServers self.orderedServers = [] assert self.servers self.servers.sort(key=lambda record: (record.priority, record.weight)) minPriority = self.servers[0].priority index = 0 weightSum = 0 weightIndex = [] for x in self.servers: if x.priority == minPriority: weightSum += x.weight weightIndex.append((index, weightSum)) index += 1 rand = random.randint(0, weightSum) for index, weight in weightIndex: if weight >= rand: chosen = self.servers[index] del self.servers[index] self.orderedServers.append(chosen) return str(chosen.target), chosen.port raise RuntimeError(f"Impossible {self.__class__.__name__} pickServer result.") def _reallyConnect(self): if self.stopAfterDNS: self.stopAfterDNS = 0 return self.host, self.port = self.pickServer() assert self.host is not None, "Must have a host to connect to." assert self.port is not None, "Must have a port to connect to." connectFunc = getattr(self.reactor, self.connectFuncName) self.connector = connectFunc( self.host, self.port, _SRVConnector_ClientFactoryWrapper(self, self.factory), *self.connectFuncArgs, **self.connectFuncKwArgs, ) def stopConnecting(self): """Stop attempting to connect.""" if self.connector: self.connector.stopConnecting() else: self.stopAfterDNS = 1 def disconnect(self): """Disconnect whatever our are state is.""" if self.connector is not None: self.connector.disconnect() else: self.stopConnecting() def getDestination(self): assert self.connector return self.connector.getDestination() def connectionFailed(self, reason): self.factory.clientConnectionFailed(self, reason) self.factory.doStop() def connectionLost(self, reason): self.factory.clientConnectionLost(self, reason) self.factory.doStop() PK y�Z��}� � tap.pynu �[��� # -*- test-case-name: twisted.names.test.test_tap -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Domain Name Server """ import os import traceback from twisted.application import internet, service from twisted.names import authority, dns, secondary, server from twisted.python import usage class Options(usage.Options): optParameters = [ ["interface", "i", "", "The interface to which to bind"], ["port", "p", "53", "The port on which to listen"], [ "resolv-conf", None, None, "Override location of resolv.conf (implies --recursive)", ], ["hosts-file", None, None, "Perform lookups with a hosts file"], ] optFlags = [ ["cache", "c", "Enable record caching"], ["recursive", "r", "Perform recursive lookups"], ["verbose", "v", "Log verbosely"], ] compData = usage.Completions( optActions={"interface": usage.CompleteNetInterfaces()} ) zones = None zonefiles = None def __init__(self): usage.Options.__init__(self) self["verbose"] = 0 self.bindfiles = [] self.zonefiles = [] self.secondaries = [] def opt_pyzone(self, filename): """Specify the filename of a Python syntax zone definition""" if not os.path.exists(filename): raise usage.UsageError(filename + ": No such file") self.zonefiles.append(filename) def opt_bindzone(self, filename): """Specify the filename of a BIND9 syntax zone definition""" if not os.path.exists(filename): raise usage.UsageError(filename + ": No such file") self.bindfiles.append(filename) def opt_secondary(self, ip_domain): """Act as secondary for the specified domain, performing zone transfers from the specified IP (IP/domain) """ args = ip_domain.split("/", 1) if len(args) != 2: raise usage.UsageError("Argument must be of the form IP[:port]/domain") address = args[0].split(":") if len(address) == 1: address = (address[0], dns.PORT) else: try: port = int(address[1]) except ValueError: raise usage.UsageError( f"Specify an integer port number, not {address[1]!r}" ) address = (address[0], port) self.secondaries.append((address, [args[1]])) def opt_verbose(self): """Increment verbosity level""" self["verbose"] += 1 def postOptions(self): if self["resolv-conf"]: self["recursive"] = True self.svcs = [] self.zones = [] for f in self.zonefiles: try: self.zones.append(authority.PySourceAuthority(f)) except Exception: traceback.print_exc() raise usage.UsageError("Invalid syntax in " + f) for f in self.bindfiles: try: self.zones.append(authority.BindAuthority(f)) except Exception: traceback.print_exc() raise usage.UsageError("Invalid syntax in " + f) for f in self.secondaries: svc = secondary.SecondaryAuthorityService.fromServerAddressAndDomains(*f) self.svcs.append(svc) self.zones.append(self.svcs[-1].getAuthority()) try: self["port"] = int(self["port"]) except ValueError: raise usage.UsageError("Invalid port: {!r}".format(self["port"])) def _buildResolvers(config): """ Build DNS resolver instances in an order which leaves recursive resolving as a last resort. @type config: L{Options} instance @param config: Parsed command-line configuration @return: Two-item tuple of a list of cache resovers and a list of client resolvers """ from twisted.names import cache, client, hosts ca, cl = [], [] if config["cache"]: ca.append(cache.CacheResolver(verbose=config["verbose"])) if config["hosts-file"]: cl.append(hosts.Resolver(file=config["hosts-file"])) if config["recursive"]: cl.append(client.createResolver(resolvconf=config["resolv-conf"])) return ca, cl def makeService(config): ca, cl = _buildResolvers(config) f = server.DNSServerFactory(config.zones, ca, cl, config["verbose"]) p = dns.DNSDatagramProtocol(f) f.noisy = 0 ret = service.MultiService() for (klass, arg) in [(internet.TCPServer, f), (internet.UDPServer, p)]: s = klass(config["port"], arg, interface=config["interface"]) s.setServiceParent(ret) for svc in config.svcs: svc.setServiceParent(ret) return ret PK y�Z�UG�z! z! $ __pycache__/_rfc1982.cpython-310.pycnu �[��� o �b�# � @ sR d Z ddlZddlmZmZ ddlmZ ddlmZ dZG dd� de�Z dgZ dS ) a� Utilities for handling RFC1982 Serial Number Arithmetic. @see: U{http://tools.ietf.org/html/rfc1982} @var RFC4034_TIME_FORMAT: RRSIG Time field presentation format. The Signature Expiration Time and Inception Time field values MUST be represented either as an unsigned decimal integer indicating seconds since 1 January 1970 00:00:00 UTC, or in the form YYYYMMDDHHmmSS in UTC. See U{RRSIG Presentation Format<https://tools.ietf.org/html/rfc4034#section-3.2>} � N)�datetime� timedelta)�nativeString)� FancyStrMixinz%Y%m%d%H%M%Sc @ s� e Zd ZdZdZd!dd�Zdedd fdd �Zdefd d�Z dd � Z dedefdd�Zdedefdd�Z dedefdd�Zdedefdd�Zdedefdd�Zdedd fdd�Zdd� Zedd� �Zdd� Zd S )"�SerialNumbera� An RFC1982 Serial Number. This class implements RFC1982 DNS Serial Number Arithmetic. SNA is used in DNS and specifically in DNSSEC as defined in RFC4034 in the DNSSEC Signature Expiration and Inception Fields. @see: U{https://tools.ietf.org/html/rfc1982} @see: U{https://tools.ietf.org/html/rfc4034} @ivar _serialBits: See C{serialBits} of L{__init__}. @ivar _number: See C{number} of L{__init__}. @ivar _modulo: The value at which wrapping will occur. @ivar _halfRing: Half C{_modulo}. If another L{SerialNumber} value is larger than this, it would lead to a wrapped value which is larger than the first and comparisons are therefore ambiguous. @ivar _maxAdd: Half C{_modulo} plus 1. If another L{SerialNumber} value is larger than this, it would lead to a wrapped value which is larger than the first. Comparisons with the original value would therefore be ambiguous. ))�_number�number�%d)�_serialBits� serialBitsr � c C sD || _ d| | _d|d | _d|d d | _t|�| j | _dS )a� Construct an L{SerialNumber} instance. @param number: An L{int} which will be stored as the modulo C{number % 2 ^ serialBits} @type number: L{int} @param serialBits: The size of the serial number space. The power of two which results in one larger than the largest integer corresponding to a serial number value. @type serialBits: L{int} � � N)r �_modulo� _halfRing�_maxAdd�intr )�selfr r � r �8/usr/lib/python3/dist-packages/twisted/names/_rfc1982.py�__init__8 s zSerialNumber.__init__�other�returnc C s>