diff --git a/.github/workflows/nightly_merge.yml b/.github/workflows/nightly_merge.yml index fc74e5415..4d54ff64c 100644 --- a/.github/workflows/nightly_merge.yml +++ b/.github/workflows/nightly_merge.yml @@ -23,11 +23,11 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: 🔀 Merge maintenance into devel - uses: robotology/gh-action-nightly-merge@v1.3.2 - with: - stable_branch: "maintenance" - development_branch: "devel" - allow_ff: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + #- name: 🔀 Merge maintenance into devel + # uses: robotology/gh-action-nightly-merge@v1.3.2 + # with: + # stable_branch: "maintenance" + # development_branch: "devel" + # allow_ff: false + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/AUTHORS.md b/AUTHORS.md index fae1ed362..7aecc1391 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -139,6 +139,8 @@ date of first contribution): * [Miroslav Šedivý](https://github.com/eumiro) * [Costas Basdekis](https://github.com/costas-basdekis) * [Joe Martella](https://github.com/martellaj) + * [Scott Lahteine](https://github.com/thinkyhead) + * [Karthikeyan Singaravelan](https://github.com/tirkarthi) 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 diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 56a0a5fce..a945a6c2a 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -1132,9 +1132,9 @@ Use `Javascript regular expressions Tools > File Watchers (you might have to enable this, it's a bundled plugin), add new: diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index a3aa5db96..63b3b63e9 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -1492,6 +1492,7 @@ class LocalFileStorage(StorageInterface): logtarget=__name__ + ".timings", message="{func}({func_args},{func_kwargs}) took {timing:.2f}ms", incl_func_args=True, + log_enter=True, ) def _list_folder(self, path, base="", force_refresh=False, **kwargs): def get_size(nodes): @@ -1519,11 +1520,8 @@ class LocalFileStorage(StorageInterface): try: with self._filelist_cache_mutex: cache = self._filelist_cache.get(path) - if ( - not force_refresh - and cache - and cache[0] >= self.last_modified(path, recursive=True) - ): + lm = self.last_modified(path, recursive=True) + if not force_refresh and cache and cache[0] >= lm: return enrich_folders(cache[1]) metadata = self._get_metadata(path) @@ -1664,7 +1662,7 @@ class LocalFileStorage(StorageInterface): continue self._filelist_cache[path] = ( - self.last_modified(path, recursive=True), + lm, result, ) return enrich_folders(result) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index f821fa89f..c0c954cd7 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -1076,10 +1076,14 @@ class SoftwareUpdatePlugin( and not self._settings.get_boolean(["ignore_throttled"]) ): # currently throttled, we refuse to run + message = ( + "System is currently throttled, refusing to update " + "anything due to possible stability issues" + ) + self._logger.error(message) flask.abort( 409, - description="System is currently throttled, refusing to update " - "anything due to possible stability issues", + description=message, ) if self._printer.is_printing() or self._printer.is_paused(): diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index b090c2651..56e8b6f75 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -680,13 +680,20 @@ $(function () { gettext("Updating, please wait.") ); }) - .fail(function () { + .fail(function (response) { self.updateInProgress = false; + var message = + "

" + + gettext( + "The update could not be started. Is it already active? Please consult octoprint.log for details." + ) + + "

