 {% set check_tags = ["permanent", "inherent", "n_a", "not_applicable"] %}
{% set additional_info = rule | get_nested(["platforms", rule.os_type, "enforcement_info", "fix", "additional_info"]) %}
{% set check_shell = rule | get_nested(["platforms", rule.os_type, "enforcement_info", "check", "shell"]) %}
{% set fix_shell = rule | get_nested(["platforms", rule.os_type, "enforcement_info", "fix", "shell"]) %}
{% if not markdown_tree | default(false) %}

### {{ rule.title }}

{% endif %}
{% if rule.tags is defined or rule.tags is not none and "supplemental" in rule.tags %}
{{ rule.discussion | include_replace | asciidoc_to_markdown }}
{% else %}
{{ rule.discussion | asciidoc_to_markdown }}
{% endif %}

{%- if rule.mechanism == "manual" %}
> **NOTE**: {% trans %} This rule is marked as manual and may not be able to be automated. It is also excluded in the compliance scan and will not report any results. {% endtrans %}
{% endif -%}

{% if not rule.tags | select('in', check_tags) | list %}
{% if rule.tags is not defined or rule.tags is none or "supplemental" not in rule.tags %}
{% if rule.os_type.lower() in NIX_OS %}
{% if markdown_tree | default(false) %}
## {% trans %}Check{% endtrans %}

{% endif %}

{% trans %}To check the state of the system, run the following command(s){% endtrans %}:

```bash
{{ rule.enforcement_info.check.shell | replace("\\\\", "\\") | replace('\\"', '"') | trim | safe }}
```
{% else %}
{{ rule.enforcement_info.check.additional_info if rule.enforcement_info.check.additional_info is not none }}
{% endif %}

{% if rule.os_type.lower() in NIX_OS %}
{% trans %}If the result is not{% endtrans %} _{{ rule.result_value }}_, {% trans %}this is a finding{% endtrans %}.
{% endif %}

{% if markdown_tree | default(false) %}
## {% trans %}Remediation Description{% endtrans %}

{% if rule.enforcement_info.fix is not none %}
{% trans %}Perform the following to configure the system to meet the requirements{% endtrans %}:
{% endif %}

{% if rule.enforcement_info.fix.shell %}
{% trans %}Run the following command(s){% endtrans %}:

```bash
{{ rule.enforcement_info.fix.shell if rule.enforcement_info.fix.shell is not none else rule.enforcement_info.fix.shell }}
```

{% elif rule.mobileconfig_info is not none and rule.enforcement_info.fix.shell %}
{% if rule.enforcement_info.fix.shell %}
```bash
{{ rule.enforcement_info.fix.shell -}}
```
{% endif %}

{% if rule.mobileconfig_info %}
```xml
{{ rule.mobileconfig_info | mobileconfig_payloads_to_xml -}}
```
{% endif %}
{% else %}
{% if rule.os_name == "macos" %}
{{ rule.enforcement_info.fix.shell | asciidoc_to_markdown }}
{% elif rule.mobileconfig_info %}
{% trans %}Deploy a configuration profile containing the following payload.{% endtrans %}

```xml
{{ rule.mobileconfig_info | mobileconfig_payloads_to_xml -}}
```
{% endif %}
{% endif %}
{% if rule.enforcement_info.fix.additional_info %}
{{ rule.enforcement_info.fix.additional_info | asciidoc_to_markdown}}
{% endif %}

## {% trans %}References{% endtrans %}

| | |
|---|---|
| **ID** | `{{ rule.rule_id }}` |
{% if rule.severity is not none %}
| **Severity** | {{ rule.severity }} |
{% endif %}
| **800-53r5** | {{ rule.references.nist.nist_800_53r5 | group_ulify if rule.references.nist.nist_800_53r5 is not none }} |
{% if "800-171" in baseline.title | upper or show_all_tags %}
| **800-171r3** | {{ rule.references.nist.nist_800_171r3 | render_rules if rule.references.nist.nist_800_171r3 is not none }} |
{% endif %}
{% if "STIG" in baseline.title | upper or show_all_tags %}
| **DISA STIG(s)** | {{ rule.references.disa.disa_stig | render_rules if rule.references.disa.disa_stig is not none }} |
{% if rule.references.disa.sfr is not none %}
| **SFR** | {{ rule.references.disa.sfr | render_rules if rule.references.disa.sfr is not none }} |
{% endif %}
{% endif %}
{% if "CIS" in baseline.title | upper or show_all_tags %}
| **CIS Benchmark** | {{ rule.references.cis.benchmark | render_rules if rule.references.cis.benchmark is not none }} |
| **CIS Controls V8** | {{ rule.references.cis.controls_v8 | render_rules if rule.references.cis.controls_v8 is not none }} |
{% endif %}
{% if "INDIGO" in baseline.title | upper or show_all_tags %}
| **indigo** | {{ rule.references.bsi.indigo | render_rules if rule.references.bsi.indigo is not none }} |
{% endif %}
{% if "CMMC" in baseline.title | upper or show_all_tags %}
| **CMMC** | {{ rule.references.disa.cmmc | render_rules if rule.references.disa.cmmc is not none }} |
{% endif %}
{% if "HICP_LP" in baseline.title | upper or show_all_tags %}
| **HICP** | {{ rule.references.hhs.hicp | render_rules if rule.references.hhs.hicp is not none }} |
{% endif %}
{% if rule.references.nist.cce is not none %}
| **CCE** | {{ rule.references.nist.cce | render_rules }} |
{% endif %}
{% if "references" in rule.customized %}
| **Custom References** | {{ rule.references.custom_refs.references | render_references if rule.references.custom_refs is not none }} |
{% endif %}
{% if show_all_tags %}
| **TAGS** | {{ rule.tags | render_rules }} |
{% endif %}
{% else %}
<table class="remediation">
<tr>
<td>
<p>
<strong>{% trans %}Remediation Description{% endtrans %}</strong><br /><br />

