Timelapse: Add snapshot imeout & SSL validation settings

Implements #2455 & #2362
This commit is contained in:
Gina Häußge committed 2018-03-07 15:20:46 +01:00
1 parent 1f9c9bed42
commit 3fcd5adfbd
9 files changed
+45 -3

No files matched your search

+2
View File
@@ -45,6 +45,8 @@ Test paths or URLs
* ``method``: The request method to use for the test. Optional, defaults to ``HEAD``.
* ``timeout``: A timeout for the request, in seconds. If no reply from the tested URL has been
received within this time frame, the check will be considered a failure. Optional, defaults to 3 seconds.
* ``validSsl``: Whether to validate the SSL connection if the ``url`` happens to be an HTTPS URL or not. Optional,
defaults to ``True``.
* ``status``: The status code(s) or named status range(s) to test for. Can be either a single
value or a list of either HTTP status codes or any of the following named status ranges:
+5 -1
View File
@@ -337,6 +337,7 @@ def utilTestPath():
url = data["url"]
method = data.get("method", "HEAD")
timeout = 3.0
valid_ssl = True
check_status = [status_ranges["normal"]]
if "timeout" in data:
@@ -345,6 +346,9 @@ def utilTestPath():
except:
return make_response("{!r} is not a valid value for timeout (must be int or float)".format(data["timeout"]), 400)
if "validSsl" in data:
valid_ssl = data["validSsl"] in valid_boolean_trues
if "status" in data:
request_status = data["status"]
if not isinstance(request_status, list):
@@ -363,7 +367,7 @@ def utilTestPath():
check_status.append([code])
try:
response = requests.request(method=method, url=url, timeout=timeout)
response = requests.request(method=method, url=url, timeout=timeout, verify=valid_ssl)
status = response.status_code
except:
status = 0
+4
View File
@@ -101,6 +101,8 @@ def getSettings():
"streamRatio": s.get(["webcam", "streamRatio"]),
"streamTimeout": s.getInt(["webcam", "streamTimeout"]),
"snapshotUrl": s.get(["webcam", "snapshot"]),
"snapshotTimeout": s.getInt(["webcam", "snapshotTimeout"]),
"snapshotSslValidation": s.getBoolean(["webcam", "snapshotSslValidation"]),
"ffmpegPath": s.get(["webcam", "ffmpeg"]),
"bitrate": s.get(["webcam", "bitrate"]),
"ffmpegThreads": s.get(["webcam", "ffmpegThreads"]),
@@ -332,6 +334,8 @@ def _saveSettings(data):
if "streamRatio" in data["webcam"] and data["webcam"]["streamRatio"] in ("16:9", "4:3"): s.set(["webcam", "streamRatio"], data["webcam"]["streamRatio"])
if "streamTimeout" in data["webcam"]: s.setInt(["webcam", "streamTimeout"], data["webcam"]["streamTimeout"])
if "snapshotUrl" in data["webcam"]: s.set(["webcam", "snapshot"], data["webcam"]["snapshotUrl"])
if "snapshotTimeout" in data["webcam"]: s.setInt(["webcam", "snapshotTimeout"], data["webcam"]["snapshotTimeout"])
if "snapshotSslValidation" in data["webcam"]: s.setBoolean(["webcam", "snapshotSslValidation"], data["webcam"]["snapshotSslValidation"])
if "ffmpegPath" in data["webcam"]: s.set(["webcam", "ffmpeg"], data["webcam"]["ffmpegPath"])
if "bitrate" in data["webcam"]: s.set(["webcam", "bitrate"], data["webcam"]["bitrate"])
if "ffmpegThreads" in data["webcam"]: s.setInt(["webcam", "ffmpegThreads"], data["webcam"]["ffmpegThreads"])
+2
View File
@@ -199,6 +199,8 @@ default_settings = {
"streamRatio": "16:9",
"streamTimeout": 5,
"snapshot": None,
"snapshotTimeout": 5,
"snapshotSslValidation": True,
"ffmpeg": None,
"ffmpegThreads": 1,
"bitrate": "5000k",
@@ -120,6 +120,8 @@ $(function() {
self.webcam_streamRatio = ko.observable(undefined);
self.webcam_streamTimeout = ko.observable(undefined);
self.webcam_snapshotUrl = ko.observable(undefined);
self.webcam_snapshotTimeout = ko.observable(undefined);
self.webcam_snapshotSslValidation = ko.observable(undefined);
self.webcam_ffmpegPath = ko.observable(undefined);
self.webcam_bitrate = ko.observable(undefined);
self.webcam_ffmpegThreads = ko.observable(undefined);
@@ -322,7 +324,12 @@ $(function() {
var errorTitle = gettext("Snapshot test failed");
self.testWebcamSnapshotUrlBusy(true);
OctoPrint.util.testUrl(self.webcam_snapshotUrl(), {method: "GET", response: "bytes"})
OctoPrint.util.testUrl(self.webcam_snapshotUrl(), {
method: "GET",
response: "bytes",
timeout: self.webcam_snapshotTimeout(),
validSsl: self.webcam_snapshotSslValidation()
})
.done(function(response) {
if (!response.result) {
showMessageDialog({
@@ -24,6 +24,8 @@
<div class="hide">
{% include "snippets/settings/webcam/ffmpegBitrate.jinja2" %}
{% include "snippets/settings/webcam/ffmpegThreads.jinja2" %}
{% include "snippets/settings/webcam/webcamSnapshotTimeout.jinja2" %}
{% include "snippets/settings/webcam/webcamSnapshotSslValidation.jinja2" %}
</div>
</div>
</form>
@@ -0,0 +1,7 @@
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: webcam_snapshotSslValidation" id="settings-webcamSnapshotSslValidation"> {{ _('Validate SSL on snapshot URL (if applicable)') }}
</label>
</div>
</div>
@@ -0,0 +1,9 @@
<div class="control-group" title="{{ _('Timeout for taking a snapshot') }}">
<label class="control-label" for="settings-webcamSnapshotTimeout">{{ _('Snapshot timeout') }}</label>
<div class="controls">
<div class="input-append">
<input type="number" min="1" class="input-mini text-right" data-bind="value: webcam_snapshotTimeout" id="settings-webcamSnapshotTimeout">
<span class="add-on">sec</span>
</div>
</div>
</div>
+6 -1
View File
@@ -363,6 +363,8 @@ class Timelapse(object):
self._capture_dir = settings().getBaseFolder("timelapse_tmp")
self._movie_dir = settings().getBaseFolder("timelapse")
self._snapshot_url = settings().get(["webcam", "snapshot"])
self._snapshot_timeout = settings().getInt(["webcam", "snapshotTimeout"])
self._snapshot_validate_ssl = settings().getBoolean(["webcam", "snapshotSslValidation"])
self._fps = fps
@@ -578,7 +580,10 @@ class Timelapse(object):
eventManager().fire(Events.CAPTURE_START, dict(file=filename))
try:
self._logger.debug("Going to capture {} from {}".format(filename, self._snapshot_url))
r = requests.get(self._snapshot_url, stream=True, timeout=5)
r = requests.get(self._snapshot_url,
stream=True,
timeout=self._snapshot_timeout,
verify=self._snapshot_validate_ssl)
r.raise_for_status()
with open (filename, "wb") as f: