diff --git a/docs/api/util.rst b/docs/api/util.rst index 1ee12ff22..e01664d20 100644 --- a/docs/api/util.rst +++ b/docs/api/util.rst @@ -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: diff --git a/src/octoprint/server/api/__init__.py b/src/octoprint/server/api/__init__.py index ea042e3a2..ed9c164fe 100644 --- a/src/octoprint/server/api/__init__.py +++ b/src/octoprint/server/api/__init__.py @@ -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 diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index ff578813a..c7023f8c7 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -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"]) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 2b29b9348..83e60498c 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -199,6 +199,8 @@ default_settings = { "streamRatio": "16:9", "streamTimeout": 5, "snapshot": None, + "snapshotTimeout": 5, + "snapshotSslValidation": True, "ffmpeg": None, "ffmpegThreads": 1, "bitrate": "5000k", diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 96abb943f..86a9ce019 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -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({ diff --git a/src/octoprint/templates/dialogs/settings/webcam.jinja2 b/src/octoprint/templates/dialogs/settings/webcam.jinja2 index 60a846c90..7a1330edc 100644 --- a/src/octoprint/templates/dialogs/settings/webcam.jinja2 +++ b/src/octoprint/templates/dialogs/settings/webcam.jinja2 @@ -24,6 +24,8 @@
{% include "snippets/settings/webcam/ffmpegBitrate.jinja2" %} {% include "snippets/settings/webcam/ffmpegThreads.jinja2" %} + {% include "snippets/settings/webcam/webcamSnapshotTimeout.jinja2" %} + {% include "snippets/settings/webcam/webcamSnapshotSslValidation.jinja2" %}
diff --git a/src/octoprint/templates/snippets/settings/webcam/webcamSnapshotSslValidation.jinja2 b/src/octoprint/templates/snippets/settings/webcam/webcamSnapshotSslValidation.jinja2 new file mode 100644 index 000000000..c3a425628 --- /dev/null +++ b/src/octoprint/templates/snippets/settings/webcam/webcamSnapshotSslValidation.jinja2 @@ -0,0 +1,7 @@ +
+
+ +
+
diff --git a/src/octoprint/templates/snippets/settings/webcam/webcamSnapshotTimeout.jinja2 b/src/octoprint/templates/snippets/settings/webcam/webcamSnapshotTimeout.jinja2 new file mode 100644 index 000000000..8f6e35c40 --- /dev/null +++ b/src/octoprint/templates/snippets/settings/webcam/webcamSnapshotTimeout.jinja2 @@ -0,0 +1,9 @@ +
+ +
+
+ + sec +
+
+
diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index 8ecd40fb2..d18fb2d9a 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -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: