Merge branch 'maintenance' into devel
# Conflicts: # setup.py # src/octoprint/plugins/printer_safety_check/__init__.py # tests/filemanager/test_filemanager.py
This commit is contained in:
commit
25f26170ff
18 files changed
+680
-67
No files matched your search
@@ -0,0 +1,40 @@
|
||||
.. _sec-bundledplugins-errortracking:
|
||||
|
||||
Error Tracking Plugin
|
||||
=====================
|
||||
|
||||
The Error Tracking plugin will cause any logged exceptions in the server and the browser interface to be sent to
|
||||
OctoPrint's `Sentry instance <https://sentry.io/>`_.
|
||||
|
||||
By enabling it you help to gather detailed information on the cause of bugs or other issues. This is especially
|
||||
valuable on release candidates, which is why this plugin will also prompt you to enable error tracking if it detects
|
||||
that you are subscribed to an RC release channel.
|
||||
|
||||
By default, even when enabled it will only be active if you are running a released OctoPrint version, so either a stable
|
||||
release or a release candidate.
|
||||
|
||||
The Error Tracking plugin is using a Sentry instance kindly provided by `sentry.io <https://sentry.io/>`_. For information on their service
|
||||
please refer to their `Security & Compliance documentation <https://sentry.io/security/>`_
|
||||
and their `Privacy Policy <https://sentry.io/privacy/>`_.
|
||||
|
||||
The Error Tracking plugin has been bundled with OctoPrint since version 1.3.11.
|
||||
|
||||
.. _sec-bundledplugins-errortracking-configuration:
|
||||
|
||||
Configuring the plugin
|
||||
----------------------
|
||||
|
||||
The plugin supports the following configuration keys:
|
||||
|
||||
* ``enabled``: Whether to enable error tracking. Defaults to ``false``.
|
||||
* ``enabled_unreleased``: Whether to also enable tracking on unreleased OctoPrint versions (anything not stable releases
|
||||
or release candidates). Defaults to ``false``.
|
||||
* ``unique_id``: Unique instance identifier, auto generated on first activation
|
||||
|
||||
.. _sec-bundledplugins-errortracking-sourcecode:
|
||||
|
||||
Source Code
|
||||
-----------
|
||||
|
||||
The source of the Error Tracking plugin is bundled with OctoPrint and can be
|
||||
found in its source repository under ``src/octoprint/plugins/errortracking``.
|
||||
@@ -9,9 +9,11 @@ Bundled Plugins
|
||||
|
||||
action_command_prompt.rst
|
||||
announcements.rst
|
||||
tracking.rst
|
||||
appkeys.rst
|
||||
backup.rst
|
||||
discovery.rst
|
||||
errortracking.rst
|
||||
forcelogin.rst
|
||||
logging.rst
|
||||
pluginmanager.rst
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
.. _sec-bundledplugins-tracking:
|
||||
|
||||
Anonymous Usage Tracking Plugin
|
||||
===============================
|
||||
|
||||
The Anonymous Usage Tracking plugin provides valuable insights into how many instances running what versions of
|
||||
OctoPrint are out there, whether they are successfully completing print jobs and various other metrics.
|
||||
|
||||
By enabling it you help to identify problems with new releases and release candidates early on, and to better tailor
|
||||
OctoPrint's future development to actual use.
|
||||
|
||||
For details on what gets tracked, please refer to `tracking.octoprint.org <https://tracking.octoprint.org>`_
|
||||
and also the `Privacy Policy at tracking.octoprint.org <https://tracking.octoprint.org/privacy>`_.
|
||||
|
||||
The Anonymous Usage Tracking plugin has been bundled with OctoPrint since version 1.3.10.
|
||||
|
||||
.. _sec-bundledplugins-tracking-configuration:
|
||||
|
||||
Configuring the plugin
|
||||
----------------------
|
||||
|
||||
The plugin supports the following configuration keys:
|
||||
|
||||
* ``enabled``: Whether to enable usage tracking. Defaults to ``false``.
|
||||
* ``unique_id``: Unique instance identifier, auto generated on first activation
|
||||
* ``server``: The tracking server to track against. Defaults to a tracking endpoint on ``https://tracking.octoprint.org``.
|
||||
* ``ping``: How often to send a ``ping`` tracking event, in seconds. Defaults to a 15min interval.
|
||||
* ``events``: Granular configuration of enabled tracking events. All default to ``true``.
|
||||
|
||||
* ``startup``: Whether to track startup/shutdown events
|
||||
* ``printjob``: Whether to track print job related events (start, completion, cancel, ...)
|
||||
* ``commerror``: Whether to track communication errors with the printer
|
||||
* ``plugin``: Whether to track plugin related events (install, uninstall, ...)
|
||||
* ``update``: Whether to track update related events (update successful or not, ...)
|
||||
* ``printer``: Whether to track printer related events (connected, firmware, ...)
|
||||
* ``printer_safety_check``: Whether to track warnings of the :ref:`Printer Safety Check <sec-bundledplugins-printer_safety_check>`
|
||||
* ``throttled``: Whether to track throttle events detected on the underlying system
|
||||
|
||||
.. _sec-bundledplugins-tracking-sourcecode:
|
||||
|
||||
Source Code
|
||||
-----------
|
||||
|
||||
The source of the Anonymous Usage Tracking plugin is bundled with OctoPrint and can be
|
||||
found in its source repository under ``src/octoprint/plugins/tracking``.
|
||||
@@ -57,7 +57,8 @@ INSTALL_REQUIRES = [
|
||||
"python-dateutil>=2.7.5,<2.8",
|
||||
"wrapt>=1.10.11,<1.11",
|
||||
"emoji>=0.5.1,<0.6",
|
||||
"frozendict>=1.2,<1.3"
|
||||
"frozendict>=1.2,<1.3",
|
||||
"sentry-sdk==0.6.6"
|
||||
]
|
||||
|
||||
# Python 2 specific requirements
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import octoprint.plugin
|
||||
import logging
|
||||
|
||||
from octoprint.util.version import get_octoprint_version_string, is_released_octoprint_version
|
||||
|
||||
from flask import jsonify
|
||||
from flask_babel import gettext
|
||||
|
||||
SENTRY_URL_SERVER = "https://827d1f11ccda4b31b924f29aaacab493@sentry.io/1373987"
|
||||
SENTRY_URL_COREUI = "https://30bdc39d2248444c8bc01484f38c9444@sentry.io/1374096"
|
||||
|
||||
SETTINGS_DEFAULTS = dict(enabled=False,
|
||||
enabled_unreleased=False,
|
||||
unique_id=None,
|
||||
url_server=SENTRY_URL_SERVER,
|
||||
url_coreui=SENTRY_URL_COREUI)
|
||||
|
||||
|
||||
class ErrorTrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
octoprint.plugin.AssetPlugin,
|
||||
octoprint.plugin.TemplatePlugin,
|
||||
octoprint.plugin.SimpleApiPlugin):
|
||||
|
||||
def get_template_configs(self):
|
||||
return [
|
||||
dict(type="settings",
|
||||
name=gettext("Error Tracking"),
|
||||
template="errortracking_settings.jinja2",
|
||||
custom_bindings=False),
|
||||
dict(type="generic", template="errortracking_javascripts.jinja2")
|
||||
]
|
||||
|
||||
def get_template_vars(self):
|
||||
enabled = self._settings.get_boolean(["enabled"])
|
||||
enabled_unreleased = self._settings.get_boolean(["enabled_unreleased"])
|
||||
|
||||
return dict(enabled=_is_enabled(enabled, enabled_unreleased),
|
||||
unique_id=self._settings.get(["unique_id"]),
|
||||
url_coreui=self._settings.get(["url_coreui"]))
|
||||
|
||||
def get_assets(self):
|
||||
return dict(js=["js/sentry.min.js", "js/errortracking.js"])
|
||||
|
||||
def get_settings_defaults(self):
|
||||
return SETTINGS_DEFAULTS
|
||||
|
||||
def on_settings_save(self, data):
|
||||
old_enabled = _is_enabled(self._settings.get_boolean(["enabled"]),
|
||||
self._settings.get_boolean(["enabled_unreleased"]))
|
||||
|
||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||
|
||||
enabled = _is_enabled(self._settings.get_boolean(["enabled"]),
|
||||
self._settings.get_boolean(["enabled_unreleased"]))
|
||||
|
||||
if old_enabled != enabled:
|
||||
_enable_errortracking()
|
||||
|
||||
def on_api_get(self, request):
|
||||
return jsonify(**self.get_template_vars())
|
||||
|
||||
|
||||
_enabled = False
|
||||
def _enable_errortracking():
|
||||
# this is a bit hackish, but we want to enable error tracking as early in the platform lifecycle as possible
|
||||
# and hence can't wait until our implementation is initialized and injected with settings
|
||||
|
||||
from octoprint.settings import settings
|
||||
global _enabled
|
||||
|
||||
if _enabled:
|
||||
return
|
||||
|
||||
version = get_octoprint_version_string()
|
||||
|
||||
s = settings()
|
||||
plugin_defaults = dict(plugins=dict(errortracking=SETTINGS_DEFAULTS))
|
||||
|
||||
enabled = s.getBoolean(["plugins", "errortracking", "enabled"], defaults=plugin_defaults)
|
||||
enabled_unreleased = s.getBoolean(["plugins", "errortracking", "enabled_unreleased"], defaults=plugin_defaults)
|
||||
url_server = s.get(["plugins", "errortracking", "url_server"], defaults=plugin_defaults)
|
||||
unique_id = s.get(["plugins", "errortracking", "unique_id"], defaults=plugin_defaults)
|
||||
if unique_id is None:
|
||||
import uuid
|
||||
unique_id = str(uuid.uuid4())
|
||||
s.set(["plugins", "errortracking", "unique_id"], unique_id, defaults=plugin_defaults)
|
||||
s.save()
|
||||
|
||||
if _is_enabled(enabled, enabled_unreleased):
|
||||
import sentry_sdk
|
||||
sentry_sdk.init(url_server,
|
||||
release=version)
|
||||
|
||||
with sentry_sdk.configure_scope() as scope:
|
||||
scope.user = dict(id=unique_id)
|
||||
|
||||
logging.getLogger("octoprint.plugin.errortracking").info("Initialized error tracking")
|
||||
_enabled = True
|
||||
|
||||
|
||||
def _is_enabled(enabled, enabled_unreleased):
|
||||
return enabled and (enabled_unreleased or is_released_octoprint_version())
|
||||
|
||||
|
||||
def __plugin_enable__():
|
||||
_enable_errortracking()
|
||||
|
||||
|
||||
__plugin_name__ = "Error Tracking"
|
||||
__plugin_author__ = "Gina Häußge"
|
||||
__plugin_implementation__ = ErrorTrackingPlugin()
|
||||
@@ -0,0 +1,103 @@
|
||||
$(function() {
|
||||
function ErrorTrackingViewModel(parameters) {
|
||||
var self = this;
|
||||
|
||||
self.settings = parameters[0];
|
||||
self.loginState = parameters[1];
|
||||
|
||||
var notification = undefined;
|
||||
var performCheck = function() {
|
||||
if (!self.loginState.isAdmin()) return;
|
||||
|
||||
// already enabled?
|
||||
if (self.settings.settings.plugins.errortracking.enabled()) return;
|
||||
|
||||
// RC release channel?
|
||||
var releaseChannel = self.settings.settings.plugins.softwareupdate.octoprint_release_channel();
|
||||
if (releaseChannel === "rc/maintenance" || releaseChannel === "rc/devel") {
|
||||
if (notification !== undefined) return;
|
||||
|
||||
// ignored?
|
||||
try {
|
||||
var ignoredString = localStorage["plugin.errortracking.notification_ignored"];
|
||||
var ignored = false;
|
||||
|
||||
if (ignoredString) {
|
||||
ignored = JSON.parse(ignoredString);
|
||||
}
|
||||
|
||||
if (ignored) return;
|
||||
} catch (ex) {
|
||||
log.error("Error while reading plugin.errortracking.notification_ignored from local storage");
|
||||
}
|
||||
|
||||
// show notification
|
||||
notification = new PNotify({
|
||||
title: gettext("Enable error reporting?"),
|
||||
text: gettext("<p>It looks like you are tracking an OctoPrint RC release channel. It " +
|
||||
"would be great if you would enable error reporting so that any kind of errors that occur " +
|
||||
"with an RC can be looked into more easily. Thank you!</p>" +
|
||||
"<p><small>You can find more information on error reporting " +
|
||||
"under Settings > Error Tracking</small></p>"),
|
||||
hide: false,
|
||||
confirm: {
|
||||
confirm: true,
|
||||
buttons: [{
|
||||
text: gettext("Ignore"),
|
||||
click: function() {
|
||||
notification.remove();
|
||||
notification = undefined;
|
||||
new PNotify({
|
||||
text: gettext("You can still enable error tracking via \"Settings\" > \"Error Tracking\"")
|
||||
});
|
||||
|
||||
if (Modernizr.localstorage) {
|
||||
localStorage["plugin.errortracking.notification_ignored"] = JSON.stringify(true);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
text: gettext("Enable"),
|
||||
addClass: "btn-primary",
|
||||
click: function() {
|
||||
self.settings.saveData({
|
||||
plugins: {
|
||||
errortracking: {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
}).done(function() {
|
||||
notification.remove();
|
||||
notification = undefined;
|
||||
location.reload(true);
|
||||
});
|
||||
}
|
||||
}]
|
||||
},
|
||||
buttons: {
|
||||
closer: false,
|
||||
sticker: false
|
||||
}
|
||||
});
|
||||
|
||||
// not an RC release channel, close notification
|
||||
} else if (notification !== undefined) {
|
||||
notification.remove();
|
||||
notification = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
var subbed = false;
|
||||
self.onStartup = self.onUserLoggedIn = self.onUserLoggedOut = function() {
|
||||
performCheck();
|
||||
if (self.settings && self.settings.settings && self.settings.settings.plugins && self.settings.settings.plugins.softwareupdate && !subbed) {
|
||||
subbed = true;
|
||||
self.settings.settings.plugins.softwareupdate.octoprint_release_channel.subscribe(performCheck);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
OCTOPRINT_VIEWMODELS.push({
|
||||
construct: ErrorTrackingViewModel,
|
||||
dependencies: ["settingsViewModel", "loginStateViewModel"]
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
/*! @sentry/browser 4.5.1 (6a390acf) | https://github.com/getsentry/sentry-javascript */
|
||||
var Sentry=function(t){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,n)};function n(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r,o,i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function s(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,a)}u((r=r.apply(t,e||[])).next())})}function a(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function u(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function c(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function l(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t}function p(t){switch(Object.prototype.toString.call(t)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return t instanceof Error}}function f(t){return"[object ErrorEvent]"===Object.prototype.toString.call(t)}function h(t){return"[object DOMError]"===Object.prototype.toString.call(t)}function d(t){return void 0===t}function v(t){return"function"==typeof t}function g(t){return"[object String]"===Object.prototype.toString.call(t)}function y(t){return"[object Object]"===Object.prototype.toString.call(t)}function m(t){return t!=t}function b(){return"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0)?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{}}function E(){var t=b(),e=t.crypto||t.msCrypto;if(void 0!==e&&e.getRandomValues){var n=new Uint16Array(8);e.getRandomValues(n),n[3]=4095&n[3]|16384,n[4]=16383&n[4]|32768;var r=function(t){for(var e=t.toString(16);e.length<4;)e="0"+e;return e};return r(n[0])+r(n[1])+r(n[2])+r(n[3])+r(n[4])+r(n[5])+r(n[6])+r(n[7])}return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})}function x(t){var e,n,r,o,i,s=[];if(!t||!t.tagName)return"";if(s.push(t.tagName.toLowerCase()),t.id&&s.push("#"+t.id),(e=t.className)&&g(e))for(n=e.split(/\s+/),i=0;i<n.length;i++)s.push("."+n[i]);var a=["type","name","title","alt"];for(i=0;i<a.length;i++)r=a[i],(o=t.getAttribute(r))&&s.push("["+r+'="'+o+'"]');return s.join("")}function _(t){if(!t)return{};var e=t.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!e)return{};var n=e[6]||"",r=e[8]||"";return{host:e[4],path:e[5],protocol:e[2],relative:e[5]+n+r}}function S(t){if(t.message)return t.message;if(t.exception&&t.exception.values&&t.exception.values[0]){var e=t.exception.values[0];return e.type&&e.value?e.type+": "+e.value:e.type||e.value||t.event_id||"<unknown>"}return t.event_id||"<unknown>"}function w(t){var e=b();if(!("console"in e))return t();var n=e.console,r={};["debug","info","warn","error","log"].forEach(function(t){t in e.console&&n[t].__sentry__&&(r[t]=n[t].__sentry_wrapped__,n[t]=n[t].__sentry_original__)});var o=t();return Object.keys(r).forEach(function(t){n[t]=r[t]}),o}function k(t,e){return void 0===e&&(e=0),0!==e&&g(t)?t.length<=e?t:t.substr(0,e)+"...":t}function O(t,e){if(!Array.isArray(t))return"";for(var n=[],r=0;r<t.length;r++){var o=t[r];try{n.push(String(o))}catch(t){n.push("[value cannot be serialized]")}}return n.join(e)}function j(t,e){return!(Line truncated
|
||||
//# sourceMappingURL=bundle.min.js.map
|
||||
@@ -0,0 +1,24 @@
|
||||
<script type="text/javascript">
|
||||
var ERRORTRACKING_ENABLED = {% if plugin_errortracking_enabled -%} true; {% else %} false; {%- endif %}
|
||||
|
||||
var ERRORTRACKING_ENABLE = function() {
|
||||
var errortracking_url_coreui = "{{ plugin_errortracking_url_coreui }}";
|
||||
var errortracking_unique_id = "{{ plugin_errortracking_unique_id }}";
|
||||
|
||||
Sentry.init({
|
||||
dsn: errortracking_url_coreui,
|
||||
release: VERSION
|
||||
});
|
||||
Sentry.configureScope(function (scope) {
|
||||
scope.setUser({"id": errortracking_unique_id});
|
||||
});
|
||||
ERRORTRACKING_ENABLED = true;
|
||||
log.info("Initialized error tracking");
|
||||
};
|
||||
|
||||
$(function() {
|
||||
if (ERRORTRACKING_ENABLED) {
|
||||
ERRORTRACKING_ENABLE();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,42 @@
|
||||
<h3>{{ _('Error Tracking') }}</h3>
|
||||
|
||||
{% trans %}
|
||||
<p>
|
||||
Error tracking will cause any logged exceptions in the server and the browser interface to be sent
|
||||
to OctoPrint's <a href="https://sentry.io/" target="_blank" rel="noopener noreferer">Sentry instance</a>.
|
||||
</p>
|
||||
<p>
|
||||
By enabling it you help to gather detailed information on the cause of bugs or other issues. This is especially valuable
|
||||
on release candidates, which is why this plugin will also prompt you to enable error tracking if it detects that
|
||||
you are subscribed to an RC release channel.
|
||||
</p>
|
||||
<p>
|
||||
Please enable this if you are running a release candidate, or are prompted to do so while debugging an issue that you reported.
|
||||
</p>
|
||||
{% endtrans %}
|
||||
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.errortracking.enabled"> {{ _('Enable error tracking') }}
|
||||
</label>
|
||||
<span class="help-block">{{ _('Please reload the page after enabling/disabling & saving') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" title="{{ _('Random unique instance ID') }}">{{ _('Instance ID') }}</label>
|
||||
<div class="controls">
|
||||
<span style="padding-top: 5px; margin-bottom: 5px; display: inline-block" data-bind="text: settings.plugins.errortracking.unique_id() || 'N/A'"></span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% trans %}
|
||||
<p>
|
||||
The Error Tracking plugin is using a Sentry instance kindly provided by
|
||||
<a href="https://sentry.io/" target="_blank" rel="noopener noreferer">sentry.io</a>. For information on their service
|
||||
please refer to their <a href="https://sentry.io/security/" target="_blank" rel="noopener noreferer">Security & Compliance documentation</a>
|
||||
and their <a href="https://sentry.io/privacy/" target="_blank" rel="noopener noreferer">Privacy Policy</a>.
|
||||
</p>
|
||||
{% endtrans %}
|
||||
@@ -9,7 +9,8 @@ import octoprint.plugin
|
||||
from octoprint.events import Events
|
||||
from octoprint.access import USER_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.util.version import get_comparable_version
|
||||
|
||||
from .checks.firmware_unsafe import FirmwareUnsafeChecks
|
||||
|
||||
import flask
|
||||
from flask_babel import gettext
|
||||
@@ -25,58 +26,10 @@ Learn more at https://faq.octoprint.org/warning-{warning_type}
|
||||
|
||||
"""
|
||||
|
||||
# Anet A8
|
||||
ANETA8_M115_TEST = ("aneta8", lambda name, data: name and name.lower().startswith("anet_a8_"))
|
||||
|
||||
# Anycubic MEGA
|
||||
ANYCUBIC_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower()
|
||||
ANYCUBIC_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower()
|
||||
ANYCUBIC_RECEIVED_TEST = ("anycubic", lambda line: line and (ANYCUBIC_AUTHOR1 in line.lower() or ANYCUBIC_AUTHOR2 in line.lower()))
|
||||
|
||||
# Creality CR-10s
|
||||
CR10S_AUTHOR = " | Author: (CR-10Slanguage)".lower()
|
||||
CR10S_RECEIVED_TEST = ("cr10s", lambda line: line and CR10S_AUTHOR in line.lower())
|
||||
|
||||
# Creality Ender 3
|
||||
ENDER3_AUTHOR = " | Author: (Ender3)".lower()
|
||||
ENDER3_RECEIVED_TEST = ("ender3", lambda line: line and ENDER3_AUTHOR in line.lower())
|
||||
|
||||
# iMe on Micro3D
|
||||
IME_M115_TEST = ("ime", lambda name, data: name and name.lower().startswith("ime"))
|
||||
|
||||
# Malyan M200 aka Monoprice Select Mini, versions less than 4.0
|
||||
MALYANM200_M115_TEST = ("malyan_m200", lambda name, data: name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < get_comparable_version("4.0"))
|
||||
|
||||
# Stock Micro3D
|
||||
MICRO3D_M115_TEST = ("micro3d", lambda name, data: name and name.lower().startswith("micro3d"))
|
||||
|
||||
# Any Repetier versions < 0.92
|
||||
REPETIER_BEFORE_092_M115_TEST = ("repetier_before_092", lambda name, data: name and name.lower().startswith("repetier") and extract_repetier_version(name) is not None and extract_repetier_version(name) < get_comparable_version("0.92"))
|
||||
|
||||
# THERMAL_PROTECTION capability reported as disabled
|
||||
THERMAL_PROTECTION_CAP_TEST = ("capability", lambda cap, enabled: cap == "THERMAL_PROTECTION" and not enabled)
|
||||
|
||||
SAFETY_CHECKS = {
|
||||
"firmware-unsafe": dict(m115=(ANETA8_M115_TEST, IME_M115_TEST, MALYANM200_M115_TEST, MICRO3D_M115_TEST,
|
||||
REPETIER_BEFORE_092_M115_TEST),
|
||||
received=(ANYCUBIC_RECEIVED_TEST, CR10S_RECEIVED_TEST, ENDER3_RECEIVED_TEST),
|
||||
cap=(THERMAL_PROTECTION_CAP_TEST,),
|
||||
message=gettext("Your printer's firmware is known to lack mandatory safety features (e.g. "
|
||||
"thermal runaway protection). This is a fire risk."))
|
||||
"firmware-unsafe": FirmwareUnsafeChecks.as_dict()
|
||||
}
|
||||
|
||||
def extract_repetier_version(name):
|
||||
"""
|
||||
Extracts the Repetier version number from the firmware name.
|
||||
|
||||
Example: "Repetier_0.91" => 0.91
|
||||
"""
|
||||
version = None
|
||||
if "_" in name:
|
||||
_, version = name.split("_", 1)
|
||||
version = get_comparable_version(version, base=True)
|
||||
return version
|
||||
|
||||
class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
|
||||
octoprint.plugin.EventHandlerPlugin,
|
||||
octoprint.plugin.SimpleApiPlugin,
|
||||
@@ -111,6 +64,8 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
|
||||
def on_event(self, event, payload):
|
||||
if event == Events.DISCONNECTED:
|
||||
self._reset_warnings()
|
||||
self._reset_state()
|
||||
self._reset_checks()
|
||||
|
||||
##~~ SimpleApiPlugin API
|
||||
|
||||
@@ -154,20 +109,35 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
|
||||
changes = False
|
||||
|
||||
for warning_type, check_data in SAFETY_CHECKS.items():
|
||||
checks = check_data.get(check_type)
|
||||
checks = check_data.get("checks")
|
||||
message = check_data.get("message")
|
||||
if not checks or not message:
|
||||
continue
|
||||
|
||||
for check_name, check in checks:
|
||||
if check(*args, **kwargs):
|
||||
for check in checks:
|
||||
if not check.active:
|
||||
# skip non active checks
|
||||
continue
|
||||
|
||||
method = getattr(check, check_type, None)
|
||||
if not callable(method):
|
||||
# skip uncallable checks
|
||||
continue
|
||||
|
||||
# execute method
|
||||
try:
|
||||
method(*args, **kwargs)
|
||||
except:
|
||||
self._logger.exception("There was an error running method {} on check {!r}".format(check_type, check))
|
||||
continue
|
||||
|
||||
# check if now triggered
|
||||
if check.triggered:
|
||||
self._register_warning(warning_type, message)
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
self._event_bus.fire(Events.PLUGIN_PRINTER_SAFETY_CHECK_WARNING, dict(check_type=check_type,
|
||||
check_name=check_name,
|
||||
self._event_bus.fire(Events.PLUGIN_PRINTER_SAFETY_CHECK_WARNING, dict(check_name=check.name,
|
||||
warning_type=warning_type))
|
||||
|
||||
changes = True
|
||||
break
|
||||
|
||||
@@ -183,6 +153,18 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
|
||||
self._warnings.clear()
|
||||
self._ping_clients()
|
||||
|
||||
def _reset_state(self):
|
||||
self._scan_received = True
|
||||
|
||||
def _reset_checks(self):
|
||||
for warning_type, check_data in SAFETY_CHECKS.items():
|
||||
checks = check_data.get("checks")
|
||||
if not checks:
|
||||
continue
|
||||
|
||||
for check in checks:
|
||||
check.reset()
|
||||
|
||||
def _log_to_terminal(self, message):
|
||||
if self._printer:
|
||||
lines = message.split("\n")
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
|
||||
class Check(object):
|
||||
name = None
|
||||
|
||||
def __init__(self):
|
||||
self._active = True
|
||||
self._triggered = False
|
||||
|
||||
def received(self, line):
|
||||
"""Called when receiving a new line from the printer"""
|
||||
pass
|
||||
|
||||
def m115(self, name, data):
|
||||
"""Called when receiving the response to an M115 from the printer"""
|
||||
pass
|
||||
|
||||
def cap(self, cap, enabled):
|
||||
"""Called when receiving a capability report line"""
|
||||
pass
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
"""Whether this check is still active"""
|
||||
return self._active
|
||||
|
||||
@property
|
||||
def triggered(self):
|
||||
"""Whether the check has been triggered"""
|
||||
return self._triggered
|
||||
|
||||
def reset(self):
|
||||
self._active = True
|
||||
self._triggered = False
|
||||
|
||||
|
||||
class AuthorCheck(Check):
|
||||
authors = ()
|
||||
|
||||
AUTHOR = "| Author: ".lower()
|
||||
|
||||
def received(self, line):
|
||||
if not line:
|
||||
return
|
||||
|
||||
lower_line = line.lower()
|
||||
if self.AUTHOR in lower_line:
|
||||
self._triggered = any(map(lambda x: x in lower_line, self.authors))
|
||||
self._active = False
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
from flask_babel import gettext
|
||||
from octoprint.util.version import get_comparable_version
|
||||
from . import Check, AuthorCheck
|
||||
|
||||
class FirmwareUnsafeChecks(object):
|
||||
@classmethod
|
||||
def as_dict(cls):
|
||||
return dict(checks=(AnetA8Check(), AnycubicCheck(), CrealityCR10sCheck(), CrealityEnder3Check(),
|
||||
MalyanM200Check(), Micro3DIMECheck(), Micro3DStockCheck(), RepetierBefore092Check(),
|
||||
ThermalProtectionCapCheck()),
|
||||
message=gettext("Your printer's firmware is known to lack mandatory safety features (e.g. "
|
||||
"thermal runaway protection). This is a fire risk."))
|
||||
|
||||
class AnetA8Check(Check):
|
||||
"""
|
||||
Anet A8 stock firmware
|
||||
|
||||
Identified through firmware name "ANET_A8_".
|
||||
"""
|
||||
name = "anet_a8"
|
||||
|
||||
def m115(self, name, data):
|
||||
self._triggered = name and name.lower().startswith("anet_a8_")
|
||||
self._active = False
|
||||
|
||||
class AnycubicCheck(Check):
|
||||
"""
|
||||
Anycubic MEGA stock firmware
|
||||
|
||||
Identified through "Author: (Jolly, xxxxxxxx.CO.)" or "| Author: (**Jolly, xxxxxxxx.CO.**)" in startup messages
|
||||
combined with "echo:Vx.y.z" in startup messages, with x.y.z < 1.1.2.
|
||||
"""
|
||||
name = "anycubic"
|
||||
|
||||
AUTHOR = "| Author: ".lower()
|
||||
VERSION = "echo:V"
|
||||
|
||||
CRITICAL_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower()
|
||||
CRITICAL_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower()
|
||||
|
||||
FIXED_VERSION = get_comparable_version("1.1.2")
|
||||
|
||||
def __init__(self):
|
||||
Check.__init__(self)
|
||||
self._author_matches = None
|
||||
self._version_matches = None
|
||||
|
||||
def received(self, line):
|
||||
if not line:
|
||||
return
|
||||
|
||||
lower_line = line.lower()
|
||||
if self.AUTHOR in lower_line:
|
||||
self._author_matches = self.CRITICAL_AUTHOR1 in lower_line or self.CRITICAL_AUTHOR2 in lower_line
|
||||
elif line.startswith(self.VERSION):
|
||||
self._version_matches = self._broken_version(line)
|
||||
else:
|
||||
return
|
||||
|
||||
self._evaluate()
|
||||
|
||||
def _broken_version(self, line):
|
||||
version_str = line[len(self.VERSION):]
|
||||
version = get_comparable_version(version_str, base=True)
|
||||
if version is not None and version <= self.FIXED_VERSION:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _evaluate(self):
|
||||
if self._author_matches is None or self._version_matches is None:
|
||||
return
|
||||
self._triggered = self._author_matches and self._version_matches
|
||||
self._active = False
|
||||
|
||||
def reset(self):
|
||||
Check.reset(self)
|
||||
self._author_matches = None
|
||||
self._version_matches = None
|
||||
|
||||
class CrealityCR10sCheck(AuthorCheck):
|
||||
"""
|
||||
Creality CR10s
|
||||
|
||||
Identified through " | Author: (CR-10Slanguage)" in startup messages.
|
||||
"""
|
||||
name = "creality_cr10s"
|
||||
authors = (" | Author: (CR-10Slanguage)".lower(),)
|
||||
|
||||
class CrealityEnder3Check(AuthorCheck):
|
||||
"""
|
||||
Creality Ender3
|
||||
|
||||
Identified through " | Author: (Ender3)" in startup messages.
|
||||
"""
|
||||
name = "creality_ender3"
|
||||
authors = (" | Author: (Ender3)".lower(),)
|
||||
|
||||
class MalyanM200Check(Check):
|
||||
"""
|
||||
Malyan M200 stock firmware prior to version 4.0
|
||||
|
||||
Identified through firmware name "Malyan*", model "M200" and version < 4.0.
|
||||
"""
|
||||
name = "malyan_m200"
|
||||
|
||||
FIXED_VERSION = get_comparable_version("4.0")
|
||||
|
||||
def m115(self, name, data):
|
||||
self._triggered = name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < self.FIXED_VERSION
|
||||
self._active = False
|
||||
|
||||
class Micro3DIMECheck(Check):
|
||||
"""
|
||||
Micro3D with IME firmware
|
||||
|
||||
Identified through firmware name "iME*".
|
||||
"""
|
||||
name = "micro3d_ime"
|
||||
|
||||
def m115(self, name, data):
|
||||
self._triggered = name and name.lower().startswith("ime")
|
||||
self._active = False
|
||||
|
||||
class Micro3DStockCheck(Check):
|
||||
"""
|
||||
Micro3D with IME firmware
|
||||
|
||||
Identified through firmware name "Micro3D*".
|
||||
"""
|
||||
name = "micro3d"
|
||||
|
||||
def m115(self, name, data):
|
||||
self._triggered = name and name.lower().startswith("micro3d")
|
||||
self._active = False
|
||||
|
||||
class RepetierBefore092Check(Check):
|
||||
"""
|
||||
Repetier firmware prior to version 0.92
|
||||
|
||||
Identified through firmware name "Repetier_x.y.z" with x.y.z < 0.92
|
||||
"""
|
||||
name = "repetier_before_092"
|
||||
|
||||
FIXED_VERSION = get_comparable_version("0.92")
|
||||
|
||||
def m115(self, name, data):
|
||||
if name and name.lower().startswith("repetier"):
|
||||
version = self._extract_repetier_version(name)
|
||||
self._triggered = version is not None and version < self.FIXED_VERSION
|
||||
self._active = False
|
||||
|
||||
def _extract_repetier_version(self, name):
|
||||
"""
|
||||
Extracts the Repetier version number from the firmware name.
|
||||
|
||||
Example: "Repetier_0.91" => 0.91
|
||||
"""
|
||||
version = None
|
||||
if "_" in name:
|
||||
_, version = name.split("_", 1)
|
||||
version = get_comparable_version(version, base=True)
|
||||
return version
|
||||
|
||||
class ThermalProtectionCapCheck(Check):
|
||||
"""
|
||||
Firmware reporting disabled THERMAL_PROTECTION capability
|
||||
"""
|
||||
name = "capability"
|
||||
|
||||
def cap(self, cap, enabled):
|
||||
if cap == "THERMAL_PROTECTION":
|
||||
self._triggered = not enabled
|
||||
self._active = False
|
||||
@@ -197,7 +197,7 @@ def index():
|
||||
|
||||
default_additional_etag = [enable_accesscontrol,
|
||||
enable_gcodeviewer,
|
||||
enable_timelapse]
|
||||
enable_timelapse] + sorted(["{}:{}".format(k, v) for k, v in _plugin_vars.items()])
|
||||
|
||||
def get_preemptively_cached_view(key, view, data=None, additional_request_data=None, additional_unless=None):
|
||||
if (data is None and additional_request_data is None) or g.locale is None:
|
||||
|
||||
@@ -309,7 +309,8 @@ default_settings = {
|
||||
"section_printer", "serial", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts",
|
||||
"section_features", "features", "webcam", "accesscontrol", "gcodevisualizer", "api", "plugin_appkeys",
|
||||
"section_octoprint", "server", "folders", "appearance", "plugin_logging", "plugin_pluginmanager",
|
||||
"plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_pi_support"
|
||||
"plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_errortracking",
|
||||
"plugin_pi_support"
|
||||
],
|
||||
"usersettings": ["access", "interface"],
|
||||
"wizard": ["access"],
|
||||
|
||||
@@ -569,7 +569,9 @@ $(function() {
|
||||
output.push(gettext("Filament") + ": " + layer.filament[0].toFixed(2) + "mm");
|
||||
} else {
|
||||
for (var i = 0; i < layer.filament.length; i++) {
|
||||
output.push(gettext("Filament") + " (" + gettext("Tool") + " " + i + "): " + layer.filament[i].toFixed(2) + "mm");
|
||||
if (layer.filament[i] !== undefined) {
|
||||
output.push(gettext("Filament") + " (" + gettext("Tool") + " " + i + "): " + layer.filament[i].toFixed(2) + "mm");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +71,18 @@ $(function() {
|
||||
self.titlePrintButton = ko.observable(self.TITLE_PRINT_BUTTON_UNPAUSED);
|
||||
self.titlePauseButton = ko.observable(self.TITLE_PAUSE_BUTTON_UNPAUSED);
|
||||
|
||||
self.estimatedPrintTimeString = ko.pureComputed(function() {
|
||||
var estimatedPrintTimeStringHlpr = function (fmt) {
|
||||
if (self.lastPrintTime())
|
||||
return self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(self.lastPrintTime()) : formatDuration(self.lastPrintTime());
|
||||
return fmt(self.lastPrintTime());
|
||||
if (self.estimatedPrintTime())
|
||||
return self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(self.estimatedPrintTime()) : formatDuration(self.estimatedPrintTime());
|
||||
return fmt(self.estimatedPrintTime());
|
||||
return "-";
|
||||
}
|
||||
self.estimatedPrintTimeString = ko.pureComputed(function() {
|
||||
return estimatedPrintTimeStringHlpr(self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime : formatDuration);
|
||||
});
|
||||
self.estimatedPrintTimeExactString = ko.pureComputed(function() {
|
||||
return estimatedPrintTimeStringHlpr(formatDuration);
|
||||
});
|
||||
self.byteString = ko.pureComputed(function() {
|
||||
if (!self.filesize())
|
||||
@@ -94,7 +100,7 @@ $(function() {
|
||||
return "-";
|
||||
return formatDuration(self.printTime());
|
||||
});
|
||||
self.printTimeLeftString = ko.pureComputed(function() {
|
||||
var printTimeLeftStringHlpr = function (fmt) {
|
||||
if (self.printTimeLeft() === undefined) {
|
||||
if (!self.printTime() || !(self.isPrinting() || self.isPaused())) {
|
||||
return "-";
|
||||
@@ -102,8 +108,14 @@ $(function() {
|
||||
return gettext("Still stabilizing...");
|
||||
}
|
||||
} else {
|
||||
return self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(self.printTimeLeft()) : formatDuration(self.printTimeLeft());
|
||||
return fmt(self.printTimeLeft());
|
||||
}
|
||||
}
|
||||
self.printTimeLeftString = ko.pureComputed(function() {
|
||||
return printTimeLeftStringHlpr(self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime : formatDuration);
|
||||
});
|
||||
self.printTimeLeftExactString = ko.pureComputed(function() {
|
||||
return printTimeLeftStringHlpr(formatDuration);
|
||||
});
|
||||
self.printTimeLeftOriginString = ko.pureComputed(function() {
|
||||
var value = self.printTimeLeftOrigin();
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
<!-- ko foreach: filament -->
|
||||
<span data-bind="text: 'Filament (' + name() + '): ', title: 'Filament usage for ' + name()"></span><strong data-bind="text: formatFilament(data())"></strong><br>
|
||||
<!-- /ko -->
|
||||
<span title="{{ _('Estimated total print time based on analysis of the file or past prints') }}">{{ _('Approx. Total Print Time') }}</span>: <strong data-bind="text: estimatedPrintTimeString"></strong><br>
|
||||
<span title="{{ _('Estimated total print time based on analysis of the file or past prints') }}">{{ _('Approx. Total Print Time') }}</span>: <strong data-bind="text: estimatedPrintTimeString, attr: {title: estimatedPrintTimeExactString}"></strong><br>
|
||||
<hr>
|
||||
<span title="{{ _('Total print time so far') }}">{{ _('Print Time') }}</span>: <strong data-bind="text: printTimeString"></strong><br>
|
||||
<span title="{{ _('Estimated time until the print job is done. This is only an estimate and accuracy depends heavily on various factors!') }}">{{ _('Print Time Left') }}</span>: <strong data-bind="text: printTimeLeftString"></strong> <span id="state_printtimeleft_popover" style="display: none" data-bind="visible: printTimeLeftOrigin, attr: {title: printTimeLeftOriginString}, css: printTimeLeftOriginClass">●</span><br>
|
||||
<span title="{{ _('Estimated time until the print job is done. This is only an estimate and accuracy depends heavily on various factors!') }}">{{ _('Print Time Left') }}</span>: <strong data-bind="text: printTimeLeftString, attr: {title: printTimeLeftExactString}"></strong> <span id="state_printtimeleft_popover" style="display: none" data-bind="visible: printTimeLeftOrigin, attr: {title: printTimeLeftOriginString}, css: printTimeLeftOriginClass">●</span><br>
|
||||
<span title="{{ _('Bytes printed vs total bytes of file') }}">{{ _('Printed') }}</span>: <strong data-bind="text: byteString"></strong><br>
|
||||
|
||||
|
||||
|
||||
@@ -122,6 +122,10 @@ def get_comparable_version(version_string, base=False):
|
||||
if "-" in version_string:
|
||||
version_string = version_string[:version_string.find("-")]
|
||||
|
||||
# Debian has the python version set to 2.7.15+ which is not PEP440 compliant (bug 914072)
|
||||
if version_string.endswith("+"):
|
||||
version_string = version_string[:-1]
|
||||
|
||||
version = pkg_resources.parse_version(version_string)
|
||||
|
||||
# A leading v is common in github release tags and old setuptools doesn't remove it.
|
||||
|
||||
Reference in new issue
Block a user