{#- ---------------------------------------------------------------------------- Macro for rendering the main menu of the application. Entries in the menu are automatically hidden based on the permissions of the current user. ----------------------------------------------------------------------------- #} {%- macro render_menu_main() -%} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the authentication and anonymous submenus of the application. These menus get special handling. ----------------------------------------------------------------------------- #} {%- macro render_submenu_auth() -%} {%- if current_user.is_authenticated %} {%- else %} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the single view button. ----------------------------------------------------------------------------- #} {%- macro render_view_buttons(endpoint_names, btn_size = 'xs', with_title = False, css_class = '') %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the quicksearch dropdown. ----------------------------------------------------------------------------- #} {%- macro render_quicksearch(search_list) %} {%- if search_list %} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the time window pager. ----------------------------------------------------------------------------- #} {%- macro render_timepager(qparams, dt_from, tiid) %} {%- set dt_from = dt_from.replace(tzinfo = None) %} {%- set dt_to = get_datetime_window(tiid, 'next', dt_from) %} {%- if dt_from and dt_to %} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the locale switcher widget. ----------------------------------------------------------------------------- #} {%- macro render_locale_switcher() %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering various usefull widgets. ----------------------------------------------------------------------------- #} {%- macro render_alert(category, dismissible = True, forceicon = None) %} {%- if category == 'error' %} {%- set category = 'danger' %} {% elif category == 'message' %} {%- set category = 'info' %} {%- endif %}
{%- if dismissible %} {%- endif %} {%- if forceicon %} {{ get_icon(forceicon) }} {%- else %} {{ get_icon('alert-' + category) }} {%- endif %} {{ caller() }}
{%- endmacro %} {%- macro render_help_popover(title, helptext, btn_size = 'xs', placement = 'left') %} {{ get_icon('help') }} {%- endmacro %} {%- macro render_pager(endpoint, qparams, ii_low, ii_high, ii_limit) %} {%- set x = qparams.__setitem__('page', (qparams.get('page', 1) - 1)) %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering raw view of item internals. ----------------------------------------------------------------------------- #} {%- macro render_raw_item_view(item) %}

{{ get_icon('debug') }} {{ _('Raw item') }}


{{ item | pprint }}
{%- endmacro %} {%- macro render_raw_var(label, var) %}

{{ get_icon('debug') }} {{ _('Variable dump:') }} {{ label }}


{%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering event report related widgets. ----------------------------------------------------------------------------- #} {%- macro render_report_label_type(report, with_label = False) %} {%- if report.type == 'summary' %} {{ get_icon('r-t-summary') }}{% if with_label %} {{ _('summary') | upper }}{% endif %} {%- elif report.type == 'extra' %} {{ get_icon('r-t-extra') }}{% if with_label %} {{ _('extra') | upper }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_report_label_severity(report, with_label = False) %} {%- if report.severity == 'low' %} {{ get_icon('r-s-low') }}{% if with_label %} {{ _('low') | upper }}{% endif %} {%- elif report.severity == 'medium' %} {{ get_icon('r-s-medium') }}{% if with_label %} {{ _('medium') | upper }}{% endif %} {%- elif report.severity == 'high' %} {{ get_icon('r-s-high') }}{% if with_label %} {{ _('high') | upper }}{% endif %} {%- elif report.severity == 'critical' %} {{ get_icon('r-s-critical') }}{% if with_label %} {{ _('critical') | upper }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_report_label_weight(report) %} {%- if report.evcount_rep < 10 %} {{ get_icon('weight') }} {{ report.evcount_rep}} {%- elif report.evcount_rep < 100 %} {{ get_icon('weight') }} {{ report.evcount_rep}} {%- elif report.evcount_rep < 1000 %} {{ get_icon('weight') }} {{ report.evcount_rep}} {%- else %} {{ get_icon('weight') }} {{ report.evcount_rep}} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering event related widgets. ----------------------------------------------------------------------------- #} {%- macro render_info_timeinterval(lower, upper) -%} {%- if lower < upper -%} {{ _('%(delta)s ago', delta = babel_format_timedelta(upper - lower)) }} {%- else -%} {{ _('%(delta)s in future', delta = babel_format_timedelta(lower - upper)) }} {%- endif -%} {%- endmacro %} {%- macro render_event_label_severity(event, with_label = False) %} {%- set tmpval = event.get_severity() %} {%- if not tmpval or tmpval == 'unknown' %} {{ get_icon('r-s-unknown') }}{% if with_label %} {{ _(tmpval) | upper }}{% endif %} {%- elif tmpval == 'low' %} {{ get_icon('r-s-low') }}{% if with_label %} {{ _(tmpval) | upper }}{% endif %} {%- elif tmpval == 'medium' %} {{ get_icon('r-s-medium') }}{% if with_label %} {{ _(tmpval) | upper }}{% endif %} {%- elif tmpval == 'high' %} {{ get_icon('r-s-high') }}{% if with_label %} {{ _(tmpval) | upper }}{% endif %} {%- elif tmpval == 'critical' %} {{ get_icon('r-s-critical') }}{% if with_label %} {{ _(tmpval) | upper }}{% endif %} {%- endif %} {%- endmacro %} {#- Complex internal macro for rendering context search action dropdown menu for given group. Main use cases are rendering context action menus for values on event search result and event detail views. string csag_group: Name of the context search action group for which to render the widget. list item_list: List of items for which to generate the widgets. This macro can generate multiple witgets at once, which is very handy for example on event search result view. list mark_list: List of items, that should be highlighted. This is usefull for for example for highlighting search results within the result set. bool align_right: Align dropdown to the right instead of the default left. bool separate_dropdown: Generate dropdown separatelly from the label (use only caret for the button label). bool without_label: Generate widget without the label. bool as_code: Generate separate label inside HTML CODE tags. int item_limit: Limit number of items for which to generate the widgets. This feature is usefull for limiting number of displayed items in the result, for example for keeping the table columns in the result from bloating up. string empty_title: Title to be displayed in case the item_list is empty. string empty_icon: Icon to be displayed in case the item_list is empty. bool add_newline: Add newline after each widget. -#} {%- macro _render_widget_csag(csag_group, item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False, as_code = False, item_limit = 0, empty_title = _('-- unassigned --'), empty_icon = 'unassigned', add_newline = False) %} {%- if item_list -%} {%- set tmp_csag_list = get_csag(csag_group) -%} {%- for subitem in item_list -%} {#- Limit number of items from item_list for which to generate CSAG widget. -#} {%- if item_limit and loop.index > item_limit -%} {%- if loop.index0 == item_limit -%} ({{ _('%(count)s more', count = loop.length - loop.index0) }}) {%- endif -%} {%- else -%} {%- if separate_dropdown and not without_label %} {%- if as_code %}{%- endif %}{% if mark_list and subitem.__str__() in mark_list %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %}{%- if as_code %}{%- endif %} {%- endif -%}
{%- endif %} {%- if add_newline and not loop.last %}
{% endif %} {% endfor %} {%- else %} {{ get_icon(empty_icon) }} {%- endif %} {%- endmacro %} {%- macro render_widget_csag_abuse(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False) %} {{ _render_widget_csag( 'abuses', item_list, mark_list, align_right, separate_dropdown, without_label ) }} {%- endmacro %} {%- macro render_widget_csag_address(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False, item_limit = 0, add_newline = False) %} {{ _render_widget_csag( 'ips', item_list, mark_list, align_right, separate_dropdown, without_label, True, item_limit, _('-- undisclosed --'), 'undisclosed', add_newline ) }} {%- endmacro %} {%- macro render_widget_csag_category(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False) %} {{ _render_widget_csag( 'categories', item_list, mark_list, align_right, separate_dropdown, without_label ) }} {%- endmacro %} {%- macro render_widget_csag_class(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False) %} {{ _render_widget_csag( 'classes', item_list, mark_list, align_right, separate_dropdown, without_label ) }} {%- endmacro %} {%- macro render_widget_csag_detector(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False) %} {{ _render_widget_csag( 'detectors', item_list, mark_list, align_right, separate_dropdown, without_label ) }} {%- endmacro %} {%- macro render_widget_csag_detectortype(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False) %} {{ _render_widget_csag( 'detector_types', item_list, mark_list, align_right, separate_dropdown, without_label ) }} {%- endmacro %} {%- macro render_widget_csag_hosttype(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False) %} {{ _render_widget_csag( 'host_types', item_list, mark_list, align_right, separate_dropdown, without_label ) }} {%- endmacro %} {%- macro render_widget_csag_port(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False, item_limit = 0) %} {{ _render_widget_csag( 'ports', item_list, mark_list, align_right, separate_dropdown, without_label, True, item_limit, _('-- undisclosed --'), 'undisclosed' ) }} {%- endmacro %} {%- macro render_widget_csag_protocol(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False, item_limit = 0) %} {{ _render_widget_csag( 'protocols', item_list, mark_list, align_right, separate_dropdown, without_label, True, item_limit, _('-- undisclosed --'), 'undisclosed' ) }} {%- endmacro %} {%- macro render_widget_csag_severity(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False) %} {%- if item_list %} {%- for subitem in item_list %} {%- if separate_dropdown and not without_label %} {% if mark_list and subitem in mark_list %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- if subitem == 'low' %} {%- set tmpcolor = 'btn-info' %} {%- set tmpicon = 'r-s-low' %} {%- elif subitem == 'medium' %} {%- set tmpcolor = 'btn-primary' %} {%- set tmpicon = 'r-s-medium' %} {%- elif subitem == 'high' %} {%- set tmpcolor = 'btn-warning' %} {%- set tmpicon = 'r-s-high' %} {%- elif subitem == 'critical' %} {%- set tmpcolor = 'btn-danger' %} {%- set tmpicon = 'r-s-critical' %} {%- else %} {%- set tmpcolor = 'btn-default' %} {%- set tmpicon = 'r-s-unknown' %} {%- endif %}
{%- endfor %} {%- else %} {{ get_icon('unassigned') }} {%- endif %} {%- endmacro %} {%- macro render_label_item_state(state, with_label = False) %} {%- if state %} {{ get_icon('item-enabled') }}{% if with_label %} {{ _('Enabled') }}{% endif %} {%- else %} {{ get_icon('item-disabled') }}{% if with_label %} {{ _('Disabled') }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_labels_role_list(role_list, item, with_label = False) -%} {%- for role_name in role_list -%} {%- if item.has_role(role_name) -%} {{ get_icon('item-enabled') }} {{ role_name }} {{ get_icon('role-{}'.format(role_name)) }} {%- else -%} {{ get_icon('item-disabled') }} {{ role_name }} {{ get_icon('role-{}'.format(role_name)) }} {%- endif -%} {%- if not loop.last -%} {%- endif -%} {%- endfor -%} {%- endmacro -%}