mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-19 13:42:56 +08:00
fish_config: Listen on both IPv6 and IPv4.
A subclass of TCPServer was created to deny any non-local connections and to listen using an IPv6 socket.
This commit is contained in:
parent
3c5d5b344e
commit
10642a34f1
|
@ -250,6 +250,16 @@ class FishVar:
|
||||||
if self.exported: flags.append('exported')
|
if self.exported: flags.append('exported')
|
||||||
return [self.name, self.value, ', '.join(flags)]
|
return [self.name, self.value, ', '.join(flags)]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def verify_request(self, request, client_address):
|
||||||
|
return client_address[0] in FishConfigTCPServer.WHITELIST
|
||||||
|
|
||||||
|
|
||||||
class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
|
|
||||||
def write_to_wfile(self, txt):
|
def write_to_wfile(self, txt):
|
||||||
|
@ -613,7 +623,7 @@ PORT = 8000
|
||||||
while PORT <= 9000:
|
while PORT <= 9000:
|
||||||
try:
|
try:
|
||||||
Handler = FishConfigHTTPRequestHandler
|
Handler = FishConfigHTTPRequestHandler
|
||||||
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
httpd = FishConfigTCPServer(("::", PORT), Handler)
|
||||||
# Success
|
# Success
|
||||||
break
|
break
|
||||||
except socket.error:
|
except socket.error:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user