예제 #1
0
def show_create_view_dialog(next_url=None):
    vs_ds = DatasourceSelection()

    ds = "services"  # Default selection

    title = _("Create view")
    breadcrumb = visuals.visual_page_breadcrumb("views", title, "create")
    make_header(
        html,
        title,
        breadcrumb,
        make_simple_form_page_menu(
            _("View"),
            breadcrumb,
            form_name="create_view",
            button_name="_save",
            save_title=_("Continue"),
        ),
    )

    if request.var("_save") and transactions.check_transaction():
        try:
            ds = vs_ds.from_html_vars("ds")
            vs_ds.validate_value(ds, "ds")

            if not next_url:
                next_url = makeuri(
                    request,
                    [("datasource", ds)],
                    filename="create_view_infos.py",
                )
            else:
                next_url = next_url + "&datasource=%s" % ds
            raise HTTPRedirect(next_url)
        except MKUserError as e:
            html.user_error(e)

    html.begin_form("create_view")
    html.hidden_field("mode", "create")

    forms.header(_("Select Datasource"))
    forms.section(vs_ds.title())
    vs_ds.render_input("ds", ds)
    html.help(vs_ds.help())
    forms.end()

    html.hidden_fields()
    html.end_form()
    html.footer()
예제 #2
0
파일: werks.py 프로젝트: LinuxHaus/checkmk
def _werk_table_options_from_request() -> Dict[str, Any]:
    if request.var("show_unack") and not request.has_var("wo_set"):
        return _default_werk_table_options()

    werk_table_options: Dict[str, Any] = {}
    for name, _height, vs, default_value in _werk_table_option_entries():
        value = default_value
        try:
            if request.has_var("wo_set"):
                value = vs.from_html_vars("wo_" + name)
                vs.validate_value(value, "wo_" + name)
        except MKUserError as e:
            html.user_error(e)

        werk_table_options.setdefault(name, value)

    from_date, until_date = Timerange.compute_range(
        werk_table_options["date"]).range
    werk_table_options["date_range"] = from_date, until_date

    return werk_table_options
예제 #3
0
    def page(self) -> cmk.gui.pages.PageResult:
        """Renders an iframe to view the content of the RobotMK log file"""
        site_id, host_name, service_description = _get_mandatory_request_vars()

        breadcrumb: Breadcrumb = make_service_breadcrumb(
            HostName(host_name), service_description)
        title = self._title() + _(" of service %s on host %s") % (
            service_description, host_name)
        try:
            content = _get_html_from_livestatus(self._report_type(), site_id,
                                                host_name, service_description)
        except MKLivestatusNotFoundError:
            make_header(
                html,
                title=title,
                breadcrumb=breadcrumb,
            )
            html.user_error(
                MKUserError(None,
                            _("You are not permitted to view this page")))
            return

        if not content[0]:
            make_header(
                html,
                title=title,
                breadcrumb=breadcrumb,
            )
            html.user_error(MKUserError(None, _("No logs could be found.")))
            return

        # Only render page menu with download option if content is not empty
        # and user is permitted
        make_header(
            html,
            title=title,
            breadcrumb=breadcrumb,
            page_menu=self._page_menu(breadcrumb, site_id, host_name,
                                      service_description),
        )

        iframe: str = self._report_type()
        html.iframe(
            content="",
            src=makeuri_contextless(
                request,
                [
                    ("report_type", self._report_type()),
                    ("site", site_id),
                    ("host", host_name),
                    ("service", service_description),
                ],
                filename="robotmk_report.py",
            ),
            name="%s_report" % self._report_type(),
            id_=iframe,
        )

        html.javascript('cmk.utils.content_scrollbar("main_page_content");')
        html.javascript(
            "cmk.utils.add_height_to_simple_bar_content_of_iframe(%s);" %
            json.dumps(iframe))
예제 #4
0
def test_user_error(request_context):
    with output_funnel.plugged():
        html.user_error(
            MKUserError(None, "asd <script>alert(1)</script> <br> <b>"))
        c = output_funnel.drain()
    assert c == '<div class="error">asd &lt;script&gt;alert(1)&lt;/script&gt; <br> <b></div>'
예제 #5
0
파일: mobile.py 프로젝트: LinuxHaus/checkmk
    def render(
        self,
        rows: Rows,
        show_checkboxes: bool,
        num_columns: int,
        show_filters: List[Filter],
        unfiltered_amount_of_rows: int,
    ) -> None:
        view_spec = self.view.spec
        home = ("mobile.py", "Home", "home")

        page = request.var("page")
        if not page:
            if view_spec.get("mustsearch"):
                page = "filter"
            else:
                page = "data"

        title = views.view_title(self.view.spec, self.view.context)
        navbar = [
            ("data", _("Results"), "grid", "results_button"),
            ("filter", _("Filter"), "search", ""),
        ]
        if user.may("general.act"):
            navbar.append(("commands", _("Commands"), "gear", ""))

        # Should we show a page with context links?
        context_links = list(
            views.collect_context_links(self.view, rows, mobile=True, visual_types=["views"])
        )

        if context_links:
            navbar.append(("context", _("Context"), "arrow-r", ""))
        page_id = "view_" + view_spec["name"]

        if page == "filter":
            jqm_page_header(_("Filter / Search"), left_button=home, id_="filter")
            _show_filter_form(show_filters, self.view.context)
            jqm_page_navfooter(navbar, "filter", page_id)

        elif page == "commands":
            # Page: Commands
            if user.may("general.act"):
                jqm_page_header(_("Commands"), left_button=home, id_="commands")
                show_commands = True
                if request.has_var("_do_actions"):
                    try:
                        show_commands = do_commands(self.view.datasource.infos[0], rows)
                    except MKUserError as e:
                        html.user_error(e)
                        show_commands = True
                if show_commands:
                    _show_command_form(self.view.datasource, rows)
                jqm_page_navfooter(navbar, "commands", page_id)

        elif page == "data":
            # Page: data rows of view
            jqm_page_header(
                title,
                left_button=home,
                right_button=("javascript:document.location.reload();", _("Reload"), "refresh"),
                id_="data",
            )
            html.open_div(id_="view_results")
            if len(rows) == 0:
                html.write_text(_("No hosts/services found."))
            else:
                try:
                    if cmk.gui.view_utils.row_limit_exceeded(
                        unfiltered_amount_of_rows, self.view.row_limit
                    ):
                        cmk.gui.view_utils.query_limit_exceeded_warn(self.view.row_limit, user)
                        del rows[self.view.row_limit :]
                    self.view.layout.render(
                        rows,
                        view_spec,
                        self.view.group_cells,
                        self.view.row_cells,
                        num_columns,
                        show_checkboxes and not html.do_actions(),
                    )
                except Exception as e:
                    logger.exception("error rendering mobile view")
                    html.write_text(_("Error showing view: %s") % e)
            html.close_div()
            jqm_page_navfooter(navbar, "data", page_id)

        # Page: Context buttons
        elif page == "context":
            jqm_page_header(_("Context"), left_button=home, id_="context")
            _show_context_links(context_links)
            jqm_page_navfooter(navbar, "context", page_id)