diff --git a/src/conf.py b/src/conf.py index 9082ffdc0..80f1dc6a5 100644 --- a/src/conf.py +++ b/src/conf.py @@ -1246,15 +1246,18 @@ class IP(registry.String): else: registry.String.setValue(self, v) +class ListOfIPs(registry.SpaceSeparatedListOfStrings): + Value = IP + registerGlobalValue(supybot.servers.http, 'singleStack', registry.Boolean(True, _("""If true, uses IPV6_V6ONLY to disable forwaring of IPv4 traffic to IPv6 sockets. On *nix, has the same effect as setting kernel variable net.ipv6.bindv6only to 1."""))) 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."""))) 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."""))) registerGlobalValue(supybot.servers.http, 'port', registry.Integer(8080, _("""Determines what port the HTTP server will diff --git a/src/httpserver.py b/src/httpserver.py index 734b104cd..59c2ca274 100644 --- a/src/httpserver.py +++ b/src/httpserver.py @@ -434,9 +434,9 @@ def startServer(): The callback should be an instance of a child of SupyHTTPServerCallback.""" global http_servers 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())) - for x in configGroup.hosts6().split(' ') if x != ''] + for x in configGroup.hosts6() if x != ''] http_servers = [] for protocol, address in (addresses4 + addresses6): server = SupyHTTPServer(address, protocol, SupyHTTPRequestHandler) diff --git a/src/utils/net.py b/src/utils/net.py index 7f8633d72..dbcc65d22 100644 --- a/src/utils/net.py +++ b/src/utils/net.py @@ -108,6 +108,9 @@ def isIPV4(s): >>> isIPV4('abc.abc.abc.abc') 0 """ + if set(s) - set('0123456789.'): + # inet_aton ignores trailing data after the first valid IP address + return False try: return bool(socket.inet_aton(str(s))) except socket.error: diff --git a/test/test_utils.py b/test/test_utils.py index cfc106af3..be77d1244 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -514,12 +514,14 @@ class NetTest(SupyTestCase): isIP = utils.net.isIP self.failIf(isIP('a.b.c')) 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('100.100.100.100')) self.failUnless(isIP('255.255.255.255')) def testIsIPV6(self): f = utils.net.isIPV6 + self.failIf(f('2001:: 2001::')) self.failUnless(f('2001::')) self.failUnless(f('2001:888:0:1::666'))