Exemplo n.º 1
0
 def getSortValue(self, attr, listingType):
   """
   Provides the value of a single attribute used for sorting purposes.
   """
   
   connLine = self.lines[0]
   if attr == entries.SortAttr.IP_ADDRESS:
     if connLine.isPrivate(): return SCRUBBED_IP_VAL # orders at the end
     return connLine.sortIpAddr
   elif attr == entries.SortAttr.PORT:
     return connLine.sortPort
   elif attr == entries.SortAttr.HOSTNAME:
     if connLine.isPrivate(): return ""
     return connLine.foreign.getHostname("")
   elif attr == entries.SortAttr.FINGERPRINT:
     return connLine.foreign.getFingerprint()
   elif attr == entries.SortAttr.NICKNAME:
     myNickname = connLine.foreign.getNickname()
     if myNickname == "UNKNOWN": return "z" * 20 # orders at the end
     else: return myNickname.lower()
   elif attr == entries.SortAttr.CATEGORY:
     return Category.indexOf(connLine.getType())
   elif attr == entries.SortAttr.UPTIME:
     return connLine.startTime
   elif attr == entries.SortAttr.COUNTRY:
     if connections.isIpAddressPrivate(self.lines[0].foreign.getIpAddr()): return ""
     else: return connLine.foreign.getLocale("")
   else:
     return entries.ConnectionPanelEntry.getSortValue(self, attr, listingType)
Exemplo n.º 2
0
    def getSortValue(self, attr, listingType):
        """
    Provides the value of a single attribute used for sorting purposes.
    """

        connLine = self.lines[0]
        if attr == entries.SortAttr.IP_ADDRESS:
            if connLine.isPrivate():
                return SCRUBBED_IP_VAL  # orders at the end
            return connLine.sortIpAddr
        elif attr == entries.SortAttr.PORT:
            return connLine.sortPort
        elif attr == entries.SortAttr.HOSTNAME:
            if connLine.isPrivate(): return ""
            return connLine.foreign.getHostname("")
        elif attr == entries.SortAttr.FINGERPRINT:
            return connLine.foreign.getFingerprint()
        elif attr == entries.SortAttr.NICKNAME:
            myNickname = connLine.foreign.getNickname()
            if myNickname == "UNKNOWN": return "z" * 20  # orders at the end
            else: return myNickname.lower()
        elif attr == entries.SortAttr.CATEGORY:
            return Category.indexOf(connLine.getType())
        elif attr == entries.SortAttr.UPTIME:
            return connLine.startTime
        elif attr == entries.SortAttr.COUNTRY:
            if connections.isIpAddressPrivate(
                    self.lines[0].foreign.getIpAddr()):
                return ""
            else:
                return connLine.foreign.getLocale("")
        else:
            return entries.ConnectionPanelEntry.getSortValue(
                self, attr, listingType)
Exemplo n.º 3
0
 def getDestinationLabel(self, maxLength, includeLocale=False, includeHostname=False):
   """
   Provides a short description of the destination. This is made up of two
   components, the base <ip addr>:<port> and an extra piece of information in
   parentheses. The IP address is scrubbed from private connections.
   
   Extra information is...
   - the port's purpose for exit connections
   - the locale and/or hostname if set to do so, the address isn't private,
     and isn't on the local network
   - nothing otherwise
   
   Arguments:
     maxLength       - maximum length of the string returned
     includeLocale   - possibly includes the locale
     includeHostname - possibly includes the hostname
   """
   
   # the port and port derived data can be hidden by config or without includePort
   includePort = self.includePort and (CONFIG["features.connection.showExitPort"] or self.getType() != Category.EXIT)
   
   # destination of the connection
   ipLabel = "<scrubbed>" if self.isPrivate() else self.foreign.getIpAddr()
   portLabel = ":%s" % self.foreign.getPort() if includePort else ""
   dstAddress = ipLabel + portLabel
   
   # Only append the extra info if there's at least a couple characters of
   # space (this is what's needed for the country codes).
   if len(dstAddress) + 5 <= maxLength:
     spaceAvailable = maxLength - len(dstAddress) - 3
     
     if self.getType() == Category.EXIT and includePort:
       purpose = connections.getPortUsage(self.foreign.getPort())
       
       if purpose:
         # BitTorrent is a common protocol to truncate, so just use "Torrent"
         # if there's not enough room.
         if len(purpose) > spaceAvailable and purpose == "BitTorrent":
           purpose = "Torrent"
         
         # crops with a hyphen if too long
         purpose = uiTools.cropStr(purpose, spaceAvailable, endType = uiTools.Ending.HYPHEN)
         
         dstAddress += " (%s)" % purpose
     elif not connections.isIpAddressPrivate(self.foreign.getIpAddr()):
       extraInfo = []
       conn = torTools.getConn()
       
       if includeLocale and not conn.isGeoipUnavailable():
         foreignLocale = self.foreign.getLocale("??")
         extraInfo.append(foreignLocale)
         spaceAvailable -= len(foreignLocale) + 2
       
       if includeHostname:
         dstHostname = self.foreign.getHostname()
         
         if dstHostname:
           # determines the full space available, taking into account the ", "
           # dividers if there's multiple pieces of extra data
           
           maxHostnameSpace = spaceAvailable - 2 * len(extraInfo)
           dstHostname = uiTools.cropStr(dstHostname, maxHostnameSpace)
           extraInfo.append(dstHostname)
           spaceAvailable -= len(dstHostname)
       
       if extraInfo:
         dstAddress += " (%s)" % ", ".join(extraInfo)
   
   return dstAddress[:maxLength]
