Esempio n. 1
0
    def bridgeevent_AddNickWithHostname(self, n, hostname):
        # Set up hostname and hostmask.
        scfg = getServiceConfig()
        ad = Ad().setRawIPPort(n.ipp)

        # Set regular hostname, falling back to IP if none exists.
        if hostname:
            n.hostname = hostname
        else:
            n.hostname = ad.getTextIP()

        # Set cloaked hostname.
        try:
            hm = scfg.hostmasker
        except AttributeError:
            # Masking disabled.
            n.hostmask = n.hostname
        else:
            # Masking enabled.
            try:
                if not hostname:
                    raise BadHostnameError
                n.hostmask = hm.maskHostname(hostname)
            except BadHostnameError:
                n.hostmask = hm.maskIPv4(ad)

        osm = self.getOnlineStateManager()

        # Check channel bans on-join.
        if self.isNodeChannelBanned(n):
            chunks = []
            osm.bsm.addKickChunk(chunks,
                                 n,
                                 cfg.irc_to_dc_bot,
                                 "Channel Ban",
                                 rejoin=True,
                                 silent=True)
            osm.bsm.sendBridgeChange(chunks)

            # Remove from Dtella nick list
            del n.inick
            osm.nkm.removeNode(n, "ChanBanned")
            n.setNoUser()
            return

        # Announce new user to IRC.
        if self.ircs:
            self.ircs.event_AddDtNode(n, n_user(n.ipp))

        # Send queued chat messages
        osm.cms.flushQueue(n)
Esempio n. 2
0
    def queryLocation(self, my_ipp):
        # Try to convert the IP address into a human-readable location name.
        # This might be slightly more complicated than it really needs to be.

        CHECK(local.use_locations)

        ad = Ad().setRawIPPort(my_ipp)
        my_ip = ad.getTextIP()

        # Set my local ip in the state
        # self.state.local_ip = my_ip
        # self.state.saveState()

        skip = False
        for ip,loc in self.location.items():
            if ip == my_ip:
                skip = True
            elif loc:
                # Forget old entries
                del self.location[ip]

        # If we already had an entry for this IP, then don't start
        # another lookup.
        if skip:
            return

        # A location of None indicates that a lookup is in progress
        self.location[my_ip] = None

        def cb(hostname):

            # Use local_config to transform this hostname into a
            # human-readable location
            loc = local.hostnameToLocation(hostname)

            # If we got a location, save it, otherwise dump the
            # dictionary entry
            if loc:
                self.location[my_ip] = loc
            else:
                del self.location[my_ip]

            # Maybe send an info update
            if self.osm:
                self.osm.updateMyInfo()

        # Start lookup
        ipToHostname(ad).addCallback(cb)
Esempio n. 3
0
    def queryLocation(self, my_ipp):
        # Try to convert the IP address into a human-readable location name.
        # This might be slightly more complicated than it really needs to be.

        CHECK(local.use_locations)

        ad = Ad().setRawIPPort(my_ipp)
        my_ip = ad.getTextIP()

        # Set my local ip in the state
        # self.state.local_ip = my_ip
        # self.state.saveState()

        skip = False
        for ip, loc in self.location.items():
            if ip == my_ip:
                skip = True
            elif loc:
                # Forget old entries
                del self.location[ip]

        # If we already had an entry for this IP, then don't start
        # another lookup.
        if skip:
            return

        # A location of None indicates that a lookup is in progress
        self.location[my_ip] = None

        def cb(hostname):

            # Use local_config to transform this hostname into a
            # human-readable location
            loc = local.hostnameToLocation(hostname)

            # If we got a location, save it, otherwise dump the
            # dictionary entry
            if loc:
                self.location[my_ip] = loc
            else:
                del self.location[my_ip]

            # Maybe send an info update
            if self.osm:
                self.osm.updateMyInfo()

        # Start lookup
        ipToHostname(ad).addCallback(cb)
