Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
464d9c0757 | ||
|
|
94ae90ab80 | ||
|
|
33b89550a4 | ||
|
|
9661469532 | ||
|
|
b06c222a7d | ||
|
|
9f85b54681 | ||
|
|
5d1ad5d75d | ||
|
|
dc32f955b7 | ||
|
|
220592c267 | ||
|
|
0faa6879b4 | ||
|
|
71b5de91bf | ||
|
|
928d62a517 | ||
|
|
78bd3b1a52 | ||
|
|
b9bab0577b | ||
|
|
c41551a643 | ||
|
|
6c92dd1303 | ||
|
|
124f01ca2d | ||
|
|
0dece85fa7 | ||
|
|
caebf90ee9 | ||
|
|
0c77014903 | ||
|
|
231a796200 | ||
|
|
fe755405e8 | ||
|
|
2200f2186c | ||
|
|
b57b7cb606 | ||
|
|
f2b2496e58 | ||
|
|
e603b98d0d | ||
|
|
e235fc299f | ||
|
|
4f25ed546e | ||
|
|
f72b9db6a9 | ||
|
|
80e8e33283 | ||
|
|
00d0396417 | ||
|
|
59e39662f1 | ||
|
|
038e1b9a57 | ||
|
|
bbefeeeb02 | ||
|
|
2801da5c51 | ||
|
|
471dab9406 | ||
|
|
1deb247ce5 | ||
|
|
4469a2d84a |
No files matched your search
+5
-2
@@ -29,5 +29,8 @@ improve/.* 1.3.13 2a42f02aecaedf2c55579984e0bc94e44402cc15 pep440-dev
|
||||
staging/maintenance 1.3.12rc4 a70a45f062687beb510fb3192e4227754e1dff39 pep440-dev
|
||||
regressionfix/.* 1.3.12rc4 a70a45f062687beb510fb3192e4227754e1dff39 pep440-dev
|
||||
|
||||
# every other branch is a development branch and thus gets resolved to 1.4.0-dev for now
|
||||
.* 1.4.0 7f5d03d0549bcbd26f40e7e4a3297ea5204fb1cc pep440-dev
|
||||
# staging/devel is currently the branch for preparation of 1.4.0rc3
|
||||
staging/devel 1.4.0rc3 e603b98d0dc552e570034aae52291737695dd0f6 pep440-dev
|
||||
|
||||
# every other branch is a development branch and thus gets resolved to 1.5.0-dev for now
|
||||
.* 1.5.0 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev
|
||||
+7
-6
@@ -8,22 +8,22 @@ thanks to everyone who contributed!
|
||||
|
||||
* Andre Bubel
|
||||
* Andrew Moorby
|
||||
* ANTONIO AUGUSTO DE LIMA PONTES
|
||||
* Arnljot Arntsen
|
||||
* BigTreeTech
|
||||
* Boris Hussein
|
||||
* Brad Jackson
|
||||
* Christian Petropolis
|
||||
* Christian Wolf
|
||||
* COLLE+McVOY
|
||||
* D Brian Kimmel
|
||||
* DeltaMaker 3D Printers
|
||||
* Dorian Gray
|
||||
* E3D BigBox
|
||||
* Eric Betts
|
||||
* Ernesto Martinez
|
||||
* Franziska Kunsmann
|
||||
* GadgetAngel
|
||||
* George Robles
|
||||
* Greg Holloway
|
||||
* Hugh Blemings
|
||||
* jean-claude migneault
|
||||
* Jeff Renfer
|
||||
* Jeremiah Avery
|
||||
@@ -33,10 +33,10 @@ thanks to everyone who contributed!
|
||||
* Kaile Riser
|
||||
* Kale Stedman
|
||||
* Kazuhiro Ogura
|
||||
* Kenneth Jiang
|
||||
* Kyle Menigoz
|
||||
* LA 3D Printer Repair
|
||||
* Lee Dohm
|
||||
* LulzBot®
|
||||
* Makespace Madrid
|
||||
* Mark Walker
|
||||
* Martin Majewski
|
||||
@@ -50,13 +50,14 @@ thanks to everyone who contributed!
|
||||
* Randy C. Will
|
||||
* Ranjib Dey
|
||||
* Robert Gusek
|
||||
* Samer Najia
|
||||
* Ronald Griehsler
|
||||
* Shawn Lewis
|
||||
* Simon Hallam
|
||||
* Stefan Krister
|
||||
* Sven Mueller
|
||||
* The3DprintingMagic.com
|
||||
* Trent Shumay
|
||||
* Ulrich Kempken
|
||||
* Vladislav Kuzemchik
|
||||
|
||||
and 1653 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)!
|
||||
and 1678 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)!
|
||||
+88
-34
@@ -200,6 +200,94 @@ Available plugin hooks
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
.. _sec-plugins-hook-permissions:
|
||||
|
||||
octoprint.access.permissions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. py:function:: additional_permissions_hook(*args, **kwargs)
|
||||
|
||||
Return a list of additional permissions to register in the system on behalf of the plugin. Use this
|
||||
to add granular permissions to your plugin which can be configured for users and user groups in the general
|
||||
access control settings of OctoPrint.
|
||||
|
||||
Additional permissions must be modelled as ``dict``s with at least a ``key`` and ``name`` field. Possible
|
||||
fields are as follows:
|
||||
|
||||
* ``key``: A key for the permission to be used for referring to it from source code. This will turned uppercase
|
||||
and prefixed with ``PLUGIN_<PLUGIN IDENTIFIER>_`` before being made available on ``octoprint.access.permissions.Permissions``,
|
||||
e.g. ``my_permission`` on the plugin with identifier ``example`` turns into ``PLUGIN_EXAMPLE_MY_PERMISSION`` and
|
||||
can be accessed as ``octoprint.access.permissions.Permissions.PLUGIN_EXAMPLE_MY_PERMISSION`` on the server and
|
||||
``permissions.PLUGIN_EXAMPLE_MY_PERMISSION`` on the ``AccessViewModel`` on the client. Must only contain a-z, A-Z, 0-9 and _.
|
||||
* ``name``: A human readable name for the permission.
|
||||
* ``description``: A human readable description of the permission.
|
||||
* ``permissions``: A list of permissions this permission includes, by key.
|
||||
* ``roles``: A list of roles this permission includes. Roles are simple strings you define. Usually one role will
|
||||
suffice.
|
||||
* ``dangerous``: Whether this permission should be considered dangerous (``True``) or not (``False``)
|
||||
* ``default_groups``: A list of standard groups this permission should be apply to by default. Standard groups
|
||||
are ``admins``, ``users``, ``readonly`` and ``guests``
|
||||
|
||||
The following example is based on some actual code included in the bundled Application Keys plugin and defines
|
||||
one additional permission called ``ADMIN`` with a role ``admin`` which is marked as dangerous (since it gives
|
||||
access to the management to other user's application keys) and by default will only be given to the standard admin
|
||||
group:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def get_additional_permissions(*args, **kwargs):
|
||||
return [
|
||||
dict(key="ADMIN",
|
||||
name="Admin access",
|
||||
description=gettext("Allows administrating all application keys"),
|
||||
roles=["admin"],
|
||||
dangerous=True,
|
||||
default_groups=[ADMIN_GROUP])
|
||||
]
|
||||
|
||||
__plugin_hooks__ = {
|
||||
"octoprint.access.permissions": get_additional_permissions
|
||||
}
|
||||
|
||||
Once registered it can be referenced under the key ``PLUGIN_APPKEYS_ADMIN``.
|
||||
|
||||
:return: A list of additional permissions to register in the system.
|
||||
:rtype: A list of dicts.
|
||||
|
||||
.. _sec-plugins-hook-users-factory:
|
||||
|
||||
octoprint.access.users.factory
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. py:function:: user_manager_factory_hook(components, settings, *args, **kwargs)
|
||||
|
||||
Return a :class:`~octoprint.access.users.UserManager` instance to use as global user manager object. This will
|
||||
be called only once during initial server startup.
|
||||
|
||||
The provided ``components`` is a dictionary containing the already initialized system components:
|
||||
|
||||
* ``plugin_manager``: The :class:`~octoprint.plugin.core.PluginManager`
|
||||
* ``printer_profile_manager``: The :class:`~octoprint.printer.profile.PrinterProfileManager`
|
||||
* ``event_bus``: The :class:`~octoprint.events.EventManager`
|
||||
* ``analysis_queue``: The :class:`~octoprint.filemanager.analysis.AnalysisQueue`
|
||||
* ``slicing_manager``: The :class:`~octoprint.slicing.SlicingManager`
|
||||
* ``file_manager``: The :class:`~octoprint.filemanager.FileManager`
|
||||
* ``plugin_lifecycle_manager``: The :class:`~octoprint.server.LifecycleManager`
|
||||
* ``preemptive_cache``: The :class:`~octoprint.server.util.flask.PreemptiveCache`
|
||||
|
||||
If the factory returns anything but ``None``, it will be assigned to the global ``userManager`` instance.
|
||||
|
||||
If none of the registered factories return a user manager instance, the class referenced by the ``config.yaml``
|
||||
entry ``accessControl.userManager`` will be initialized if possible, otherwise a stock
|
||||
:class:`~octoprint.access.users.FilebasedUserManager` will be instantiated, linked to the default user storage
|
||||
file ``~/.octoprint/users.yaml``.
|
||||
|
||||
:param dict components: System components to use for user manager instance initialization
|
||||
:param SettingsManager settings: The global settings manager instance to fetch configuration values from if necessary
|
||||
:return: The ``userManager`` instance to use globally.
|
||||
:rtype: UserManager subclass or None
|
||||
|
||||
|
||||
.. _sec-plugins-hook-accesscontrol-keyvalidator:
|
||||
|
||||
octoprint.accesscontrol.keyvalidator
|
||||
@@ -1525,40 +1613,6 @@ octoprint.ui.web.templatetypes
|
||||
:return: a list of 3-tuples (template type, rule, sorting spec)
|
||||
:rtype: list
|
||||
|
||||
.. _sec-plugins-hook-users-factory:
|
||||
|
||||
octoprint.access.users.factory
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. py:function:: user_manager_factory_hook(components, settings, *args, **kwargs)
|
||||
|
||||
Return a :class:`~octoprint.access.users.UserManager` instance to use as global user manager object. This will
|
||||
be called only once during initial server startup.
|
||||
|
||||
The provided ``components`` is a dictionary containing the already initialized system components:
|
||||
|
||||
* ``plugin_manager``: The :class:`~octoprint.plugin.core.PluginManager`
|
||||
* ``printer_profile_manager``: The :class:`~octoprint.printer.profile.PrinterProfileManager`
|
||||
* ``event_bus``: The :class:`~octoprint.events.EventManager`
|
||||
* ``analysis_queue``: The :class:`~octoprint.filemanager.analysis.AnalysisQueue`
|
||||
* ``slicing_manager``: The :class:`~octoprint.slicing.SlicingManager`
|
||||
* ``file_manager``: The :class:`~octoprint.filemanager.FileManager`
|
||||
* ``plugin_lifecycle_manager``: The :class:`~octoprint.server.LifecycleManager`
|
||||
* ``preemptive_cache``: The :class:`~octoprint.server.util.flask.PreemptiveCache`
|
||||
|
||||
If the factory returns anything but ``None``, it will be assigned to the global ``userManager`` instance.
|
||||
|
||||
If none of the registered factories return a user manager instance, the class referenced by the ``config.yaml``
|
||||
entry ``accessControl.userManager`` will be initialized if possible, otherwise a stock
|
||||
:class:`~octoprint.access.users.FilebasedUserManager` will be instantiated, linked to the default user storage
|
||||
file ``~/.octoprint/users.yaml``.
|
||||
|
||||
:param dict components: System components to use for user manager instance initialization
|
||||
:param SettingsManager settings: The global settings manager instance to fetch configuration values from if necessary
|
||||
:return: The ``userManager`` instance to use globally.
|
||||
:rtype: UserManager subclass or None
|
||||
|
||||
|
||||
.. _sec-plugins-hook-timelapse-capture-pre:
|
||||
|
||||
octoprint.timelapse.capture.pre
|
||||
|
||||
@@ -37,9 +37,9 @@ INSTALL_REQUIRES = [
|
||||
# anything below this should be checked on releases for new versions
|
||||
|
||||
"Flask-Login>=0.4.1,<0.5",
|
||||
"Flask-Principal>=0.4,<0.5",
|
||||
"Flask-Babel>=0.12,<0.13",
|
||||
"Flask-Assets>=0.12,<0.13",
|
||||
"blinker>=1.4,<1.5", # dependency of the now vendor bundled flask_principal
|
||||
"werkzeug>=0.16,<0.17",
|
||||
"cachelib>=0.1,<0.2",
|
||||
"PyYAML>=5.1,<6",
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
#import sys
|
||||
#if sys.version_info[0] >= 3:
|
||||
# raise RuntimeError("Sorry, OctoPrint does not yet support Python 3")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import octoprint
|
||||
octoprint.main()
|
||||
@@ -18,7 +18,7 @@ from octoprint.settings import settings
|
||||
from octoprint.util import atomic_write
|
||||
from octoprint.access import ADMIN_GROUP, USER_GROUP, GUEST_GROUP, READONLY_GROUP
|
||||
from octoprint.access.permissions import Permissions, OctoPrintPermission
|
||||
from flask_principal import Need, Permission
|
||||
from octoprint.vendor.flask_principal import Need, Permission
|
||||
|
||||
DEFAULT_ADMIN_PERMISSIONS = [Permissions.ADMIN]
|
||||
"""Default admin permissions are the legacy permissions from before 1.4.0"""
|
||||
|
||||
@@ -8,7 +8,7 @@ __copyright__ = "Copyright (C) 2017 The OctoPrint Project - Released under terms
|
||||
from future.utils import with_metaclass
|
||||
from flask import g, abort
|
||||
from flask_babel import gettext
|
||||
from flask_principal import Permission, PermissionDenied, RoleNeed, Need
|
||||
from octoprint.vendor.flask_principal import Permission, PermissionDenied, RoleNeed, Need
|
||||
|
||||
from functools import wraps
|
||||
from collections import OrderedDict, defaultdict
|
||||
|
||||
@@ -21,7 +21,7 @@ from builtins import range, bytes
|
||||
|
||||
from octoprint.settings import settings as s
|
||||
|
||||
from octoprint.util import atomic_write, to_bytes, deprecated, monotonic_time
|
||||
from octoprint.util import atomic_write, to_bytes, deprecated, monotonic_time, generate_api_key
|
||||
from octoprint.util import get_fully_qualified_classname as fqcn
|
||||
|
||||
from octoprint.access.permissions import Permissions, OctoPrintPermission
|
||||
@@ -55,7 +55,10 @@ class UserManager(GroupChangeListener, object):
|
||||
if self.enabled:
|
||||
return AnonymousUser([self._group_manager.guest_group])
|
||||
else:
|
||||
return AdminUser([self._group_manager.admin_group])
|
||||
return AdminUser([self._group_manager.admin_group, self._group_manager.user_group])
|
||||
|
||||
def api_user_factory(self):
|
||||
return ApiUser([self._group_manager.admin_group, self._group_manager.user_group])
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
@@ -107,7 +110,7 @@ class UserManager(GroupChangeListener, object):
|
||||
return user
|
||||
|
||||
def logout_user(self, user):
|
||||
if user is None or user.is_anonymous:
|
||||
if user is None or user.is_anonymous or isinstance(user, AdminUser):
|
||||
return
|
||||
|
||||
if isinstance(user, LocalProxy):
|
||||
@@ -743,7 +746,7 @@ class FilebasedUserManager(UserManager):
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
user._apikey = ''.join('%02X' % z for z in bytes(uuid.uuid4().bytes))
|
||||
user._apikey = generate_api_key()
|
||||
self._dirty = True
|
||||
self._save()
|
||||
return user._apikey
|
||||
|
||||
@@ -7,7 +7,7 @@ import os
|
||||
import yaml
|
||||
import io
|
||||
import time
|
||||
from binascii import hexlify
|
||||
import uuid
|
||||
from collections import defaultdict
|
||||
from flask_babel import gettext
|
||||
|
||||
@@ -15,12 +15,11 @@ import octoprint.plugin
|
||||
from octoprint.settings import valid_boolean_trues
|
||||
from octoprint.server.util.flask import restricted_access, no_firstrun_access
|
||||
from octoprint.server import NO_CONTENT, current_user, admin_permission
|
||||
from octoprint.util import atomic_write, monotonic_time, ResettableTimer
|
||||
from octoprint.util import atomic_write, monotonic_time, ResettableTimer, generate_api_key
|
||||
|
||||
from octoprint.access import ADMIN_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
|
||||
CUTOFF_TIME = 10 * 60 # 10min
|
||||
POLL_TIMEOUT = 5 # 5 seconds
|
||||
|
||||
@@ -381,7 +380,7 @@ class AppKeysPlugin(octoprint.plugin.AssetPlugin,
|
||||
for user_id, data in self._keys.items():
|
||||
if any(filter(lambda x: x.api_key == api_key, data)):
|
||||
if self._user_manager.enabled:
|
||||
return self._user_manager.findUser(userid=user_id)
|
||||
return self._user_manager.find_user(userid=user_id)
|
||||
elif user_id == "_admin" or user_id == "dummy":
|
||||
# dummy = backwards compatible
|
||||
return self._user_manager.anonymous_user_factory()
|
||||
@@ -399,7 +398,7 @@ class AppKeysPlugin(octoprint.plugin.AssetPlugin,
|
||||
return result
|
||||
|
||||
def _generate_key(self):
|
||||
return hexlify(os.urandom(16))
|
||||
return generate_api_key()
|
||||
|
||||
def _load_keys(self):
|
||||
with self._keys_lock:
|
||||
|
||||
@@ -13,8 +13,8 @@ from octoprint.util.version import get_octoprint_version_string, is_released_oct
|
||||
from flask import jsonify
|
||||
from flask_babel import gettext
|
||||
|
||||
SENTRY_URL_SERVER = "https://90eab6758d324033b1523a47633d17f3@sentry.io/1373987"
|
||||
SENTRY_URL_COREUI = "https://ae03048024f841fc9724c3f5c19557a4@sentry.io/1374096"
|
||||
SENTRY_URL_SERVER = "https://e8dadc4407e74f159e77919e551bd1a7@sentry.io/1373987"
|
||||
SENTRY_URL_COREUI = "https://1da95af9c999483ba5705577f24d1e28@sentry.io/1374096"
|
||||
|
||||
SETTINGS_DEFAULTS = dict(enabled=False,
|
||||
enabled_unreleased=False,
|
||||
|
||||
@@ -36,7 +36,7 @@ class PrintTimeEstimator(object):
|
||||
interval = settings().getFloat(["serial", "timeout", "sdStatus"])
|
||||
if interval <= 0:
|
||||
interval = 1.0
|
||||
rolling_window = 15 / interval
|
||||
rolling_window = int(15 // interval)
|
||||
if rolling_window < 1:
|
||||
rolling_window = 1
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import uuid
|
||||
from octoprint.vendor.sockjs.tornado import SockJSRouter
|
||||
from flask import Flask, g, request, session, Blueprint, Request, Response, current_app
|
||||
from flask_login import LoginManager, current_user, session_protected, user_logged_out
|
||||
from flask_principal import Principal, Permission, RoleNeed, identity_loaded, identity_changed, UserNeed, Identity, AnonymousIdentity
|
||||
from octoprint.vendor.flask_principal import Principal, Permission, RoleNeed, identity_loaded, identity_changed, UserNeed, Identity, AnonymousIdentity
|
||||
from flask_babel import Babel, gettext, ngettext
|
||||
from flask_assets import Environment, Bundle
|
||||
from babel import Locale
|
||||
@@ -31,9 +31,11 @@ import os
|
||||
import sys
|
||||
import logging
|
||||
import logging.config
|
||||
import mimetypes
|
||||
import atexit
|
||||
import signal
|
||||
import base64
|
||||
import re
|
||||
|
||||
try:
|
||||
import fcntl
|
||||
@@ -123,8 +125,7 @@ def on_identity_loaded(sender, identity):
|
||||
def _clear_identity(sender):
|
||||
# Remove session keys set by Flask-Principal
|
||||
for key in ('identity.id', 'identity.name', 'identity.auth_type'):
|
||||
if key in session:
|
||||
del session[key]
|
||||
session.pop(key, None)
|
||||
|
||||
# switch to anonymous identity
|
||||
identity_changed.send(sender, identity=AnonymousIdentity())
|
||||
@@ -132,8 +133,9 @@ def _clear_identity(sender):
|
||||
|
||||
@session_protected.connect_via(app)
|
||||
def on_session_protected(sender):
|
||||
# session was protected, that means the user is no more and we need to clear our identity
|
||||
_clear_identity(sender)
|
||||
# session was deleted by session protection, that means the user is no more and we need to clear our identity
|
||||
if session.get("remember", None) == "clear":
|
||||
_clear_identity(sender)
|
||||
|
||||
|
||||
@user_logged_out.connect_via(app)
|
||||
@@ -147,7 +149,7 @@ def load_user(id):
|
||||
return None
|
||||
|
||||
if id == "_api":
|
||||
return users.ApiUser([groupManager.admin_group])
|
||||
return userManager.api_user_factory()
|
||||
|
||||
if session and "usersession.id" in session:
|
||||
sessionid = session["usersession.id"]
|
||||
@@ -278,10 +280,12 @@ class Server(object):
|
||||
self._setup_heartbeat_logging()
|
||||
pluginManager = self._plugin_manager
|
||||
|
||||
# monkey patch some stuff
|
||||
# monkey patch/fix some stuff
|
||||
util.tornado.fix_json_encode()
|
||||
util.flask.fix_flask_jsonify()
|
||||
|
||||
self._setup_mimetypes()
|
||||
|
||||
additional_translation_folders = []
|
||||
if not safe_mode:
|
||||
additional_translation_folders += [self._settings.getBaseFolder("translations")]
|
||||
@@ -1368,6 +1372,17 @@ class Server(object):
|
||||
self._logger.exception("Error processing after_request hooks from plugin {}".format(plugin),
|
||||
extra=dict(plugin=plugin))
|
||||
|
||||
def _setup_mimetypes(self):
|
||||
# Safety measures for Windows... apparently the mimetypes module takes its translation from the windows
|
||||
# registry, and if for some weird reason that gets borked the reported MIME types can be all over the place.
|
||||
# Since at least in Chrome that can cause hilarious issues with JS files (refusal to run them and thus a
|
||||
# borked UI) we make sure that .js always maps to the correct application/javascript, and also throw in a
|
||||
# .css -> text/css for good measure.
|
||||
#
|
||||
# See #3367
|
||||
mimetypes.add_type("application/javascript", ".js")
|
||||
mimetypes.add_type("text/css", ".css")
|
||||
|
||||
def _setup_assets(self):
|
||||
global app
|
||||
global assets
|
||||
@@ -1700,8 +1715,6 @@ class Server(object):
|
||||
assets.register("less_app", less_app_bundle)
|
||||
|
||||
def _setup_login_manager(self):
|
||||
util.flask.fix_flask_login_remote_address()
|
||||
|
||||
global loginManager
|
||||
|
||||
loginManager = LoginManager()
|
||||
@@ -1870,6 +1883,8 @@ class Server(object):
|
||||
|
||||
from octoprint.access.permissions import PluginOctoPrintPermission
|
||||
|
||||
key_whitelist = re.compile(r"[A-Za-z0-9_]*")
|
||||
|
||||
def permission_key(plugin, definition):
|
||||
return "PLUGIN_{}_{}".format(plugin.upper(), definition["key"].upper())
|
||||
|
||||
@@ -1942,6 +1957,10 @@ class Server(object):
|
||||
if not "key" in p or not "name" in p:
|
||||
continue
|
||||
|
||||
if not key_whitelist.match(p["key"]):
|
||||
self._logger.warn("Got permission with invalid key from plugin {}: {}".format(name, p["key"]))
|
||||
continue
|
||||
|
||||
if not process_regular_permission(plugin_info, p):
|
||||
postponed.append((plugin_info, p))
|
||||
except Exception:
|
||||
|
||||
@@ -10,7 +10,8 @@ import logging
|
||||
|
||||
from flask import Blueprint, request, jsonify, abort, current_app, session, make_response, g
|
||||
from flask_login import login_user, logout_user, current_user
|
||||
from flask_principal import Identity, identity_changed, AnonymousIdentity
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from octoprint.vendor.flask_principal import Identity, identity_changed, AnonymousIdentity
|
||||
|
||||
import octoprint.access.users
|
||||
import octoprint.util.net as util_net
|
||||
@@ -72,6 +73,8 @@ def pluginData(name):
|
||||
if response is not None:
|
||||
return response
|
||||
return NO_CONTENT
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
logging.getLogger(__name__).exception("Error calling SimpleApiPlugin {}".format(name),
|
||||
extra=dict(plugin=name))
|
||||
@@ -107,6 +110,8 @@ def pluginCommand(name):
|
||||
if response is not None:
|
||||
return response
|
||||
return NO_CONTENT
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
logging.getLogger(__name__).exception("Error while executing SimpleApiPlugin {}".format(name),
|
||||
extra=dict(plugin=name))
|
||||
@@ -205,7 +210,7 @@ def apiVersion():
|
||||
@api.route("/login", methods=["POST"])
|
||||
def login():
|
||||
data = request.get_json()
|
||||
if data is None:
|
||||
if not data:
|
||||
data = request.values
|
||||
|
||||
if octoprint.server.userManager.enabled and "user" in data and "pass" in data:
|
||||
|
||||
@@ -12,14 +12,13 @@ PY3 = sys.version_info[0] == 3
|
||||
from octoprint.settings import settings
|
||||
import octoprint.timelapse
|
||||
import octoprint.server
|
||||
from octoprint.access.users import ApiUser
|
||||
|
||||
from octoprint.util import deprecated
|
||||
from octoprint.util import deprecated, to_unicode
|
||||
from octoprint.plugin import plugin_manager
|
||||
|
||||
import flask as _flask
|
||||
import flask_login
|
||||
import flask_principal
|
||||
import octoprint.vendor.flask_principal as flask_principal
|
||||
import logging
|
||||
|
||||
from . import flask
|
||||
@@ -180,7 +179,7 @@ def get_user_for_apikey(apikey):
|
||||
if apikey is not None:
|
||||
if apikey == settings().get(["api", "key"]):
|
||||
# master key was used
|
||||
return ApiUser([octoprint.server.groupManager.admin_group])
|
||||
return octoprint.server.userManager.api_user_factory()
|
||||
|
||||
if octoprint.server.userManager.enabled:
|
||||
user = octoprint.server.userManager.find_user(apikey=apikey)
|
||||
@@ -234,7 +233,7 @@ def get_user_for_authorization_header(header):
|
||||
|
||||
header = header.replace('Basic ', '', 1)
|
||||
try:
|
||||
header = base64.b64decode(header)
|
||||
header = to_unicode(base64.b64decode(header))
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import tornado.web
|
||||
import flask
|
||||
import flask.json
|
||||
import flask_login
|
||||
import flask_principal
|
||||
import octoprint.vendor.flask_principal as flask_principal
|
||||
import flask_assets
|
||||
import webassets.updater
|
||||
import webassets.utils
|
||||
@@ -242,20 +242,6 @@ def fix_webassets_filtertool():
|
||||
|
||||
FilterTool._wrap_cache = fixed_wrap_cache
|
||||
|
||||
def fix_flask_login_remote_address():
|
||||
def fixed_get_remote_addr():
|
||||
"""Backported from https://github.com/maxcountryman/flask-login/pull/217"""
|
||||
|
||||
from flask import request
|
||||
address = request.headers.get('X-Forwarded-For', request.remote_addr)
|
||||
if address is not None:
|
||||
# An 'X-Forwarded-For' header includes a comma separated list of the
|
||||
# addresses, the first address being the actual remote address.
|
||||
address = address.encode('utf-8').split(b',')[0].strip()
|
||||
return address
|
||||
|
||||
flask_login._get_remote_addr = fixed_get_remote_addr
|
||||
|
||||
def fix_flask_jsonify():
|
||||
def fixed_jsonify(*args, **kwargs):
|
||||
"""Backported from https://github.com/pallets/flask/blob/7e714bd28b6e96d82b2848b48cf8ff48b517b09b/flask/json/__init__.py#L257"""
|
||||
@@ -590,31 +576,36 @@ def passive_login():
|
||||
|
||||
return u
|
||||
|
||||
if user is not None and user.is_active:
|
||||
# login known user
|
||||
logger.info("Passively logging in user {} from {}".format(user.get_id(), remote_address))
|
||||
user = login(user)
|
||||
def determine_user(u):
|
||||
if not u.is_anonymous and u.is_active:
|
||||
# known active user
|
||||
logger.info("Passively logging in user {} from {}".format(u.get_id(), remote_address))
|
||||
|
||||
elif settings().getBoolean(["accessControl", "autologinLocal"]) \
|
||||
and settings().get(["accessControl", "autologinAs"]) is not None \
|
||||
and settings().get(["accessControl", "localNetworks"]) is not None \
|
||||
and not "active_logout" in flask.request.cookies:
|
||||
elif settings().getBoolean(["accessControl", "autologinLocal"]) \
|
||||
and settings().get(["accessControl", "autologinAs"]) is not None \
|
||||
and settings().get(["accessControl", "localNetworks"]) is not None \
|
||||
and not "active_logout" in flask.request.cookies:
|
||||
# attempt local autologin
|
||||
autologin_as = settings().get(["accessControl", "autologinAs"])
|
||||
local_networks = _local_networks()
|
||||
logger.debug("Checking if remote address {} is in localNetworks ({!r})".format(remote_address, local_networks))
|
||||
|
||||
autologin_as = settings().get(["accessControl", "autologinAs"])
|
||||
local_networks = _local_networks()
|
||||
logger.debug("Checking if remote address {} is in localNetworks ({!r})".format(remote_address, local_networks))
|
||||
try:
|
||||
if netaddr.IPAddress(remote_address) in local_networks:
|
||||
autologin_user = octoprint.server.userManager.find_user(autologin_as)
|
||||
if autologin_user is not None and autologin_user.is_active:
|
||||
logger.info("Passively logging in user {} from {} via autologin".format(autologin_as, remote_address))
|
||||
return autologin_user
|
||||
except Exception:
|
||||
logger.exception("Could not autologin user {} from {} for networks {}".format(autologin_as, remote_address, local_networks))
|
||||
|
||||
try:
|
||||
if netaddr.IPAddress(remote_address) in local_networks:
|
||||
autologin_user = octoprint.server.userManager.findUser(autologin_as)
|
||||
if autologin_user is not None and autologin_user.is_active:
|
||||
autologin_user = octoprint.server.userManager.login_user(autologin_user)
|
||||
if not u.is_active:
|
||||
# inactive user, switch to anonymous
|
||||
u = octoprint.server.userManager.anonymous_user_factory()
|
||||
|
||||
logger.info("Passively logging in user {} from {} via autologin".format(user.get_id(), local_networks))
|
||||
user = login(autologin_user)
|
||||
except Exception:
|
||||
logger.exception("Could not autologin user {} for networks {}".format(autologin_as, local_networks))
|
||||
return u
|
||||
|
||||
user = login(determine_user(user))
|
||||
response = user.as_dict()
|
||||
response["_is_external_client"] = ip_check_enabled and not is_lan_address(remote_address,
|
||||
additional_private=ip_check_trusted)
|
||||
|
||||
@@ -460,6 +460,8 @@ class UploadStorageFallbackHandler(RequestlessExceptionLoggingMixin,
|
||||
|
||||
fields = dict((self._suffixes[key], value) for (key, value) in parameters.items())
|
||||
for n, p in fields.items():
|
||||
if n is None or p is None:
|
||||
continue
|
||||
key = name + b"." + octoprint.util.to_bytes(n)
|
||||
self._new_body += b"--%s\r\n" % self._multipart_boundary
|
||||
self._new_body += b"Content-Disposition: form-data; name=\"%s\"\r\n" % key
|
||||
|
||||
@@ -591,7 +591,7 @@ def fetch_template_data(refresh=False):
|
||||
# tabs
|
||||
|
||||
templates["tab"]["entries"] = dict(
|
||||
temperature=(gettext("Temperature"), dict(template="tabs/temperature.jinja2", _div="temp", styles=["display: none;"], data_bind="visible: loginState.hasAnyPermissionKo(access.permissions.STATUS, access.permissions.CONTROL) && visible()")),
|
||||
temperature=(gettext("Temperature"), dict(template="tabs/temperature.jinja2", _div="temp", styles=["display: none;"], data_bind="visible: loginState.hasAnyPermissionKo(access.permissions.STATUS, access.permissions.CONTROL)() && visible()")),
|
||||
control=(gettext("Control"), dict(template="tabs/control.jinja2", _div="control", styles=["display: none;"], data_bind="visible: loginState.hasAnyPermissionKo(access.permissions.WEBCAM, access.permissions.CONTROL)")),
|
||||
gcodeviewer=(gettext("GCode Viewer"), dict(template="tabs/gcodeviewer.jinja2", _div="gcode", styles=["display: none;"], data_bind="visible: loginState.hasPermissionKo(access.permissions.GCODE_VIEWER)")),
|
||||
terminal=(gettext("Terminal"), dict(template="tabs/terminal.jinja2", _div="term", styles=["display: none;"], data_bind="visible: loginState.hasPermissionKo(access.permissions.MONITOR_TERMINAL)")),
|
||||
|
||||
@@ -49,7 +49,7 @@ try:
|
||||
except ImportError:
|
||||
from collections import KeysView
|
||||
|
||||
from octoprint.util import atomic_write, is_hidden_path, dict_merge, CaseInsensitiveSet
|
||||
from octoprint.util import atomic_write, is_hidden_path, dict_merge, CaseInsensitiveSet, generate_api_key
|
||||
|
||||
_APPNAME = "OctoPrint"
|
||||
|
||||
@@ -1811,7 +1811,7 @@ class Settings(object):
|
||||
f.write(script)
|
||||
|
||||
def generateApiKey(self):
|
||||
apikey = ''.join('%02X' % z for z in bytes(uuid.uuid4().bytes))
|
||||
apikey = generate_api_key()
|
||||
self.set(["api", "key"], apikey)
|
||||
self.save(force=True)
|
||||
return apikey
|
||||
|
||||
@@ -1 +1 @@
|
||||
.btn{display:inline-block;*display:inline;*zoom:1;padding:4px 12px;margin-bottom:0;font-size:14px;line-height:20px;text-align:center;vertical-align:middle;cursor:pointer;color:#333;text-shadow:0 1px 1px rgba(255,255,255,.75);background-color:#f5f5f5;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;*background-color:#e6e6e6;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border:1px solid #ccc;*border:0;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*margin-left:.3em;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05)}.btn.active,.btn.disabled,.btn:active,.btn:focus,.btn:hover,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn.active,.btn:active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:focus,.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:#333 dotted thin;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class*=" icon-"],.btn-large [class^=icon-]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class*=" icon-"],.btn-small [class^=icon-]{margin-top:0}.btn-mini [class*=" icon-"],.btn-mini [class^=icon-]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-left:0;padding-right:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type=submit].btn-block,input[type=reset].btn-block,input[type=button].btn-block{width:100%}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#04c;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary.active,.btn-primary.disabled,.btn-primary:active,.btn-primary:focus,.btn-primary:hover,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary.active,.btn-primary:active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#f89406;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning.active,.btn-warning.disabled,.btn-warning:active,.btn-warning:focus,.btn-warning:hover,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning.active,.btn-warning:active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#da4f49;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeaLine truncated
|
||||
.btn{display:inline-block;*display:inline;*zoom:1;padding:4px 12px;margin-bottom:0;font-size:14px;line-height:20px;text-align:center;vertical-align:middle;cursor:pointer;color:#333;text-shadow:0 1px 1px rgba(255,255,255,.75);background-color:#f5f5f5;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;*background-color:#e6e6e6;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border:1px solid #ccc;*border:0;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*margin-left:.3em;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05)}.btn.active,.btn.disabled,.btn:active,.btn:focus,.btn:hover,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn.active,.btn:active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:focus,.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:#333 dotted thin;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class*=" icon-"],.btn-large [class^=icon-]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class*=" icon-"],.btn-small [class^=icon-]{margin-top:0}.btn-mini [class*=" icon-"],.btn-mini [class^=icon-]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-left:0;padding-right:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type=submit].btn-block,input[type=reset].btn-block,input[type=button].btn-block{width:100%}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#04c;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary.active,.btn-primary.disabled,.btn-primary:active,.btn-primary:focus,.btn-primary:hover,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary.active,.btn-primary:active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#f89406;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning.active,.btn-warning.disabled,.btn-warning:active,.btn-warning:focus,.btn-warning:hover,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning.active,.btn-warning:active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#da4f49;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeaLine truncated
|
||||
@@ -159,7 +159,7 @@
|
||||
return entry;
|
||||
}
|
||||
|
||||
if (!entry.hasOwnProperty("children")) {
|
||||
if (!entry.hasOwnProperty("children") || !entry.children) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
|
||||
}
|
||||
self._printerErrorCancelNotification = new PNotify({
|
||||
title: gettext("Error reported by printer"),
|
||||
text: _.sprintf(gettext("Your printer's firmware reported an error. Due to that the ongoing print job will be cancelled. Reported error: %(firmwareError)s"), _.escape(payload)),
|
||||
text: _.sprintf(gettext("Your printer's firmware reported an error. Due to that the ongoing print job will be cancelled. Reported error: %(firmwareError)s"), {firmwareError: _.escape(payload.firmwareError)}),
|
||||
type: "error",
|
||||
hide: false
|
||||
});
|
||||
@@ -274,24 +274,24 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
|
||||
switch (payload.reason) {
|
||||
case "firmware": {
|
||||
title = gettext("Error reported by printer");
|
||||
text = _.sprintf(gettext("Your printer's firmware reported an error. Due to that OctoPrint will disconnect. Reported error: %(error)s"), _.escape(payload));
|
||||
text = _.sprintf(gettext("Your printer's firmware reported an error. Due to that OctoPrint will disconnect. Reported error: %(error)s"), {error: _.escape(payload.error)});
|
||||
break;
|
||||
}
|
||||
case "resend":
|
||||
case "resend_loop":
|
||||
case "timeout": {
|
||||
title = gettext("Communication error");
|
||||
text = _.sprintf(gettext("There was a communication error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s"), _.escape(payload));
|
||||
text = _.sprintf(gettext("There was a communication error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s"), {error: _.escape(payload.error)});
|
||||
break;
|
||||
}
|
||||
case "connection": {
|
||||
title = gettext("Error connecting to printer");
|
||||
text = _.sprintf(gettext("There was an error while trying to connect to your printer. Error: %(error)s"), _.escape(payload));
|
||||
text = _.sprintf(gettext("There was an error while trying to connect to your printer. Error: %(error)s"), {error: _.escape(payload.error)});
|
||||
break;
|
||||
}
|
||||
case "start_print": {
|
||||
title = gettext("Error starting a print");
|
||||
text = _.sprintf(gettext("There was an error while trying to start a print job. Error: %(error)s"), _.escape(payload));
|
||||
text = _.sprintf(gettext("There was an error while trying to start a print job. Error: %(error)s"), {error: _.escape(payload.error)});
|
||||
break;
|
||||
}
|
||||
case "autodetect_port":
|
||||
@@ -301,7 +301,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
|
||||
}
|
||||
default: {
|
||||
title = gettext("Unknown error");
|
||||
text = _.sprintf(gettext("There was an unknown error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s"), _.escape(payload));
|
||||
text = _.sprintf(gettext("There was an unknown error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s"), {error: _.escape(payload.error)});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +227,7 @@ $(function() {
|
||||
PNotify.prototype.options.stack.firstpos2 = 20;
|
||||
PNotify.prototype.options.stack.spacing1 = 20;
|
||||
PNotify.prototype.options.stack.spacing2 = 20;
|
||||
PNotify.prototype.options.stack.context = $("#page-container-main");
|
||||
PNotify.prototype.options.delay = 5000;
|
||||
PNotify.prototype.options.animate_speed = "fast";
|
||||
|
||||
|
||||
@@ -837,7 +837,7 @@ $(function() {
|
||||
return element;
|
||||
}
|
||||
|
||||
if (!element.hasOwnProperty("children")) {
|
||||
if (!element.hasOwnProperty("children") || !element.children) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ $(function() {
|
||||
self.userneeds({});
|
||||
}
|
||||
|
||||
if (data.name) {
|
||||
if (data && data.name) {
|
||||
self.username(data.name);
|
||||
self.currentUser(data);
|
||||
|
||||
|
||||
@@ -1004,6 +1004,10 @@ ul.dropdown-menu li a {
|
||||
|
||||
/** Notifications */
|
||||
|
||||
.ui-pnotify{
|
||||
position:fixed;
|
||||
}
|
||||
|
||||
.ui-pnotify .alert a {
|
||||
color: #c09853;
|
||||
}
|
||||
@@ -1543,7 +1547,6 @@ input[type="number"].input-nospin {
|
||||
// page wide login form
|
||||
#page-container-needlogin {
|
||||
background-color: #ffffff;
|
||||
z-index: 12300;
|
||||
.form-signin {
|
||||
max-width: 300px;
|
||||
padding: 19px 29px 29px;
|
||||
|
||||
@@ -39,7 +39,39 @@
|
||||
</div>
|
||||
</noscript>
|
||||
|
||||
<div class="page-container" id="page-container-main" {% if enableLoadAnimation -%}style="display: none"{%- endif %} data-bind="visible: visible">
|
||||
{% if enableLoadingAnimation %}
|
||||
<div id="page-container-loading" data-bind="visible: loading">
|
||||
<div class="wrapper">
|
||||
<div class="outer">
|
||||
<div class="inner">
|
||||
<div class="content">
|
||||
<h1 id="page-container-loading-header">{{ _('Loading OctoPrint\'s UI, please wait...') }}</h1>
|
||||
<i id="page-container-loading-spinner" class="fa fa-spinner fa-spin fa-4x"></i>
|
||||
<p id="page-container-loading-error" style="display: none"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="container" id="page-container-needlogin" style="display: none" data-bind="visible: needlogin">
|
||||
<form class="form-signin">
|
||||
<h2 class="form-signin-heading">{{ _('Please log in') }}</h2>
|
||||
|
||||
<div class="alert alert-error" style="display: none" data-bind="visible: login_error, text: login_error"></div>
|
||||
|
||||
<input type="text" data-bind="value: login_username" class="input-block-level" placeholder="{{ _('Username')|edq }}" autofocus>
|
||||
<input type="password" data-bind="value: login_password" class="input-block-level" placeholder="{{ _('Password')|edq }}">
|
||||
<span class="pull-right"><small><a href="https://faq.octoprint.org/forgotten-password" id="login-forgotpassword" target="_blank" tabindex="-1">{{ _('Forgot password?') }}</a></small></span>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="value: login_remember"> {{ _('Remember me') }}
|
||||
</label>
|
||||
<button class="btn btn-block btn-large btn-primary" type="submit" data-bind="click: login">{{ _('Log in') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="page-container" id="page-container-main" {% if enableLoadAnimation %}style="display: none"{% endif %} data-bind="visible: visible">
|
||||
<!-- ko allowBindings: false -->
|
||||
<div id="navbar" class="navbar navbar-static-top">
|
||||
<div class="navbar-inner" data-bind="css: appearanceClasses">
|
||||
@@ -176,36 +208,5 @@
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
|
||||
{% if enableLoadingAnimation %}
|
||||
<div id="page-container-loading" data-bind="visible: loading">
|
||||
<div class="wrapper">
|
||||
<div class="outer">
|
||||
<div class="inner">
|
||||
<div class="content">
|
||||
<h1 id="page-container-loading-header">{{ _('Loading OctoPrint\'s UI, please wait...') }}</h1>
|
||||
<i id="page-container-loading-spinner" class="fa fa-spinner fa-spin fa-4x"></i>
|
||||
<p id="page-container-loading-error" style="display: none"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="container" id="page-container-needlogin" style="display: none" data-bind="visible: needlogin">
|
||||
<form class="form-signin">
|
||||
<h2 class="form-signin-heading">{{ _('Please log in') }}</h2>
|
||||
|
||||
<div class="alert alert-error" style="display: none" data-bind="visible: login_error, text: login_error"></div>
|
||||
|
||||
<input type="text" data-bind="value: login_username" class="input-block-level" placeholder="{{ _('Username')|edq }}" autofocus>
|
||||
<input type="password" data-bind="value: login_password" class="input-block-level" placeholder="{{ _('Password')|edq }}">
|
||||
<span class="pull-right"><small><a href="https://faq.octoprint.org/forgotten-password" id="login-forgotpassword" target="_blank" tabindex="-1">{{ _('Forgot password?') }}</a></small></span>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="value: login_remember"> {{ _('Remember me') }}
|
||||
</label>
|
||||
<button class="btn btn-block btn-large btn-primary" type="submit" data-bind="click: login">{{ _('Log in') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -39,7 +39,7 @@
|
||||
</div>
|
||||
|
||||
{% if enableSdSupport %}
|
||||
<div class="sd-trigger accordion-heading-button btn-group" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.CONTROL) && $root.filesListVisible()">
|
||||
<div class="sd-trigger accordion-heading-button btn-group" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.CONTROL)() && $root.filesListVisible()">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" title="{{ _('SD Card operations')|edq }}">
|
||||
<span class="icon-sd-black-14"></span>
|
||||
</a>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-bind="visible: keycontrolPossible && loginState.hasPermissionKo(access.permissions.WEBCAM) && loginState.hasPermissionKo(access.permissions.CONTROL)">
|
||||
<div data-bind="visible: keycontrolPossible() && loginState.hasPermissionKo(access.permissions.WEBCAM)() && loginState.hasPermissionKo(access.permissions.CONTROL)()">
|
||||
<small class="muted">{{ _("Hint: If you move your mouse over the picture, you enter keyboard control mode.") }}</small>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -85,7 +85,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- Extrusion control panel -->
|
||||
<div id="control-jog-extrusion" class="jog-panel" style="display: none;" data-bind="visible: loginState.hasPermissionKo(access.permissions.CONTROL) && tools().length > 0">
|
||||
<div id="control-jog-extrusion" class="jog-panel" style="display: none;" data-bind="visible: loginState.hasPermissionKo(access.permissions.CONTROL)() && tools().length > 0">
|
||||
<h1>Tool (E)</h1>
|
||||
<div>
|
||||
<div class="btn-group control-box">
|
||||
|
||||
@@ -465,7 +465,7 @@ class Timelapse(object):
|
||||
"""
|
||||
Override this to perform additional actions upon start of a print job.
|
||||
"""
|
||||
self.start_timelapse(payload["file"])
|
||||
self.start_timelapse(payload["name"])
|
||||
|
||||
def on_print_done(self, event, payload):
|
||||
"""
|
||||
@@ -478,7 +478,7 @@ class Timelapse(object):
|
||||
Override this to perform additional actions upon the pausing of a print job.
|
||||
"""
|
||||
if not self._in_timelapse:
|
||||
self.start_timelapse(payload["file"])
|
||||
self.start_timelapse(payload["name"])
|
||||
|
||||
def event_subscriptions(self):
|
||||
"""
|
||||
@@ -502,14 +502,14 @@ class Timelapse(object):
|
||||
"""
|
||||
return None
|
||||
|
||||
def start_timelapse(self, gcodeFile):
|
||||
self._logger.debug("Starting timelapse for %s" % gcodeFile)
|
||||
def start_timelapse(self, gcode_file):
|
||||
self._logger.debug("Starting timelapse for %s" % gcode_file)
|
||||
|
||||
self._image_number = 0
|
||||
self._capture_errors = 0
|
||||
self._capture_success = 0
|
||||
self._in_timelapse = True
|
||||
self._gcode_file = os.path.basename(gcodeFile)
|
||||
self._gcode_file = os.path.basename(gcode_file)
|
||||
self._file_prefix = "{}_{}".format(os.path.splitext(self._gcode_file)[0], time.strftime("%Y%m%d%H%M%S"))
|
||||
|
||||
def stop_timelapse(self, do_create_movie=True, success=True):
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large.
Load diff
@@ -33,6 +33,7 @@ try:
|
||||
except ImportError:
|
||||
import Queue as queue
|
||||
|
||||
# noinspection PyCompatibility
|
||||
from past.builtins import basestring, unicode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -131,8 +132,6 @@ def pp(value):
|
||||
def warning_decorator_factory(warning_type):
|
||||
def specific_warning(message, stacklevel=1, since=None, includedoc=None, extenddoc=False):
|
||||
def decorator(func):
|
||||
func.__qualname__ = to_native_str('warning_decorator_factory')
|
||||
func.__annotations__ = dict()
|
||||
@wraps(func)
|
||||
def func_wrapper(*args, **kwargs):
|
||||
# we need to increment the stacklevel by one because otherwise we'll get the location of our
|
||||
@@ -1836,3 +1835,11 @@ def timing(f):
|
||||
logging.getLogger("octoprint.util.timing").debug("func:{} took {:0.2f}s".format(f.__name__,
|
||||
end - start))
|
||||
return decorator
|
||||
|
||||
|
||||
def generate_api_key():
|
||||
# noinspection PyCompatibility
|
||||
from builtins import bytes
|
||||
import uuid
|
||||
|
||||
return ''.join('%02X' % z for z in bytes(uuid.uuid4().bytes))
|
||||
@@ -31,7 +31,7 @@ class IspBase():
|
||||
def chipErase(self):
|
||||
self.sendISP([0xAC, 0x80, 0x00, 0x00])
|
||||
|
||||
class IspError():
|
||||
class IspError(Exception):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
def __str__(self):
|
||||
|
||||
@@ -98,8 +98,8 @@ class Stk500v2(ispBase.IspBase):
|
||||
for c in data:
|
||||
message += struct.pack(">B", c)
|
||||
checksum = 0
|
||||
for c in message:
|
||||
checksum ^= ord(c)
|
||||
for c in bytearray(message):
|
||||
checksum ^= c
|
||||
message += struct.pack(">B", checksum)
|
||||
try:
|
||||
self.serial.write(message)
|
||||
|
||||
@@ -11,7 +11,8 @@ import logging
|
||||
import re
|
||||
import time
|
||||
|
||||
from . import to_unicode
|
||||
from . import to_unicode, to_bytes
|
||||
from .platform import get_os
|
||||
|
||||
from past.builtins import unicode
|
||||
|
||||
@@ -164,6 +165,10 @@ class CommandlineCaller(object):
|
||||
self._logger.debug("Calling: {}".format(joined_command))
|
||||
self.on_log_call(joined_command)
|
||||
|
||||
# if we are running under windows, make sure there are no unicode strings in the env
|
||||
if get_os() == "windows" and "env" in kwargs:
|
||||
kwargs["env"] = dict((k, to_bytes(v)) for k, v in kwargs["env"].items())
|
||||
|
||||
kwargs.update(dict(async_=True, stdout=sarge.Capture(), stderr=sarge.Capture()))
|
||||
|
||||
p = sarge.run(command, **kwargs)
|
||||
|
||||
+486
@@ -0,0 +1,486 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
flask_principal
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Identity management for Flask.
|
||||
|
||||
:copyright: (c) 2012 by Ali Afshar.
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
__version__ = '0.4.0'
|
||||
|
||||
import sys
|
||||
|
||||
from functools import partial, wraps
|
||||
from collections import deque
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from flask import g, session, current_app, abort, request
|
||||
from flask.signals import Namespace
|
||||
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
signals = Namespace()
|
||||
|
||||
|
||||
identity_changed = signals.signal('identity-changed', doc="""
|
||||
Signal sent when the identity for a request has been changed.
|
||||
|
||||
Actual name: ``identity-changed``
|
||||
|
||||
Authentication providers should send this signal when authentication has been
|
||||
successfully performed. Flask-Principal connects to this signal and
|
||||
causes the identity to be saved in the session.
|
||||
|
||||
For example::
|
||||
|
||||
from flaskext.principal import Identity, identity_changed
|
||||
|
||||
def login_view(req):
|
||||
username = req.form.get('username')
|
||||
# check the credentials
|
||||
identity_changed.send(app, identity=Identity(username))
|
||||
""")
|
||||
|
||||
|
||||
identity_loaded = signals.signal('identity-loaded', doc="""
|
||||
Signal sent when the identity has been initialised for a request.
|
||||
|
||||
Actual name: ``identity-loaded``
|
||||
|
||||
Identity information providers should connect to this signal to perform two
|
||||
major activities:
|
||||
|
||||
1. Populate the identity object with the necessary authorization provisions.
|
||||
2. Load any additional user information.
|
||||
|
||||
For example::
|
||||
|
||||
from flaskext.principal import identity_loaded, RoleNeed, UserNeed
|
||||
|
||||
@identity_loaded.connect
|
||||
def on_identity_loaded(sender, identity):
|
||||
# Get the user information from the db
|
||||
user = db.get(identity.name)
|
||||
# Update the roles that a user can provide
|
||||
for role in user.roles:
|
||||
identity.provides.add(RoleNeed(role.name))
|
||||
# Save the user somewhere so we only look it up once
|
||||
identity.user = user
|
||||
""")
|
||||
|
||||
|
||||
Need = namedtuple('Need', ['method', 'value'])
|
||||
"""A required need
|
||||
|
||||
This is just a named tuple, and practically any tuple will do.
|
||||
|
||||
The ``method`` attribute can be used to look up element 0, and the ``value``
|
||||
attribute can be used to look up element 1.
|
||||
"""
|
||||
|
||||
|
||||
UserNeed = partial(Need, 'id')
|
||||
UserNeed.__doc__ = """A need with the method preset to `"id"`."""
|
||||
|
||||
|
||||
RoleNeed = partial(Need, 'role')
|
||||
RoleNeed.__doc__ = """A need with the method preset to `"role"`."""
|
||||
|
||||
|
||||
TypeNeed = partial(Need, 'type')
|
||||
TypeNeed.__doc__ = """A need with the method preset to `"type"`."""
|
||||
|
||||
|
||||
ActionNeed = partial(Need, 'action')
|
||||
TypeNeed.__doc__ = """A need with the method preset to `"action"`."""
|
||||
|
||||
|
||||
ItemNeed = namedtuple('ItemNeed', ['method', 'value', 'type'])
|
||||
"""A required item need
|
||||
|
||||
An item need is just a named tuple, and practically any tuple will do. In
|
||||
addition to other Needs, there is a type, for example this could be specified
|
||||
as::
|
||||
|
||||
ItemNeed('update', 27, 'posts')
|
||||
('update', 27, 'posts') # or like this
|
||||
|
||||
And that might describe the permission to update a particular blog post. In
|
||||
reality, the developer is free to choose whatever convention the permissions
|
||||
are.
|
||||
"""
|
||||
|
||||
|
||||
class PermissionDenied(RuntimeError):
|
||||
"""Permission denied to the resource"""
|
||||
|
||||
|
||||
class Identity(object):
|
||||
"""Represent the user's identity.
|
||||
|
||||
:param id: The user id
|
||||
:param auth_type: The authentication type used to confirm the user's
|
||||
identity.
|
||||
|
||||
The identity is used to represent the user's identity in the system. This
|
||||
object is created on login, or on the start of the request as loaded from
|
||||
the user's session.
|
||||
|
||||
Once loaded it is sent using the `identity-loaded` signal, and should be
|
||||
populated with additional required information.
|
||||
|
||||
Needs that are provided by this identity should be added to the `provides`
|
||||
set after loading.
|
||||
"""
|
||||
def __init__(self, id, auth_type=None):
|
||||
self.id = id
|
||||
self.auth_type = auth_type
|
||||
self.provides = set()
|
||||
|
||||
def can(self, permission):
|
||||
"""Whether the identity has access to the permission.
|
||||
|
||||
:param permission: The permission to test provision for.
|
||||
"""
|
||||
return permission.allows(self)
|
||||
|
||||
def __repr__(self):
|
||||
return '<{0} id="{1}" auth_type="{2}" provides={3}>'.format(
|
||||
self.__class__.__name__, self.id, self.auth_type, self.provides
|
||||
)
|
||||
|
||||
|
||||
class AnonymousIdentity(Identity):
|
||||
"""An anonymous identity"""
|
||||
|
||||
def __init__(self):
|
||||
Identity.__init__(self, None)
|
||||
|
||||
|
||||
class IdentityContext(object):
|
||||
"""The context of an identity for a permission.
|
||||
|
||||
.. note:: The principal is usually created by the flaskext.Permission.require method
|
||||
call for normal use-cases.
|
||||
|
||||
The principal behaves as either a context manager or a decorator. The
|
||||
permission is checked for provision in the identity, and if available the
|
||||
flow is continued (context manager) or the function is executed (decorator).
|
||||
"""
|
||||
|
||||
def __init__(self, permission, http_exception=None):
|
||||
self.permission = permission
|
||||
self.http_exception = http_exception
|
||||
"""The permission of this principal
|
||||
"""
|
||||
|
||||
@property
|
||||
def identity(self):
|
||||
"""The identity of this principal
|
||||
"""
|
||||
return g.identity
|
||||
|
||||
def can(self):
|
||||
"""Whether the identity has access to the permission
|
||||
"""
|
||||
return self.identity.can(self.permission)
|
||||
|
||||
def __call__(self, f):
|
||||
@wraps(f)
|
||||
def _decorated(*args, **kw):
|
||||
with self:
|
||||
rv = f(*args, **kw)
|
||||
return rv
|
||||
return _decorated
|
||||
|
||||
def __enter__(self):
|
||||
# check the permission here
|
||||
if not self.can():
|
||||
if self.http_exception:
|
||||
abort(self.http_exception)
|
||||
raise PermissionDenied(self.permission)
|
||||
|
||||
def __exit__(self, *args):
|
||||
return False
|
||||
|
||||
|
||||
class Permission(object):
|
||||
"""Represents needs, any of which must be present to access a resource
|
||||
|
||||
:param needs: The needs for this permission
|
||||
"""
|
||||
def __init__(self, *needs):
|
||||
"""A set of needs, any of which must be present in an identity to have
|
||||
access.
|
||||
"""
|
||||
|
||||
self.needs = set(needs)
|
||||
self.excludes = set()
|
||||
|
||||
def _bool(self):
|
||||
return bool(self.can())
|
||||
|
||||
def __nonzero__(self):
|
||||
"""Equivalent to ``self.can()``.
|
||||
"""
|
||||
return self._bool()
|
||||
|
||||
def __bool__(self):
|
||||
"""Equivalent to ``self.can()``.
|
||||
"""
|
||||
return self._bool()
|
||||
|
||||
def __and__(self, other):
|
||||
"""Does the same thing as ``self.union(other)``
|
||||
"""
|
||||
return self.union(other)
|
||||
|
||||
def __or__(self, other):
|
||||
"""Does the same thing as ``self.difference(other)``
|
||||
"""
|
||||
return self.difference(other)
|
||||
|
||||
def __contains__(self, other):
|
||||
"""Does the same thing as ``other.issubset(self)``.
|
||||
"""
|
||||
return other.issubset(self)
|
||||
|
||||
def __repr__(self):
|
||||
return '<{0} needs={1} excludes={2}>'.format(
|
||||
self.__class__.__name__, self.needs, self.excludes
|
||||
)
|
||||
|
||||
def require(self, http_exception=None):
|
||||
"""Create a principal for this permission.
|
||||
|
||||
The principal may be used as a context manager, or a decroator.
|
||||
|
||||
If ``http_exception`` is passed then ``abort()`` will be called
|
||||
with the HTTP exception code. Otherwise a ``PermissionDenied``
|
||||
exception will be raised if the identity does not meet the
|
||||
requirements.
|
||||
|
||||
:param http_exception: the HTTP exception code (403, 401 etc)
|
||||
"""
|
||||
return IdentityContext(self, http_exception)
|
||||
|
||||
def test(self, http_exception=None):
|
||||
"""
|
||||
Checks if permission available and raises relevant exception
|
||||
if not. This is useful if you just want to check permission
|
||||
without wrapping everything in a require() block.
|
||||
|
||||
This is equivalent to::
|
||||
|
||||
with permission.require():
|
||||
pass
|
||||
"""
|
||||
|
||||
with self.require(http_exception):
|
||||
pass
|
||||
|
||||
def reverse(self):
|
||||
"""
|
||||
Returns reverse of current state (needs->excludes, excludes->needs)
|
||||
"""
|
||||
|
||||
p = Permission()
|
||||
p.needs.update(self.excludes)
|
||||
p.excludes.update(self.needs)
|
||||
return p
|
||||
|
||||
def union(self, other):
|
||||
"""Create a new permission with the requirements of the union of this
|
||||
and other.
|
||||
|
||||
:param other: The other permission
|
||||
"""
|
||||
p = Permission(*self.needs.union(other.needs))
|
||||
p.excludes.update(self.excludes.union(other.excludes))
|
||||
return p
|
||||
|
||||
def difference(self, other):
|
||||
"""Create a new permission consisting of requirements in this
|
||||
permission and not in the other.
|
||||
"""
|
||||
|
||||
p = Permission(*self.needs.difference(other.needs))
|
||||
p.excludes.update(self.excludes.difference(other.excludes))
|
||||
return p
|
||||
|
||||
def issubset(self, other):
|
||||
"""Whether this permission needs are a subset of another
|
||||
|
||||
:param other: The other permission
|
||||
"""
|
||||
return (
|
||||
self.needs.issubset(other.needs) and
|
||||
self.excludes.issubset(other.excludes)
|
||||
)
|
||||
|
||||
def allows(self, identity):
|
||||
"""Whether the identity can access this permission.
|
||||
|
||||
:param identity: The identity
|
||||
"""
|
||||
if self.needs and not self.needs.intersection(identity.provides):
|
||||
return False
|
||||
|
||||
if self.excludes and self.excludes.intersection(identity.provides):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def can(self):
|
||||
"""Whether the required context for this permission has access
|
||||
|
||||
This creates an identity context and tests whether it can access this
|
||||
permission
|
||||
"""
|
||||
return self.require().can()
|
||||
|
||||
|
||||
class Denial(Permission):
|
||||
"""
|
||||
Shortcut class for passing excluded needs.
|
||||
"""
|
||||
|
||||
def __init__(self, *excludes):
|
||||
self.excludes = set(excludes)
|
||||
self.needs = set()
|
||||
|
||||
|
||||
def session_identity_loader():
|
||||
if 'identity.id' in session and 'identity.auth_type' in session:
|
||||
identity = Identity(session['identity.id'],
|
||||
session['identity.auth_type'])
|
||||
return identity
|
||||
|
||||
|
||||
def session_identity_saver(identity):
|
||||
session['identity.id'] = identity.id
|
||||
session['identity.auth_type'] = identity.auth_type
|
||||
session.modified = True
|
||||
|
||||
|
||||
class Principal(object):
|
||||
"""Principal extension
|
||||
|
||||
:param app: The flask application to extend
|
||||
:param use_sessions: Whether to use sessions to extract and store
|
||||
identification.
|
||||
:param skip_static: Whether to ignore static endpoints.
|
||||
"""
|
||||
def __init__(self, app=None, use_sessions=True, skip_static=False):
|
||||
self.identity_loaders = deque()
|
||||
self.identity_savers = deque()
|
||||
# XXX This will probably vanish for a better API
|
||||
self.use_sessions = use_sessions
|
||||
self.skip_static = skip_static
|
||||
|
||||
if app is not None:
|
||||
self.init_app(app)
|
||||
|
||||
def _init_app(self, app):
|
||||
from warnings import warn
|
||||
warn(DeprecationWarning(
|
||||
'_init_app is deprecated, use the new init_app '
|
||||
'method instead.'), stacklevel=1
|
||||
)
|
||||
self.init_app(app)
|
||||
|
||||
def init_app(self, app):
|
||||
if hasattr(app, 'static_url_path'):
|
||||
self._static_path = app.static_url_path
|
||||
else:
|
||||
self._static_path = app.static_path
|
||||
|
||||
app.before_request(self._on_before_request)
|
||||
identity_changed.connect(self._on_identity_changed, app)
|
||||
|
||||
if self.use_sessions:
|
||||
self.identity_loader(session_identity_loader)
|
||||
self.identity_saver(session_identity_saver)
|
||||
|
||||
def set_identity(self, identity):
|
||||
"""Set the current identity.
|
||||
|
||||
:param identity: The identity to set
|
||||
"""
|
||||
|
||||
self._set_thread_identity(identity)
|
||||
for saver in self.identity_savers:
|
||||
saver(identity)
|
||||
|
||||
def identity_loader(self, f):
|
||||
"""Decorator to define a function as an identity loader.
|
||||
|
||||
An identity loader function is called before request to find any
|
||||
provided identities. The first found identity is used to load from.
|
||||
|
||||
For example::
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
principals = Principal(app)
|
||||
|
||||
@principals.identity_loader
|
||||
def load_identity_from_weird_usecase():
|
||||
return Identity('ali')
|
||||
"""
|
||||
self.identity_loaders.appendleft(f)
|
||||
return f
|
||||
|
||||
def identity_saver(self, f):
|
||||
"""Decorator to define a function as an identity saver.
|
||||
|
||||
An identity loader saver is called when the identity is set to persist
|
||||
it for the next request.
|
||||
|
||||
For example::
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
principals = Principal(app)
|
||||
|
||||
@principals.identity_saver
|
||||
def save_identity_to_weird_usecase(identity):
|
||||
my_special_cookie['identity'] = identity
|
||||
"""
|
||||
self.identity_savers.appendleft(f)
|
||||
return f
|
||||
|
||||
def _set_thread_identity(self, identity):
|
||||
g.identity = identity
|
||||
identity_loaded.send(current_app._get_current_object(),
|
||||
identity=identity)
|
||||
|
||||
def _on_identity_changed(self, app, identity):
|
||||
if self._is_static_route():
|
||||
return
|
||||
|
||||
self.set_identity(identity)
|
||||
|
||||
def _on_before_request(self):
|
||||
if self._is_static_route():
|
||||
return
|
||||
|
||||
g.identity = AnonymousIdentity()
|
||||
for loader in self.identity_loaders:
|
||||
identity = loader()
|
||||
if identity is not None:
|
||||
self.set_identity(identity)
|
||||
return
|
||||
|
||||
def _is_static_route(self):
|
||||
return (
|
||||
self.skip_static and
|
||||
request.path.startswith(self._static_path)
|
||||
)
|
||||
@@ -105,7 +105,11 @@ class SettingsTestCase(unittest.TestCase):
|
||||
def test_deprecated_forwarded_getter(self, deprecated, current, forwarded):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
called_method = getattr(self.settings, forwarded)
|
||||
|
||||
# further mock out our mocked function so things work as they should
|
||||
called_method.__name__ = to_native_str(forwarded)
|
||||
called_method.__qualname__ = to_native_str(forwarded)
|
||||
called_method.__annotations__ = dict()
|
||||
|
||||
method = getattr(self.plugin_settings, deprecated)
|
||||
self.assertTrue(callable(method))
|
||||
@@ -169,7 +173,11 @@ class SettingsTestCase(unittest.TestCase):
|
||||
def test_deprecated_forwarded_setter(self, deprecated, current, forwarded, value):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
called_method = getattr(self.settings, forwarded)
|
||||
|
||||
# further mock out our mocked function so things work as they should
|
||||
called_method.__name__ = to_native_str(forwarded)
|
||||
called_method.__qualname__ = to_native_str(forwarded)
|
||||
called_method.__annotations__ = dict()
|
||||
|
||||
method = getattr(self.plugin_settings, deprecated)
|
||||
self.assertTrue(callable(method))
|
||||
|
||||
Binary file not shown.
+2404
-810
File diff suppressed because it is too large.
Load diff
+33
-33
@@ -6,9 +6,9 @@
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: OctoPrint 1.4.0.dev2469+g454c5e494\n"
|
||||
"Project-Id-Version: OctoPrint 1.4.0rc3.dev24+g94ae90ab8\n"
|
||||
"Report-Msgid-Bugs-To: i18n@octoprint.org\n"
|
||||
"POT-Creation-Date: 2019-11-22 18:38+0100\n"
|
||||
"POT-Creation-Date: 2019-12-12 12:47+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -303,16 +303,16 @@ msgstr ""
|
||||
msgid "Refresh Announcements"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/plugins/appkeys/__init__.py:123
|
||||
#: src/octoprint/plugins/appkeys/__init__.py:122
|
||||
msgid "Allows administrating all application keys"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/plugins/appkeys/__init__.py:131
|
||||
#: src/octoprint/plugins/appkeys/__init__.py:132
|
||||
#: src/octoprint/plugins/appkeys/__init__.py:133
|
||||
msgid "Application Keys"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/plugins/appkeys/__init__.py:439
|
||||
#: src/octoprint/plugins/appkeys/__init__.py:438
|
||||
msgid ""
|
||||
"Without this plugin third party clients will no longer be able to obtain "
|
||||
"an API key without you manually copy-pasting it."
|
||||
@@ -726,13 +726,13 @@ msgid "Server Commands"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/plugins/corewizard/subwizards.py:50
|
||||
#: src/octoprint/server/views.py:603
|
||||
#: src/octoprint/server/views.py:615
|
||||
msgid "Webcam & Timelapse"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/plugins/corewizard/subwizards.py:65
|
||||
#: src/octoprint/plugins/corewizard/templates/corewizard_acl_wizard.jinja2:1
|
||||
#: src/octoprint/server/views.py:609
|
||||
#: src/octoprint/server/views.py:621
|
||||
msgid "Access Control"
|
||||
msgstr ""
|
||||
|
||||
@@ -1781,7 +1781,7 @@ msgid ""
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2:39
|
||||
#: src/octoprint/server/views.py:515
|
||||
#: src/octoprint/server/views.py:527
|
||||
msgid "Plugins"
|
||||
msgstr ""
|
||||
|
||||
@@ -2157,7 +2157,7 @@ msgid "Software Update"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/plugins/softwareupdate/__init__.py:1134
|
||||
#: src/octoprint/server/views.py:607
|
||||
#: src/octoprint/server/views.py:619
|
||||
#: src/octoprint/static/js/app/viewmodels/appearance.js:99
|
||||
#: src/octoprint/static/js/app/viewmodels/appearance.js:104
|
||||
#: src/octoprint/static/js/app/viewmodels/appearance.js:106
|
||||
@@ -2790,105 +2790,105 @@ msgid ""
|
||||
"tracking.octoprint.org</a>.\n"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:574
|
||||
#: src/octoprint/server/views.py:586
|
||||
#: src/octoprint/templates/dialogs/settings/serialconnection.jinja2:12
|
||||
msgid "Connection"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:575
|
||||
#: src/octoprint/server/views.py:587
|
||||
#: src/octoprint/templates/sidebar/state.jinja2:1
|
||||
msgid "State"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:576
|
||||
#: src/octoprint/server/views.py:588
|
||||
msgid "Files"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:582
|
||||
#: src/octoprint/server/views.py:594
|
||||
msgid "Temperature"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:583
|
||||
#: src/octoprint/server/views.py:595
|
||||
msgid "Control"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:584
|
||||
#: src/octoprint/server/views.py:596
|
||||
msgid "GCode Viewer"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:585
|
||||
#: src/octoprint/server/views.py:597
|
||||
msgid "Terminal"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:586
|
||||
#: src/octoprint/server/views.py:598
|
||||
#: src/octoprint/templates/sidebar/state.jinja2:9
|
||||
msgid "Timelapse"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:592
|
||||
#: src/octoprint/server/views.py:604
|
||||
msgid "Printer"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:594
|
||||
#: src/octoprint/server/views.py:606
|
||||
msgid "Serial Connection"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:595
|
||||
#: src/octoprint/server/views.py:607
|
||||
#: src/octoprint/templates/dialogs/settings/printerprofiles.jinja2:1
|
||||
msgid "Printer Profiles"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:596
|
||||
#: src/octoprint/server/views.py:608
|
||||
msgid "Temperatures"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:597
|
||||
#: src/octoprint/server/views.py:609
|
||||
msgid "Terminal Filters"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:598
|
||||
#: src/octoprint/server/views.py:610
|
||||
msgid "GCODE Scripts"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:600 src/octoprint/server/views.py:602
|
||||
#: src/octoprint/server/views.py:612 src/octoprint/server/views.py:614
|
||||
msgid "Features"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:604
|
||||
#: src/octoprint/server/views.py:616
|
||||
msgid "GCODE Visualizer"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:605
|
||||
#: src/octoprint/server/views.py:617
|
||||
msgid "API"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:610
|
||||
#: src/octoprint/server/views.py:622
|
||||
#: src/octoprint/templates/dialogs/settings/folders.jinja2:2
|
||||
#: src/octoprint/templates/sidebar/files_header.jinja2:12
|
||||
msgid "Folders"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:611
|
||||
#: src/octoprint/server/views.py:623
|
||||
msgid "Appearance"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:612
|
||||
#: src/octoprint/server/views.py:624
|
||||
msgid "Server"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:618
|
||||
#: src/octoprint/server/views.py:630
|
||||
msgid "Access"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:619
|
||||
#: src/octoprint/server/views.py:631
|
||||
msgid "Interface"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:635
|
||||
#: src/octoprint/server/views.py:647
|
||||
msgid "Start"
|
||||
msgstr ""
|
||||
|
||||
#: src/octoprint/server/views.py:636
|
||||
#: src/octoprint/server/views.py:648
|
||||
#: src/octoprint/templates/dialogs/wizard.jinja2:57
|
||||
msgid "Finish"
|
||||
msgstr ""
|
||||
|
||||
Reference in new issue
Block a user