From 4caf4ef09b402111b7abf36425315271ce588108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 6 Nov 2018 14:02:49 +0100 Subject: [PATCH 01/27] Fix GCODE viewer not being able to load files Side effect of the ForcedLogin plugin and a bug in get_flask_user_from_request. Closes #2873 --- src/octoprint/server/util/flask.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index fc3b148f0..cdec02307 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -1109,7 +1109,8 @@ def get_flask_user_from_request(request): apikey = octoprint.server.util.get_api_key(request) if settings().getBoolean(["api", "enabled"]) and apikey is not None: user = octoprint.server.util.get_user_for_apikey(apikey) - else: + + if user is None: user = flask_login.current_user return user From 343195477b8aa973e12dfe73b29be97736235b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 6 Nov 2018 14:47:39 +0100 Subject: [PATCH 02/27] Fix connection fail if fw doesn't send start Closes #2872 --- src/octoprint/util/__init__.py | 3 +++ src/octoprint/util/comm.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index b23681bc4..6f74fcaf9 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -1299,6 +1299,9 @@ class CountedEvent(object): else: self._internal_set(self._counter - 1) + def reset(self): + self.clear(completely=True) + def wait(self, timeout=None): self._event.wait(timeout) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index cfbedd623..f6bd0e754 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2322,7 +2322,7 @@ class MachineCom(object): def _on_external_reset(self): # hold queue processing, clear queues and acknowledgements, reset line number and last lines with self._send_queue.blocked(): - self._clear_to_send.clear(completely=True) + self._clear_to_send.reset() with self._command_queue.blocked(): self._command_queue.clear() self._send_queue.clear() @@ -2493,7 +2493,7 @@ class MachineCom(object): # first hook to succeed wins, but any can pass on to the next self._changeState(self.STATE_OPEN_SERIAL) self._serial = serial_obj - self._clear_to_send.clear() + self._clear_to_send.reset() return True return False From 68ca2c5e51a2934be40dc0df01848e10abb50b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 6 Nov 2018 15:52:41 +0100 Subject: [PATCH 03/27] Pin regex dependency to last known working version See #2874 and https://bitbucket.org/mrabarnett/mrab-regex/issues/301/typeerror-character-mapping-must-return --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 8c0f76646..3da12ab63 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ INSTALL_REQUIRES = [ "Jinja2>=2.8.1,<2.9", # Jinja 2.9 has breaking changes WRT template scope - we can't # guarantee backwards compatibility for plugins and such with that # version, hence we need to pin to a lower version for now. See #1697 + "regex==2018.11.3", # Current version as of 2018-11-06 is broken. See #2874 "werkzeug>=0.8.3,<0.9", "tornado==4.5.3", #"sockjs-tornado>=1.0.3,<1.1", # current version is incompatible to tornado 5, we use a From e23fe4a925b676a1ee2dd9eca95bdad6a70b8df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 6 Nov 2018 17:34:01 +0100 Subject: [PATCH 04/27] forcelogin: Fix issue when running with acl disabled Closes one variant of #2876 --- src/octoprint/plugins/forcelogin/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/octoprint/plugins/forcelogin/__init__.py b/src/octoprint/plugins/forcelogin/__init__.py index 1c5ce3f6b..126d0b30b 100644 --- a/src/octoprint/plugins/forcelogin/__init__.py +++ b/src/octoprint/plugins/forcelogin/__init__.py @@ -85,6 +85,9 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): # ACL hasn't been configured yet, make an exception return + elif not self._user_manager.enabled: + # ACL isn't enabled + return if flask.request.endpoint in ("api.login",): return @@ -99,6 +102,9 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): # ACL hasn't been configured yet, make an exception return + elif not self._user_manager.enabled: + # ACL isn't enabled + return import tornado.web from octoprint.server.util.flask import get_flask_user_from_request @@ -111,6 +117,9 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): # ACL hasn't been configured yet, make an exception return True + elif not self._user_manager.enabled: + # ACL isn't enabled + return True return user is not None and not user.is_anonymous() and user.is_active() @@ -118,6 +127,9 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): # ACL hasn't been configured yet, make an exception return True + elif not self._user_manager.enabled: + # ACL isn't enabled + return True if message in ("connected", "reauthRequired"): return True From c1482eaacdc2ad5f6133c574936d1a8bbe81f8ae Mon Sep 17 00:00:00 2001 From: tedder Date: Tue, 6 Nov 2018 15:37:45 -0800 Subject: [PATCH 05/27] add throttle_state to tracking - weave the throttle_state through pi_support and tracking. This should come in handy to see how many throttled Pis are out there, as well as if it is correllated with canceled prints. - upgraded disclosure of tracking information so it shows as INFO-level in the logs and all the information is dumped. If tracking.octoprint.org gets it, I should have it too :) --- src/octoprint/plugins/pi_support/__init__.py | 22 ++++++++++++++----- src/octoprint/plugins/tracking/__init__.py | 23 +++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/octoprint/plugins/pi_support/__init__.py b/src/octoprint/plugins/pi_support/__init__.py index 28b4f3d03..04f85ea29 100644 --- a/src/octoprint/plugins/pi_support/__init__.py +++ b/src/octoprint/plugins/pi_support/__init__.py @@ -35,10 +35,9 @@ _FLAG_PAST_UNDERVOLTAGE = 1 << 16 _FLAG_PAST_FREQ_CAPPED = 1 << 17 _FLAG_PAST_THROTTLED = 1 << 18 - class ThrottleState(object): @classmethod - def from_value(cls, value): + def from_value(cls, value=0): if value == 0: return ThrottleState() @@ -47,10 +46,12 @@ class ThrottleState(object): throttled=_FLAG_THROTTLED & value == _FLAG_THROTTLED, past_undervoltage=_FLAG_PAST_UNDERVOLTAGE & value == _FLAG_PAST_UNDERVOLTAGE, past_freq_capped=_FLAG_PAST_FREQ_CAPPED & value == _FLAG_PAST_FREQ_CAPPED, - past_throttled=_FLAG_PAST_THROTTLED & value == _FLAG_PAST_THROTTLED) + past_throttled=_FLAG_PAST_THROTTLED & value == _FLAG_PAST_THROTTLED, + raw_value=value) return ThrottleState(**kwargs) def __init__(self, **kwargs): + self._raw_value = kwargs.get('raw_value', -1) self._undervoltage = False self._freq_capped = False self._throttled = False @@ -111,7 +112,8 @@ class ThrottleState(object): and self._past_throttled == other._past_throttled def as_dict(self): - return dict(current_undervoltage=self.current_undervoltage, + return dict(raw_value=self._raw_value, + current_undervoltage=self.current_undervoltage, past_undervoltage=self.past_undervoltage, current_overheat=self.current_overheat, past_overheat=self.past_overheat, @@ -242,6 +244,10 @@ class PiSupportPlugin(octoprint.plugin.EnvironmentDetectionPlugin, def _check_throttled_state_condition(self): return self._throttle_functional + def get_throttle_state(self, run_now=False): + '''public method to pass around in plugin_helpers''' + return self._throttle_state.as_dict() + def _check_throttled_state(self): command = self._settings.get(["vcgencmd_throttle_check_command"]) @@ -299,5 +305,11 @@ def __plugin_check__(): return "raspberry pi" in proc_dt_model.lower() def __plugin_load__(): + plugin = PiSupportPlugin() global __plugin_implementation__ - __plugin_implementation__ = PiSupportPlugin() + __plugin_implementation__ = plugin + + global __plugin_helpers__ + __plugin_helpers__ = dict( + get_throttled=plugin.get_throttle_state + ) diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 108b275e5..30e65d46b 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -82,15 +82,23 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._environment = environment ##~~ StartupPlugin + def on_startup(self, *args, **kwargs): + self._helpers_get_throttle_state = None def on_after_startup(self): - self._track_startup() - ping = self._settings.get_int(["ping"]) if ping: self._ping_worker = RepeatedTimer(ping, self._track_ping) self._ping_worker.start() + # cautiously look for the get_throttled helper from pi_support + pi_helper = self._plugin_manager.get_helpers("pi_support", "get_throttled") + if pi_helper and 'get_throttled' in pi_helper: + self._helpers_get_throttle_state = pi_helper['get_throttled'] + + # now that we have everything set up, phone home. + self._track_startup() + ##~~ ShutdownPlugin def on_shutdown(self): @@ -160,8 +168,12 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, freq=self._environment[b"hardware"][b"freq"], ram=self._environment[b"hardware"][b"ram"]) + if self._helpers_get_throttle_state: + payload[b"throttle_state"] = self._helpers_get_throttle_state() + if b"plugins" in self._environment and b"pi_support" in self._environment[b"plugins"]: payload[b"pi_model"] = self._environment[b"plugins"][b"pi_support"][b"model"] + if b"octopi_version" in self._environment[b"plugins"][b"pi_support"]: payload[b"octopi_version"] = self._environment[b"plugins"][b"pi_support"][b"octopi_version"] @@ -219,6 +231,11 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, track_event = "print_failed" elif event == Events.PRINT_CANCELLED: track_event = "print_cancelled" + else: + logger.info("unknown event, skipping: {}".format(event)) + + if self._helpers_get_throttle_state: + args[b"throttle_state"] = self._helpers_get_throttle_state() if track_event is not None: self._track(track_event, **args) @@ -254,7 +271,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, params=params, timeout=3.1, headers=headers) - self._logger.debug("Sent tracking event to {}".format(url)) + self._logger.info("Sent tracking event to {}, params: {}".format(url, kwargs)) except: if self._logger.isEnabledFor(logging.DEBUG): self._logger.exception("Error while sending event to anonymous usage tracking".format(url)) From 8596ae5c4a1551a0860d07e01e4e8af511b58f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 7 Nov 2018 11:10:31 +0100 Subject: [PATCH 06/27] SWU: Make sure check providers are in the correct format Just in case there's some odd data in `config.yaml` as reported in https://github.com/foosel/OctoPrint/issues/2871#issuecomment-436507623 --- src/octoprint/plugins/softwareupdate/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index fd17d0897..e5cc6f7ba 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -117,6 +117,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, update_check_hooks = self._plugin_manager.get_hooks("octoprint.plugin.softwareupdate.check_config") check_providers = self._settings.get(["check_providers"], merged=True) + if not isinstance(check_providers, dict): + check_providers = dict() + effective_configs = dict() for name, hook in update_check_hooks.items(): From 76f48b3b137691679efdeb88d6d38aed34a1647f Mon Sep 17 00:00:00 2001 From: tedder Date: Thu, 8 Nov 2018 01:29:15 +0000 Subject: [PATCH 07/27] PR feedback: throttle state and uuid - add a way to get the raw value only from throttle state (glad I already plumbed it into the object!) - add warning about not sending uuid, modify the log entry too --- src/octoprint/plugins/pi_support/__init__.py | 8 ++++++-- src/octoprint/plugins/tracking/__init__.py | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/pi_support/__init__.py b/src/octoprint/plugins/pi_support/__init__.py index 04f85ea29..69c3a9448 100644 --- a/src/octoprint/plugins/pi_support/__init__.py +++ b/src/octoprint/plugins/pi_support/__init__.py @@ -244,8 +244,12 @@ class PiSupportPlugin(octoprint.plugin.EnvironmentDetectionPlugin, def _check_throttled_state_condition(self): return self._throttle_functional - def get_throttle_state(self, run_now=False): - '''public method to pass around in plugin_helpers''' + def get_throttle_state(self, raw_value_only=False, run_now=False): + '''public method to pass around in plugin_helpers.''' + + # Not using the `run_now` yet, but leaving it as a placeholder. + + if raw_value_only: return self._throttle_state._raw_value return self._throttle_state.as_dict() def _check_throttled_state(self): diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 30e65d46b..fbe7561a4 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -169,7 +169,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, ram=self._environment[b"hardware"][b"ram"]) if self._helpers_get_throttle_state: - payload[b"throttle_state"] = self._helpers_get_throttle_state() + payload[b"throttle_state"] = self._helpers_get_throttle_state(raw_value_only=True) if b"plugins" in self._environment and b"pi_support" in self._environment[b"plugins"]: payload[b"pi_model"] = self._environment[b"plugins"][b"pi_support"][b"model"] @@ -263,15 +263,18 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, server = self._settings.get([b"server"]) url = server.format(id=self._settings.get([b"unique_id"]), event=event) + # don't print the URL or uuid! That would expose the uuid in forums if pasted. + # (it's okay for the user to know their uuid, but it shouldn't be shared) headers = {"User-Agent": "OctoPrint/{}".format(get_octoprint_version_string())} try: params = urlencode(kwargs, doseq=True).replace("+", "%20") + requests.get(url, params=params, timeout=3.1, headers=headers) - self._logger.info("Sent tracking event to {}, params: {}".format(url, kwargs)) + self._logger.info("Sent tracking event to /{}, params: {}".format(event, kwargs)) except: if self._logger.isEnabledFor(logging.DEBUG): self._logger.exception("Error while sending event to anonymous usage tracking".format(url)) From 98c84b6bb9304919929d4602631dd7b4f473a113 Mon Sep 17 00:00:00 2001 From: tedder Date: Thu, 8 Nov 2018 01:34:45 +0000 Subject: [PATCH 08/27] fix test, match dict --- tests/plugins/pi_support/test_pi_support.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/plugins/pi_support/test_pi_support.py b/tests/plugins/pi_support/test_pi_support.py index be33f8c71..c7607bde8 100644 --- a/tests/plugins/pi_support/test_pi_support.py +++ b/tests/plugins/pi_support/test_pi_support.py @@ -150,4 +150,5 @@ class ThrottleStateTestCase(unittest.TestCase): current_overheat=False, past_overheat=True, current_issue=True, - past_issue=True)) + past_issue=True, + raw_value=-1)) From 1ec61a9fe6fbfa2fff71ad056d3623715792d9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 8 Nov 2018 13:41:56 +0100 Subject: [PATCH 09/27] Give the favicon mask SVG width and height attrs Otherwise it won't render correctly in Firefox due to drawImage silently failing, see also https://bugzilla.mozilla.org/show_bug.cgi?id=700533 Closes #2879 --- src/octoprint/static/img/mask-theme.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/static/img/mask-theme.svg b/src/octoprint/static/img/mask-theme.svg index 1d09f4d45..dd8350b79 100644 --- a/src/octoprint/static/img/mask-theme.svg +++ b/src/octoprint/static/img/mask-theme.svg @@ -1,7 +1,7 @@ + viewBox="0 0 107.1 107.1" width="256" height="256" style="enable-background:new 0 0 107.1 107.1;" xml:space="preserve">