Skip to content

Commit

Permalink
Add option for not validating subnet mask
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Apr 24, 2019
1 parent 7da5f56 commit ca7f353
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
19 changes: 7 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions etc/panda-webcontrol-no-subnet-validation.list
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/no-subnet-validation
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion src/panda-webcontrol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging.handlers
import code
import argparse
import os

from tornado.web import RequestHandler
from tornado.template import Loader
Expand All @@ -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")
Expand Down Expand Up @@ -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()

Expand All @@ -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)

Expand Down

0 comments on commit ca7f353

Please sign in to comment.