Esempio n. 4
0
    def bridgeevent_AddNickWithHostname(self, n, hostname):
        # Set up hostname and hostmask.
        scfg = getServiceConfig()
        ad = Ad().setRawIPPort(n.ipp)

        # Set regular hostname, falling back to IP if none exists.
        if hostname:
            n.hostname = hostname
        else:
            n.hostname = ad.getTextIP()

        # Set cloaked hostname.
        try:
            hm = scfg.hostmasker
        except AttributeError:
            # Masking disabled.
            n.hostmask = n.hostname
        else:
            # Masking enabled.
            try:
                if not hostname:
                    raise BadHostnameError
                n.hostmask = hm.maskHostname(hostname)
            except BadHostnameError:
                n.hostmask = hm.maskIPv4(ad)
 
        osm = self.getOnlineStateManager()

        # Check channel bans on-join.
        if self.isNodeChannelBanned(n):
            chunks = []
            osm.bsm.addKickChunk(
                chunks, n, cfg.irc_to_dc_bot, "Channel Ban",
                rejoin=True, silent=True)
            osm.bsm.sendBridgeChange(chunks)

            # Remove from Dtella nick list
            del n.inick
            osm.nkm.removeNode(n, "ChanBanned")
            n.setNoUser()
            return

        # Announce new user to IRC.
        if self.ircs:
            self.ircs.event_AddDtNode(n, n_user(n.ipp))

        # Send queued chat messages
        osm.cms.flushQueue(n)
Esempio n. 5
0
File: dc.py Progetto: LiPeK/dtella
    def formatMyInfo(self):
        # Build and return a hacked-up version of my info string.

        # Get version string
        ver_string = get_version_string()

        # Split info string
        try:
            info = split_info(self.info)
        except ValueError:
            # No info.  Just use the offline version tag
            return "<%s>" % ver_string

        # Split description into description and <tag>
        desc, tag = split_tag(info[0])

        # Update tag
        if tag:
            info[0] = "%s<%s,%s>" % (desc, tag, ver_string)
        else:
            info[0] = "%s<%s>" % (desc, ver_string)

        if local.use_locations:
            # Try to get my location name.
            try:
                ad = Ad().setRawIPPort(self.main.osm.me.ipp)
                loc = self.main.location[ad.getTextIP()]
            except (AttributeError, KeyError):
                loc = None

            # If I got a location name, splice it into my connection field
            if loc:
                # Append location suffix, if it exists
                suffix = self.main.state.suffix
                if suffix:
                    loc = '%s|%s' % (loc, suffix)
                
                info[2] = loc + info[2][-1:]

        info = '$'.join(info)

        if len(info) > 255:
            self.pushStatus("*** Your info string is too long!")
            info = ''

        return info
Esempio n. 6
0
    def formatMyInfo(self):
        # Build and return a hacked-up version of my info string.

        # Get version string
        ver_string = get_version_string()

        # Split info string
        try:
            info = split_info(self.info)
        except ValueError:
            # No info.  Just use the offline version tag
            return "<%s>" % ver_string

        # Split description into description and <tag>
        desc, tag = split_tag(info[0])

        # Update tag
        if tag:
            info[0] = "%s<%s,%s>" % (desc, tag, ver_string)
        else:
            info[0] = "%s<%s>" % (desc, ver_string)

        if local.use_locations:
            # Try to get my location name.
            try:
                ad = Ad().setRawIPPort(self.main.osm.me.ipp)
                loc = self.main.location[ad.getTextIP()]
            except (AttributeError, KeyError):
                loc = None

            # If I got a location name, splice it into my connection field
            if loc:
                # Append location suffix, if it exists
                suffix = self.main.state.suffix
                if suffix:
                    loc = '%s|%s' % (loc, suffix)

                info[2] = loc + info[2][-1:]

        info = '$'.join(info)

        if len(info) > 255:
            self.pushStatus("*** Your info string is too long!")
            info = ''

        return info