def inpage_search_form(mode: Optional[str] = None, default_value: str = "") -> None: form_name = "inpage_search_form" reset_button_id = "%s_reset" % form_name was_submitted = request.get_ascii_input("filled_in") == form_name html.begin_form(form_name, add_transid=False) html.text_input( "search", size=32, default_value=default_value, placeholder=_("Filter"), required=True, title="", ) html.hidden_fields() if mode: html.hidden_field("mode", mode, add_var=True) reset_url = request.get_ascii_input_mandatory("reset_url", requested_file_with_query(request)) html.hidden_field("reset_url", reset_url, add_var=True) html.button("submit", "", cssclass="submit", help_=_("Apply")) html.buttonlink(reset_url, "", obj_id=reset_button_id, title=_("Reset")) html.end_form() html.javascript( "cmk.page_menu.inpage_search_init(%s, %s)" % (json.dumps(reset_button_id), json.dumps(was_submitted)) )
def display(self, value: FilterHTTPVariables) -> None: current_value = value.get(self.query_filter.request_vars[0], "") html.text_input(self.htmlvars[0], current_value, self.query_filter.negateable and "neg" or "") if self.query_filter.negateable: checkbox_component(self.query_filter.request_vars[1], value, _("negate"))
def test_text_input(request_context): with output_funnel.plugged(): html.text_input("tralala") written_text = "".join(output_funnel.drain()) assert compare_html( written_text, '<input style="" name="tralala" type="text" class="text" value=\'\' />' ) with output_funnel.plugged(): html.text_input("blabla", cssclass="blubb") written_text = "".join(output_funnel.drain()) assert compare_html( written_text, '<input style="" name="tralala" type="text" class="blubb" value=\'\' />' ) with output_funnel.plugged(): html.text_input("blabla", autocomplete="yep") written_text = "".join(output_funnel.drain()) assert compare_html( written_text, '<input style="" name="blabla" autocomplete="yep" type="text" class="text" value=\'\' />', ) with output_funnel.plugged(): html.text_input("blabla", placeholder="placido", data_world="welt", data_max_labels=42) written_text = "".join(output_funnel.drain()) assert compare_html( written_text, '<input style="" name="tralala" type="text" class="text" value=\'\' />' )
def page(self): # TODO: remove subclass specific things specifict things (everything with _type == 'user') html.begin_form("attr") forms.header(_("Properties")) forms.section(_("Name"), simple=not self._new, is_required=True) html.help( _( "The name of the attribute is used as an internal key. It cannot be " "changed later." ) ) if self._new: html.text_input("name", self._attr.get("name", "")) html.set_focus("name") else: html.write_text(self._name) html.set_focus("title") forms.section(_("Title") + "<sup>*</sup>", is_required=True) html.help(_("The title is used to label this attribute.")) html.text_input("title", self._attr.get("title", "")) forms.section(_("Topic")) html.help(_("The attribute is added to this section in the edit dialog.")) html.dropdown("topic", self._topics, deflt=self._attr.get("topic", self._default_topic)) forms.section(_("Help Text") + "<sup>*</sup>") html.help(_("You might want to add some helpful description for the attribute.")) html.text_area("help", self._attr.get("help", "")) forms.section(_("Data type")) html.help(_("The type of information to be stored in this attribute.")) if self._new: html.dropdown("type", custom_attr_types(), deflt=self._attr.get("type", "")) else: html.write_text(dict(custom_attr_types())[self._attr.get("type")]) self._add_extra_form_sections() self._show_in_table_option() forms.section(_("Add to monitoring configuration")) html.help(self._macro_help) html.checkbox( "add_custom_macro", self._attr.get("add_custom_macro", False), label=self._macro_label ) forms.end() html.show_localization_hint() html.hidden_fields() html.end_form()
def display(self, value: FilterHTTPVariables) -> None: html.write_text(_("From:") + " ") html.text_input(self.htmlvars[0], default_value=value.get(self.htmlvars[0], ""), style="width: 80px;") if self.unit: html.write_text(" %s " % self.unit) html.write_text(" " + _("To:") + " ") html.text_input(self.htmlvars[1], default_value=value.get(self.htmlvars[1], ""), style="width: 80px;") if self.unit: html.write_text(" %s " % self.unit)
def search_form( title: Optional[str] = None, mode: Optional[str] = None, default_value: str = "" ) -> None: html.begin_form("search", add_transid=False) if title: html.write_text(title + " ") html.text_input("search", size=32, default_value=default_value) html.hidden_fields() if mode: html.hidden_field("mode", mode, add_var=True) html.set_focus("search") html.write_text(" ") html.button("_do_seach", _("Search")) html.end_form()
def display(self, value: FilterHTTPVariables): html.open_table(class_="filtertime") for what, whatname in [("from", _("From")), ("until", _("Until"))]: varprefix = self.ident + "_" + what html.open_tr() html.td("%s:" % whatname) html.open_td() html.text_input(varprefix, default_value=value.get(varprefix, "")) html.close_td() html.open_td() html.dropdown( varprefix + "_range", query_filters.time_filter_options(), deflt=value.get(varprefix + "_range", "3600"), ) html.close_td() html.close_tr() html.close_table()
def _show_try_form(self): html.begin_form("try") forms.header(_("Try Pattern Match")) forms.section(_("Hostname")) self._vs_host().render_input("host", self._hostname) forms.section(_("Logfile")) html.help(_("Here you need to insert the original file or pathname")) html.text_input("file", size=80) forms.section(_("Text to match")) html.help( _("You can insert some text (e.g. a line of the logfile) to test the patterns defined " "for this logfile. All patterns for this logfile are listed below. Matching patterns " 'will be highlighted after clicking the "Try out" button.')) html.text_input("match", cssclass="match", size=100) forms.end() html.button("_try", _("Try out")) request.del_var("folder") # Never hand over the folder here html.hidden_fields() html.end_form()
def display(self, value: FilterHTTPVariables) -> None: html.text_input(self._varprefix + "name") html.br() display_filter_radiobuttons( varname=self._varprefix + "match", options=[ ("exact", _("exact match")), ("regex", _("regular expression, substring match")), ], default="exact", value=value, ) html.br() html.open_span(class_="min_max_row") html.write_text(_("Min. Version: ")) html.text_input( self._varprefix + "version_from", default_value=value.get(self._varprefix + "version_from", ""), size=9, ) html.write_text(" ") html.write_text(_("Max. Vers.: ")) html.text_input( self._varprefix + "version_to", default_value=value.get(self._varprefix + "version_from", ""), size=9, ) html.close_span() html.br() html.checkbox( self._varprefix + "negate", False, label=_("Negate: find hosts <b>not</b> having this package"), )
def page(self): html.help( _("The renaming of hosts is a complex operation since a host's name is being " "used as a unique key in various places. It also involves stopping and starting " "of the monitoring core. You cannot rename a host while you have pending changes." )) html.begin_form("rename_host", method="POST") html.add_confirm_on_submit( "rename_host", _("Are you sure you want to rename the host <b>%s</b>? " "This involves a restart of the monitoring core!") % (self._host.name()), ) forms.header(_("Rename host %s") % self._host.name()) forms.section(_("Current name")) html.write_text(self._host.name()) forms.section(_("New name")) html.text_input("newname", "") forms.end() html.set_focus("newname") html.hidden_fields() html.end_form()
def page(self) -> None: html.begin_form("group", method="POST") forms.header(_("Properties")) forms.section(_("Name"), simple=not self._new, is_required=True) html.help( _("The name of the group is used as an internal key. It cannot be " "changed later. It is also visible in the status GUI.")) if self._new: html.text_input("name") html.set_focus("name") else: html.write_text(self._name) html.set_focus("alias") forms.section(_("Alias"), is_required=True) html.help(_("An alias or description of this group.")) html.text_input("alias", self.group["alias"]) self._show_extra_page_elements() forms.end() html.hidden_fields() html.end_form()
def page_login() -> None: title = _("Checkmk Mobile") mobile_html_head(title) jqm_page_header(title, id_="login") html.div(_("Welcome to Checkmk Mobile."), id_="loginhead") html.begin_form("login", method="POST", add_transid=False) # Keep information about original target URL default_origtarget = ( "index.py" if requested_file_name(request) in ["login", "logout"] else makeuri(request, []) ) origtarget = request.get_url_input("_origtarget", default_origtarget) html.hidden_field("_origtarget", escaping.escape_attribute(origtarget)) html.text_input("_username", label=_("Username:"******"username", id_="input_user") html.password_input( "_password", size=None, label=_("Password:"******"current-password", id_="input_pass", ) html.br() html.button("_login", _("Login")) html.set_focus("_username") html.end_form() html.open_div(id_="loginfoot") html.img("themes/facelift/images/logo_cmk_small.png", class_="logomk") html.div( HTML(_('© <a target="_blank" href="https://checkmk.com">tribe29 GmbH</a>')), class_="copyright", ) html.close_div() # close content-div html.close_div() html.close_div() # close page-div mobile_html_foot()
def page(self): html.begin_form("random") forms.header(_("Add random hosts")) forms.section(_("Number to create")) html.write_text("%s: " % _("Hosts to create in each folder")) html.text_input("count", default_value="10", cssclass="number") html.set_focus("count") html.br() html.write_text("%s: " % _("Number of folders to create in each level")) html.text_input("folders", default_value="10", cssclass="number") html.br() html.write_text("%s: " % _("Levels of folders to create")) html.text_input("levels", default_value="1", cssclass="number") forms.end() html.hidden_fields() html.end_form()
def _show_start_form(self): html.begin_form("parentscan", method="POST") html.hidden_fields() # Mode of action html.open_p() if not self._complete_folder: num_selected = len(get_hosts_from_checkboxes()) html.write_text(_("You have selected <b>%d</b> hosts for parent scan. ") % num_selected) html.p( _( "The parent scan will try to detect the last gateway " "on layer 3 (IP) before a host. This will be done by " "calling <tt>traceroute</tt>. If a gateway is found by " "that way and its IP address belongs to one of your " "monitored hosts, that host will be used as the hosts " "parent. If no such host exists, an artifical ping-only " "gateway host will be created if you have not disabled " "this feature." ) ) forms.header(_("Settings for Parent Scan")) self._settings = ParentScanSettings( **user.load_file( "parentscan", { "where": "subfolder", "alias": _("Created by parent scan"), "recurse": True, "select": "noexplicit", "timeout": 8, "probes": 2, "ping_probes": 5, "max_ttl": 10, "force_explicit": False, }, ) ) # Selection forms.section(_("Selection")) if self._complete_folder: html.checkbox("recurse", self._settings.recurse, label=_("Include all subfolders")) html.br() html.radiobutton( "select", "noexplicit", self._settings.select == "noexplicit", _("Skip hosts with explicit parent definitions (even if empty)") + "<br>", ) html.radiobutton( "select", "no", self._settings.select == "no", _("Skip hosts hosts with non-empty parents (also if inherited)") + "<br>", ) html.radiobutton( "select", "ignore", self._settings.select == "ignore", _("Scan all hosts") + "<br>" ) # Performance forms.section(_("Performance")) html.open_table() html.open_tr() html.open_td() html.write_text(_("Timeout for responses") + ":") html.close_td() html.open_td() html.text_input("timeout", str(self._settings.timeout), size=2, cssclass="number") html.write_text(_("sec")) html.close_td() html.close_tr() html.open_tr() html.open_td() html.write_text(_("Number of probes per hop") + ":") html.close_td() html.open_td() html.text_input("probes", str(self._settings.probes), size=2, cssclass="number") html.close_td() html.close_tr() html.open_tr() html.open_td() html.write_text(_("Maximum distance (TTL) to gateway") + ":") html.close_td() html.open_td() html.text_input("max_ttl", str(self._settings.max_ttl), size=2, cssclass="number") html.close_td() html.close_tr() html.open_tr() html.open_td() html.write_text(_("Number of PING probes") + ":") html.help( _( "After a gateway has been found, Check_MK checks if it is reachable " "via PING. If not, it is skipped and the next gateway nearer to the " "monitoring core is being tried. You can disable this check by setting " "the number of PING probes to 0." ) ) html.close_td() html.open_td() html.text_input("ping_probes", str(self._settings.ping_probes), size=2, cssclass="number") html.close_td() html.close_tr() html.close_table() # Configuring parent forms.section(_("Configuration")) html.checkbox( "force_explicit", deflt=self._settings.force_explicit, label=_( "Force explicit setting for parents even if setting matches that of the folder" ), ) # Gateway creation forms.section(_("Creation of gateway hosts")) html.write_text(_("Create gateway hosts in")) html.open_ul() html.radiobutton( "where", "subfolder", self._settings.where == "subfolder", _("in the subfolder <b>%s/Parents</b>") % Folder.current_disk_folder().title(), ) html.br() html.radiobutton( "where", "here", self._settings.where == "here", _("directly in the folder <b>%s</b>") % Folder.current_disk_folder().title(), ) html.br() html.radiobutton( "where", "there", self._settings.where == "there", _("in the same folder as the host") ) html.br() html.radiobutton( "where", "nowhere", self._settings.where == "nowhere", _("do not create gateway hosts") ) html.close_ul() html.write_text(_("Alias for created gateway hosts") + ": ") html.text_input("alias", default_value=self._settings.alias) forms.end() # Start button html.button("_start", _("Start")) html.hidden_fields() html.end_form()
def page(self): search = get_search_expression() html.begin_form("role", method="POST") # ID forms.header(_("Basic properties"), css="wide") forms.section(_("Internal ID"), simple="builtin" in self._role, is_required=True) if self._role.get("builtin"): html.write_text("%s (%s)" % (self._role_id, _("builtin role"))) html.hidden_field("id", self._role_id) else: html.text_input("id", self._role_id) html.set_focus("id") # Alias forms.section(_("Alias")) html.help(_("An alias or description of the role")) html.text_input("alias", self._role.get("alias", ""), size=50) # Based on if not self._role.get("builtin"): forms.section(_("Based on role")) html.help( _( "Each user defined role is based on one of the builtin roles. " "When created it will start with all permissions of that role. When due to a software " "update or installation of an addons new permissions appear, the user role will get or " "not get those new permissions based on the default settings of the builtin role it's " "based on." ) ) role_choices: Choices = [ (i, r["alias"]) for i, r in self._roles.items() if r.get("builtin") ] html.dropdown( "basedon", role_choices, deflt=self._role.get("basedon", "user"), ordered=True ) forms.end() html.h2(_("Permissions")) # Permissions base_role_id = self._role.get("basedon", self._role_id) html.help( _( "When you leave the permissions at "default" then they get their " "settings from the factory defaults (for builtin roles) or from the " "factory default of their base role (for user define roles). Factory defaults " "may change due to software updates. When choosing another base role, all " "permissions that are on default will reflect the new base role." ) ) for section in permission_section_registry.get_sorted_sections(): # Now filter by the optional search term filtered_perms = [] for perm in permission_registry.get_sorted_permissions(section): if search and ( search not in perm.title.lower() and search not in perm.name.lower() ): continue filtered_perms.append(perm) if not filtered_perms: continue forms.header(section.title, isopen=search is not None, css="wide") for perm in filtered_perms: forms.section(perm.title) pvalue = self._role["permissions"].get(perm.name) def_value = base_role_id in perm.defaults choices: Choices = [ ("yes", _("yes")), ("no", _("no")), ("default", _("default (%s)") % (def_value and _("yes") or _("no"))), ] deflt = {True: "yes", False: "no"}.get(pvalue, "default") html.dropdown("perm_" + perm.name, choices, deflt=deflt, style="width: 130px;") html.help(perm.description) forms.end() html.hidden_fields() html.end_form()
def render_input(self, varprefix: str, value: Optional[str]) -> None: if value is None: value = "" html.text_input(varprefix + "attr_" + self.name(), value, size=self._size)
def display(self, value: FilterHTTPVariables) -> None: html.write_text(_("Min. Version:")) html.text_input(self.htmlvars[0], default_value=value.get(self.htmlvars[0], ""), size=7) html.write_text(" ") html.write_text(_("Max. Version:")) html.text_input(self.htmlvars[1], default_value=value.get(self.htmlvars[1], ""), size=7)