Exemplo n.º 4
0
    def getDestinationLabel(self,
                            maxLength,
                            includeLocale=False,
                            includeHostname=False):
        """
    Provides a short description of the destination. This is made up of two
    components, the base <ip addr>:<port> and an extra piece of information in
    parentheses. The IP address is scrubbed from private connections.
    
    Extra information is...
    - the port's purpose for exit connections
    - the locale and/or hostname if set to do so, the address isn't private,
      and isn't on the local network
    - nothing otherwise
    
    Arguments:
      maxLength       - maximum length of the string returned
      includeLocale   - possibly includes the locale
      includeHostname - possibly includes the hostname
    """

        # the port and port derived data can be hidden by config or without includePort
        includePort = self.includePort and (
            CONFIG["features.connection.showExitPort"]
            or self.getType() != Category.EXIT)

        # destination of the connection
        ipLabel = "<scrubbed>" if self.isPrivate() else self.foreign.getIpAddr(
        )
        portLabel = ":%s" % self.foreign.getPort() if includePort else ""
        dstAddress = ipLabel + portLabel

        # Only append the extra info if there's at least a couple characters of
        # space (this is what's needed for the country codes).
        if len(dstAddress) + 5 <= maxLength:
            spaceAvailable = maxLength - len(dstAddress) - 3

            if self.getType() == Category.EXIT and includePort:
                purpose = connections.getPortUsage(self.foreign.getPort())

                if purpose:
                    # BitTorrent is a common protocol to truncate, so just use "Torrent"
                    # if there's not enough room.
                    if len(purpose
                           ) > spaceAvailable and purpose == "BitTorrent":
                        purpose = "Torrent"

                    # crops with a hyphen if too long
                    purpose = uiTools.cropStr(purpose,
                                              spaceAvailable,
                                              endType=uiTools.Ending.HYPHEN)

                    dstAddress += " (%s)" % purpose
            elif not connections.isIpAddressPrivate(self.foreign.getIpAddr()):
                extraInfo = []
                conn = torTools.getConn()

                if includeLocale and not conn.isGeoipUnavailable():
                    foreignLocale = self.foreign.getLocale("??")
                    extraInfo.append(foreignLocale)
                    spaceAvailable -= len(foreignLocale) + 2

                if includeHostname:
                    dstHostname = self.foreign.getHostname()

                    if dstHostname:
                        # determines the full space available, taking into account the ", "
                        # dividers if there's multiple pieces of extra data

                        maxHostnameSpace = spaceAvailable - 2 * len(extraInfo)
                        dstHostname = uiTools.cropStr(dstHostname,
                                                      maxHostnameSpace)
                        extraInfo.append(dstHostname)
                        spaceAvailable -= len(dstHostname)

                if extraInfo:
                    dstAddress += " (%s)" % ", ".join(extraInfo)

        return dstAddress[:maxLength]