mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Properly handle multiple hosts in supybot.servers.http.hosts4.
See ebb48a4808
(which I reverted).
This commit is contained in:
parent
96694a31f6
commit
11bbc89c9d
@ -1246,15 +1246,18 @@ class IP(registry.String):
|
|||||||
else:
|
else:
|
||||||
registry.String.setValue(self, v)
|
registry.String.setValue(self, v)
|
||||||
|
|
||||||
|
class ListOfIPs(registry.SpaceSeparatedListOfStrings):
|
||||||
|
Value = IP
|
||||||
|
|
||||||
registerGlobalValue(supybot.servers.http, 'singleStack',
|
registerGlobalValue(supybot.servers.http, 'singleStack',
|
||||||
registry.Boolean(True, _("""If true, uses IPV6_V6ONLY to disable
|
registry.Boolean(True, _("""If true, uses IPV6_V6ONLY to disable
|
||||||
forwaring of IPv4 traffic to IPv6 sockets. On *nix, has the same
|
forwaring of IPv4 traffic to IPv6 sockets. On *nix, has the same
|
||||||
effect as setting kernel variable net.ipv6.bindv6only to 1.""")))
|
effect as setting kernel variable net.ipv6.bindv6only to 1.""")))
|
||||||
registerGlobalValue(supybot.servers.http, 'hosts4',
|
registerGlobalValue(supybot.servers.http, 'hosts4',
|
||||||
IP('0.0.0.0', _("""Space-separated list of IPv4 hosts the HTTP server
|
ListOfIPs(['0.0.0.0'], _("""Space-separated list of IPv4 hosts the HTTP server
|
||||||
will bind.""")))
|
will bind.""")))
|
||||||
registerGlobalValue(supybot.servers.http, 'hosts6',
|
registerGlobalValue(supybot.servers.http, 'hosts6',
|
||||||
IP('::0', _("""Space-separated list of IPv6 hosts the HTTP server will
|
ListOfIPs(['::0'], _("""Space-separated list of IPv6 hosts the HTTP server will
|
||||||
bind.""")))
|
bind.""")))
|
||||||
registerGlobalValue(supybot.servers.http, 'port',
|
registerGlobalValue(supybot.servers.http, 'port',
|
||||||
registry.Integer(8080, _("""Determines what port the HTTP server will
|
registry.Integer(8080, _("""Determines what port the HTTP server will
|
||||||
|
@ -434,9 +434,9 @@ def startServer():
|
|||||||
The callback should be an instance of a child of SupyHTTPServerCallback."""
|
The callback should be an instance of a child of SupyHTTPServerCallback."""
|
||||||
global http_servers
|
global http_servers
|
||||||
addresses4 = [(4, (x, configGroup.port()))
|
addresses4 = [(4, (x, configGroup.port()))
|
||||||
for x in configGroup.hosts4().split(' ') if x != '']
|
for x in configGroup.hosts4() if x != '']
|
||||||
addresses6 = [(6, (x, configGroup.port()))
|
addresses6 = [(6, (x, configGroup.port()))
|
||||||
for x in configGroup.hosts6().split(' ') if x != '']
|
for x in configGroup.hosts6() if x != '']
|
||||||
http_servers = []
|
http_servers = []
|
||||||
for protocol, address in (addresses4 + addresses6):
|
for protocol, address in (addresses4 + addresses6):
|
||||||
server = SupyHTTPServer(address, protocol, SupyHTTPRequestHandler)
|
server = SupyHTTPServer(address, protocol, SupyHTTPRequestHandler)
|
||||||
|
@ -108,6 +108,9 @@ def isIPV4(s):
|
|||||||
>>> isIPV4('abc.abc.abc.abc')
|
>>> isIPV4('abc.abc.abc.abc')
|
||||||
0
|
0
|
||||||
"""
|
"""
|
||||||
|
if set(s) - set('0123456789.'):
|
||||||
|
# inet_aton ignores trailing data after the first valid IP address
|
||||||
|
return False
|
||||||
try:
|
try:
|
||||||
return bool(socket.inet_aton(str(s)))
|
return bool(socket.inet_aton(str(s)))
|
||||||
except socket.error:
|
except socket.error:
|
||||||
|
@ -514,12 +514,14 @@ class NetTest(SupyTestCase):
|
|||||||
isIP = utils.net.isIP
|
isIP = utils.net.isIP
|
||||||
self.failIf(isIP('a.b.c'))
|
self.failIf(isIP('a.b.c'))
|
||||||
self.failIf(isIP('256.0.0.0'))
|
self.failIf(isIP('256.0.0.0'))
|
||||||
|
self.failIf(isIP('127.0.0.1 127.0.0.1'))
|
||||||
self.failUnless(isIP('0.0.0.0'))
|
self.failUnless(isIP('0.0.0.0'))
|
||||||
self.failUnless(isIP('100.100.100.100'))
|
self.failUnless(isIP('100.100.100.100'))
|
||||||
self.failUnless(isIP('255.255.255.255'))
|
self.failUnless(isIP('255.255.255.255'))
|
||||||
|
|
||||||
def testIsIPV6(self):
|
def testIsIPV6(self):
|
||||||
f = utils.net.isIPV6
|
f = utils.net.isIPV6
|
||||||
|
self.failIf(f('2001:: 2001::'))
|
||||||
self.failUnless(f('2001::'))
|
self.failUnless(f('2001::'))
|
||||||
self.failUnless(f('2001:888:0:1::666'))
|
self.failUnless(f('2001:888:0:1::666'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user