Server side range checking for timelapse config

This commit is contained in:
Gina Häußge 2015-02-24 19:24:11 +01:00
parent 197859b675
commit b273e06e88
2 changed files with 26 additions and 14 deletions

View file

@ -7,7 +7,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
import os
from flask import request, jsonify, url_for
from flask import request, jsonify, url_for, make_response
from werkzeug.utils import secure_filename
import octoprint.timelapse
@ -79,26 +79,38 @@ def setTimelapseConfig():
if "postRoll" in request.values:
try:
config["postRoll"] = int(request.values["postRoll"])
postRoll = int(request.values["postRoll"])
except ValueError:
pass
return make_response("Invalid value for postRoll: %r" % request.values["postRoll"], 400)
else:
if postRoll >= 0:
config["postRoll"] = postRoll
else:
return make_response("Invalid value for postRoll: %d" % postRoll, 400)
if "fps" in request.values:
try:
config["fps"] = int(request.values["fps"])
fps = int(request.values["fps"])
except ValueError:
pass
return make_response("Invalid value for fps: %r" % request.values["fps"], 400)
else:
if fps > 0:
config["fps"] = fps
else:
return make_response("Invalid value for fps: %d" % fps, 400)
if "interval" in request.values:
interval = 10
try:
interval = int(request.values["interval"])
except ValueError:
pass
config["options"] = {
"interval": interval
}
return make_response("Invalid value for interval: %r" % request.values["interval"])
else:
if interval > 0:
config["options"] = {
"interval": interval
}
else:
return make_response("Invalid value for interval: %d" % interval)
if admin_permission.can() and "save" in request.values and request.values["save"] in valid_boolean_trues:
octoprint.timelapse.configureTimelapse(config, True)

View file

@ -76,11 +76,11 @@ def configureTimelapse(config=None, persist=False):
type = config["type"]
postRoll = 0
if "postRoll" in config:
if "postRoll" in config and config["postRoll"] >= 0:
postRoll = config["postRoll"]
fps = 25
if "fps" in config:
if "fps" in config and config["fps"] > 0:
fps = config["fps"]
if type is None or "off" == type:
@ -89,7 +89,7 @@ def configureTimelapse(config=None, persist=False):
current = ZTimelapse(postRoll=postRoll, fps=fps)
elif "timed" == type:
interval = 10
if "options" in config and "interval" in config["options"]:
if "options" in config and "interval" in config["options"] and config["options"]["interval"] > 0:
interval = config["options"]["interval"]
current = TimedTimelapse(postRoll=postRoll, interval=interval, fps=fps)