{% if rule.enforcement_info.fix is not none %}
{% trans %}Perform the following to configure the system to meet the requirements{% endtrans %}:
{% endif %}

{% if rule.enforcement_info.fix.shell %}
{% trans %}Run the following command(s){% endtrans %}:

```bash
{{ rule.enforcement_info.fix.shell if rule.enforcement_info.fix.shell is not none else rule.enforcement_info.fix.shell }}
```

{% elif rule.mobileconfig_info is not none and rule.enforcement_info.fix.shell %}
{% if rule.enforcement_info.fix.shell %}
```bash
{{ rule.enforcement_info.fix.shell -}}
```
{% endif %}

{% if rule.mobileconfig_info %}
```xml
{{ rule.mobileconfig_info | mobileconfig_payloads_to_xml -}}
```
{% endif %}
{% else %}
{% if rule.os_name == "macos" %}
{{ rule.enforcement_info.fix.shell | asciidoc_to_markdown }}
{% elif rule.mobileconfig_info %}
{% trans %}Deploy a configuration profile containing the following payload.{% endtrans %}

```xml
{{ rule.mobileconfig_info | mobileconfig_payloads_to_xml -}}
```
{% endif %}
{% endif %}
{% if rule.enforcement_info.fix.additional_info %}
{{ rule.enforcement_info.fix.additional_info | asciidoc_to_markdown}}
{% endif %}

</p>
</td>
</tr>
</table>
{% endif %}

{% if not markdown_tree | default(false) %}
<table class="outer-table" border="1">
  <tr>
    <td> ID </td>
    {% if rule.severity is not none %}
    <td>{{ rule.rule_id }}<br />{{ rule.severity }}</td>
    {% else %}
    <td>{{ rule.rule_id }}</td>
    {% endif %}
  </tr>
  <tr>
    <td>{% trans %}References{% endtrans %}</td>
    <td>
      <table class="nested-table">
        <tr>
          <td><strong>800-53r5</strong></td>
          <td>{{ rule.references.nist.nist_800_53r5 | group_ulify if rule.references.nist.nist_800_53r5 is not none }}</td>
        </tr>
        {% if "800-171" in baseline.title | upper or show_all_tags %}
        <tr>
          <td><strong>800-171r3</strong></td>
          <td>{{ rule.references.nist.nist_800_171r3 | render_rules if rule.references.nist.nist_800_171r3 is not none }}</td>
        </tr>
        {% endif %}
        {% if "STIG" in baseline.title | upper or show_all_tags %}
        <tr>
          <td><strong>DISA STIG(s)</strong></td>
          <td>{{ rule.references.disa.disa_stig | render_rules if rule.references.disa.disa_stig is not none }}</td>
        </tr>
        {% if rule.references.disa.sfr is not none %}
        <tr>
          <td><strong>SFR</strong></td>
          <td>{{ rule.references.disa.sfr | render_rules if rule.references.disa.sfr is not none }}</td>
        </tr>
        {% endif %}
        {% endif %}
        {% if "CIS" in baseline.title | upper or show_all_tags %}
        <tr>
          <td><strong>CIS Benchmark</strong></td>
          <td>{{ rule.references.cis.benchmark | render_rules if rule.references.cis.benchmark is not none }}</td>
        </tr>
        <tr>
          <td><strong>CIS Controls V8</strong></td>
          <td>{{ rule.references.cis.controls_v8 | render_rules if rule.references.cis.controls_v8 is not none }}</td>
        </tr>
        {% endif %}
        {% if "INDIGO" in baseline.title | upper or show_all_tags %}
        <tr>
          <td><strong>indigo<strong></td>
          <td>{{ rule.references.bsi.indigo | render_rules if rule.references.bsi.indigo is not none }}</td>
        </tr>
        {% endif %}
        {% if "CMMC" in baseline.title | upper or show_all_tags %}
        <tr>
          <td><strong>CMMC</strong></td>
          <td>{{ rule.references.disa.cmmc | render_rules if rule.references.disa.cmmc is not none }}</td>
        </tr>
        {% endif %}
        {% if "HICP_LP" in baseline.title | upper or show_all_tags %}
        <tr>
          <td><strong>HICP</strong></td>
          <td>{{ rule.references.hhs.hicp | render_rules if rule.references.hhs.hicp is not none }}</td>
        </tr>
        {% endif %}
        {% if rule.references.nist.cce is not none %}
        <tr>
          <td><strong>CCE</strong></td>
          <td>{{ rule.references.nist.cce | render_rules }}</td>
        </tr>
        {% endif %}
        {% if "references" in rule.customized %}
        <tr>
          <td><strong>Custom References</strong></td>
          <td>{{ rule.references.custom_refs.references | render_references if rule.references.custom_refs is not none }}</td>
        </tr>
        {% endif %}
        {% if show_all_tags %}
        <tr>
          <td><strong>TAGS</strong></td>
          <td>{{ rule.tags | render_rules }}</td>
        </tr>
        {% endif %}
      </table>
    </td>
  </tr>
</table>
{% endif %}
{% endif %}
{% endif %}
