mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-28 22:41:06 -05:00
Hostmasks: rewrite a whole bunch of stuff
This commit is contained in:
parent
cb3c8770ac
commit
002f155445
@ -51,7 +51,7 @@ Hostmasks = conf.registerPlugin('Hostmasks')
|
|||||||
class BantypeValue(registry.OnlySomeStrings):
|
class BantypeValue(registry.OnlySomeStrings):
|
||||||
validStrings = ('1', '2', '3', '4')
|
validStrings = ('1', '2', '3', '4')
|
||||||
conf.registerGlobalValue(Hostmasks, 'banType',
|
conf.registerGlobalValue(Hostmasks, 'banType',
|
||||||
BantypeValue('1', _("""Chooses the preferred ban type for the
|
BantypeValue('4', _("""Chooses the preferred ban type for the
|
||||||
banmask command. 1 = *!*@address.isp.net; 2 = *!~ident@address.isp.net;
|
banmask command. 1 = *!*@address.isp.net; 2 = *!~ident@address.isp.net;
|
||||||
3 = *!*@*.isp.net; 4 = *!~ident@*.isp.net""")))
|
3 = *!*@*.isp.net; 4 = *!~ident@*.isp.net""")))
|
||||||
|
|
||||||
|
@ -129,14 +129,12 @@ class Hostmasks(callbacks.Plugin):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _isvHost(self, hostname):
|
def _isvHost(self, hostname):
|
||||||
isvHost = re.search("/", hostname)
|
if "/" in hostname or hostname.endswith("."):
|
||||||
if isvHost:
|
|
||||||
return True
|
return True
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def _isv6cloak(self, hostname):
|
def _isv6cloak(self, hostname):
|
||||||
if re.search(":", hostname):
|
if ":" in hostname:
|
||||||
# Look for unreal-style cloaks (1234abcd:2345bcde:3456cdef:IP)
|
# Look for unreal-style cloaks (1234abcd:2345bcde:3456cdef:IP)
|
||||||
v6cloaku = re.match("([0-9A-F]{8}:){3}IP", hostname)
|
v6cloaku = re.match("([0-9A-F]{8}:){3}IP", hostname)
|
||||||
# Use our super lazy regexp for charybdis-style v6 cloaks
|
# Use our super lazy regexp for charybdis-style v6 cloaks
|
||||||
@ -155,45 +153,45 @@ class Hostmasks(callbacks.Plugin):
|
|||||||
"""
|
"""
|
||||||
if not nick:
|
if not nick:
|
||||||
nick = msg.nick
|
nick = msg.nick
|
||||||
splithostmask = self._SplitHostmask(irc, nick)
|
unick, ident, host = self._SplitHostmask(irc, nick)
|
||||||
bantype = self.registryValue('banType')
|
bantype = self.registryValue('banType')
|
||||||
if bantype == '1':
|
if bantype == '1':
|
||||||
banmask = '*!*@%s' % splithostmask[2]
|
banmask = '*!*@%s' % host
|
||||||
elif bantype == '2':
|
elif bantype == '2':
|
||||||
banmask = '*!%s@%s' % (splithostmask[1], splithostmask[2])
|
banmask = '*!%s@%s' % (ident, host)
|
||||||
else:
|
else:
|
||||||
splithost = splithostmask[2].split('.', 2)
|
splithost = host.split('.', 2)
|
||||||
|
v6splithost = host.split(":", 3)
|
||||||
wildhost = ''
|
wildhost = ''
|
||||||
if self.registryValue('smartBans'):
|
if self.registryValue('smartBans'):
|
||||||
v6splithost = splithostmask[2].split(":", 3)
|
if self._isv4IP(host) or \
|
||||||
if self._isv4IP(splithostmask[2]) or \
|
self._isv4cloak(host):
|
||||||
self._isv4cloak(splithostmask[2]):
|
v4cloak = host.split(".", 2)
|
||||||
v4cloak = splithostmask[2].split(".", 2)
|
|
||||||
wildhost = '%s.%s.*' % (v4cloak[0], v4cloak[1])
|
wildhost = '%s.%s.*' % (v4cloak[0], v4cloak[1])
|
||||||
elif self._isvHost(splithostmask[2]):
|
elif self._isvHost(host):
|
||||||
wildhost = splithostmask[2]
|
wildhost = host
|
||||||
elif self._isv6IP(splithostmask[2]) or \
|
elif self._isv6IP(host) or \
|
||||||
self._isv6cloak(splithostmask[2]) == 'c':
|
self._isv6cloak(host) == 'c':
|
||||||
try:
|
try:
|
||||||
wildhost = '%s:%s:%s:*' % (v6splithost[0],
|
wildhost = '%s:%s:%s:*' % (v6splithost[0],
|
||||||
v6splithost[1], v6splithost[2])
|
v6splithost[1], v6splithost[2])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
wildhost = splithostmask[2]
|
wildhost = host
|
||||||
elif self._isv6cloak(splithostmask[2]) == 'u':
|
elif self._isv6cloak(host) == 'u':
|
||||||
try:
|
try:
|
||||||
wildhost = '*:%s:%s:IP' % (v6splithost[1],
|
wildhost = '*:%s:%s:IP' % (v6splithost[1],
|
||||||
v6splithost[2])
|
v6splithost[2])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
wildhost = splithostmask[2]
|
wildhost = host
|
||||||
if not wildhost:
|
if not wildhost:
|
||||||
if len(splithost) <= 2:
|
if len(splithost) <= 2:
|
||||||
wildhost = splithostmask[2] # Hostmask is too short
|
wildhost = host # Hostmask is too short
|
||||||
else:
|
else:
|
||||||
wildhost = '*.%s.%s' % (splithost[1], splithost[2])
|
wildhost = '*.%s.%s' % (splithost[1], splithost[2])
|
||||||
if bantype == '3':
|
if bantype == '3':
|
||||||
banmask = '*!*@%s' % wildhost
|
banmask = '*!*@%s' % wildhost
|
||||||
if bantype == '4':
|
if bantype == '4':
|
||||||
banmask = '*!%s@%s' % (splithostmask[1], wildhost)
|
banmask = '*!%s@%s' % (ident, wildhost)
|
||||||
irc.reply(banmask)
|
irc.reply(banmask)
|
||||||
banmask = wrap(banmask, [(additional('nick'))])
|
banmask = wrap(banmask, [(additional('nick'))])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user