示例#1
0
    def checkIncomingNick(self, n):
        # Validate new nicks as they join.
        # If successful, return inick, else raise NickError.
        try:
            inick = dc_to_irc(n.nick)

            if inick.lower() == self.bot_user.inick.lower():
                raise NickError("Nick '%s' conflicts with IRC bot." % inick)

            for q, reason in self.qlines.itervalues():
                if q.match(inick):
                    raise NickError(
                        "Nick '%s' is Q-lined: %s" % (inick, reason))

        except NickError, e:
            LOG.debug("Bad nick: %s %s" % (n.nick, str(e)))
            # Bad nick.  KICK!

            osm = self.main.osm
            chunks = []
            osm.bsm.addKickChunk(
                chunks, n, cfg.irc_to_dc_bot, str(e),
                rejoin=False, silent=True)
            osm.bsm.sendBridgeChange(chunks)
            raise
示例#2
0
    def checkIncomingNick(self, n):
        # Validate new nicks as they join.
        # If successful, return inick, else raise NickError.
        try:
            inick = dc_to_irc(n.nick)

            if inick.lower() == self.bot_user.inick.lower():
                raise NickError("Nick '%s' conflicts with IRC bot." % inick)

            for q, reason in self.qlines.itervalues():
                if q.match(inick):
                    raise NickError("Nick '%s' is Q-lined: %s" %
                                    (inick, reason))

        except NickError, e:
            LOG.debug("Bad nick: %s %s" % (n.nick, str(e)))
            # Bad nick.  KICK!

            osm = self.main.osm
            chunks = []
            osm.bsm.addKickChunk(chunks,
                                 n,
                                 cfg.irc_to_dc_bot,
                                 str(e),
                                 rejoin=False,
                                 silent=True)
            osm.bsm.sendBridgeChange(chunks)
            raise
示例#3
0
def runDconfigPusher():
    import dtella.bridge_config as cfg
    setLogFile(cfg.file_base + ".log", 4 << 20, 4)
    LOG.debug("Dconfig Pusher Logging Manager Initialized")

    addTwistedErrorCatcher(LOG.critical)

    from dtella.bridge.push_dconfig_main import DtellaMain_DconfigPusher
    dtMain = DtellaMain_DconfigPusher()
    reactor.run()
示例#4
0
def runDconfigPusher():
    import dtella.bridge_config as cfg
    setLogFile(cfg.file_base + ".log", 4<<20, 4)
    LOG.debug("Dconfig Pusher Logging Manager Initialized")

    addTwistedErrorCatcher(LOG.critical)

    from dtella.bridge.push_dconfig_main import DtellaMain_DconfigPusher
    dtMain = DtellaMain_DconfigPusher()
    reactor.run()
示例#5
0
def runClient(dc_port):
    #Logging for Dtella Client
    setLogFile("dtella.log", 1 << 20, 1)
    LOG.debug("Client Logging Manager Initialized")

    from dtella.client.main import DtellaMain_Client
    dtMain = DtellaMain_Client()

    import dtella.local_config as local
    from dtella.common.util import get_version_string

    def botErrorReporter(text):
        dch = dtMain.dch
        if dch:
            dch.bot.say(
                "Something bad happened.  You might want to email this to "
                "[email protected] so we'll know about it:\n"
                "Version: %s %s\n%s" %
                (local.hub_name, get_version_string()[3:], text))

    addTwistedErrorCatcher(botErrorReporter)
    addTwistedErrorCatcher(LOG.critical)

    from dtella.client.dc import DCFactory
    dfactory = DCFactory(dtMain, dc_port)

    LOG.info("%s %s" % (local.hub_name, local.version))

    def cb(first):
        try:
            reactor.listenTCP(dc_port, dfactory, interface='127.0.0.1')
        except twisted.internet.error.CannotListenError:
            if first:
                LOG.warning("TCP bind failed.  Killing old process...")
                if terminate(dc_port):
                    LOG.info("Ok.  Sleeping...")
                    reactor.callLater(2.0, cb, False)
                else:
                    LOG.error("Kill failed.  Giving up.")
                    reactor.stop()
            else:
                LOG.error("Bind failed again.  Giving up.")
                reactor.stop()
        else:
            LOG.info("Listening on 127.0.0.1:%d" % dc_port)
            dtMain.startConnecting()

    reactor.callWhenRunning(cb, True)
    reactor.run()
