]> jfr.im git - irc/freenode/Sigyn.git/commitdiff
deduplicate logic for per-user ipv6 netmask
authorjellytoo <redacted>
Fri, 13 Oct 2017 16:47:36 +0000 (18:47 +0200)
committerGitHub <redacted>
Fri, 13 Oct 2017 16:47:36 +0000 (18:47 +0200)
plugin.py

index d3cd1b1f9dd87314ff677e791cfb9f5183c476bc..ff1a72c04ee6dd68a3cbd7486ba1b038492e0acf 100644 (file)
--- a/plugin.py
+++ b/plugin.py
@@ -820,6 +820,23 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
     checkresolve = wrap(checkresolve,['owner','hostmask'])
 
     # internal stuff
+    
+    def _ipv6_user_block (self, h):
+        if ':' in h:
+        # todo use a separate file to handle various ipv6 providers.
+        if h.startswith('2400:6180:') or h.startswith('2604:a880:') or h.startswith('2a03:b0c0:') or h.startswith('2001:0:53aa:64c:'):
+            h = '%s/116' % h
+        elif h.startswith('2600:3c01'):
+            h = '%s/124' % h
+        elif h.startswith('2001:4801:'):
+            h = '%s/68' % h
+        elif h.startswith('2a02:2b88:'):
+            h = '%s/128' % h
+        elif h.startswith('2a01:488::'):
+            h = h                  
+        if not '/' in h:
+            h = ipaddress.ip_network(u'%s/64' % h, False).with_prefixlen
+        return h
 
     def resolve (self,irc,prefix,channel='',dnsbl=False):
         (nick,ident,host) = ircutils.splitHostmask(prefix)
@@ -852,20 +869,7 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
             self.log.debug('%s resolved as %s' % (prefix,L))
             if len(L) == 1:
                 h = L[0]
-                if ':' in h:
-                    # todo use a separate file to handle various ipv6 providers.
-                    if h.startswith('2400:6180:') or h.startswith('2604:a880:') or h.startswith('2a03:b0c0:') or h.startswith('2001:0:53aa:64c:'):
-                        h = '%s/116' % h
-                    elif h.startswith('2600:3c01'):
-                        h = '%s/124' % h
-                    elif h.startswith('2001:4801:'):
-                        h = '%s/68' % h
-                    elif h.startswith('2a02:2b88:'):
-                        h = '%s/128' % h
-                    elif h.startswith('2a01:488::'):
-                        h = h                  
-                    if not '/' in h:
-                        h = ipaddress.ip_network(u'%s/64' % h, False).with_prefixlen
+                h = self._ipv6_user_block(h)
                 self.log.debug('%s is resolved as %s@%s' % (prefix,ident,h))
                 if dnsbl:
                     ip = h
@@ -939,18 +943,7 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
                 self.cache[prefix] = '%s@%s' % (ident,host)
             elif utils.net.bruteIsIPV6(host):
                 h = host
-                if h.startswith('2400:6180:') or h.startswith('2604:a880:') or h.startswith('2a03:b0c0:') or h.startswith('2001:0:53aa:64c:'):
-                    h = '%s/116' % h
-                elif h.startswith('2600:3c01'):
-                    h = '%s/124' % h
-                elif h.startswith('2001:4801'):
-                    h = '%s/68' % h
-                elif h.startswith('2a02:2b88:'):
-                    h = '%s/128' % h
-                elif h.startswith('2a01:488::'):
-                    h = h
-                if not '/' in h:
-                    h = ipaddress.ip_network(u'%s/64' % h, False).with_prefixlen
+                h = self._ipv6_user_block(h)
                 self.cache[prefix] = '%s@%s' % (ident,h)
             else:
                 i = self.getIrc(irc)