diff --git a/src/octoprint/server/api/system.py b/src/octoprint/server/api/system.py index 2d927fd1a..2478787ac 100644 --- a/src/octoprint/server/api/system.py +++ b/src/octoprint/server/api/system.py @@ -62,6 +62,25 @@ def getSystemInfo(): return jsonify(systeminfo=systeminfo) +@api.route("/system/startup", methods=["GET"]) +@no_firstrun_access +@Permissions.SYSTEM.require(403) +def getStartupInformation(): + from octoprint.server import safe_mode + from octoprint.settings import settings + + result = {} + + if safe_mode is not None: + result["safe_mode"] = safe_mode + + flagged_basefolders = settings().flagged_basefolders + if flagged_basefolders: + result["flagged_basefolders"] = flagged_basefolders + + return jsonify(startup=result) + + def _usageForFolders(): data = {} for folder_name in s().get(["folder"]).keys(): diff --git a/src/octoprint/settings/__init__.py b/src/octoprint/settings/__init__.py index 84c94db89..8685a6e5c 100644 --- a/src/octoprint/settings/__init__.py +++ b/src/octoprint/settings/__init__.py @@ -494,6 +494,8 @@ class Settings: self._path_update_callbacks = defaultdict(list) self._deprecated_paths = defaultdict(dict) + self.flagged_basefolders = {} + self._init_basedir(basedir) if configfile is not None: @@ -1805,7 +1807,7 @@ class Settings: check_writable=check_writable, deep_check_writable=deep_check_writable, ) - except Exception: + except Exception as exc: if folder != default_folder and allow_fallback: self._logger.exception( "Invalid configured {} folder at {}, attempting to " @@ -1820,6 +1822,7 @@ class Settings: deep_check_writable=deep_check_writable, ) folder = default_folder + self.flagged_basefolders[type] = str(exc) try: self.remove(["folder", type]) diff --git a/src/octoprint/static/js/app/client/system.js b/src/octoprint/static/js/app/client/system.js index 2e95d64a1..796e44566 100644 --- a/src/octoprint/static/js/app/client/system.js +++ b/src/octoprint/static/js/app/client/system.js @@ -8,6 +8,7 @@ var url = "api/system"; var commandUrl = "api/system/commands"; var infoUrl = "api/system/info"; + var startupUrl = "api/system/startup"; var OctoPrintSystemClient = function (base) { this.base = base; @@ -29,6 +30,10 @@ return this.base.get(infoUrl, opts); }; + OctoPrintSystemClient.prototype.getStartupData = function (opts) { + return this.base.get(startupUrl, opts); + }; + OctoPrintClient.registerComponent("system", OctoPrintSystemClient); return OctoPrintSystemClient; }); diff --git a/src/octoprint/static/js/app/viewmodels/system.js b/src/octoprint/static/js/app/viewmodels/system.js index 365602cb2..d54991378 100644 --- a/src/octoprint/static/js/app/viewmodels/system.js +++ b/src/octoprint/static/js/app/viewmodels/system.js @@ -8,8 +8,11 @@ $(function () { self.lastCommandResponse = undefined; self.systemActions = ko.observableArray([]); + self._startupNotification = undefined; + self.requestData = function () { self.requestCommandData(); + self.requestStartupData(); }; self.requestCommandData = function () { @@ -52,6 +55,52 @@ $(function () { self.systemActions(actions); }; + self.requestStartupData = function () { + if (!self.loginState.hasPermission(self.access.permissions.SYSTEM)) { + return $.Deferred().reject().promise(); + } + + return OctoPrint.system.getStartupData().done(self.fromStartupResponse); + }; + + self.fromStartupResponse = function (response) { + const startupData = response.startup; + + if (startupData.flagged_basefolders) { + if (self._startupNotification) self._startupNotification.remove(); + + let html = + "

" + + gettext( + "The following folder(s) were found to be unusable by OctoPrint during startup and have been turned back to the default:" + ) + + "

"; + html += ""; + html += + "

" + + gettext( + "Please check the permissions of these folders and make sure they are writable by the user running OctoPrint. In case of network shares, make sure they have been mounted before OctoPrint starts." + ) + + "

"; + + self._startupNotification = new PNotify({ + title: gettext("Warning"), + text: html, + type: "warning", + hide: false + }); + } + }; + self.triggerCommand = function (commandSpec) { if (!self.loginState.hasPermission(self.access.permissions.SYSTEM)) { return $.Deferred().reject().promise();