示例#6
0
def runClient(dc_port):
    #Logging for Dtella Client
    setLogFile("dtella.log", 1<<20, 1)
    LOG.debug("Client Logging Manager Initialized")

    from dtella.client.main import DtellaMain_Client
    dtMain = DtellaMain_Client()

    import dtella.local_config as local
    from dtella.common.util import get_version_string

    def botErrorReporter(text):
        dch = dtMain.dch
        if dch:
            dch.bot.say(
                "Something bad happened.  You might want to email this to "
                "[email protected] so we'll know about it:\n"
                "Version: %s %s\n%s" %
                (local.hub_name, get_version_string()[3:], text))

    addTwistedErrorCatcher(botErrorReporter)
    addTwistedErrorCatcher(LOG.critical)

    from dtella.client.dc import DCFactory
    dfactory = DCFactory(dtMain, dc_port)

    LOG.info("%s %s" % (local.hub_name, local.version))

    def cb(first):
        try:
            reactor.listenTCP(dc_port, dfactory, interface='127.0.0.1')
        except twisted.internet.error.CannotListenError:
            if first:
                LOG.warning("TCP bind failed.  Killing old process...")
                if terminate(dc_port):
                    LOG.info("Ok.  Sleeping...")
                    reactor.callLater(2.0, cb, False)
                else:
                    LOG.error("Kill failed.  Giving up.")
                    reactor.stop()
            else:
                LOG.error("Bind failed again.  Giving up.")
                reactor.stop()
        else:
            LOG.info("Listening on 127.0.0.1:%d" % dc_port)
            dtMain.startConnecting()

    reactor.callWhenRunning(cb, True)
    reactor.run()
示例#7
0
def runBridge():
    import dtella.bridge_config as cfg
    setLogFile(cfg.file_base + ".log", 4<<20, 4)
    LOG.debug("Bridge Logging Manager Initialized")

    addTwistedErrorCatcher(LOG.critical)

    from dtella.bridge.main import DtellaMain_Bridge
    dtMain = DtellaMain_Bridge()

    from dtella.bridge.bridge_server import getServiceConfig
    scfg = getServiceConfig()
    scfg.startService(dtMain)

    reactor.run()
示例#8
0
    def signPacket(self, packet, broadcast):
        data = ''.join(packet)

        if broadcast:
            body = data[0:2] + data[10:]
        else:
            body = data

        data_hash = md5(body).digest()

        t = time.time()
        sig, = self.rsa_obj.sign(data_hash, None)
        LOG.debug("Sign Time = %f sec" % (time.time() - t))

        packet.append(long_to_bytes(sig))
示例#9
0
    def signPacket(self, packet, broadcast):
        data = ''.join(packet)

        if broadcast:
            body = data[0:2] + data[10:]
        else:
            body = data

        data_hash = md5(body).digest()

        t = time.time()
        sig, = self.rsa_obj.sign(data_hash, None)
        LOG.debug("Sign Time = %f sec" % (time.time() - t))

        packet.append(long_to_bytes(sig))
示例#10
0
def runBridge():
    import dtella.bridge_config as cfg
    setLogFile(cfg.file_base + ".log", 4 << 20, 4)
    LOG.debug("Bridge Logging Manager Initialized")

    addTwistedErrorCatcher(LOG.critical)

    from dtella.bridge.main import DtellaMain_Bridge
    dtMain = DtellaMain_Bridge()

    from dtella.bridge.bridge_server import getServiceConfig
    scfg = getServiceConfig()
    scfg.startService(dtMain)

    reactor.run()
示例#11
0
    def setChannelBan(self, whoset, on_off, banmask):
        if on_off:
            self.chanbans[banmask] = wild_to_regex(banmask)
            action = "added"
        else:
            self.chanbans.pop(banmask, None)
            action = "removed"
        LOG.debug("bans= %s" % self.chanbans.keys())

        try:
            osm = self.getOnlineStateManager()
        except NotOnline:
            return

        chunks = []
        osm.bsm.addChatChunk(
            chunks, cfg.irc_to_dc_bot,
            "%s %s ban: %s" % (irc_to_dc(whoset), action, banmask))
        osm.bsm.sendBridgeChange(chunks)
示例#12
0
    def setChannelBan(self, whoset, on_off, banmask):
        if on_off:
            self.chanbans[banmask] = wild_to_regex(banmask)
            action = "added"
        else:
            self.chanbans.pop(banmask, None)
            action = "removed"
        LOG.debug( "bans= %s" % self.chanbans.keys() )

        try:
            osm = self.getOnlineStateManager()
        except NotOnline:
            return

        chunks = []
        osm.bsm.addChatChunk(
            chunks, cfg.irc_to_dc_bot,
            "%s %s ban: %s" % (irc_to_dc(whoset), action, banmask))
        osm.bsm.sendBridgeChange(chunks)
