Esempio n. 1
0
def initDaemon():
    """ Start the daemon """
    Hellanzb.isDaemon = True
    Hellanzb.nzbQueue = []
    Hellanzb.queueDirIgnore = []
    Hellanzb.loggedIdleMessage = True

    try:
        ensureDaemonDirs()
        initXMLRPCServer()
        ensureCleanDirs() # needs to be called AFTER initXMLRPCServer
    except FatalError, fe:
        error('Exiting', fe)
        from Hellanzb.Core import shutdownAndExit
        shutdownAndExit(1)
Esempio n. 2
0
def initFillServers():
    """ Determine if fill servers are enabled (more than 1 fillserver priorities are set in
    the config file). Flatten out the fill server priorities so that they begin at 0 and
    increment by 1 """
    fillServerPriorities = {}
    for serverId, serverDict in Hellanzb.SERVERS.iteritems():
        if serverDict.get('enabled') is False:
            continue
        fillServerPriority = serverDict.get('fillserver')
        # Consider = None as = 0
        if fillServerPriority is None:
            fillServerPriority = serverDict['fillserver'] = 0
        try:
            fillServerPriority = int(fillServerPriority)
        except ValueError, ve:
            # Let's not assume what the user wanted -- raise a FatalError so they can
            # fix the priority value
            shutdownAndExit(1,
                            message='There was a problem with the fillserver value of server: %s:\n%s' \
                             % (serverId, str(ve)))
        if fillServerPriority not in fillServerPriorities:
            fillServerPriorities.setdefault(fillServerPriority, []).append(serverDict)
        serverDict['fillserver'] = fillServerPriority
Esempio n. 3
0
def initFillServers():
    """ Determine if fill servers are enabled (more than 1 fillserver priorities are set in
    the config file). Flatten out the fill server priorities so that they begin at 0 and
    increment by 1 """
    fillServerPriorities = {}
    for serverId, serverDict in Hellanzb.SERVERS.iteritems():
        if serverDict.get('enabled') is False:
            continue
        fillServerPriority = serverDict.get('fillserver')
        # Consider = None as = 0
        if fillServerPriority is None:
            fillServerPriority = serverDict['fillserver'] = 0
        try:
            fillServerPriority = int(fillServerPriority)
        except ValueError, ve:
            # Let's not assume what the user wanted -- raise a FatalError so they can
            # fix the priority value
            shutdownAndExit(1,
                            message='There was a problem with the fillserver value of server: %s:\n%s' \
                             % (serverId, str(ve)))
        if fillServerPriority not in fillServerPriorities:
            fillServerPriorities.setdefault(fillServerPriority,
                                            []).append(serverDict)
        serverDict['fillserver'] = fillServerPriority
Esempio n. 4
0
def connectServer(serverName, serverDict, defaultAntiIdle, defaultIdleTimeout):
    """ Establish connections to the specified server according to the server information dict
    (constructed from the config file). Returns the number of connections that were attempted
    to be made """
    defaultConnectTimeout = 30
    connectionCount = 0
    hosts = serverDict['hosts']
    connections = int(serverDict['connections'])

    for host in hosts:
        antiIdle = int(setWithDefault(serverDict, 'antiIdle', defaultAntiIdle))
        idleTimeout = int(
            setWithDefault(serverDict, 'idleTimeout', defaultIdleTimeout))
        skipGroupCmd = setWithDefault(serverDict, 'skipGroupCmd', False)
        fillServer = setWithDefault(serverDict, 'fillserver', 0)
        useSSL = setWithDefault(serverDict, 'ssl', False)

        nsf = NZBLeecherFactory(serverDict['username'], serverDict['password'],
                                idleTimeout, antiIdle, host, serverName,
                                skipGroupCmd, fillServer)
        color = nsf.color
        Hellanzb.nsfs.append(nsf)

        split = host.split(':')
        host = split[0]
        if len(split) == 2:
            port = int(split[1])
        else:
            port = 119
        nsf.host, nsf.port = host, port

        preWrappedNsf = nsf
        nsf = HellaThrottlingFactory(nsf)

        ctxf = None
        if useSSL:
            try:
                from twisted.internet.ssl import Connector as SSLConnector
                from twisted.internet.ssl import ClientContextFactory
            except ImportError, ie:
                error('Unable to use SSL for server: %s\npyOpenSSL is not '
                      'installed: %s' % (serverName, str(ie)))
                shutdownAndExit(1)
            ctxf = ClientContextFactory()

        for connection in range(connections):
            if serverDict.has_key('bindTo') and serverDict['bindTo'] != None and \
                    serverDict['bindTo'] != '':
                if antiIdle != 0:
                    if useSSL:
                        reactor.connectSSL(host,
                                           port,
                                           nsf,
                                           ctxf,
                                           bindAddress=(serverDict['bindTo'],
                                                        0))
                    else:
                        reactor.connectTCP(host,
                                           port,
                                           nsf,
                                           bindAddress=(serverDict['bindTo'],
                                                        0))
                else:
                    if useSSL:
                        connector = SSLConnector(host,
                                                 port,
                                                 nsf,
                                                 ctxf,
                                                 defaultConnectTimeout,
                                                 (serverDict['bindTo'], 0),
                                                 reactor=reactor)
                    else:
                        connector = Connector(host,
                                              port,
                                              nsf,
                                              defaultConnectTimeout,
                                              (serverDict['bindTo'], 0),
                                              reactor=reactor)
            else:
                if antiIdle != 0:
                    if useSSL:
                        reactor.connectSSL(host, port, nsf, ctxf)
                    else:
                        reactor.connectTCP(host, port, nsf)
                else:
                    if useSSL:
                        connector = SSLConnector(host,
                                                 port,
                                                 nsf,
                                                 ctxf,
                                                 defaultConnectTimeout,
                                                 None,
                                                 reactor=reactor)
                    else:
                        connector = Connector(host,
                                              port,
                                              nsf,
                                              defaultConnectTimeout,
                                              None,
                                              reactor=reactor)

            if antiIdle == 0:
                preWrappedNsf.leecherConnectors.append(connector)
            connectionCount += 1
        preWrappedNsf.setConnectionCount(connectionCount)
