aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/tools
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-05-17 19:13:50 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-05-17 19:13:50 -0700
commita83323705df2dbbe0f7e0379f810d6b805436097 (patch)
tree9c4d5e34ba77cb469699900e6601d82ea570fd4f /share/tools
parent49b49d7ed467c4b87fc5dcacc4004a4c6b5de238 (diff)
Make fish_config work correctly when IPv6 is disabled in the kernel
Fixes #1754
Diffstat (limited to 'share/tools')
-rwxr-xr-xshare/tools/web_config/webconfig.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py
index 8f591d17..5438a43e 100755
--- a/share/tools/web_config/webconfig.py
+++ b/share/tools/web_config/webconfig.py
@@ -6,6 +6,7 @@ import sys
import multiprocessing.pool
import os
import operator
+import socket
IS_PY2 = sys.version_info[0] == 2
if IS_PY2:
@@ -18,6 +19,14 @@ else:
import socketserver as SocketServer
from urllib.parse import parse_qs
+# Check to see if IPv6 is enabled in the kernel
+HAS_IPV6 = True
+try:
+ s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
+ s.close()
+except:
+ HAS_IPV6 = False
+
# Disable CLI web browsers
term = os.environ.pop('TERM', None)
import webbrowser
@@ -419,7 +428,7 @@ class FishConfigTCPServer(SocketServer.TCPServer):
"""TCPServer that only accepts connections from localhost (IPv4/IPv6)."""
WHITELIST = set(['::1', '::ffff:127.0.0.1', '127.0.0.1'])
- address_family = socket.AF_INET6
+ address_family = socket.AF_INET6 if HAS_IPV6 else socket.AF_INET
def verify_request(self, request, client_address):
return client_address[0] in FishConfigTCPServer.WHITELIST
@@ -910,16 +919,18 @@ authkey = binascii.b2a_hex(os.urandom(16)).decode('ascii')
# Try to find a suitable port
PORT = 8000
+HOST = "::" if HAS_IPV6 else "localhost"
while PORT <= 9000:
try:
Handler = FishConfigHTTPRequestHandler
- httpd = FishConfigTCPServer(("::", PORT), Handler)
+ httpd = FishConfigTCPServer((HOST, PORT), Handler)
# Success
break
except socket.error:
err_type, err_value = sys.exc_info()[:2]
# str(err_value) handles Python3 correctly
if 'Address already in use' not in str(err_value):
+ print(str(err_value))
break
PORT += 1