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
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
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()
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()
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()
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()
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()
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))
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()
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)
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)
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()
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)
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)
def updateSuccess(self, result): self.busy = False LOG.debug("Dconfig Update Successful: %s" % result) self.scheduleUpdate(cfg.dconfig_push_interval)
def fail_cb(detail): LOG.debug("bC failed: %s" % detail)
def showSystemMessage(self, text): LOG.debug(text) dch = self.dch if dch: dch.bot.say(text)