示例#13
0
    def addDCHandler(self, dch):

        CHECK(not self.dch)
        CHECK(dch.state == 'ready')

        self.dch = dch

        # Cancel the disconnect timeout
        dcall_discard(self, 'disconnect_dcall')

        # Start connecting, or get status of current connection
        text = self.startConnecting()
        if text:
            # We must already be connecting/online.
            # Show the last status message.
            LOG.debug(text)
            dch.pushStatus(text)

            # Send a message if there's a newer version
            self.dcfg.resetReportedVersion()
            self.dcfg.reportNewVersion()

        self.stateChange_ObserverUp()
示例#14
0
    def addDCHandler(self, dch):

        CHECK(not self.dch)
        CHECK(dch.state == 'ready')

        self.dch = dch

        # Cancel the disconnect timeout
        dcall_discard(self, 'disconnect_dcall')

        # Start connecting, or get status of current connection
        text = self.startConnecting()
        if text:
            # We must already be connecting/online.
            # Show the last status message.
            LOG.debug(text)
            dch.pushStatus(text)

            # Send a message if there's a newer version
            self.dcfg.resetReportedVersion()
            self.dcfg.reportNewVersion()

        self.stateChange_ObserverUp()
示例#15
0
    def showLoginStatus(self, text, counter=None):

        # counter can be:
        # - int: set the counter to this value
        # - 'inc': increment from the previous counter value
        # - None: don't show a counter

        if type(counter) is int:
            self.login_counter = counter
        elif counter == 'inc':
            self.login_counter += 1

        if counter is not None:
            # Prepend a number
            text = "%d. %s" % (self.login_counter, text)

            # Remember this for new DC clients
            self.login_text = text
        
        LOG.debug(text)
        dch = self.dch
        if dch:
            dch.pushStatus(text)
示例#16
0
    def showLoginStatus(self, text, counter=None):

        # counter can be:
        # - int: set the counter to this value
        # - 'inc': increment from the previous counter value
        # - None: don't show a counter

        if type(counter) is int:
            self.login_counter = counter
        elif counter == 'inc':
            self.login_counter += 1

        if counter is not None:
            # Prepend a number
            text = "%d. %s" % (self.login_counter, text)

            # Remember this for new DC clients
            self.login_text = text

        LOG.debug(text)
        dch = self.dch
        if dch:
            dch.pushStatus(text)
示例#17
0
    def advanceQueue(self):
        # Only continue if we have a queue, and spare capacity
        if not (self.dnsq and self.limiter > 0):
            return

        self.limiter -= 1
        ip, ent = self.dnsq.popleft()

        def cb(hostname):
            for ipp in ent.waiting_ipps:
                self.signOn(ipp, hostname)

            ent.waiting_ipps.clear()

            if hostname is None:
                del self.cache[ip]
            else:
                ent.hostname = hostname

            self.limiter += 1
            self.advanceQueue()

        LOG.debug("Querying %s" % Ad().setRawIP(ip).getTextIP())
        ipToHostname(Ad().setRawIP(ip)).addCallback(cb)
示例#18
0
    def advanceQueue(self):
        # Only continue if we have a queue, and spare capacity
        if not (self.dnsq and self.limiter > 0):
            return

        self.limiter -= 1
        ip, ent = self.dnsq.popleft()

        def cb(hostname):
            for ipp in ent.waiting_ipps:
                self.signOn(ipp, hostname)

            ent.waiting_ipps.clear()

            if hostname is None:
                del self.cache[ip]
            else:
                ent.hostname = hostname

            self.limiter += 1
            self.advanceQueue()

        LOG.debug("Querying %s" % Ad().setRawIP(ip).getTextIP())
        ipToHostname(Ad().setRawIP(ip)).addCallback(cb)
示例#19
0
    def updateSuccess(self, result):
        self.busy = False

        LOG.debug("Dconfig Update Successful: %s" % result)

        self.scheduleUpdate(cfg.dconfig_push_interval)
示例#20
0
 def fail_cb(detail):
     LOG.debug("bC failed: %s" % detail)
示例#21
0
 def fail_cb(detail):
     LOG.debug("bC failed: %s" % detail)
示例#22
0
 def showSystemMessage(self, text):      
     LOG.debug(text)
     dch = self.dch
     if dch:
         dch.bot.say(text)
示例#23
0
    def updateSuccess(self, result):
        self.busy = False

        LOG.debug("Dconfig Update Successful: %s" % result)

        self.scheduleUpdate(cfg.dconfig_push_interval)