def _from_vars(self): ident = html.get_ascii_input("ident") if ident is not None: try: entry = self._store.filter_editable_entries(self._store.load_for_reading())[ident] except KeyError: raise MKUserError("ident", _("This %s does not exist.") % self._mode_type.name_singular()) self._new = False self._ident = ident self._entry = entry return clone = html.get_ascii_input("clone") if clone is not None: try: entry = self._store.filter_editable_entries(self._store.load_for_reading())[clone] except KeyError: raise MKUserError("clone", _("This %s does not exist.") % self._mode_type.name_singular()) self._new = True self._ident = None self._entry = copy.deepcopy(entry) return self._new = True self._ident = None self._entry = {}
def _from_vars(self): self._search = get_search_expression() self._topic = html.get_ascii_input("topic") if self._topic and not self._search: if not re.match("^[a-zA-Z0-9_./]+$", self._topic): raise MKUserError("topic", _("Invalid topic")) self._path = tuple( self._topic.split("/")) # e.g. [ "hw", "network" ] else: self._path = tuple() for comp in self._path: ID().validate_value(comp, None) # Beware against code injection! self._manpages = self._get_check_catalog() self._titles = man_pages.man_page_catalog_titles() self._has_second_level = None if self._topic and not self._search: for t, has_second_level, title, _helptext in self._man_page_catalog_topics( ): if t == self._path[0]: self._has_second_level = has_second_level self._topic_title = title break if len(self._path) == 2: self._topic_title = self._titles.get(self._path[1], self._path[1])
def _init_host(self): hostname = html.get_ascii_input("host") # may be empty in new/clone mode if not watolib.Folder.current().has_host(hostname): raise MKUserError("host", _("You called this page with an invalid host name.")) return watolib.Folder.current().host(hostname)
def _from_vars(self): self._hostname = html.get_ascii_input("host") # may be empty in new/clone mode self._host = watolib.Folder.current().host(self._hostname) if self._host is None: raise MKUserError("host", _('The given host does not exist.')) self._host.need_permission("read") # TODO: Validate? self._service = html.get_unicode_input("service")
def query_limit_exceeded_warn(limit, user_config): """Compare query reply against limits, warn in the GUI about incompleteness""" text = _("Your query produced more than %d results. ") % limit if html.get_ascii_input( "limit", "soft") == "soft" and user_config.may("general.ignore_soft_limit"): text += html.render_a(_('Repeat query and allow more results.'), target="_self", href=html.makeuri([("limit", "hard")])) elif html.get_ascii_input("limit") == "hard" and user_config.may( "general.ignore_hard_limit"): text += html.render_a(_('Repeat query without limit.'), target="_self", href=html.makeuri([("limit", "none")])) text += " " + _( "<b>Note:</b> the shown results are incomplete and do not reflect the sort order." ) html.show_warning(text)
def _from_vars(self): host_name = html.get_ascii_input("host") if not watolib.Folder.current().has_host(host_name): raise MKUserError("host", _("You called this page with an invalid host name.")) if not config.user.may("wato.rename_hosts"): raise MKAuthException(_("You don't have the right to rename hosts")) self._host = watolib.Folder.current().host(host_name) self._host.need_permission("write")
def get_request(self): # type: () -> FetchAgentOutputRequest config.user.need_permission("wato.download_agent_output") ascii_input = html.get_ascii_input("request") if ascii_input is None: raise MKUserError( "request", _("The parameter \"%s\" is missing.") % "request") return FetchAgentOutputRequest.deserialize( ast.literal_eval(ascii_input))
def _localize_request(): previous_language = cmk.gui.i18n.get_current_language() user_language = html.get_ascii_input("lang", config.user.language) html.set_language_cookie(user_language) cmk.gui.i18n.localize(user_language) # All plugins might have to be reloaded due to a language change. Only trigger # a second plugin loading when the user is really using a custom localized GUI. # Otherwise the load_all_plugins() at the beginning of the request is sufficient. if cmk.gui.i18n.get_current_language() != previous_language: _load_all_plugins()
def _init_host(self): clonename = html.get_ascii_input("clone") if clonename: if not watolib.Folder.current().has_host(clonename): raise MKUserError("host", _("You called this page with an invalid host name.")) if not config.user.may("wato.clone_hosts"): raise MKAuthException(_("Sorry, you are not allowed to clone hosts.")) host = watolib.Folder.current().host(clonename) self._verify_host_type(host) return host else: return self._init_new_host_object()
def _from_vars(self): self._check_type = html.get_ascii_input("check_type") # TODO: There is one check "sap.value-groups" which will be renamed to "sap.value_groups". # As long as the old one is available, allow a minus here. if not re.match("^[-a-zA-Z0-9_.]+$", self._check_type): raise MKUserError("check_type", _("Invalid check type")) # TODO: remove call of automation and then the automation. This can be done once the check_info # data is also available in the "cmk." module because the get-check-manpage automation not only # fetches the man page. It also contains info from check_info. What a hack. self._manpage = watolib.check_mk_local_automation("get-check-manpage", [self._check_type]) if self._manpage is None: raise MKUserError(None, _("There is no manpage for this check."))
def _from_vars(self): self._varname = html.get_ascii_input("varname") try: self._config_variable = config_variable_registry[self._varname]() self._valuespec = self._config_variable.valuespec() except KeyError: raise MKUserError( "varname", _("The global setting \"%s\" does not exist.") % self._varname) if not self._may_edit_configvar(self._varname): raise MKAuthException( _("You are not permitted to edit this global setting.")) self._current_settings = watolib.load_configuration_settings() self._global_settings = {}
def test_get_ascii_input(register_builtin_html): html.request.set_var("xyz", "x") html.request.set_var("abc", "äbc") assert html.get_ascii_input("xyz") == "x" assert isinstance(html.get_ascii_input("xyz"), str) with pytest.raises(MKUserError) as e: html.get_ascii_input("abc") assert "must only contain ASCII" in "%s" % e assert html.get_ascii_input("get_default", "xyz") == "xyz" assert html.get_ascii_input("zzz") is None
def action(self): if not html.transaction_valid(): return if not html.request.has_var("_action"): return if html.request.var("_action") != "delete": return self._handle_custom_action(html.request.var("_action")) confirm = wato_confirm(_("Confirm deletion"), self._delete_confirm_message()) if confirm is False: return False elif not confirm: return html.check_transaction() # invalidate transid entries = self._store.load_for_modification() ident = html.get_ascii_input("_delete") if ident not in entries: raise MKUserError( "_delete", _("This %s does not exist.") % self._mode_type.name_singular()) if ident not in self._store.filter_editable_entries(entries): raise MKUserError("_delete", \ _("You are not allowed to delete this %s.") % self._mode_type.name_singular()) self._validate_deletion(ident, entries[ident]) entry = entries.pop(ident) self._add_change( "delete", entry, _("Removed the %s '%s'") % (self._mode_type.name_singular(), ident)) self._store.save(entries) return None, _( "The %s has been deleted.") % self._mode_type.name_singular()
def get_request(self): # type: () -> FetchAgentOutputRequest config.user.need_permission("wato.download_agent_output") return FetchAgentOutputRequest.deserialize(ast.literal_eval( html.get_ascii_input("request")))