mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-25 20:41:18 -05:00
Make supybot.plugins.Web.urlWhitelist channel-specific
This commit is contained in:
parent
35731acd86
commit
ccf26351f5
@ -74,11 +74,12 @@ conf.registerChannelValue(Web, 'checkIgnored',
|
|||||||
registry.Boolean(True, _("""Determines whether the title snarfer checks
|
registry.Boolean(True, _("""Determines whether the title snarfer checks
|
||||||
if the author of a message is ignored.""")))
|
if the author of a message is ignored.""")))
|
||||||
|
|
||||||
conf.registerGlobalValue(Web, 'urlWhitelist',
|
conf.registerChannelValue(Web, 'urlWhitelist',
|
||||||
registry.SpaceSeparatedListOfStrings([], """If set, bot will only fetch data
|
registry.SpaceSeparatedListOfStrings([], """If set, bot will only fetch data
|
||||||
from urls in the whitelist, i.e. starting with http://domain/optionalpath/. This will
|
from urls in the whitelist, i.e. starting with http://domain/optionalpath/. This will
|
||||||
apply to all commands that retrieve data from user-supplied URLs,
|
apply to all commands that retrieve data from user-supplied URLs,
|
||||||
including fetch, headers, title, doctype."""))
|
including fetch, headers, title, doctype."""),
|
||||||
|
opSettable=False)
|
||||||
|
|
||||||
conf.registerGlobalValue(Web, 'timeout',
|
conf.registerGlobalValue(Web, 'timeout',
|
||||||
registry.NonNegativeInteger(5, """Determines the maximum number of
|
registry.NonNegativeInteger(5, """Determines the maximum number of
|
||||||
|
@ -274,7 +274,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
return
|
return
|
||||||
if self.registryValue('titleSnarfer', channel, network):
|
if self.registryValue('titleSnarfer', channel, network):
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
if not self._checkURLWhitelist(url):
|
if not self._checkURLWhitelist(irc, msg, url):
|
||||||
return
|
return
|
||||||
r = self.registryValue('nonSnarfingRegexp', channel, network)
|
r = self.registryValue('nonSnarfingRegexp', channel, network)
|
||||||
if r and r.search(url):
|
if r and r.search(url):
|
||||||
@ -303,11 +303,13 @@ class Web(callbacks.PluginRegexp):
|
|||||||
titleSnarfer = urlSnarfer(titleSnarfer)
|
titleSnarfer = urlSnarfer(titleSnarfer)
|
||||||
titleSnarfer.__doc__ = utils.web._httpUrlRe
|
titleSnarfer.__doc__ = utils.web._httpUrlRe
|
||||||
|
|
||||||
def _checkURLWhitelist(self, url):
|
def _checkURLWhitelist(self, irc, msg, url):
|
||||||
if not self.registryValue('urlWhitelist'):
|
if not self.registryValue('urlWhitelist',
|
||||||
|
channel=msg.channel, network=irc.network):
|
||||||
return True
|
return True
|
||||||
passed = False
|
passed = False
|
||||||
for wu in self.registryValue('urlWhitelist'):
|
for wu in self.registryValue('urlWhitelist',
|
||||||
|
channel=msg.channel, network=irc.network):
|
||||||
if wu.endswith('/') and url.find(wu) == 0:
|
if wu.endswith('/') and url.find(wu) == 0:
|
||||||
passed = True
|
passed = True
|
||||||
break
|
break
|
||||||
@ -325,7 +327,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
Returns the HTTP headers of <url>. Only HTTP urls are valid, of
|
Returns the HTTP headers of <url>. Only HTTP urls are valid, of
|
||||||
course.
|
course.
|
||||||
"""
|
"""
|
||||||
if not self._checkURLWhitelist(url):
|
if not self._checkURLWhitelist(irc, msg, url):
|
||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
timeout = self.registryValue('timeout')
|
timeout = self.registryValue('timeout')
|
||||||
@ -362,7 +364,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
Returns the DOCTYPE string of <url>. Only HTTP urls are valid, of
|
Returns the DOCTYPE string of <url>. Only HTTP urls are valid, of
|
||||||
course.
|
course.
|
||||||
"""
|
"""
|
||||||
if not self._checkURLWhitelist(url):
|
if not self._checkURLWhitelist(irc, msg, url):
|
||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
size = conf.supybot.protocols.http.peekSize()
|
size = conf.supybot.protocols.http.peekSize()
|
||||||
@ -384,7 +386,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
Returns the Content-Length header of <url>. Only HTTP urls are valid,
|
Returns the Content-Length header of <url>. Only HTTP urls are valid,
|
||||||
of course.
|
of course.
|
||||||
"""
|
"""
|
||||||
if not self._checkURLWhitelist(url):
|
if not self._checkURLWhitelist(irc, msg, url):
|
||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
timeout = self.registryValue('timeout')
|
timeout = self.registryValue('timeout')
|
||||||
@ -417,7 +419,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
If --no-filter is given, the bot won't strip special chars (action,
|
If --no-filter is given, the bot won't strip special chars (action,
|
||||||
DCC, ...).
|
DCC, ...).
|
||||||
"""
|
"""
|
||||||
if not self._checkURLWhitelist(url):
|
if not self._checkURLWhitelist(irc, msg, url):
|
||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
r = self.getTitle(irc, url, True, msg)
|
r = self.getTitle(irc, url, True, msg)
|
||||||
@ -457,7 +459,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
supybot.plugins.Web.fetch.maximum. If that configuration variable is
|
supybot.plugins.Web.fetch.maximum. If that configuration variable is
|
||||||
set to 0, this command will be effectively disabled.
|
set to 0, this command will be effectively disabled.
|
||||||
"""
|
"""
|
||||||
if not self._checkURLWhitelist(url):
|
if not self._checkURLWhitelist(irc, msg, url):
|
||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
max = self.registryValue('fetch.maximum')
|
max = self.registryValue('fetch.maximum')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user