Пример #1
0
	def on_open(self, info):
		self._pluginManager.register_message_receiver(self.on_plugin_message)
		self._remoteAddress = self._get_remote_address(info)
		self._logger.info("New connection from client: %s" % self._remoteAddress)

		self._userManager.register_login_status_listener(self)
		self._groupManager.register_listener(self)

		plugin_signature = lambda impl: "{}:{}".format(impl._identifier, impl._plugin_version)
		template_plugins = list(map(plugin_signature, self._pluginManager.get_implementations(octoprint.plugin.TemplatePlugin)))
		asset_plugins = list(map(plugin_signature, self._pluginManager.get_implementations(octoprint.plugin.AssetPlugin)))
		ui_plugins = sorted(set(template_plugins + asset_plugins))

		import hashlib
		plugin_hash = hashlib.md5()
		plugin_hash.update(",".join(ui_plugins).encode('utf-8'))

		config_hash = settings().config_hash

		# connected => update the API key, might be necessary if the client was left open while the server restarted
		self._emit("connected", dict(apikey=octoprint.server.UI_API_KEY,
		                             version=octoprint.server.VERSION,
		                             display_version=octoprint.server.DISPLAY_VERSION,
		                             branch=octoprint.server.BRANCH,
		                             plugin_hash=plugin_hash.hexdigest(),
		                             config_hash=config_hash,
		                             debug=octoprint.server.debug,
		                             safe_mode=octoprint.server.safe_mode,
		                             permissions=[permission.as_dict() for permission in Permissions.all()]))

		self._eventManager.fire(Events.CLIENT_OPENED, {"remoteAddress": self._remoteAddress})
		self._register()
Пример #2
0
    def _save(self, force=False):
        if self._groupfile is None or not self._dirty and not force:
            return

        groups = dict()
        for key in self._groups.keys():
            group = self._groups[key]
            groups[key] = dict(
                name=group._name,
                description=group._description,
                permissions=self._from_permissions(*group._permissions),
                subgroups=self._from_groups(*group._subgroups),
                default=group._default)

        data = dict(groups=groups, tracked=[x.key for x in Permissions.all()])

        with atomic_write(self._groupfile,
                          mode='wt',
                          permissions=0o600,
                          max_permissions=0o666) as f:
            import yaml
            yaml.safe_dump(data,
                           f,
                           default_flow_style=False,
                           indent=4,
                           allow_unicode=True)
            self._dirty = False
        self._load()
Пример #3
0
    def _save(self, force=False):
        if self._groupfile is None or not self._dirty and not force:
            return

        groups = {}
        for key in self._groups.keys():
            group = self._groups[key]
            groups[key] = {
                "permissions": self._from_permissions(*group._permissions),
                "subgroups": self._from_groups(*group._subgroups),
                "default": group._default,
            }
            if key not in self._default_groups:
                groups[key]["name"] = group.get_name()
                groups[key]["description"] = group.get_description()

        data = {
            "_version": self.FILE_VERSION,
            "groups": groups,
            "tracked": [x.key for x in Permissions.all()],
        }

        with atomic_write(self._groupfile,
                          mode="wt",
                          permissions=0o600,
                          max_permissions=0o666) as f:
            yaml.save_to_file(data, file=f, pretty=True)
            self._dirty = False
        self._load()
Пример #4
0
    def permissions(self):
        if self._permissions is None:
            return []

        if Permissions.ADMIN in self._permissions:
            return Permissions.all()

        return list(filter(lambda p: p is not None, self._permissions))
Пример #5
0
    def _save(self, force=False):
        if self._groupfile is None or not self._dirty and not force:
            return

        groups = dict()
        for key, group in self._groups.items():
            if not group or not isinstance(group, Group):
                self.logger.debug('Not saving %s' % key)
                continue

            if isinstance(group, LDAPGroup):
                self.logger.debug("Saving group %s as %s" %
                                  (group.get_name(), LDAPGroup.__name__))
                groups[key] = dict(
                    type=LDAPGroup.GROUP_TYPE,
                    dn=group.distinguished_name,
                    name=group.get_name(),
                    description=group.get_description(),
                    permissions=self._from_permissions(*group.permissions),
                    subgroups=self._from_groups(*group.subgroups),
                    default=group.is_default())
            else:
                self.logger.debug("Saving group %s as %s" %
                                  (group.get_name(), Group.__name__))
                groups[key] = dict(
                    name=group._name,
                    description=group._description,
                    permissions=self._from_permissions(*group._permissions),
                    subgroups=self._from_groups(*group._subgroups),
                    default=group._default)

        data = dict(groups=groups, tracked=[x.key for x in Permissions.all()])

        with atomic_write(self._groupfile,
                          mode='wt',
                          permissions=0o600,
                          max_permissions=0o666) as f:
            import yaml
            yaml.safe_dump(data,
                           f,
                           default_flow_style=False,
                           indent=4,
                           allow_unicode=True)
            self._dirty = False
        self._load()
Пример #6
0
 def effective_permissions(self):
     if self._permissions is None:
         return []
     return list(
         filter(lambda p: p is not None and self.has_permission(p),
                Permissions.all()))
Пример #7
0
 def default_permissions_for_group(cls, group):
     result = []
     for permission in Permissions.all():
         if group in permission.default_groups:
             result.append(permission)
     return result
Пример #8
0
def get_permissions():
    return jsonify(
        permissions=[permission.as_dict() for permission in Permissions.all()])