diff --git a/AUTHORS.md b/AUTHORS.md index 21add4213..ae615647f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -82,6 +82,7 @@ date of first contribution): * [Shawn Bruce](https://github.com/kantlivelong) * [Claudiu Ceia] (https://github.com/ClaudiuCeia) * [Goswin von Brederlow](https://github.com/mrvn) + * [Luke McKechnie](https://github.com/galamdring) 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/events/index.rst b/docs/events/index.rst index 225331f5a..4e675c8f8 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -237,7 +237,7 @@ UpdatedFiles .. deprecated:: 1.2.0 - The ``gcode`` modification type has been superceeded by ``printables``. It is currently still available for + The ``gcode`` modification type has been superseded by ``printables``. It is currently still available for reasons of backwards compatibility and will also be sent on modification of ``printables``. It will however be removed with 1.4.0. diff --git a/docs/jsclientlib/base.rst b/docs/jsclientlib/base.rst index d393f27e2..618299fd1 100644 --- a/docs/jsclientlib/base.rst +++ b/docs/jsclientlib/base.rst @@ -119,7 +119,7 @@ :param string method: The HTTP method to use for the request (optional) :param string url: The URL to perform the request against (optional) :param object data: The data to send in the request body (optional) - :param object opts: Additonal options to use for the request (optional) + :param object opts: Additional options to use for the request (optional) :returns Promise: A `jQuery Promise `_ for the request's response .. js:function:: OctoPrintClient.get(url, opts) diff --git a/docs/jsclientlib/util.rst b/docs/jsclientlib/util.rst index 6168e1af5..74b10cbea 100644 --- a/docs/jsclientlib/util.rst +++ b/docs/jsclientlib/util.rst @@ -21,7 +21,7 @@ .. js:function:: OctoPrintClient.util.testPath(path, additional, opts) - Test the provided ``path`` for existance. More test criteria supported by the :ref:`path test command ` + Test the provided ``path`` for existence. More test criteria supported by the :ref:`path test command ` can be provided via the ``additional`` object. **Example 1** diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 172de5b3c..75b9bd7a5 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -53,6 +53,13 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, octoprint.plugin.EventHandlerPlugin): ARCHIVE_EXTENSIONS = (".zip", ".tar.gz", ".tgz", ".tar") + + # valid pip install URL schemes according to https://pip.pypa.io/en/stable/reference/pip_install/ + URL_SCHEMES = ("http", "https", "git", + "git+http", "git+https", "git+ssh", "git+git", + "hg+http", "hg+https", "hg+static-http", "hg+ssh", + "svn", "svn+svn", "svn+http", "svn+https", "svn+ssh", + "bzr+http", "bzr+https", "bzr+ssh", "bzr+sftp", "bzr+ftp", "bzr+lp") OPERATING_SYSTEMS = dict(windows=["win32"], linux=lambda x: x.startswith("linux"), @@ -312,6 +319,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, def command_install(self, url=None, path=None, force=False, reinstall=None, dependency_links=False): if url is not None: + if not any(map(lambda scheme: url.starts_with(scheme + "://"), self.URL_SCHEMES)): + raise ValueError("Invalid URL to pip install from") + source = url source_type = "url" already_installed_check = lambda line: url in line diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index 84911058a..7d59a9b34 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -240,23 +240,57 @@ $(function() { }; self.invalidUrl = ko.pureComputed(function() { + // supported pip install URL schemes, according to https://pip.pypa.io/en/stable/reference/pip_install/ + var allowedUrlSchemes = ["http", "https", + "git", "git+http", "git+https", "git+ssh", "git+git", + "hg+http", "hg+https", "hg+static-http", "hg+ssh", + "svn", "svn+svn", "svn+http", "svn+https", "svn+ssh", + "bzr+http", "bzr+https", "bzr+ssh", "bzr+sftp", "brz+ftp", "bzr+lp"]; + var url = self.installUrl(); - return url !== undefined && url.trim() != "" && !(_.startsWith(url.toLocaleLowerCase(), "http://") || _.startsWith(url.toLocaleLowerCase(), "https://")); + var lowerUrl = url !== undefined ? url.toLocaleLowerCase() : undefined; + + var lowerUrlStartsWithScheme = function(scheme) { + return _.startsWith(lowerUrl, scheme + "://"); + }; + + return url !== undefined && url.trim() !== "" + && !(_.any(allowedUrlSchemes, lowerUrlStartsWithScheme)); }); self.enableUrlInstall = ko.pureComputed(function() { var url = self.installUrl(); - return self.enableManagement() && self.pipAvailable() && !self.safeMode() && self.online() && url !== undefined && url.trim() != "" && !self.invalidUrl(); + return self.enableManagement() + && self.pipAvailable() + && !self.safeMode() + && self.online() + && url !== undefined + && url.trim() !== "" + && !self.invalidUrl(); }); self.invalidArchive = ko.pureComputed(function() { + var allowedArchiveExtensions = [".zip", ".tar.gz", ".tgz", ".tar"]; + var name = self.uploadFilename(); - return name !== undefined && !(_.endsWith(name.toLocaleLowerCase(), ".zip") || _.endsWith(name.toLocaleLowerCase(), ".tar.gz") || _.endsWith(name.toLocaleLowerCase(), ".tgz") || _.endsWith(name.toLocaleLowerCase(), ".tar")); + var lowerName = name !== undefined ? name.toLocaleLowerCase() : undefined; + + var lowerNameHasExtension = function(extension) { + return _.endsWith(lowerName, extension); + }; + + return name !== undefined + && !(_.any(allowedArchiveExtensions, lowerNameHasExtension)); }); self.enableArchiveInstall = ko.pureComputed(function() { var name = self.uploadFilename(); - return self.enableManagement() && self.pipAvailable() && !self.safeMode() && name !== undefined && name.trim() != "" && !self.invalidArchive(); + return self.enableManagement() + && self.pipAvailable() + && !self.safeMode() + && name !== undefined + && name.trim() !== "" + && !self.invalidArchive(); }); self.uploadElement.fileupload({ diff --git a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 index 10f921dbc..b85052950 100644 --- a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 +++ b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 @@ -197,7 +197,7 @@ - {{ _('This does not look like a valid "http://" or "https://" URL.') }} + {{ _('This does not look like a valid URL. Expected http, https or any of the supported VCS URLs.', url='https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support') }}

{{ _('... from an uploaded archive') }}

diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 873dfec2f..184bb564e 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -958,7 +958,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): }) callback.on_printer_send_initial_data(data) except: - self._logger.exception("Error while trying to send inital state update") + self._logger.exception("Error while trying to send initial state update") def _getStateFlags(self): return { diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 09e0c5223..6ab0d4cba 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -1127,6 +1127,23 @@ def restricted_access(func): return decorated_view +def firstrun_only_access(func): + """ + If you decorate a view with this, it will ensure that first setup has _not_ been + done for OctoPrint's Access Control. Otherwise it + will cause a HTTP 403 status code to be returned by the decorated resource. + """ + @functools.wraps(func) + def decorated_view(*args, **kwargs): + # if OctoPrint has been set up yet, abort + if settings().getBoolean(["server", "firstRun"]) and (octoprint.server.userManager is None or not octoprint.server.userManager.hasBeenCustomized()): + return func(*args, **kwargs) + else: + return flask.make_response("OctoPrint is already setup, this resource is not longer available.", 403) + + return decorated_view + + class AppSessionManager(object): VALIDITY_UNVERIFIED = 1 * 60 # 1 minute diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index a203bd259..f432077e8 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -125,7 +125,7 @@ $(function() { return exports; })(); - log.debug("Browser enviroment:", OctoPrint.coreui.browser); + log.debug("Browser environment:", OctoPrint.coreui.browser); //~~ AJAX setup @@ -180,7 +180,7 @@ $(function() { gettext("Printing"), gettext("Paused"), gettext("Closed"), - gettext("Transfering file to SD") + gettext("Transferring file to SD") ]; //~~ Initialize PNotify @@ -340,7 +340,7 @@ $(function() { continue; } - // we could resolve the depdendencies and the view model is not defined yet => add it, it's now fully processed + // we could resolve the dependencies and the view model is not defined yet => add it, it's now fully processed var viewModelBindTargets = viewModel.elements; if (additionalBindings.hasOwnProperty(viewModel.name)) { @@ -692,7 +692,7 @@ $(function() { * onServerConnect below takes care of the passive login. Only once that's completed it tells * our DataUpdater that it's ok to trigger any callbacks in view models. On the initial * server connect (during first initialization) we also trigger the settings fetch and - * binding proceedure once that's done, but only then. + * binding procedure once that's done, but only then. * * Or, as a fancy diagram: https://gist.githubusercontent.com/foosel/0cdc3a03cf5311804271f12e87293c0c/raw/abc84fdc3b13030d70961539d9c132ae39c32085/octoprint_web_startup.txt */ @@ -706,7 +706,7 @@ $(function() { // passive login request. // // This is to ensure that we have no concurrent requests triggered by socket events - // overriding each other's session during app intialization + // overriding each other's session during app initialization dataUpdater.initialized(); }); }; diff --git a/src/octoprint/static/js/app/viewmodels/slicing.js b/src/octoprint/static/js/app/viewmodels/slicing.js index d2d47098a..a02a6a5eb 100644 --- a/src/octoprint/static/js/app/viewmodels/slicing.js +++ b/src/octoprint/static/js/app/viewmodels/slicing.js @@ -15,7 +15,7 @@ $(function() { self.defaultProfile = undefined; self.destinationFilename = ko.observable(); - self.gcodeFilename = self.destinationFilename; // TODO: for backwards compatiblity, mark deprecated ASAP + self.gcodeFilename = self.destinationFilename; // TODO: for backwards compatibility, mark deprecated ASAP self.title = ko.observable(); self.slicer = ko.observable(); diff --git a/src/octoprint/static/js/app/viewmodels/system.js b/src/octoprint/static/js/app/viewmodels/system.js index 6b3002c0f..7637c04ac 100644 --- a/src/octoprint/static/js/app/viewmodels/system.js +++ b/src/octoprint/static/js/app/viewmodels/system.js @@ -51,7 +51,7 @@ $(function() { if (commandSpec.async) { text = gettext("The command \"%(command)s\" executed successfully"); } else { - text = gettext("The command \"%(command)s\" was triggered asychronously"); + text = gettext("The command \"%(command)s\" was triggered asynchronously"); } new PNotify({ diff --git a/src/octoprint/templates/navbar/login.jinja2 b/src/octoprint/templates/navbar/login.jinja2 index bc215b904..370ed299b 100644 --- a/src/octoprint/templates/navbar/login.jinja2 +++ b/src/octoprint/templates/navbar/login.jinja2 @@ -3,7 +3,7 @@