{#- ---------------------------------------------------------------------------- Macro for rendering of dropdown submenus. Entries in the menus are automatically hidden based on the permissions of the current user. ----------------------------------------------------------------------------- #} {%- macro render_dropdown_submenus(submenus, align_right) -%} {% endmacro %} {#- ---------------------------------------------------------------------------- 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_endpoint_link(endpoint_name, params = {}, label = False, css_class = '', with_icon = False) %} {%- set tmp_endpoint_class = get_endpoint_class(endpoint_name, quiet = True) %} {%- if tmp_endpoint_class %} {% if with_icon %}{{ get_icon(tmp_endpoint_class.get_view_icon()) }} {% endif %}{% if label %}{{ label }}{% else %}{{ tmp_endpoint_class.get_menu_title(**params) }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_view_buttons(endpoint_names, btn_size = 'sm', 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_p, dt_from_p, tiid) %} {%- if dt_from_p %} {%- set qparams = make_copy_deep(qparams_p) %} {%- set dt_from = make_copy_deep(dt_from_p) %} {%- 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 %} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the locale switcher widget. ----------------------------------------------------------------------------- #} {%- macro render_locale_switcher() %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering various usefull widgets. ----------------------------------------------------------------------------- #} {%- macro render_alert(alert_level, dismissible = True, forceicon = None) %} {%- if alert_level == 'error' %} {%- set alert_level = 'danger' %} {% elif alert_level == 'message' %} {%- set alert_level = 'info' %} {%- endif %}
{%- if dismissible %} {%- endif %} {%- if forceicon %} {{ get_icon(forceicon) }} {%- else %} {{ get_icon('alert-' + alert_level) }} {%- endif %} {{ caller() }}
{%- endmacro %} {%- macro render_help_popover(title, helptext, btn_size = 'sm', 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 render_sorter(endpoint, qparams, sortname) %} {%- set origsort = qparams.get('sortby', None) %} {%- set x = qparams.__setitem__('sortby', '{}.desc'.format(sortname)) -%}{{ get_icon('action-sort-desc') }}{%- set x = qparams.__setitem__('sortby', '{}.asc'.format(sortname)) -%}{{ get_icon('action-sort-asc') }} {%- set x = qparams.__setitem__('sortby', origsort) %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering raw view of item internals. ----------------------------------------------------------------------------- #} {%- macro render_timemarks(timemark_list, key = '', show_to_render_time=True) %} {%- set dur_ns = {} %} {%- if timemark_list %} {%- set total_duration = timemark_list[-1][0] - timemark_list[0][0] %} {%- endif %}

{% for time_mark in timemark_list %} {% endfor %}
{{ time_mark[3] }}:{{ time_mark[2] }}:{{ time_mark[1] }} {{ get_icon('clock') }}  {%- if loop.index0 != 0 %} {%- set time_mark_prev = timemark_list[loop.index0 - 1] %} {{ time_mark[0] - timemark_list[loop.index0 - 1][0] }} s  {{ babel_format_percent((time_mark[0] - time_mark_prev[0])/total_duration) }} {% endif %} {% if time_mark[2] == 'end' %} {%- set dur_key = '{}:begin:{}'.format(time_mark[3], time_mark[1]) %} {%- if dur_key in dur_ns and dur_ns[dur_key] != timemark_list[loop.index0 - 1][0] %} {{ time_mark[0] - dur_ns[dur_key] }} s  {{ babel_format_percent((time_mark[0] - dur_ns[dur_key])/total_duration) }} {%- endif %} {%- elif time_mark[2] == 'begin' %} {%- set dur_key = '{}:{}:{}'.format(time_mark[3], time_mark[2], time_mark[1]) %} {%- set _dummy = dur_ns.update({dur_key: time_mark[0]}) %} {%- endif %} {{ time_mark[4] }}

{{ _('Total duration') }}: {%- if timemark_list %}{{ total_duration }}{%- endif %}
{%- if show_to_render_time %} {{ _('Duration to rendering time') }}: {%- if timemark_list %}{{ get_datetime_utc() - timemark_list[0][0] }}{%- endif %}
{%- endif %}

{%- endmacro %} {%- macro render_sql_queries(query_list, key = '') %}

    {%- for q in query_list %}
  1. {% highlight 'sql' %}{{ q | wordwrap(140) }}{% endhighlight %}
  2. {%- endfor %}
{%- endmacro %} {%- macro render_raw_item_view(item) %}
{{ get_icon('debug') }} {{ _('Raw item') }}

{{ item | pprint }}
{{ item | pprint_item }}
{%- endmacro %} {%- macro render_raw_var(label, var) %}
{{ get_icon('debug') }} {{ _('Variable dump:') }} {{ label }}
{{ var | pprint }}
{{ var.__repr__() }}

{{ var.__str__() }}
{%- 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').capitalize() }}{% endif %} {%- elif report.type == 'extra' %} {{ get_icon('r-t-extra') }}{% if with_label %} {{ _('extra').capitalize() }}{% endif %} {%- elif report.type == 'target' %} {{ get_icon('r-t-target') }}{% if with_label %} {{ _('target').capitalize() }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_report_label_severity(report, with_label = False) %} {%- if report.severity == 'info' %} {{ get_icon('r-s-info') }}{% if with_label %} {{ _('info').capitalize() }}{% endif %} {%- elif report.severity == 'low' %} {{ get_icon('r-s-low') }}{% if with_label %} {{ _('low').capitalize() }}{% endif %} {%- elif report.severity == 'medium' %} {{ get_icon('r-s-medium') }}{% if with_label %} {{ _('medium').capitalize() }}{% endif %} {%- elif report.severity == 'high' %} {{ get_icon('r-s-high') }}{% if with_label %} {{ _('high').capitalize() }}{% endif %} {%- elif report.severity == 'critical' %} {{ get_icon('r-s-critical') }}{% if with_label %} {{ _('critical').capitalize() }}{% 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 %} {% macro render_popover(time, timezone_name) %} {{ format_datetime_wz(time, None, tz) }} ({{ item.structured_data['timezone'] }}) {% if tz != tz_utc -%}
{{ format_datetime(time, None, utc=True, rfc_complaint=False) }} {%- endif %} {% endmacro %} {% macro render_different_time_formats(time, timezone_name) %} {%- endmacro %} {% macro format_number(number, empty_value='---') -%} {% if number %}{{ number }}{% else %}{{ empty_value }}{% endif %} {%- endmacro %} {% macro report_table_header(report_type, default=None) -%} {%- if report_type != 'target' -%} {{ _('Source') }} {%- endif -%} {{ _('First event') }} {{ _('Last event') }} {{ _('Detectors') }} {{ _('Messages') }} {%- endmacro %} {% macro report_table_row(key, data, is_authenticated, report_type, default=None) -%} {% if is_authenticated and report_type != 'target' -%} {{ render_widget_csag_address([key]) }} {% elif report_type != 'target' -%} {{ key }} {% endif -%} {{ render_different_time_formats(data['first_time'], data['timezone']) }} {{ render_different_time_formats(data['last_time'], data['timezone']) }} {{ format_number(data['detectors_count']) }} {{ format_number(data['count']) }} {%- endmacro %} {%- macro report_header(item, menu, breadcrumbs_last) -%}
{%- if not unauth %} {%- endif %}

{{ item.label }}

{{ render_report_label_type(item, with_label = True) }} {{ render_report_label_severity(item, with_label = True) }} {{ render_report_label_weight(item) }} {%- if item.evcount_flt_blk %} {{ get_icon('report-data-filtered') }} {%- endif %} {%- if item.structured_data and item.structured_data.get("relapsed") %} {{ get_icon('report-data-relapsed') }} {%- endif %} {%- if item.flag_testdata %} {{ get_icon('report-data-test') }} {%- endif %} {%- if item.flag_mailed %} {{ get_icon('report-data-mailed') }} {%- endif %}
{%- if item.is_old_type() %} {%- call render_alert('warning', False) %} {{ _('This report is in the old format, so the displayed data might be incomplete. Please look at the data in JSON if necessary.') }} {%- endcall %} {%- endif %} {%- if item.flag_testdata %} {%- call render_alert('info', False, 'debug') %} {{ _('This report was generated from test data.') }} {%- endcall %} {%- endif %} {%- if not current_user.is_authenticated %} {%- call render_alert('warning', False) %} {{ _('You are currently viewing this report in unauthenticated mode. Please be aware, that additional functions are available only to authenticated users. Please login or register new account to use them.') }} {%- endcall %} {%- endif %}
{{ menu }}

{{ _('Unprotected access link') }}: {{ item.label }}

{%- if current_user.is_authenticated and item.parent %}

{{ _('Parent summary report') }}: {{ item.parent.label }}

{%- endif %}

{{ _('Group') }}: {%- for group in item.groups %} {%- if current_user.is_authenticated %} {%- if loop.index != 1 %},{%- endif %} {{ group.name }} {%- else %} {%- if loop.index != 1 %},{%- endif %} {{ group.name }} {%- endif %} {%- else %} --- {%- endfor %}

{{ _('Report window') }}: {{ babel_format_datetime(item.dt_from) }} - {{ babel_format_datetime(item.dt_to) }} ({{ babel_format_timedelta(item.delta) }})

{{ _('Report created') }}: {{ babel_format_datetime(item.createtime) }} ({{ _('%(delta)s ago', delta = babel_format_timedelta(current_datetime_utc - item.createtime)) }})

{{ _('Report mailed') }}: {% if item.flag_mailed %} {{ render_mailed(item, True) }} {% endif %}

{{ _('Event count') }}: {{ item.evcount_rep }} {{ _('reported') }}{% if item.type == 'summary' %} ({{ item.evcount_all }} {{ _('matched') }}, {{ item.evcount_new }} {{ _('new events') }}, {{ item.evcount_flt_blk }} {{ _('filtered out') }}, {{ item.evcount_det_blk if item.evcount_det_blk else 0 }} {{ _('uncredible') }}, {{ item.evcount_thr_blk }} {{ _('thresholded') }}, {{ item.evcount_rlp }} {{ _('relapsed') }}){% elif item.type != 'target' %}, {{ item.evcount_all }} {{ _('total in parent summary report') }}{% endif %}

{%- if item.filtering -%}

{{ _('Filtering') }}: {%- for subitem in item.filtering | dictsort %} {% if can_access_endpoint('filters.list', item) %} {{ subitem[0] }} {% else %} {{ subitem[0] }} {% endif %} {{ subitem[1] }} {% if not loop.last %},{% endif %} {%- endfor %}

{%- 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_mailed(item, replace_to_and_cc=False) -%} {{ babel_format_datetime(item.mail_dt) }} ({{ _('%(delta)s ago', delta = babel_format_timedelta(current_datetime_utc - item.mail_dt)) }}) {% if item.mail_to and replace_to_and_cc -%} {{ _('to') }} {{ item.mail_to | join(', ') | replace('to:', '') | replace('cc:', '') }} {%- elif item.mail_to and not replace_to_and_cc -%} {{ _('to') }} {{ item.mail_to | join(', ') }} {% 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, as_code = True, item_limit = 0, add_newline = False) %} {{ _render_widget_csag( 'ips', item_list, mark_list, align_right, separate_dropdown, without_label, as_code, 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_hostname(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False, as_code = True, item_limit = 0, add_newline = False) %} {{ _render_widget_csag( 'hostnames', item_list, mark_list, align_right, separate_dropdown, without_label, as_code, item_limit, _('-- undisclosed --'), 'undisclosed', add_newline ) }} {%- 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_simple(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False, item_limit = 0) %} {{ _render_widget_csag( 'severities', item_list, mark_list, align_right, separate_dropdown, without_label, False, item_limit ) }} {%- 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 == 'info' %} {%- set tmpcolor = 'btn-secondary' %} {%- set tmpicon = 'r-s-info' %} {%- elif 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-secondary' %} {%- set tmpicon = 'r-s-unknown' %} {%- endif %}
{%- endfor %} {%- else %} {{ get_icon('unassigned') }} {%- endif %} {%- endmacro %} {%- macro no_csag(item_list, mark_list = None, align_right = False, separate_dropdown = False, without_label = False, item_limit = 0, add_newline = False) %} {%- endmacro %} {%- macro render_widget_csag_any(csag_group, item_list) %} {%- if csag_group == 'abuses' %} {% set csag_macro = render_widget_csag_abuse %} {%- elif csag_group == 'ips' %} {% set csag_macro = render_widget_csag_address %} {%- elif csag_group == 'categories' %} {% set csag_macro = render_widget_csag_category %} {%- elif csag_group == 'classes' %} {% set csag_macro = render_widget_csag_class %} {%- elif csag_group == 'detectors' %} {% set csag_macro = render_widget_csag_detector %} {%- elif csag_group == 'detector_types' %} {% set csag_macro = render_widget_csag_detectortype %} {%- elif csag_group == 'hostnames' %} {% set csag_macro = render_widget_csag_hostname %} {%- elif csag_group == 'host_types' %} {% set csag_macro = render_widget_csag_hosttype %} {%- elif csag_group == 'ports' %} {% set csag_macro = render_widget_csag_port %} {%- elif csag_group == 'protocols' %} {% set csag_macro = render_widget_csag_protocol %} {%- elif csag_group == 'severities' %} {% set csag_macro = render_widget_csag_severity_simple %} {%- else %} {% set csag_macro = no_csag %} {%- endif %} {{ csag_macro(item_list, **kwargs) }} {%- 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 -%} {%- macro ref_to_html_link(ref) -%} {%- import '_macros.common.txt.j2' as macros_common -%} {%- set ref = decode_url(ref) -%} {%- if ref.startswith("cve") -%} {%- set cve = ref.split(":")[1] %} {{cve}} {%- elif ref.startswith("cvr:") -%} {# CESNET vulnerability report namespace Syntax: "cvr:ID" or "cvr:ID-item_index1,item_index2,item_index3..." (indexes start from 1) - "cvr:12-2,3" means report items 2 and 3 from report with ID 12 - "cvr:13" means all report items from report with ID 13 #} {%- set id = ref.split(":")[1].split("-")[0] %} {{ _('CESNET Vulnerability Report') }} (ID {{id}}) {%- elif macros_common.ref_to_link(ref).startswith("http") -%} {{ref}} {%- else -%} {{ref}} {%- endif -%} {%- endmacro -%}