Example #1
0
def load_plugins():
    global loaded_with_language, dashboards, builtin_dashboards_transformed
    if loaded_with_language == current_language:
        return

    # Load plugins for dashboards. Currently these files
    # just may add custom dashboards by adding to builtin_dashboards.
    load_web_plugins("dashboard", globals())
    builtin_dashboards_transformed = False

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language

    # Clear this structure to prevent users accessing dashboard structures created
    # by other users, make them see these dashboards
    dashboards = {}

    # Declare permissions for all dashboards
    config.declare_permission_section("dashboard", _("Dashboards"), do_sort = True)
    for name, board in builtin_dashboards.items():
        config.declare_permission("dashboard.%s" % name,
                board["title"],
                board.get("description", ""),
                config.builtin_role_ids)

    # Make sure that custom views also have permissions
    config.declare_dynamic_permissions(lambda: visuals.declare_custom_permissions('dashboards'))
Example #2
0
def load_plugins():
    global loaded_with_language, dashboards, builtin_dashboards_transformed
    if loaded_with_language == current_language:
        return

    # Load plugins for dashboards. Currently these files
    # just may add custom dashboards by adding to builtin_dashboards.
    load_web_plugins("dashboard", globals())
    builtin_dashboards_transformed = False

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language

    # Clear this structure to prevent users accessing dashboard structures created
    # by other users, make them see these dashboards
    dashboards = {}

    # Declare permissions for all dashboards
    config.declare_permission_section("dashboard", _("Dashboards"), do_sort=True)
    for name, board in builtin_dashboards.items():
        config.declare_permission(
            "dashboard.%s" % name, board["title"], board.get("description", ""), config.builtin_role_ids
        )

    # Make sure that custom views also have permissions
    config.declare_dynamic_permissions(lambda: visuals.declare_custom_permissions("dashboards"))
Example #3
0
def load_plugins():
    global loaded_with_language
    if loaded_with_language == current_language:
        return

    # Load plugins for dashboards. Currently these files
    # just may add custom dashboards by adding to builtin_dashboards.
    load_web_plugins("dashboard", globals())

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language

    # In future there will be user editable dashboards just like
    # views which will be loaded. Currently we only use the builtin
    # dashboads.
    global dashboards
    dashboards = builtin_dashboards

    # Declare permissions for all dashboards
    config.declare_permission_section("dashboard", _("Dashboards"))
    for name, dashboard in dashboards.items():
        config.declare_permission("dashboard.%s" % name,
                dashboard["title"],
                dashboard.get("description", ''),
                config.builtin_role_ids)
Example #4
0
def load_plugins(force):
    global loaded_with_language
    if loaded_with_language == current_language and not force:
        return

    config.declare_permission_section("notification_plugin",
                                      _("Notification plugins"),
                                      do_sort=True)

    for name, attrs in wato.load_notification_scripts().items():
        config.declare_permission("notification_plugin.%s" % name,
                                  _u(attrs["title"]), u"", ["admin", "user"])

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language
Example #5
0
def load_plugins():
    global loaded_with_language
    if loaded_with_language == current_language:
        return

    # Load all snapins
    global sidebar_snapins
    sidebar_snapins = {}
    load_web_plugins("sidebar", globals())

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language

    # Declare permissions: each snapin creates one permission
    config.declare_permission_section("sidesnap", _("Sidebar snapins"))
    for name, snapin in sidebar_snapins.items():
        config.declare_permission("sidesnap.%s" % name, snapin["title"],
                                  snapin["description"], snapin["allowed"])
Example #6
0
def load_plugins():
    global loaded_with_language
    if loaded_with_language == current_language:
        return

    load_web_plugins("webapi", globals())

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language

    config.declare_permission("webapi.api_allowed", _("API accessible"),
                                                    _("This permissions specifies if the role "\
                                                      "is able to use web API functions at all"),
                              config.builtin_role_ids)

    # Declare permissions for all api actions
    config.declare_permission_section("webapi", _("Web API"), do_sort = True)
    for name, settings in api_actions.items():
        full_description  = "%s<br>API function <tt>{site}/check_mk/webapi.py?action=%s</tt>" % (settings.get("description",""), name)
        example_request = settings.get("example_request")
        if example_request:
            full_description += "<br>"
            if example_request[0]:
                full_description += "<br>Optional GET parameters<br><table>"
                for entry in example_request[0]:
                    full_description += "<tr><td><tt>%s</tt></td><td>%s</td></tr>" % entry
                full_description += "</table>"
            if example_request[1]:
                full_description +=  "<br>Example request ( Json formatted POST parameter <tt>request=</tt> ):<br>"
                try:
                    import json
                    full_description += "<pre>%s</pre>" % json.dumps(example_request[1], sort_keys = True, indent = 2)
                except:
                    full_description += "<pre>%s</pre>" % pprint.pformat(example_request[1])

        config.declare_permission("webapi.%s" % name,
                settings["title"],
                full_description,
                config.builtin_role_ids)
