diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-23 15:56:12 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-23 15:56:12 +0800 |
commit | e0a8e62d8931694b184f9f3c1aeddc2d87b7c359 (patch) | |
tree | c381d245bcf17207af2903e9df8fd786d97dfaea | |
parent | 8215466fbfce7c3c48dcde64f1d8093369c88a2c (diff) | |
download | fg21sim-e0a8e62d8931694b184f9f3c1aeddc2d87b7c359.tar.bz2 |
webui: WSHandler: remove "check_origin()" and "hosts_allowed" option
-rwxr-xr-x | bin/fg21sim-webui | 16 | ||||
-rw-r--r-- | fg21sim/webui/handlers/websocket.py | 43 |
2 files changed, 0 insertions, 59 deletions
diff --git a/bin/fg21sim-webui b/bin/fg21sim-webui index 20d1a36..364b8fb 100755 --- a/bin/fg21sim-webui +++ b/bin/fg21sim-webui @@ -18,7 +18,6 @@ which is built using the Tornado_ web server and WebSocket_ protocol. import os import sys import logging -import ipaddress import webbrowser import tornado.ioloop @@ -39,25 +38,12 @@ define("port", default=21127, type=int, help="Server listen port") define("debug", default=False, help="Enable the debug mode") define("no_browser", default=False, help="Do not open the Web UI in a browser after startup") -define("hosts_allowed", default="any", type=str, - help=("Hosts allowed to access the Web UI. " - "The network addresses should be given in CIDR format, e.g., " - "'192.168.0.0/24'. " - "Specify 'any' to allow any hosts. " - "Note that the localhost/127.0.0.1 is always allowed.")) def main(): options.logging = None parse_command_line() - # Validate the value of ``options.hosts_allowed`` - if options.hosts_allowed.upper() != "ANY": - try: - ipaddress.ip_network(options.hosts_allowed) - except ValueError as e: - raise ValueError("Option 'hosts_allowed' invalid: " + str(e)) - if options.host == "": options.host = "0.0.0.0" @@ -80,8 +66,6 @@ def main(): # Open the Web UI in a new browser tab webbrowser.open_new_tab(access_url) - logger.info("Hosts allowed to access the Web UI: {0}".format( - options.hosts_allowed)) tornado.ioloop.IOLoop.current().start() diff --git a/fg21sim/webui/handlers/websocket.py b/fg21sim/webui/handlers/websocket.py index 0b854ec..ca116a3 100644 --- a/fg21sim/webui/handlers/websocket.py +++ b/fg21sim/webui/handlers/websocket.py @@ -21,9 +21,6 @@ import logging import tornado.websocket from tornado.escape import json_encode -from tornado.options import options - -from ..utils import get_host_ip, ip_in_network logger = logging.getLogger(__name__) @@ -54,52 +51,12 @@ class WSHandler(tornado.websocket.WebSocketHandler): ``WebSocket.on_message()``: may NOT be a coroutine at the moment (v4.3). See [2]_ and [3]_ . - Attributes - ---------- - from_localhost : bool - Set to ``True`` if the access is from the localhost, - otherwise ``False``. - References ---------- .. _[1] WAMP: Web Application Messaging Protocl, http://wamp-proto.org/ .. _[2] https://stackoverflow.com/a/35543856/4856091 .. _[3] https://stackoverflow.com/a/33724486/4856091 """ - from_localhost = None - - def check_origin(self, origin): - """ - Check the origin of the WebSocket connection to determine whether - the access is allowed. - - Attributes - ---------- - from_localhost : bool - Set to ``True`` if the access is from the "localhost" (i.e., - 127.0.0.1), otherwise ``False``. - """ - self.from_localhost = False - logger.info("WebSocket: origin: {0}".format(origin)) - ip = get_host_ip(url=origin) - network = options.hosts_allowed - if ip == "127.0.0.1": - self.from_localhost = True - allow = True - logger.info("WebSocket: origin is 'localhost'") - elif network.upper() == "ANY": - # Any hosts are allowed - allow = True - logger.warning("WebSocket: ANY hosts are allowed") - elif ip_in_network(ip, network): - allow = True - logger.info("WebSocket: client from allowed network: %s" % network) - else: - allow = False - logger.error("WebSocket: " + - "client is NOT in the allowed network: %s" % network) - return allow - def open(self): """Invoked when a new WebSocket is opened by the client.""" # Add to the set of current connected clients |