From 7765e9afa9085b5e1d74d6513887438300d0b719 Mon Sep 17 00:00:00 2001 From: Stevil Knevil Date: Thu, 6 May 2021 17:33:55 +0100 Subject: [PATCH 1/7] Implemented ignored commands --- docs/configuration/config_yaml.rst | 5 +++++ src/octoprint/server/api/settings.py | 5 +++++ src/octoprint/settings.py | 1 + .../static/js/app/viewmodels/settings.js | 7 +++++++ .../dialogs/settings/serialconnection.jinja2 | 7 +++++++ src/octoprint/util/comm.py | 16 ++++++++++++++++ 6 files changed, 41 insertions(+) diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index a945a6c2a..992e9af39 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -708,6 +708,11 @@ Use the following settings to configure the serial connection to the printer: - M0 - M1 + # Commands which should not be sent to the printer and just silently ignored. + # An example of when you may wish to use this could be useful if you wish to manually change a filament on M600, + # by using that as a Pausing command (below) + ignoredCommands: + # Commands which should cause OctoPrint to pause any ongoing prints. pausingCommands: - M0 diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 39d7db81a..19e030b5d 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -202,6 +202,7 @@ def getSettings(): "longRunningCommands": s.get(["serial", "longRunningCommands"]), "checksumRequiringCommands": s.get(["serial", "checksumRequiringCommands"]), "blockedCommands": s.get(["serial", "blockedCommands"]), + "ignoredCommands": s.get(["serial", "ignoredCommands"]), "pausingCommands": s.get(["serial", "pausingCommands"]), "emergencyCommands": s.get(["serial", "emergencyCommands"]), "helloCommand": s.get(["serial", "helloCommand"]), @@ -766,6 +767,10 @@ def _saveSettings(data): data["serial"]["blockedCommands"], (list, tuple) ): s.set(["serial", "blockedCommands"], data["serial"]["blockedCommands"]) + if "ignoredCommands" in data["serial"] and isinstance( + data["serial"]["ignoredCommands"], (list, tuple) + ): + s.set(["serial", "ignoredCommands"], data["serial"]["ignoredCommands"]) if "pausingCommands" in data["serial"] and isinstance( data["serial"]["pausingCommands"], (list, tuple) ): diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 2a7c9fe39..963987934 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -135,6 +135,7 @@ default_settings = { "blacklistedBaudrates": [], "longRunningCommands": ["G4", "G28", "G29", "G30", "G32", "M400", "M226", "M600"], "blockedCommands": ["M0", "M1"], + "ignoredCommands": [], "pausingCommands": ["M0", "M1", "M25"], "emergencyCommands": ["M112", "M108", "M410"], "checksumRequiringCommands": ["M110"], diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 1e0cc0fdf..f6cc79a93 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -206,6 +206,7 @@ $(function () { self.serial_longRunningCommands = ko.observable(undefined); self.serial_checksumRequiringCommands = ko.observable(undefined); self.serial_blockedCommands = ko.observable(undefined); + self.serial_ignoredCommands = ko.observable(undefined); self.serial_pausingCommands = ko.observable(undefined); self.serial_emergencyCommands = ko.observable(undefined); self.serial_helloCommand = ko.observable(undefined); @@ -1057,6 +1058,9 @@ $(function () { blockedCommands: function () { return splitTextToArray(self.serial_blockedCommands(), ",", true); }, + ignoredCommands: function () { + return splitTextToArray(self.serial_ignoredCommands(), ",", true); + }, pausingCommands: function () { return splitTextToArray(self.serial_pausingCommands(), ",", true); }, @@ -1259,6 +1263,9 @@ $(function () { blockedCommands: function (value) { self.serial_blockedCommands(value.join(", ")); }, + ignoredCommands: function (value) { + self.serial_ignoredCommands(value.join(", ")); + }, pausingCommands: function (value) { self.serial_pausingCommands(value.join(", ")); }, diff --git a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 index 52b391fa6..e712742d6 100644 --- a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 +++ b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 @@ -401,6 +401,13 @@ {{ _('Use this to specify commands that should never be sent to the printer. Just the G or M code, comma separated. Defaults to M0 and M1 since most firmware will block until a button on the controller has been pressed if it receives either of those two commands.') }} +
+ +
+ + {{ _('Use this to specify commands that should be silently ignored and never be sent to the printer. Just the G or M code, comma separated. Unlike blocked commands above, there will be no warning popup when these commands are encountered.') }} +
+
diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index a5dcd8895..fe0fb80c2 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -645,6 +645,7 @@ class MachineCom(object): ["serial", "checksumRequiringCommands"] ) self._blocked_commands = settings().get(["serial", "blockedCommands"]) + self._ignored_commands = settings().get(["serial", "ignoredCommands"]) self._pausing_commands = settings().get(["serial", "pausingCommands"]) self._emergency_commands = settings().get(["serial", "emergencyCommands"]) self._sanity_check_tools = settings().getBoolean(["serial", "sanityCheckTools"]) @@ -5297,6 +5298,21 @@ class MachineCom(object): }, ) return (None,) + if gcode in self._ignored_commands: + message = "Not sending {} to printer, it's configured as an ignored command".format( + gcode + ) + self._log("Info: " + message) + self._logger.info(message) + eventManager().fire( + Events.COMMAND_SUPPRESSED, + { + "command": cmd, + "message": message, + "severity": "info", + }, + ) + return (None,) def _command_phase_sending( self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs From 98454a2827d31d78d0606e88b6053f8892b4a693 Mon Sep 17 00:00:00 2001 From: Stevil Knevil Date: Thu, 6 May 2021 17:45:41 +0100 Subject: [PATCH 2/7] Updated Authors.md --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 705d6bb33..cbdfc50f8 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -144,6 +144,7 @@ date of first contribution): * [Yvan Rodrigues](https://github.com/TwoRedCells) * [Elton Law](https://github.com/eltonlaw) * ["sparxooo"](https://github.com/sparxooo) + * ["Stevil Knevil"](https://github.com/StevilKnevil) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and From e403e8cc750e1124a3316549b64c229a768a110a Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Sun, 9 May 2021 16:58:39 +0100 Subject: [PATCH 3/7] :zap: Don't re-render the plugin repository if notmodified Closes #4131 --- .../plugins/pluginmanager/static/js/pluginmanager.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index 7d7eba04b..6248965f2 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -693,11 +693,15 @@ $(function () { } OctoPrint.plugins.pluginmanager - .getRepository(!!options.refresh) + .getRepository(!!options.refresh, {ifModified: true}) .fail(function () { deferred.reject(); }) - .done(function (data) { + .done(function (data, status, xhr) { + // Don't update if cached - requires ifModified: true to pass through + // the 304 status, otherwise it fakes it and produces 200 all the time. + if (xhr.status === 304) return; + self.fromRepositoryResponse(data.repository); self.online(data.online !== undefined ? data.online : true); deferred.resolveWith(data); From 7234b26d2a1980b4c1baa8415ac49b927c9dcc60 Mon Sep 17 00:00:00 2001 From: Eyal <109809+eyal0@users.noreply.github.com> Date: Tue, 11 May 2021 09:34:16 -0600 Subject: [PATCH 4/7] bedZ should be a float --- src/octoprint/server/api/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index c3e6cea10..d718707c3 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -643,7 +643,7 @@ def _saveSettings(data): if "runAt" in data["gcodeAnalysis"]: s.set(["gcodeAnalysis", "runAt"], data["gcodeAnalysis"]["runAt"]) if "bedZ" in data["gcodeAnalysis"]: - s.setBoolean(["gcodeAnalysis", "bedZ"], data["gcodeAnalysis"]["bedZ"]) + s.setFloat(["gcodeAnalysis", "bedZ"], data["gcodeAnalysis"]["bedZ"]) if "serial" in data: if "autoconnect" in data["serial"]: From 2c03ecdfff8f111fd2f9d9db1bdb6a8d01fdfe84 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Wed, 12 May 2021 00:08:32 +0100 Subject: [PATCH 5/7] :bug: Fix SameSite=None cookie When passing Python's NoneType down to Werkzeug, it uses this logic: ```python if samesite is not None: samesite = samesite.title() if samesite not in {"Strict", "Lax", "None"}: raise ValueError("SameSite must be 'Strict', 'Lax', or 'None'.") ``` This means that when OctoPrint converted any strings 'None' into NoneType, they would not show up in the Set-Cookie header. Investigation: https://community.octoprint.org/t/unable-to-log-into-octoprint-through-an-iframe-on-home-assistant/33977/20?u=charlie_powell Link to werkzeug source: https://github.com/pallets/werkzeug/blob/1dde4b1790f9c46b7122bb8225e6b48a5b22a615/src/werkzeug/http.py#L1213-L1217 Docs, while not explicitly clear, here: https://werkzeug.palletsprojects.com/en/1.0.x/http/?highlight=dump_cookie#werkzeug.http.dump_cookie --- src/octoprint/server/util/flask.py | 6 ++++-- tests/server/util/test_flask.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 4afa58051..cf7434f0b 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -567,8 +567,10 @@ class OctoPrintFlaskResponse(flask.Response): if samesite is not None: samesite = samesite.lower() if samesite == "none": - samesite = None - if samesite not in (None, "strict", "lax"): + # Must be string "None" + samesite = "None" + if samesite not in ("None", "strict", "lax"): + # If NoneType, the cookie is not set samesite = None kwargs["samesite"] = samesite diff --git a/tests/server/util/test_flask.py b/tests/server/util/test_flask.py index 6596e232c..397eeccf7 100644 --- a/tests/server/util/test_flask.py +++ b/tests/server/util/test_flask.py @@ -503,7 +503,7 @@ class OctoPrintFlaskResponseTest(unittest.TestCase): @data( [None, None, False, None, None], - [None, None, False, "none", None], + [None, None, False, "none", "None"], [None, None, False, "lax", "lax"], [None, None, False, "StRiCt", "strict"], [None, None, False, "INVALID", None], From d83d4b15280bd716274f8012c78653c6578e5625 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Wed, 12 May 2021 16:45:27 +0100 Subject: [PATCH 6/7] :pencil: Adjust/clarify docs --- docs/configuration/config_yaml.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index a945a6c2a..c8d461e15 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -904,9 +904,9 @@ Use the following settings to configure the server: # Settings for further configuration of the cookies that OctoPrint sets (login, remember me, ...) cookies: - # SameSite setting to use on the cookies. Possible values are None, Lax and Strict. Defaults to None but - # be advised that browsers will soon force this to Lax unless also being set as Secure and served over - # https, which will cause issues with embedding OctoPrint in frames. + # SameSite setting to use on the cookies. Possible values are None, Lax and Strict. Defaults to not set but + # be advised that many browsers now default to Lax unless set as Secure, explicitly setting the cookie type + # here and served over https, which causes issues with embedding OctoPrint in frames. # # See also https://www.chromestatus.com/feature/5088147346030592, # https://www.chromestatus.com/feature/5633521622188032 and issue #3482 From d153bad51b5371368c2537399096188c9b4ca75e Mon Sep 17 00:00:00 2001 From: Harald Wagener Date: Thu, 13 May 2021 11:25:06 +0200 Subject: [PATCH 7/7] Update messages.po tiny grammar fix. --- src/octoprint/translations/de/LC_MESSAGES/messages.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/translations/de/LC_MESSAGES/messages.po b/src/octoprint/translations/de/LC_MESSAGES/messages.po index 34c282e10..dca455d93 100644 --- a/src/octoprint/translations/de/LC_MESSAGES/messages.po +++ b/src/octoprint/translations/de/LC_MESSAGES/messages.po @@ -5852,7 +5852,7 @@ msgid "\n" " web interface now by clicking the button below.\n" " " msgstr "\n" -" Die Serverversion hat sich geändert, ein Neuladen des Webinterfaces ist notwendig. Das wird evtl. laufenden Printjobs nicht unterbrechen. Bitte lade das Webinterface jetzt neu, indem du auf den Button unten klickst." +" Die Serverversion hat sich geändert, ein Neuladen des Webinterfaces ist notwendig. Das wird evtl. laufende Printjobs nicht unterbrechen. Bitte lade das Webinterface jetzt neu, indem du auf den Button unten klickst." #: src/octoprint/templates/sidebar/connection.jinja2:8 msgid "Save connection settings"