Example #7
0
def load_plugins(force):
    global loaded_with_language
    if loaded_with_language == current_language and not force:
        return

    # Load all snapins
    global sidebar_snapins
    sidebar_snapins = {}
    global search_plugins
    search_plugins = []
    load_web_plugins("sidebar", globals())

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language

    # Declare permissions: each snapin creates one permission
    config.declare_permission_section("sidesnap", _("Sidebar snapins"), do_sort=True)
    for name, snapin in sidebar_snapins.items():
        config.declare_permission("sidesnap.%s" % name, snapin["title"], snapin["description"], snapin["allowed"])
Example #8
0
def load_plugins(force):
    global loaded_with_language
    if loaded_with_language == current_language and not force:
        return

    # Load all snapins
    global sidebar_snapins
    sidebar_snapins = {}
    global search_plugins
    search_plugins = []

    config.declare_permission_section("sidesnap",
                                      _("Sidebar snapins"),
                                      do_sort=True)

    load_web_plugins("sidebar", globals())

    transform_old_dict_based_snapins()

    # This must be set after plugin loading to make broken plugins raise
    # exceptions all the time and not only the first time (when the plugins
    # are loaded).
    loaded_with_language = current_language
def load():
    global loaded_with_language
    if loaded_with_language == current_language:
        return

    config.declare_permission_section("general", _('General Permissions'), 10)

    config.declare_permission("general.use",
         _("Use Multisite at all"),
         _("Users without this permission are not let in at all"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.see_all",
         _("See all Nagios objects"),
         _("See all objects regardless of contacts and contact groups. "
           "If combined with 'perform commands' then commands may be done on all objects."),
         [ "admin", "guest" ])

    config.declare_permission("general.edit_views",
         _("Customize views and use them"),
         _("Allows to create own views, customize builtin views and use them."),
         [ "admin", "user" ])

    config.declare_permission("general.publish_views",
         _("Publish views"),
         _("Make views visible and usable for other users"),
         [ "admin", "user" ])

    config.declare_permission("general.force_views",
         _("Modify builtin views"),
         _("Make own published views override builtin views for all users"),
         [ "admin" ])

    config.declare_permission("general.view_option_columns",
         _("Change view display columns"),
         _("Interactively change the number of columns being displayed by a view (does not edit or customize the view)"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.view_option_refresh",
         _("Change view display refresh"),
         _("Interactively change the automatic browser reload of a view being displayed (does not edit or customize the view)"),
         [ "admin", "user" ])

    config.declare_permission("general.painter_options",
         _("Change column display options"),
         _("Some of the display columns offer options for customizing their output. "
         "For example time stamp columns can be displayed absolute, relative or "
         "in a mixed style. This permission allows the user to modify display options"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.act",
         _("Perform commands"),
         _("Allows users to perform Nagios commands. If no further permissions "
           "are granted, actions can only be done on objects one is a contact for"),
         [ "admin", "user" ])

    config.declare_permission("general.see_sidebar",
         _("Use Check_MK sidebar"),
         _("Without this permission the Check_MK sidebar will be invisible"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.configure_sidebar",
         _("Configure sidebar"),
         _("This allows the user to add, move and remove sidebar snapins."),
         [ "admin", "user" ])

    config.declare_permission('general.edit_profile',
        _('Edit the user profile'),
        _('Permits the user to change the user profile settings.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.edit_notifications',
        _('Edit personal notification settings'),
        _('This allows a user to edit his personal notification settings. You also need the permission '
          '<i>Edit the user profile</i> in order to do this.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.edit_user_attributes',
        _('Edit personal user attributes'),
        _('This allows a user to edit his personal user attributes. You also need the permission '
          '<i>Edit the user profile</i> in order to do this.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.change_password',
        _('Edit the user password'),
        _('Permits the user to change the password.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.logout',
        _('Logout'),
        _('Permits the user to logout.'),
        [ 'admin', 'user', 'guest' ]
    )

    config.declare_permission("general.ignore_soft_limit",
         _("Ignore soft query limit"),
         _("Allows to ignore the soft query limit imposed upon the number of datasets returned by a query"),
         [ "admin", "user" ])

    config.declare_permission("general.ignore_hard_limit",
         _("Ignore hard query limit"),
         _("Allows to ignore the hard query limit imposed upon the number of datasets returned by a query"),
         [ "admin" ])

    loaded_with_language = current_language
Example #10
0
def load():
    global loaded_with_language
    if loaded_with_language == current_language:
        return

    config.declare_permission_section("general", _('General Permissions'), 10)

    config.declare_permission(
        "general.use", _("Use Multisite at all"),
        _("Users without this permission are not let in at all"),
        ["admin", "user", "guest"])

    config.declare_permission(
        "general.see_all", _("See all Nagios objects"),
        _("See all objects regardless of contacts and contact groups. "
          "If combined with 'perform commands' then commands may be done on all objects."
          ), ["admin", "guest"])

    config.declare_permission(
        "general.edit_views", _("Customize views and use them"),
        _("Allows to create own views, customize builtin views and use them."),
        ["admin", "user"])

    config.declare_permission(
        "general.publish_views", _("Publish views"),
        _("Make views visible and usable for other users"), ["admin", "user"])

    config.declare_permission(
        "general.see_user_views", _("See user views"),
        _("Is needed for seeing views that other users have created."),
        ["admin", "user", "guest"])

    config.declare_permission(
        "general.force_views", _("Modify builtin views"),
        _("Make own published views override builtin views for all users"),
        ["admin"])

    config.declare_permission(
        "general.view_option_columns", _("Change view display columns"),
        _("Interactively change the number of columns being displayed by a view (does not edit or customize the view)"
          ), ["admin", "user", "guest"])

    config.declare_permission(
        "general.view_option_refresh", _("Change view display refresh"),
        _("Interactively change the automatic browser reload of a view being displayed (does not edit or customize the view)"
          ), ["admin", "user"])

    config.declare_permission(
        "general.painter_options", _("Change column display options"),
        _("Some of the display columns offer options for customizing their output. "
          "For example time stamp columns can be displayed absolute, relative or "
          "in a mixed style. This permission allows the user to modify display options"
          ), ["admin", "user", "guest"])

    config.declare_permission(
        "general.act", _("Perform commands"),
        _("Allows users to perform Nagios commands. If no further permissions "
          "are granted, actions can only be done on objects one is a contact for"
          ), ["admin", "user"])

    config.declare_permission(
        "general.see_sidebar", _("Use Check_MK sidebar"),
        _("Without this permission the Check_MK sidebar will be invisible"),
        ["admin", "user", "guest"])

    config.declare_permission(
        "general.configure_sidebar", _("Configure sidebar"),
        _("This allows the user to add, move and remove sidebar snapins."),
        ["admin", "user"])

    config.declare_permission(
        'general.edit_profile', _('Edit the user profile'),
        _('Permits the user to change the user profile settings.'),
        ['admin', 'user'])

    config.declare_permission(
        'general.edit_notifications', _('Edit personal notification settings'),
        _('This allows a user to edit his personal notification settings. You also need the permission '
          '<i>Edit the user profile</i> in order to do this.'),
        ['admin', 'user'])

    config.declare_permission(
        'general.edit_user_attributes', _('Edit personal user attributes'),
        _('This allows a user to edit his personal user attributes. You also need the permission '
          '<i>Edit the user profile</i> in order to do this.'),
        ['admin', 'user'])

    config.declare_permission('general.change_password',
                              _('Edit the user password'),
                              _('Permits the user to change the password.'),
                              ['admin', 'user'])

    config.declare_permission('general.logout', _('Logout'),
                              _('Permits the user to logout.'),
                              ['admin', 'user', 'guest'])

    config.declare_permission(
        "general.ignore_soft_limit", _("Ignore soft query limit"),
        _("Allows to ignore the soft query limit imposed upon the number of datasets returned by a query"
          ), ["admin", "user"])

    config.declare_permission(
        "general.ignore_hard_limit", _("Ignore hard query limit"),
        _("Allows to ignore the hard query limit imposed upon the number of datasets returned by a query"
          ), ["admin"])

    loaded_with_language = current_language
Example #11
0
def load_plugins():
    global loaded_with_language
    if loaded_with_language == current_language:
        return

    config.declare_permission_section("general", _('General Permissions'), 10)

    config.declare_permission("general.use",
         _("Use Multisite at all"),
         _("Users without this permission are not let in at all"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.see_all",
         _("See all Nagios objects"),
         _("See all objects regardless of contacts and contact groups. "
           "If combined with 'perform commands' then commands may be done on all objects."),
         [ "admin", "guest" ])

    declare_visual_permissions('views', _("views"))
    declare_visual_permissions('dashboards', _("dashboards"))

    config.declare_permission("general.view_option_columns",
         _("Change view display columns"),
         _("Interactively change the number of columns being displayed by a view (does not edit or customize the view)"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.view_option_refresh",
         _("Change view display refresh"),
         _("Interactively change the automatic browser reload of a view being displayed (does not edit or customize the view)"),
         [ "admin", "user" ])

    config.declare_permission("general.painter_options",
         _("Change column display options"),
         _("Some of the display columns offer options for customizing their output. "
         "For example time stamp columns can be displayed absolute, relative or "
         "in a mixed style. This permission allows the user to modify display options"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.act",
         _("Perform commands"),
         _("Allows users to perform Nagios commands. If no further permissions "
           "are granted, actions can only be done on objects one is a contact for"),
         [ "admin", "user" ])

    config.declare_permission("general.see_sidebar",
         _("Use Check_MK sidebar"),
         _("Without this permission the Check_MK sidebar will be invisible"),
         [ "admin", "user", "guest" ])

    config.declare_permission("general.configure_sidebar",
         _("Configure sidebar"),
         _("This allows the user to add, move and remove sidebar snapins."),
         [ "admin", "user" ])

    config.declare_permission('general.edit_profile',
        _('Edit the user profile'),
        _('Permits the user to change the user profile settings.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.edit_notifications',
        _('Edit personal notification settings'),
        _('This allows a user to edit his personal notification settings. You also need the permission '
          '<i>Edit the user profile</i> in order to do this.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.disable_notifications',
        _('Disable all personal notifications'),
        _('This permissions provides a checkbox in the personal settings of the user that '
          'allows him to completely disable all of his notifications. Use with caution.'),
        [ 'admin', ]
    )

    config.declare_permission('general.edit_user_attributes',
        _('Edit personal user attributes'),
        _('This allows a user to edit his personal user attributes. You also need the permission '
          '<i>Edit the user profile</i> in order to do this.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.change_password',
        _('Edit the user password'),
        _('Permits the user to change the password.'),
        [ 'admin', 'user' ]
    )

    config.declare_permission('general.logout',
        _('Logout'),
        _('Permits the user to logout.'),
        [ 'admin', 'user', 'guest' ]
    )

    config.declare_permission("general.ignore_soft_limit",
         _("Ignore soft query limit"),
         _("Allows to ignore the soft query limit imposed upon the number of datasets returned by a query"),
         [ "admin", "user" ])

    config.declare_permission("general.ignore_hard_limit",
         _("Ignore hard query limit"),
         _("Allows to ignore the hard query limit imposed upon the number of datasets returned by a query"),
         [ "admin" ])

    config.declare_permission("general.acknowledge_werks",
         _("Acknowledge Incompatible Werks"),
         _("In the change log of the Check_MK software version the administrator can manage change log entries "
           "(Werks) that requrire user interaction. These <i>incompatible Werks</i> can be acknowledged only "
           "if the user has this permission."),
         [ "admin" ])


    loaded_with_language = current_language
Example #12
0
class Overridable:
    @classmethod
    def parameters(self, clazz):
        if clazz.has_overriding_permission("publish"):
            return [(_("General Properties"), [
                (2.2, 'public',
                 Checkbox(title=_("Visibility"),
                          label=_('Make available for all users'))),
            ])]
        else:
            return []

    @classmethod
    def _page_handlers(self, clazz):
        return {
            "%ss" % clazz.type_name(): lambda: clazz.page_list(),
            "edit_%s" % clazz.type_name(): lambda: clazz.page_edit(),
        }

    def page_header(self):
        header = self.phrase("title") + " - " + self.title()
        if not self.is_mine():
            header += " (%s)" % self.owner()
        return header

    # Checks wether a page is publicly visible. This does not only need a flag
    # in the page itself, but also the permission from its owner to publish it.
    def is_public(self):
        return self._["public"] and (not self.owner() or config.user_may(
            self.owner(), "general.publish_" + self.type_name()))

    # Same, but checks if the owner has the permission to override builtin views
    def is_public_forced(self):
        return self.is_public() and \
          config.user_may(self.owner(), "general.force_" + self.type_name())

    def is_hidden(self):
        return self._.get("hidden", False)

    # Derived method for conveniance
    def is_builtin(self):
        return not self.owner()

    def is_mine(self):
        return self.owner() == config.user_id

    def owner(self):
        return self._["owner"]

    # Checks if the current user is allowed to see a certain page
    # TODO: Wie is die Semantik hier genau? Umsetzung vervollständigen!
    def may_see(self):
        perm_name = "%s.%s" % (self.type_name(), self.name())
        if config.permission_exists(perm_name) and not config.may(perm_name):
            return False

        # if self.owner() == "" and not config.may(perm_name):
        #    return False

        return True
        #    continue # not allowed to see this view

        # TODO: Permissions
        ### visual = visuals[(owner, visual_name)]
        ### if owner == config.user_id or \
        ###    (visual["public"] and owner != '' and config.user_may(owner, "general.publish_" + what)):
        ###     custom.append((owner, visual_name, visual))
        ### elif visual["public"] and owner == "":
        ###     builtin.append((owner, visual_name, visual))

    def may_delete(self):
        if self.is_builtin():
            return False
        elif self.is_mine():
            return True
        else:
            return config.may('general.delete_foreign_%s' % self.type_name())

    def may_edit(self):
        if self.is_builtin():
            return False
        elif self.is_mine():
            return True
        else:
            return config.may('general.edit_foreign_%s' % self.type_name())

    def edit_url(self):
        owner = not self.is_mine() and ("&owner=%s" % self.owner()) or ""
        return "edit_%s.py?load_name=%s%s" % (self.type_name(), self.name(),
                                              owner)

    def clone_url(self):
        backurl = html.urlencode(html.makeuri([]))
        return "edit_%s.py?load_user=%s&load_name=%s&mode=clone&back=%s" \
                    % (self.type_name(), self.owner(), self.name(), backurl)

    def delete_url(self):
        add_vars = [('_delete', self.name())]
        if not self.is_mine():
            add_vars.append(('_owner', self.owner()))
        return html.makeactionuri(add_vars)

    @classmethod
    def create_url(self):
        return "edit_%s.py?mode=create" % self.type_name()

    @classmethod
    def list_url(self):
        return "%ss.py" % self.type_name()

    @classmethod
    def context_button_list(self):
        html.context_button(self.phrase("title_plural"), self.list_url(),
                            self.type_name())

    def context_button_edit(self):
        html.context_button(_("Edit"), self.edit_url(), "edit")

    @classmethod
    def declare_overriding_permissions(self):
        config.declare_permission(
            "general.edit_" + self.type_name(),
            _("Customize %s and use them") % self.phrase("title_plural"),
            _("Allows to create own %s, customize builtin %s and use them.") %
            (self.phrase("title_plural"), self.phrase("title_plural")),
            ["admin", "user"])

        config.declare_permission(
            "general.publish_" + self.type_name(),
            _("Publish %s") % self.phrase("title_plural"),
            _("Make %s visible and usable for other users.") %
            self.phrase("title_plural"), ["admin", "user"])

        config.declare_permission(
            "general.see_user_" + self.type_name(),
            _("See user %s") % self.phrase("title_plural"),
            _("Is needed for seeing %s that other users have created.") %
            self.phrase("title_plural"), ["admin", "user", "guest"])

        config.declare_permission(
            "general.force_" + self.type_name(),
            _("Modify builtin %s") % self.phrase("title_plural"),
            _("Make own published %s override builtin %s for all users.") %
            (self.phrase("title_plural"), self.phrase("title_plural")),
            ["admin"])

        config.declare_permission(
            "general.edit_foreign_" + self.type_name(),
            _("Edit foreign %s") % self.phrase("title_plural"),
            _("Allows to edit %s created by other users.") %
            self.phrase("title_plural"), ["admin"])

        config.declare_permission(
            "general.delete_foreign_" + self.type_name(),
            _("Delete foreign %s") % self.phrase("title_plural"),
            _("Allows to delete %s created by other users.") %
            self.phrase("title_plural"), ["admin"])

    @classmethod
    def has_overriding_permission(self, how):
        return config.may("general.%s_%s" % (how, self.type_name()))

    @classmethod
    def need_overriding_permission(self, how):
        if not self.has_overriding_permission(how):
            raise MKAuthException(
                _("Sorry, you lack the permission. Operation: %s, table: %s") %
                (how, self.phrase("title_plural")))

    # Return all pages visible to the user, implements shadowing etc.
    @classmethod
    def pages(self):
        self.load()
        pages = {}

        # Builtin pages
        for page in self.instances():
            if page.is_public() and page.may_see() and page.is_builtin():
                pages[page.name()] = page

        # Public pages by normal other users
        for page in self.instances():
            if page.is_public() and page.may_see():
                pages[page.name()] = page

        # Public pages by admin users, forcing their versions over others
        for page in self.instances():
            if page.is_public() and page.may_see() and page.is_public_forced():
                pages[page.name()] = page

        # My own pages
        for page in self.instances():
            if page.is_mine() and config.may("general.edit_" +
                                             self.type_name()):
                pages[page.name()] = page

        return sorted(pages.values(),
                      cmp=lambda a, b: cmp(a.title(), b.title()))

    # Find a page by name, implements shadowing and
    # publishing und overriding by admins
    @classmethod
    def find_page(self, name):
        self.load()

        mine = None
        forced = None
        builtin = None
        foreign = None

        for page in self.instances():
            if page.name() != name:
                continue

            if page.is_mine() and config.may("general.edit_" +
                                             self.type_name()):
                mine = page

            elif page.is_public() and page.may_see():
                if page.is_public_forced():
                    forced = page
                elif page.is_builtin():
                    builtin = page
                else:
                    foreign = page

        if mine:
            return mine
        elif forced:
            return forced
        elif builtin:
            return builtin
        elif foreign:
            return foreign
        else:
            return None

    @classmethod
    def find_my_page(self, name):
        for page in self.instances():
            if page.is_mine() and page.name() == name:
                return page

    @classmethod
    def find_foreign_page(self, owner, name):
        try:
            return self.instance((owner, name))
        except KeyError:
            return None

    @classmethod
    def builtin_pages(self):
        return {}

    # Lädt alle Dinge vom aktuellen User-Homeverzeichnis und
    # mergt diese mit den übergebenen eingebauten
    @classmethod
    def load(self):
        self.clear_instances()

        # First load builtin pages. Set username to ''
        for name, page_dict in self.builtin_pages().items():
            page_dict["owner"] = ''  # might have been forgotten on copy action
            page_dict["public"] = True
            page_dict["name"] = name
            new_page = self(page_dict)
            self.add_instance(("", name), new_page)

        # Now scan users subdirs for files "user_$type_name.mk"
        subdirs = os.listdir(config.config_dir)
        for user in subdirs:
            try:
                path = "%s/%s/user_%ss.mk" % (config.config_dir, user,
                                              self.type_name())
                if not os.path.exists(path):
                    continue

                user_pages = eval(file(path).read())
                for name, page_dict in user_pages.items():
                    page_dict["owner"] = user
                    page_dict["name"] = name
                    self.add_instance((user, name), self(page_dict))

            except SyntaxError, e:
                raise MKGeneralException(
                    _("Cannot load %s from %s: %s") % (what, path, e))

        # FIXME: Better switch to "new style classes" and use super() and then override load()
        # in the subclass. Brings more flexibility.
        if hasattr(self, "_load"):
            self._load()

        # Declare permissions - one for each of the pages, if it is public
        config.declare_permission_section(self.type_name(),
                                          self.phrase("title_plural"),
                                          do_sort=True)

        for instance in self.instances():
            if instance.is_public():
                self.declare_permission(instance)
Example #13
0
# Boston, MA 02110-1301 USA.

import config, re, pprint, time
import weblib
from lib import *


# Python 2.3 does not have 'set' in normal namespace.
# But it can be imported from 'sets'
try:
    set()
except NameError:
    from sets import Set as set


config.declare_permission_section("bi", "BI - Check_MK Business Intelligence")
config.declare_permission("bi.see_all",
        "See all hosts and services",
        "With this permission set, the BI aggregation rules are applied to all "
        "hosts and services - not only those the user is a contact for. If you "
        "remove this permissions then the user will see incomplete aggregation "
        "trees with status based only on those items.",
        [ "admin", "guest" ])

#      ____                _              _
#     / ___|___  _ __  ___| |_ __ _ _ __ | |_ ___
#    | |   / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
#    | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
#     \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
#
import config

#   .----------------------------------------------------------------------.
#   |        ____                     _         _                          |
#   |       |  _ \ ___ _ __ _ __ ___ (_)___ ___(_) ___  _ __  ___          |
#   |       | |_) / _ \ '__| '_ ` _ \| / __/ __| |/ _ \| '_ \/ __|         |
#   |       |  __/  __/ |  | | | | | | \__ \__ \ | (_) | | | \__ \         |
#   |       |_|   \___|_|  |_| |_| |_|_|___/___/_|\___/|_| |_|___/         |
#   |                                                                      |
#   +----------------------------------------------------------------------+
#   |                                                                      |
#   | Declare general permissions for Multisite                            |
#   '----------------------------------------------------------------------'

config.declare_permission_section("general", _('General Permissions'), 10)

config.declare_permission(
    "general.use", _("Use Multisite at all"),
    _("Users without this permission are not let in at all"),
    ["admin", "user", "guest"])

config.declare_permission(
    "general.see_all", _("See all Nagios objects"),
    _("See all objects regardless of contacts and contact groups. "
      "If combined with 'perform commands' then commands may be done on all objects."
      ), ["admin", "guest"])

config.declare_permission("general.edit_views", _("Edit views"),
                          _("Create own views and customize builtin views"),
                          ["admin", "user"])
import config

#   .----------------------------------------------------------------------.
#   |        ____                     _         _                          |
#   |       |  _ \ ___ _ __ _ __ ___ (_)___ ___(_) ___  _ __  ___          |
#   |       | |_) / _ \ '__| '_ ` _ \| / __/ __| |/ _ \| '_ \/ __|         |
#   |       |  __/  __/ |  | | | | | | \__ \__ \ | (_) | | | \__ \         |
#   |       |_|   \___|_|  |_| |_| |_|_|___/___/_|\___/|_| |_|___/         |
#   |                                                                      |
#   +----------------------------------------------------------------------+
#   |                                                                      |
#   | Declare general permissions for Multisite                            |
#   '----------------------------------------------------------------------'

config.declare_permission_section("general", _('General Permissions'), 10)

config.declare_permission("general.use",
     _("Use Multisite at all"),
     _("Users without this permission are not let in at all"),
     [ "admin", "user", "guest" ])

config.declare_permission("general.see_all",
     _("See all Nagios objects"),
     _("See all objects regardless of contacts and contact groups. "
       "If combined with 'perform commands' then commands may be done on all objects."),
     [ "admin", "guest" ])

config.declare_permission("general.edit_views",
     _("Edit views"),
     _("Create own views and customize builtin views"),
Example #16
0
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

import config, re, pprint, time
import weblib
from lib import *

# Python 2.3 does not have 'set' in normal namespace.
# But it can be imported from 'sets'
try:
    set()
except NameError:
    from sets import Set as set

config.declare_permission_section("bi", "BI - Check_MK Business Intelligence")
config.declare_permission(
    "bi.see_all", "See all hosts and services",
    "With this permission set, the BI aggregation rules are applied to all "
    "hosts and services - not only those the user is a contact for. If you "
    "remove this permissions then the user will see incomplete aggregation "
    "trees with status based only on those items.", ["admin", "guest"])

#      ____                _              _
#     / ___|___  _ __  ___| |_ __ _ _ __ | |_ ___
#    | |   / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
#    | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
#     \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
#

# type of rule parameters