" +
+                        _.escape(response.responseJSON.error) +
+                        "
"; + self._showPopup({ title: gettext("Update not started!"), - text: gettext( - "The update could not be started. Is it already active? Please consult octoprint.log for details." - ), + text: message, type: "error", hide: false, buttons: { diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 534c28e91..ee31a95ec 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -755,19 +755,17 @@ class Server: } timelapses_path_validator = { "path_validation": util.tornado.path_validation_factory( - lambda path: not octoprint.util.is_hidden_path(path) - and octoprint.timelapse.valid_timelapse(path), + lambda path: valid_timelapse(path) + and os.path.realpath(os.path.abspath(path)).startswith( + settings().getBaseFolder("timelapse") + ), status_code=400, ) } - valid_log = ( - lambda path: not octoprint.util.is_hidden_path(path) - and path.endswith(".log") - and os.path.realpath(os.path.abspath(path)).startswith( - settings().getBaseFolder("logs") - ) - ) + valid_log = lambda path: not octoprint.util.is_hidden_path( + path + ) and path.endswith(".log") log_path_validator = { "path_validation": util.tornado.path_validation_factory( valid_log, @@ -776,7 +774,10 @@ class Server: } logs_path_validator = { "path_validation": util.tornado.path_validation_factory( - valid_log, + lambda path: valid_log(path) + and os.path.realpath(os.path.abspath(path)).startswith( + settings().getBaseFolder("logs") + ), status_code=400, ) } diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 9f61fe403..9b2d2e50c 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -215,7 +215,7 @@ def readGcodeFile(target, filename): if target not in [FileDestinations.LOCAL, FileDestinations.SDCARD]: abort(404) - if filename != fileManager.sanitize(target, filename): + if not _validate(target, filename): abort(404) recursive = False @@ -244,6 +244,8 @@ def _getFileDetails(origin, path, recursive=True): logtarget=__name__ + ".timings", message="{func}({func_args},{func_kwargs}) took {timing:.2f}ms", incl_func_args=True, + log_enter=True, + message_enter="Entering {func}({func_args},{func_kwargs})...", ) def _getFileList( origin, path=None, filter=None, recursive=False, level=0, allow_from_cache=True @@ -730,7 +732,7 @@ def gcodeFileCommand(filename, target): if target not in [FileDestinations.LOCAL, FileDestinations.SDCARD]: abort(404) - if filename != fileManager.sanitize(target, filename): + if not _validate(target, filename): abort(404) # valid file commands, dict mapping command name to mandatory parameters @@ -1094,7 +1096,7 @@ def gcodeFileCommand(filename, target): @no_firstrun_access @Permissions.FILES_DELETE.require(403) def deleteGcodeFile(filename, target): - if filename != fileManager.sanitize(target, filename): + if not _validate(target, filename): abort(404) if not _verifyFileExists(target, filename) and not _verifyFolderExists( @@ -1159,6 +1161,12 @@ def _getCurrentFile(): return None, None +def _validate(target, filename): + return filename == "/".join( + map(lambda x: fileManager.sanitize_name(target, x), filename.split("/")) + ) + + class WerkzeugFileWrapper(octoprint.filemanager.util.AbstractFileWrapper): """ A wrapper around a Werkzeug ``FileStorage`` object. diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index c911a2b12..0eb8848f6 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -397,7 +397,7 @@ default_settings = { "terminalFilters": [ { "name": "Suppress temperature messages", - "regex": r"(Send: (N\d+\s+)?M105)|(Recv:\s+(ok\s+((P|B|N)\d+\s+)*)?(B|T\d*):\d+)", + "regex": r"(Send: (N\d+\s+)?M105)|(Recv:\s+(ok\s+([PBN]\d+\s+)*)?([BCLPR]|T\d*):-?\d+)", }, { "name": "Suppress SD status messages", diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index ae8074a10..1a123747c 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -406,7 +406,8 @@ $(function () { self.addTerminalFilter = function () { self.terminalFilters.push({ name: "New", - regex: "(Send:\\s+(N\\d+\\s+)?M105)|(Recv:\\s+(ok\\s+)?.*(B|T\\d*):\\d+)" + regex: + "(Send:\\s+(N\\d+\\s+)?M105)|(Recv:\\s+(ok\\s+([PBN]\\d+\\s+)*)?.*([BCLPR]|T\\d*):-?\\d+)" }); }; diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 143e5111d..dc2aebad3 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -24,6 +24,13 @@ import warnings from functools import wraps from typing import Union +try: + # Python 3.4+ + from collections.abc import Iterable, MutableMapping, Set +except ImportError: + # Python 2.7 + from collections import Iterable, MutableMapping, Set + import frozendict from octoprint import UMASK @@ -970,7 +977,7 @@ def dict_flatten(dictionary, prefix="", separator="."): result = {} for k, v in dictionary.items(): key = prefix + separator + k if prefix else k - if isinstance(v, collections.MutableMapping): + if isinstance(v, MutableMapping): result.update(dict_flatten(v, prefix=key, separator=separator)) else: result[key] = v @@ -1677,7 +1684,6 @@ class CountedEvent: class InvariantContainer: def __init__(self, initial_data=None, guarantee_invariant=None): - from collections.abc import Iterable from threading import RLock if guarantee_invariant is None: @@ -1798,7 +1804,7 @@ class TypeAlreadyInQueue(Exception): self.type = t -class CaseInsensitiveSet(collections.Set): +class CaseInsensitiveSet(Set): """ Basic case insensitive set @@ -1849,33 +1855,38 @@ def time_this( expand_logtarget=False, message="{func} took {timing:.2f}ms", incl_func_args=False, + log_enter=False, + message_enter="Entering {func}...", ): def decorator(f): + func = fqfn(f) + + lt = logtarget + if expand_logtarget: + lt += "." + func + + logger = logging.getLogger(lt) + @wraps(f) def wrapper(*args, **kwargs): + data = {"func": func, "func_args": "?", "func_kwargs": "?"} + if incl_func_args and logger.isEnabledFor(logging.DEBUG): + data.update( + func_args=",".join(map(repr, args)), + func_kwargs=",".join( + map(lambda x: "{}={!r}".format(x[0], x[1]), kwargs.items()) + ), + ) + if log_enter: + logger.debug(message_enter.format(**data), extra=data) + start = time.time() try: return f(*args, **kwargs) finally: timing = (time.time() - start) * 1000 - func = fqfn(f) - - lt = logtarget - if expand_logtarget: - lt += "." + func - - logger = logging.getLogger(lt) if logger.isEnabledFor(logging.DEBUG): - data = {"func": func, "timing": timing} - if incl_func_args: - data.update( - func_args=",".join(map(repr, args)), - func_kwargs=",".join( - map( - lambda x: "{}={!r}".format(x[0], x[1]), kwargs.items() - ) - ), - ) + data.update(timing=timing) logger.debug(message.format(**data), extra=data) return wrapper