diff options
author | Anders Bergh <anders1@gmail.com> | 2014-03-04 09:59:26 +0100 |
---|---|---|
committer | David Adam <zanchey@ucc.gu.uwa.edu.au> | 2014-04-27 11:32:26 +0800 |
commit | 10642a34f17ae45bd93be3ae6021ee920d3da0c2 (patch) | |
tree | 36a77b8695e8dc35ac476a9fcdc64597e0bf8dfc /share | |
parent | 3c5d5b344ee945b99e4bb16a44af6f293601813d (diff) |
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.
Diffstat (limited to 'share')
-rwxr-xr-x | share/tools/web_config/webconfig.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py index f735a026..1b9250b1 100755 --- a/share/tools/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -250,6 +250,16 @@ class FishVar: if self.exported: flags.append('exported') 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): def write_to_wfile(self, txt): @@ -613,7 +623,7 @@ PORT = 8000 while PORT <= 9000: try: Handler = FishConfigHTTPRequestHandler - httpd = SocketServer.TCPServer(("", PORT), Handler) + httpd = FishConfigTCPServer(("::", PORT), Handler) # Success break except socket.error: |