From ca7f35364cb198e44c28a89d805d3c41bca68b84 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Wed, 24 Apr 2019 14:58:23 +0100 Subject: [PATCH] Add option for not validating subnet mask --- Makefile | 19 +++++++------------ ...panda-webcontrol-no-subnet-validation.list | 4 ++++ src/no-subnet-validation | 3 +++ src/panda-webcontrol.py | 15 ++++++++++++++- 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 etc/panda-webcontrol-no-subnet-validation.list create mode 100644 src/no-subnet-validation diff --git a/Makefile b/Makefile index cb02df6..e7f014b 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,6 @@ include CONFIG default: $(DEFAULT_TARGETS) -# This is the generated zpkg list file -ZPKG_LIST = $(TOP)/etc/panda-webcontrol.list - # The cut down malcolm package we build MALCOLM_BUILD = $(BUILD_DIR)/malcolm ANNOTYPES_BUILD = $(BUILD_DIR)/annotypes @@ -34,9 +31,6 @@ WEB_ADMIN = $(PANDA_ROOTFS)/rootfs/web-admin # A tag for our zpkg suffix export GIT_VERSION := $(shell git describe --abbrev=7 --dirty --always --tags) -# The zpkg file that will be built -WEBSERVER_ZPKG = $(BUILD_DIR)/panda-webcontrol@$(GIT_VERSION).zpg - # The .py files we depend on to build our cut down distribution MALCOLM_SOURCES := $(shell find $(PYMALCOLM)/malcolm -name \*.py) ANNOTYPES_SOURCES := $(shell find $(ANNOTYPES)/annotypes -name \*.py) @@ -90,15 +84,16 @@ $(TEMPLATES): $(MALCOLM_BUILD) $(ANNOTYPES_BUILD) $(MALCOLMJS_BUILD) cp $(PYMALCOLM)/malcolm/modules/web/www/index.html $@/withoutnav.html ./add_nav.sh $@/withoutnav.html > $@/index.html -$(WEBSERVER_ZPKG): $(ZPKG_LIST) $(SOURCES) $(TEMPLATES) +zpkg: $(SOURCES) $(TEMPLATES) rm -f $(BUILD_DIR)/*.zpg - $(MAKE_ZPKG) -t $(TOP) -b $(BUILD_DIR) -d $(BUILD_DIR) $< $(GIT_VERSION) - -zpkg: $(WEBSERVER_ZPKG) + $(MAKE_ZPKG) -t $(TOP) -b $(BUILD_DIR) -d $(BUILD_DIR) \ + $(TOP)/etc/panda-webcontrol.list $(GIT_VERSION) + $(MAKE_ZPKG) -t $(TOP) -b $(BUILD_DIR) -d $(BUILD_DIR) \ + $(TOP)/etc/panda-webcontrol-no-subnet-validation.list $(GIT_VERSION) # Push a github release -github-release: $(WEBSERVER_ZPKG) - $(MAKE_GITHUB_RELEASE) PandABlocks-webcontrol $(GIT_VERSION) $(WEBSERVER_ZPKG) +github-release: $(BUILD_DIR)/*.zpg + $(MAKE_GITHUB_RELEASE) PandABlocks-webcontrol $(GIT_VERSION) $^ clean: rm -rf $(BUILD_DIR) diff --git a/etc/panda-webcontrol-no-subnet-validation.list b/etc/panda-webcontrol-no-subnet-validation.list new file mode 100644 index 0000000..5c2ec9e --- /dev/null +++ b/etc/panda-webcontrol-no-subnet-validation.list @@ -0,0 +1,4 @@ +d share/panda-webcontrol/options + +# Add a magic file +t share/panda-webcontrol/options/no-subnet-validation src/no-subnet-validation diff --git a/src/no-subnet-validation b/src/no-subnet-validation new file mode 100644 index 0000000..440f159 --- /dev/null +++ b/src/no-subnet-validation @@ -0,0 +1,3 @@ +# Presence of this file means that the websocket server will +# allow any client to Put/Post, rather than restricting to those +# client ips in the same subnet as the host \ No newline at end of file diff --git a/src/panda-webcontrol.py b/src/panda-webcontrol.py index 05a5242..80f7be0 100755 --- a/src/panda-webcontrol.py +++ b/src/panda-webcontrol.py @@ -1,6 +1,7 @@ import logging.handlers import code import argparse +import os from tornado.web import RequestHandler from tornado.template import Loader @@ -22,6 +23,10 @@ parser.add_argument( "--templatedir", default="/opt/share/panda-webcontrol/templates", help="Directory to get templated html files from") +parser.add_argument( + "--optionsdir", default="/opt/share/panda-webcontrol/options", + help="Directory of options that can optionally be installed like" + "no-subnet-check") parser.add_argument( "--admindir", default="/usr/share/web-admin/templates", help="Directory to get web-admin templates like nav.template from") @@ -88,6 +93,12 @@ class TemplatedGuiPart(web.parts.GuiServerPart): GuiHandler = TemplateHandler +# Check the options +if os.path.exists(args.optionsdir): + options = sorted(os.listdir(args.optionsdir)) +else: + options = [] + # Make a profiler profiler = Profiler() @@ -96,7 +107,9 @@ class TemplatedGuiPart(web.parts.GuiServerPart): # Add the websocket server controller = web.controllers.HTTPServerComms(port=args.wsport, mri="WS") -controller.add_part(web.parts.WebsocketServerPart()) +controller.add_part(web.parts.WebsocketServerPart( + subnet_validation="no-subnet-validation" not in options +)) controller.add_part(TemplatedGuiPart()) process.add_controller(controller)