Esempio n. 5
0
def connectServer(serverName, serverDict, defaultAntiIdle, defaultIdleTimeout):
    """ Establish connections to the specified server according to the server information dict
    (constructed from the config file). Returns the number of connections that were attempted
    to be made """
    defaultConnectTimeout = 30
    connectionCount = 0
    hosts = serverDict['hosts']
    connections = int(serverDict['connections'])

    for host in hosts:
        antiIdle = int(setWithDefault(serverDict, 'antiIdle', defaultAntiIdle))
        idleTimeout = int(setWithDefault(serverDict, 'idleTimeout', defaultIdleTimeout))
        skipGroupCmd = setWithDefault(serverDict, 'skipGroupCmd', False)
        fillServer = setWithDefault(serverDict, 'fillserver', 0)
        useSSL = setWithDefault(serverDict, 'ssl', False)

        nsf = NZBLeecherFactory(serverDict['username'], serverDict['password'],
                                idleTimeout, antiIdle, host, serverName, skipGroupCmd,
                                fillServer)
        color = nsf.color
        Hellanzb.nsfs.append(nsf)

        split = host.split(':')
        host = split[0]
        if len(split) == 2:
            port = int(split[1])
        else:
            port = 119
        nsf.host, nsf.port = host, port

        preWrappedNsf = nsf
        nsf = HellaThrottlingFactory(nsf)

        ctxf = None
        if useSSL:
            try:
                from twisted.internet.ssl import Connector as SSLConnector
                from twisted.internet.ssl import ClientContextFactory
            except ImportError, ie:
                error('Unable to use SSL for server: %s\npyOpenSSL is not '
                      'installed: %s' % (serverName, str(ie)))
                shutdownAndExit(1)
            ctxf = ClientContextFactory()

        for connection in range(connections):
            if serverDict.has_key('bindTo') and serverDict['bindTo'] != None and \
                    serverDict['bindTo'] != '':
                if antiIdle != 0:
                    if useSSL:
                        reactor.connectSSL(host, port, nsf, ctxf, 
                                           bindAddress = (serverDict['bindTo'], 0))
                    else:
                        reactor.connectTCP(host, port, nsf,
                                           bindAddress = (serverDict['bindTo'], 0))
                else:
                    if useSSL:
                        connector = SSLConnector(host, port, nsf, ctxf, 
                                                 defaultConnectTimeout, 
                                                 (serverDict['bindTo'], 0), reactor=reactor)
                    else:
                        connector = Connector(host, port, nsf, defaultConnectTimeout,
                                              (serverDict['bindTo'], 0), reactor=reactor)
            else:
                if antiIdle != 0:
                    if useSSL:
                        reactor.connectSSL(host, port, nsf, ctxf)
                    else:
                        reactor.connectTCP(host, port, nsf)
                else:
                    if useSSL:
                        connector = SSLConnector(host, port, nsf, ctxf, 
                                                 defaultConnectTimeout, None, 
                                                 reactor=reactor)
                    else:
                        connector = Connector(host, port, nsf, 
                                              defaultConnectTimeout, None, 
                                              reactor=reactor)

            if antiIdle == 0:
                preWrappedNsf.leecherConnectors.append(connector)
            connectionCount += 1
        preWrappedNsf.setConnectionCount(connectionCount)