restricted_access => require_firstrun
We don't want to require a login session anymore in most cases, we have granular permissions for this.
This commit is contained in:
1 parent
e2a7e07a0a
commit
b6f71eeb3b
17 files changed
+106
-88
No files matched your search
@@ -21,7 +21,7 @@ import flask
|
||||
from collections import OrderedDict
|
||||
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.server.util.flask import restricted_access, with_revalidation_checking, check_etag
|
||||
from octoprint.server.util.flask import require_firstrun, with_revalidation_checking, check_etag
|
||||
from octoprint.util import utmify
|
||||
from flask_babel import gettext
|
||||
from octoprint import __version__ as OCTOPRINT_VERSION
|
||||
@@ -149,7 +149,7 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin,
|
||||
# Blueprint Plugin
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/channels", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_ANNOUNCEMENTS_READ.require(403)
|
||||
def get_channel_data(self):
|
||||
from octoprint.settings import valid_boolean_trues
|
||||
@@ -210,7 +210,7 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin,
|
||||
unless=lambda: force)(view)()
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/channels/<channel>", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_ANNOUNCEMENTS_READ.require(403)
|
||||
def channel_command(self, channel):
|
||||
from octoprint.server.util.flask import get_json_command_from_request
|
||||
|
||||
@@ -8,7 +8,7 @@ import octoprint.plugin
|
||||
from octoprint.settings import settings
|
||||
|
||||
from octoprint.server import NO_CONTENT
|
||||
from octoprint.server.util.flask import redirect_to_tornado, restricted_access
|
||||
from octoprint.server.util.flask import redirect_to_tornado, require_firstrun
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
from flask import request, jsonify, url_for, make_response
|
||||
@@ -41,7 +41,7 @@ class LoggingPlugin(octoprint.plugin.AssetPlugin,
|
||||
]
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_LOGGING_MANAGE.require(403)
|
||||
def get_all(self):
|
||||
files = self._getLogFiles()
|
||||
@@ -52,7 +52,7 @@ class LoggingPlugin(octoprint.plugin.AssetPlugin,
|
||||
setup=dict(loggers=loggers, levels=levels))
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/logs", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_LOGGING_MANAGE.require(403)
|
||||
def get_log_files(self):
|
||||
files = self._getLogFiles()
|
||||
@@ -60,13 +60,13 @@ class LoggingPlugin(octoprint.plugin.AssetPlugin,
|
||||
return jsonify(files=files, free=free, total=total)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/logs/<path:filename>", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_LOGGING_MANAGE.require(403)
|
||||
def download_log(self, filename):
|
||||
return redirect_to_tornado(request, url_for("index") + "downloads/logs/" + filename)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/logs/<path:filename>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_LOGGING_MANAGE.require(403)
|
||||
def delete_log(self, filename):
|
||||
secure = os.path.join(settings().getBaseFolder("logs"), secure_filename(filename))
|
||||
@@ -78,7 +78,7 @@ class LoggingPlugin(octoprint.plugin.AssetPlugin,
|
||||
return NO_CONTENT
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/setup", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_LOGGING_MANAGE.require(403)
|
||||
def get_logging_setup(self):
|
||||
loggers = self._get_available_loggers()
|
||||
@@ -86,13 +86,13 @@ class LoggingPlugin(octoprint.plugin.AssetPlugin,
|
||||
return jsonify(loggers=loggers, levels=levels)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/setup/levels", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_LOGGING_MANAGE.require(403)
|
||||
def get_logging_levels_api(self):
|
||||
return jsonify(self._get_logging_levels())
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/setup/levels", methods=["PUT"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_LOGGING_MANAGE.require(403)
|
||||
def set_logging_levels_api(self):
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
|
||||
@@ -11,7 +11,7 @@ import octoprint.plugin
|
||||
import octoprint.plugin.core
|
||||
|
||||
from octoprint.settings import valid_boolean_trues
|
||||
from octoprint.server.util.flask import restricted_access, with_revalidation_checking, check_etag
|
||||
from octoprint.server.util.flask import require_firstrun, with_revalidation_checking, check_etag
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.util.pip import LocalPipCaller
|
||||
from octoprint.util.version import get_octoprint_version_string, get_octoprint_version, is_octoprint_compatible
|
||||
@@ -182,7 +182,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
##~~ BlueprintPlugin
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/upload_archive", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_PLUGINMANAGER_INSTALL.require(403)
|
||||
def upload_archive(self):
|
||||
import flask
|
||||
|
||||
@@ -23,7 +23,7 @@ from . import version_checks, updaters, exceptions, util, cli
|
||||
|
||||
from flask_babel import gettext
|
||||
|
||||
from octoprint.server.util.flask import restricted_access, with_revalidation_checking, check_etag
|
||||
from octoprint.server.util.flask import require_firstrun, with_revalidation_checking, check_etag
|
||||
from octoprint.server import VERSION, REVISION, BRANCH
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.util import dict_merge, to_unicode
|
||||
@@ -486,7 +486,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
#~~ BluePrint API
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.require(403)
|
||||
def check_for_update(self):
|
||||
if "check" in flask.request.values:
|
||||
@@ -543,7 +543,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/update", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PLUGIN_SOFTWAREUPDATE_UPDATE.require(403)
|
||||
def perform_update(self):
|
||||
if self._printer.is_printing() or self._printer.is_paused():
|
||||
|
||||
@@ -17,7 +17,7 @@ import octoprint.plugin
|
||||
from octoprint.server import NO_CONTENT
|
||||
from octoprint.settings import settings as s, valid_boolean_trues
|
||||
from octoprint.server.util import noCachingExceptGetResponseHandler, enforceApiKeyRequestHandler, loginFromApiKeyRequestHandler, loginFromAuthorizationHeaderRequestHandler, corsRequestHandler, corsResponseHandler
|
||||
from octoprint.server.util.flask import restricted_access, get_json_command_from_request, passive_login
|
||||
from octoprint.server.util.flask import require_firstrun, get_json_command_from_request, passive_login
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ def pluginData(name):
|
||||
#~~ commands for plugins
|
||||
|
||||
@api.route("/plugin/<string:name>", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def pluginCommand(name):
|
||||
api_plugins = octoprint.plugin.plugin_manager().get_filtered_implementations(lambda p: p._identifier == name, octoprint.plugin.SimpleApiPlugin)
|
||||
|
||||
@@ -169,13 +169,12 @@ def wizardFinish():
|
||||
|
||||
|
||||
@api.route("/state", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def apiPrinterState():
|
||||
return make_response(("/api/state has been deprecated, use /api/printer instead", 405, []))
|
||||
|
||||
|
||||
@api.route("/version", methods=["GET"])
|
||||
@restricted_access
|
||||
def apiVersion():
|
||||
return jsonify({
|
||||
"server": octoprint.server.VERSION,
|
||||
@@ -226,7 +225,6 @@ def login():
|
||||
|
||||
|
||||
@api.route("/logout", methods=["POST"])
|
||||
@restricted_access
|
||||
def logout():
|
||||
# logout from user manager...
|
||||
_logout(current_user)
|
||||
@@ -247,7 +245,7 @@ def _logout(user):
|
||||
|
||||
|
||||
@api.route("/util/test", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.ADMIN.require(403)
|
||||
def utilTestPath():
|
||||
valid_commands = dict(
|
||||
|
||||
@@ -14,7 +14,7 @@ import octoprint.access.users as users
|
||||
|
||||
from octoprint.server import SUCCESS, groupManager, userManager
|
||||
from octoprint.server.api import api, valid_boolean_trues
|
||||
from octoprint.server.util.flask import restricted_access
|
||||
from octoprint.server.util.flask import require_firstrun
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
#~~ permission api
|
||||
@@ -26,14 +26,14 @@ def get_permissions():
|
||||
#~~ group api
|
||||
|
||||
@api.route("/access/groups", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def get_groups():
|
||||
return jsonify(groups=map(lambda g: g.as_dict(), groupManager.groups))
|
||||
|
||||
|
||||
@api.route("/access/groups", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def add_group():
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
@@ -65,7 +65,7 @@ def add_group():
|
||||
|
||||
|
||||
@api.route("/access/groups/<key>", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def get_group(key):
|
||||
group = groupManager.find_group(key)
|
||||
@@ -76,7 +76,7 @@ def get_group(key):
|
||||
|
||||
|
||||
@api.route("/access/groups/<key>", methods=["PUT"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def update_group(key):
|
||||
if "application/json" not in request.headers["Content-Type"]:
|
||||
@@ -109,7 +109,7 @@ def update_group(key):
|
||||
|
||||
|
||||
@api.route("/access/groups/<key>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def remove_group(key):
|
||||
try:
|
||||
@@ -123,7 +123,7 @@ def remove_group(key):
|
||||
#~~ user api
|
||||
|
||||
@api.route("/access/users", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def get_users():
|
||||
if not userManager.enabled:
|
||||
@@ -133,7 +133,7 @@ def get_users():
|
||||
|
||||
|
||||
@api.route("/access/users", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def add_user():
|
||||
if not userManager.enabled:
|
||||
@@ -172,7 +172,7 @@ def add_user():
|
||||
|
||||
|
||||
@api.route("/access/users/<username>", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def get_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
@@ -188,7 +188,7 @@ def get_user(username):
|
||||
|
||||
|
||||
@api.route("/access/users/<username>", methods=["PUT"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def update_user(username):
|
||||
if not userManager.enabled:
|
||||
@@ -228,7 +228,7 @@ def update_user(username):
|
||||
|
||||
|
||||
@api.route("/access/users/<username>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def remove_user(username):
|
||||
if not userManager.enabled:
|
||||
@@ -242,7 +242,7 @@ def remove_user(username):
|
||||
|
||||
|
||||
@api.route("/access/users/<username>/password", methods=["PUT"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def change_password_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
@@ -273,7 +273,7 @@ def change_password_for_user(username):
|
||||
|
||||
|
||||
@api.route("/access/users/<username>/settings", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def get_settings_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
@@ -287,7 +287,7 @@ def get_settings_for_user(username):
|
||||
return make_response("Unknown user: %s" % username, 404)
|
||||
|
||||
@api.route("/access/users/<username>/settings", methods=["PATCH"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def change_settings_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
@@ -310,7 +310,7 @@ def change_settings_for_user(username):
|
||||
return make_response("Unknown user: %s" % username, 404)
|
||||
|
||||
@api.route("/access/users/<username>/apikey", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def delete_apikey_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
@@ -326,7 +326,7 @@ def delete_apikey_for_user(username):
|
||||
|
||||
|
||||
@api.route("/access/users/<username>/apikey", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
def generate_apikey_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
@@ -10,7 +10,7 @@ from flask import request, jsonify, make_response
|
||||
from octoprint.settings import settings
|
||||
from octoprint.server import printer, printerProfileManager, NO_CONTENT
|
||||
from octoprint.server.api import api
|
||||
from octoprint.server.util.flask import restricted_access, get_json_command_from_request
|
||||
from octoprint.server.util.flask import require_firstrun, get_json_command_from_request
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
@api.route("/connection", methods=["GET"])
|
||||
@@ -28,7 +28,7 @@ def connectionState():
|
||||
|
||||
|
||||
@api.route("/connection", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONNECTION.require(403)
|
||||
def connectionCommand():
|
||||
valid_commands = {
|
||||
|
||||
@@ -10,7 +10,7 @@ from flask import request, jsonify, make_response, url_for
|
||||
from octoprint.filemanager.destinations import FileDestinations
|
||||
from octoprint.settings import settings, valid_boolean_trues
|
||||
from octoprint.server import printer, fileManager, slicingManager, eventManager, NO_CONTENT
|
||||
from octoprint.server.util.flask import restricted_access, get_json_command_from_request, with_revalidation_checking
|
||||
from octoprint.server.util.flask import require_firstrun, get_json_command_from_request, with_revalidation_checking
|
||||
from octoprint.server.api import api
|
||||
from octoprint.events import Events
|
||||
from octoprint.access.permissions import Permissions
|
||||
@@ -259,7 +259,7 @@ def _isBusy(target, path):
|
||||
return any(target == x[0] and fileManager.file_in_path(FileDestinations.LOCAL, path, x[1]) for x in fileManager.get_busy_files())
|
||||
|
||||
@api.route("/files/<string:target>", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.FILES_UPLOAD.require(403)
|
||||
def uploadGcodeFile(target):
|
||||
input_name = "file"
|
||||
@@ -473,7 +473,7 @@ def readGcodeFile(target, filename):
|
||||
|
||||
|
||||
@api.route("/files/<string:target>/<path:filename>", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.FILES_ACCESS.require(403)
|
||||
def gcodeFileCommand(filename, target):
|
||||
if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
|
||||
@@ -738,8 +738,8 @@ def gcodeFileCommand(filename, target):
|
||||
|
||||
|
||||
@api.route("/files/<string:target>/<path:filename>", methods=["DELETE"])
|
||||
@require_firstrun
|
||||
@Permissions.FILES_DELETE.require(403)
|
||||
@restricted_access
|
||||
def deleteGcodeFile(filename, target):
|
||||
if not _verifyFileExists(target, filename) and not _verifyFolderExists(target, filename):
|
||||
return make_response("File/Folder not found on '%s': %s" % (target, filename), 404)
|
||||
|
||||
@@ -8,12 +8,12 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
||||
from flask import request, make_response, jsonify
|
||||
|
||||
from octoprint.server import printer, NO_CONTENT
|
||||
from octoprint.server.util.flask import restricted_access, get_json_command_from_request
|
||||
from octoprint.server.util.flask import require_firstrun, get_json_command_from_request
|
||||
from octoprint.server.api import api
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
@api.route("/job", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.PRINT.require(403)
|
||||
def controlJob():
|
||||
if not printer.is_operational():
|
||||
|
||||
@@ -21,7 +21,7 @@ from flask import request, jsonify, make_response
|
||||
from octoprint.settings import settings
|
||||
|
||||
from octoprint.server.api import api
|
||||
from octoprint.server.util.flask import restricted_access
|
||||
from octoprint.server.util.flask import require_firstrun
|
||||
|
||||
from octoprint.plugin import plugin_manager
|
||||
from octoprint.access.permissions import Permissions
|
||||
@@ -29,7 +29,7 @@ from octoprint.access.permissions import Permissions
|
||||
from flask_babel import Locale
|
||||
|
||||
@api.route("/languages", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def getInstalledLanguagePacks():
|
||||
translation_folder = settings().getBaseFolder("translations")
|
||||
@@ -87,7 +87,7 @@ def getInstalledLanguagePacks():
|
||||
return jsonify(language_packs=result)
|
||||
|
||||
@api.route("/languages", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def uploadLanguagePack():
|
||||
input_name = "file"
|
||||
@@ -115,7 +115,7 @@ def uploadLanguagePack():
|
||||
return getInstalledLanguagePacks()
|
||||
|
||||
@api.route("/languages/<string:locale>/<string:pack>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def deleteInstalledLanguagePack(locale, pack):
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import re
|
||||
from octoprint.settings import settings, valid_boolean_trues
|
||||
from octoprint.server import printer, printerProfileManager, NO_CONTENT
|
||||
from octoprint.server.api import api
|
||||
from octoprint.server.util.flask import restricted_access, get_json_command_from_request
|
||||
from octoprint.server.util.flask import require_firstrun, get_json_command_from_request
|
||||
|
||||
from octoprint.printer import UnknownScript
|
||||
|
||||
@@ -60,7 +60,7 @@ def printerState():
|
||||
|
||||
|
||||
@api.route("/printer/tool", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONTROL.require(403)
|
||||
def printerToolCommand():
|
||||
if not printer.is_operational():
|
||||
@@ -150,6 +150,7 @@ def printerToolCommand():
|
||||
|
||||
|
||||
@api.route("/printer/tool", methods=["GET"])
|
||||
@require_firstrun
|
||||
@Permissions.STATUS.require(403)
|
||||
def printerToolState():
|
||||
if not printer.is_operational():
|
||||
@@ -162,7 +163,7 @@ def printerToolState():
|
||||
|
||||
|
||||
@api.route("/printer/bed", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONTROL.require(403)
|
||||
def printerBedCommand():
|
||||
if not printer.is_operational():
|
||||
@@ -209,6 +210,7 @@ def printerBedCommand():
|
||||
|
||||
|
||||
@api.route("/printer/bed", methods=["GET"])
|
||||
@require_firstrun
|
||||
@Permissions.STATUS.require(403)
|
||||
def printerBedState():
|
||||
if not printer.is_operational():
|
||||
@@ -228,7 +230,7 @@ def printerBedState():
|
||||
|
||||
|
||||
@api.route("/printer/printhead", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONTROL.require(403)
|
||||
def printerPrintheadCommand():
|
||||
valid_commands = {
|
||||
@@ -292,7 +294,7 @@ def printerPrintheadCommand():
|
||||
|
||||
|
||||
@api.route("/printer/sd", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONTROL.require(403)
|
||||
def printerSdCommand():
|
||||
if not settings().getBoolean(["feature", "sdSupport"]):
|
||||
@@ -323,7 +325,7 @@ def printerSdCommand():
|
||||
|
||||
|
||||
@api.route("/printer/sd", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.STATUS.require(403)
|
||||
def printerSdState():
|
||||
if not settings().getBoolean(["feature", "sdSupport"]):
|
||||
@@ -336,7 +338,7 @@ def printerSdState():
|
||||
|
||||
|
||||
@api.route("/printer/command", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONTROL.require(403)
|
||||
def printerCommand():
|
||||
if not printer.is_operational():
|
||||
@@ -397,7 +399,7 @@ def printerCommand():
|
||||
return NO_CONTENT
|
||||
|
||||
@api.route("/printer/command/custom", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONTROL.require(403)
|
||||
def getCustomControls():
|
||||
# TODO: document me
|
||||
|
||||
@@ -14,7 +14,7 @@ from werkzeug.exceptions import BadRequest
|
||||
from past.builtins import basestring
|
||||
|
||||
from octoprint.server.api import api, NO_CONTENT, valid_boolean_trues
|
||||
from octoprint.server.util.flask import restricted_access, with_revalidation_checking
|
||||
from octoprint.server.util.flask import require_firstrun, with_revalidation_checking
|
||||
from octoprint.util import dict_merge
|
||||
|
||||
from octoprint.server import printerProfileManager
|
||||
@@ -40,14 +40,14 @@ def _etag(lm=None):
|
||||
@with_revalidation_checking(etag_factory=_etag,
|
||||
lastmodified_factory=_lastmodified,
|
||||
unless=lambda: request.values.get("force", "false") in valid_boolean_trues)
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONNECTION.require(403)
|
||||
def printerProfilesList():
|
||||
all_profiles = printerProfileManager.get_all()
|
||||
return jsonify(dict(profiles=_convert_profiles(all_profiles)))
|
||||
|
||||
@api.route("/printerprofiles", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def printerProfilesAdd():
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
@@ -102,7 +102,7 @@ def printerProfilesAdd():
|
||||
return jsonify(dict(profile=_convert_profile(saved_profile)))
|
||||
|
||||
@api.route("/printerprofiles/<string:identifier>", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.CONNECTION.require(403)
|
||||
def printerProfilesGet(identifier):
|
||||
profile = printerProfileManager.get(identifier)
|
||||
@@ -112,7 +112,7 @@ def printerProfilesGet(identifier):
|
||||
return jsonify(_convert_profile(profile))
|
||||
|
||||
@api.route("/printerprofiles/<string:identifier>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def printerProfilesDelete(identifier):
|
||||
current_profile = printerProfileManager.get_current()
|
||||
@@ -127,7 +127,7 @@ def printerProfilesDelete(identifier):
|
||||
return NO_CONTENT
|
||||
|
||||
@api.route("/printerprofiles/<string:identifier>", methods=["PATCH"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def printerProfilesUpdate(identifier):
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
|
||||
@@ -16,7 +16,7 @@ from octoprint.settings import settings, valid_boolean_trues
|
||||
|
||||
from octoprint.server import admin_permission, printer
|
||||
from octoprint.server.api import api, NO_CONTENT
|
||||
from octoprint.server.util.flask import restricted_access, with_revalidation_checking
|
||||
from octoprint.server.util.flask import require_firstrun, with_revalidation_checking
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
import octoprint.plugin
|
||||
@@ -276,7 +276,7 @@ def _get_plugin_settings():
|
||||
|
||||
|
||||
@api.route("/settings", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def setSettings():
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
@@ -299,7 +299,7 @@ def setSettings():
|
||||
|
||||
|
||||
@api.route("/settings/apikey", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def generateApiKey():
|
||||
apikey = settings().generateApiKey()
|
||||
@@ -307,7 +307,7 @@ def generateApiKey():
|
||||
|
||||
|
||||
@api.route("/settings/apikey", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def deleteApiKey():
|
||||
settings().deleteApiKey()
|
||||
|
||||
@@ -9,7 +9,7 @@ from flask import request, jsonify, make_response, url_for
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
from octoprint.server import slicingManager
|
||||
from octoprint.server.util.flask import restricted_access, with_revalidation_checking
|
||||
from octoprint.server.util.flask import require_firstrun, with_revalidation_checking
|
||||
from octoprint.server.api import api, NO_CONTENT
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
@@ -103,7 +103,7 @@ def slicingListAll():
|
||||
return jsonify(result)
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SLICE.require(403)
|
||||
def slicingListSlicerProfiles(slicer):
|
||||
configured = False
|
||||
@@ -116,7 +116,7 @@ def slicingListSlicerProfiles(slicer):
|
||||
return make_response("Unknown slicer {slicer}".format(**locals()), 404)
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SLICE.require(403)
|
||||
def slicingGetSlicerProfile(slicer, name):
|
||||
try:
|
||||
@@ -131,7 +131,7 @@ def slicingGetSlicerProfile(slicer, name):
|
||||
return jsonify(result)
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["PUT"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def slicingAddSlicerProfile(slicer, name):
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
@@ -167,7 +167,7 @@ def slicingAddSlicerProfile(slicer, name):
|
||||
return r
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["PATCH"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def slicingPatchSlicerProfile(slicer, name):
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
@@ -211,7 +211,7 @@ def slicingPatchSlicerProfile(slicer, name):
|
||||
return jsonify(_getSlicingProfileData(slicer, name, saved_profile))
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def slicingDelSlicerProfile(slicer, name):
|
||||
try:
|
||||
|
||||
@@ -16,12 +16,12 @@ from octoprint.settings import settings as s
|
||||
|
||||
from octoprint.server import NO_CONTENT
|
||||
from octoprint.server.api import api
|
||||
from octoprint.server.util.flask import restricted_access, get_remote_address
|
||||
from octoprint.server.util.flask import require_firstrun, get_remote_address
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.logging import prefix_multilines
|
||||
|
||||
@api.route("/system", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SYSTEM.require(403)
|
||||
def performSystemAction():
|
||||
logging.getLogger(__name__).warn("Deprecated API call to /api/system made by {}, should be migrated to use /system/commands/custom/<action>".format(get_remote_address(request)))
|
||||
@@ -37,7 +37,7 @@ def performSystemAction():
|
||||
|
||||
|
||||
@api.route("/system/commands", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SYSTEM.require(403)
|
||||
def retrieveSystemCommands():
|
||||
return jsonify(core=_to_client_specs(_get_core_command_specs()),
|
||||
@@ -45,7 +45,7 @@ def retrieveSystemCommands():
|
||||
|
||||
|
||||
@api.route("/system/commands/<string:source>", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SYSTEM.require(403)
|
||||
def retrieveSystemCommandsForSource(source):
|
||||
if source == "core":
|
||||
@@ -59,7 +59,7 @@ def retrieveSystemCommandsForSource(source):
|
||||
|
||||
|
||||
@api.route("/system/commands/<string:source>/<string:command>", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.SYSTEM.require(403)
|
||||
def executeSystemCommand(source, command):
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,7 +16,7 @@ import octoprint.util as util
|
||||
from octoprint.settings import settings, valid_boolean_trues
|
||||
|
||||
from octoprint.server import admin_permission, printer
|
||||
from octoprint.server.util.flask import redirect_to_tornado, restricted_access, get_json_command_from_request, with_revalidation_checking
|
||||
from octoprint.server.util.flask import redirect_to_tornado, require_firstrun, get_json_command_from_request, with_revalidation_checking
|
||||
from octoprint.server.api import api
|
||||
|
||||
from octoprint.server import NO_CONTENT
|
||||
@@ -73,10 +73,10 @@ def _etag(unrendered, lm=None):
|
||||
return hash.hexdigest()
|
||||
|
||||
@api.route("/timelapse", methods=["GET"])
|
||||
@restricted_access
|
||||
@with_revalidation_checking(etag_factory=lambda lm=None: _etag(request.values.get("unrendered", "false") in valid_boolean_trues, lm=lm),
|
||||
lastmodified_factory=lambda: _lastmodified(request.values.get("unrendered", "false") in valid_boolean_trues),
|
||||
unless=lambda: request.values.get("force", "false") in valid_boolean_trues)
|
||||
@require_firstrun
|
||||
@Permissions.TIMELAPSE_LIST.require(403)
|
||||
def getTimelapseData():
|
||||
timelapse = octoprint.timelapse.current
|
||||
@@ -122,14 +122,14 @@ def getTimelapseData():
|
||||
|
||||
|
||||
@api.route("/timelapse/<filename>", methods=["GET"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.TIMELAPSE_DOWNLOAD.require(403)
|
||||
def downloadTimelapse(filename):
|
||||
return redirect_to_tornado(request, url_for("index") + "downloads/timelapse/" + filename)
|
||||
|
||||
|
||||
@api.route("/timelapse/<filename>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.TIMELAPSE_DELETE.require(403)
|
||||
def deleteTimelapse(filename):
|
||||
if util.is_allowed_file(filename, ["mpg", "mpeg", "mp4", "m4v", "mkv"]):
|
||||
@@ -146,7 +146,7 @@ def deleteTimelapse(filename):
|
||||
|
||||
|
||||
@api.route("/timelapse/unrendered/<name>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.TIMELAPSE_DELETE.require(403)
|
||||
def deleteUnrenderedTimelapse(name):
|
||||
octoprint.timelapse.delete_unrendered_timelapse(name)
|
||||
@@ -154,7 +154,7 @@ def deleteUnrenderedTimelapse(name):
|
||||
|
||||
|
||||
@api.route("/timelapse/unrendered/<name>", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.TIMELAPSE_ADMIN.require(403)
|
||||
def processUnrenderedTimelapseCommand(name):
|
||||
# valid file commands, dict mapping command name to mandatory parameters
|
||||
@@ -175,7 +175,7 @@ def processUnrenderedTimelapseCommand(name):
|
||||
|
||||
|
||||
@api.route("/timelapse", methods=["POST"])
|
||||
@restricted_access
|
||||
@require_firstrun
|
||||
@Permissions.TIMELAPSE_ADMIN.require(403)
|
||||
def setTimelapseConfig():
|
||||
data = request.get_json(silent=True)
|
||||
|
||||
@@ -1125,6 +1125,23 @@ def restricted_access(func):
|
||||
login_required decorator are met (possibly through a session already created
|
||||
by octoprint.server.util.apiKeyRequestHandler earlier in the request processing).
|
||||
|
||||
If OctoPrint's Access Control has not been setup yet (indicated by the "firstRun"
|
||||
flag from the settings being set to True and the userManager not indicating
|
||||
that it's user database has been customized from default), the decorator
|
||||
will cause a HTTP 403 status code to be returned by the decorated resource.
|
||||
"""
|
||||
@functools.wraps(func)
|
||||
def decorated_view(*args, **kwargs):
|
||||
return require_firstrun(flask_login.login_required(func))(*args, **kwargs)
|
||||
|
||||
return decorated_view
|
||||
|
||||
|
||||
def require_firstrun(func):
|
||||
"""
|
||||
If you decorate a view with this, it will ensure that first setup has been
|
||||
done for OctoPrint's Access Control.
|
||||
|
||||
If OctoPrint's Access Control has not been setup yet (indicated by the "firstRun"
|
||||
flag from the settings being set to True and the userManager not indicating
|
||||
that it's user database has been customized from default), the decorator
|
||||
@@ -1133,10 +1150,11 @@ def restricted_access(func):
|
||||
@functools.wraps(func)
|
||||
def decorated_view(*args, **kwargs):
|
||||
# if OctoPrint hasn't been set up yet, abort
|
||||
if settings().getBoolean(["server", "firstRun"]) and settings().getBoolean(["accessControl", "enabled"]) and (octoprint.server.userManager is None or not octoprint.server.userManager.has_been_customized()):
|
||||
if settings().getBoolean(["server", "firstRun"]) and settings().getBoolean(["accessControl", "enabled"]) and (
|
||||
octoprint.server.userManager is None or not octoprint.server.userManager.has_been_customized()):
|
||||
return flask.make_response("OctoPrint isn't setup yet", 403)
|
||||
|
||||
return flask_login.login_required(func)(*args, **kwargs)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return decorated_view
|
||||
|
||||
|
||||
Reference in new issue
Block a user