Skip to content

Commit

Permalink
jinja template WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberbuff committed Aug 27, 2024
1 parent 04d3f8f commit 99e7252
Show file tree
Hide file tree
Showing 524 changed files with 892 additions and 61,264 deletions.
175 changes: 20 additions & 155 deletions bin/jinja2_templates/rmm.md.j2
Original file line number Diff line number Diff line change
@@ -1,170 +1,40 @@
+++
---
description = "{{ rmm.Description | clean_multiline }}"
title = "{{ rmm.Name }}"
weight = 10
displayTitle = "{{ rmm.Name }}"
+++
---

{% raw %}
{{< block "grid-1" >}}
{{< column "mt-2 pt-1">}}
{% endraw %}

# {{ rmm.Name }}

{% if rmm.Category %}
**Category**: {{ rmm.Category }}
{% endif %}
import {Card, Badges, Details, PEMetadata, DiskArtifacts, EventLogTable, RegistryTable} from "../../components/card";
import {EuiSpacer} from "@elastic/eui"

### Description
# {{ rmm.Name }}

{{ rmm.Description }}

{% if rmm.Author %}
**Author**: {{ rmm.Author }}
{% endif %}

{% if rmm.Created %}
**Created**: {{ rmm.Created }}
{% endif %}

{% if rmm.LastModified %}
**Last Modified**: {{ rmm.LastModified }}
{% endif %}

{% if rmm.Details %}
### Details
<Details author={"{{rmm.Author}}"}
website={"{{rmm.Website}}"}
created={"{{rmm.Created}}"}
lastModified={"{{rmm.LastModified}}"}
privileges={"{{rmm.Details.Privileges}}"}
pricing={"{{rmm.Details.Pricing}}"}
category={"{{rmm.Category}}"}
verification={"{{rmm.Details.Verification}}"}
/>

{% if rmm.Details.Website %}
- **Website**: [{{ rmm.Details.Website }}]({{ rmm.Details.Website }})
{% endif %}

{% if rmm.Details.PEMetadata %}
#### PE Metadata
{% if rmm.Details.PEMetadata is mapping %}
{% for key, value in rmm.Details.PEMetadata.items() %}
- **{{ key }}**: {{ value }}
{% endfor %}
{% else %}
{% for item in rmm.Details.PEMetadata %}
{% for key, value in item.items() %}
- **{{ key }}**: {{ value }}
{% endfor %}
{% endfor %}
{% endif %}
{% endif %}

{% if rmm.Details.Privileges %}
- **Privileges**: {{ rmm.Details.Privileges }}
{% endif %}

{% if rmm.Details.Free is not none %}
- **Free**: {{ "Yes" if rmm.Details.Free else "No" }}
{% endif %}

{% if rmm.Details.Verification is not none %}
- **Verification**: {{ "Yes" if rmm.Details.Verification else "No" }}
{% if rmm.Details.InstallationPaths %}
#### Installation Paths
<Card code={"{{"\\n".join(rmm.Details.InstallationPaths)}}"}/>
{% endif %}

{% if rmm.Details.SupportedOS %}
#### Supported Operating Systems
{% for os in rmm.Details.SupportedOS %}
- {{ os }}
{% endfor %}
#### Supported OS
<Badges color="warning" badges={ {{dump(rmm.Details.SupportedOS)}} }/>
{% endif %}

{% if rmm.Details.Capabilities %}
#### Capabilities
{% for capability in rmm.Details.Capabilities %}
- {{ capability }}
{% endfor %}
{% endif %}

{% if rmm.Details.Vulnerabilities %}
#### Known Vulnerabilities
{% for vulnerability in rmm.Details.Vulnerabilities %}
- [{{ vulnerability }}]({{ vulnerability }})
{% endfor %}
{% endif %}

{% if rmm.Details.InstallationPaths %}
#### Installation Paths
{% for path in rmm.Details.InstallationPaths %}
- `{{ path }}`
{% endfor %}
{% endif %}
{% endif %}

{% if rmm.Artifacts %}
### Forensic Artifacts

{% if rmm.Artifacts.Disk %}
#### Disk Artifacts
{% for artifact in rmm.Artifacts.Disk %}
- **File**: `{{ artifact.File }}`
{% if artifact.Description %}
**Description**: {{ artifact.Description }}
{% endif %}
{% if artifact.Example %}
**Example**:
```
{{ artifact.Example }}
```
{% endif %}
{% if artifact.OS %}
**OS**: {{ artifact.OS }}
{% endif %}
{% endfor %}
{% endif %}

{% if rmm.Artifacts.EventLog %}
#### Event Log Artifacts
{% for artifact in rmm.Artifacts.EventLog %}
- Event Details:
{% for key, value in artifact.items() %}
- **{{ key }}**: {{ value }}
{% endfor %}
{% endfor %}
{% endif %}

{% if rmm.Artifacts.Registry %}
#### Registry Artifacts
{% for artifact in rmm.Artifacts.Registry %}
- **Path**: `{{ artifact.Path }}`
{% if artifact.Description %}
**Description**: {{ artifact.Description }}
{% endif %}
{% endfor %}
{% endif %}

{% if rmm.Artifacts.Network %}
#### Network Artifacts
{% for artifact in rmm.Artifacts.Network %}
- {% if artifact.Description %}**Description**: {{ artifact.Description }}{% endif %}
{% if artifact.Domains %}
**Domains**:
{% for domain in artifact.Domains %}
- `{{ domain }}`
{% endfor %}
{% endif %}
{% if artifact.Ports %}
**Ports**:
{% for port in artifact.Ports %}
- `{{ port }}`
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

{% if rmm.Artifacts.Other %}
#### Other Artifacts
{% for artifact in rmm.Artifacts.Other %}
- {% if artifact.Type %}**Type**: {{ artifact.Type }}{% endif %}
{% if artifact.Value %}
**Value**: {{ artifact.Value }}
{% endif %}
{% endfor %}
{% endif %}
<Badges color="#FFA500" badges={ {{dump(rmm.Details.Capabilities)}} }/>
{% endif %}

{% if rmm.Detections %}
Expand Down Expand Up @@ -199,8 +69,3 @@ displayTitle = "{{ rmm.Name }}"
- {{ ack.Person }}{% if ack.Handle %} ({{ ack.Handle }}){% endif %}
{% endfor %}
{% endif %}

{% raw %}
{{< /column >}}
{{< /block >}}
{% endraw %}
29 changes: 15 additions & 14 deletions bin/site.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import csv

def write_rmm_tools_csv(rmm_tools, output_dir, VERBOSE):
output_file = os.path.join(output_dir, 'content', 'api', 'rmm_tools.csv')
output_file = os.path.join(output_dir, 'public', 'api', 'rmm_tools.csv')

header = ['Name', 'Category', 'Description', 'Author', 'Created', 'LastModified',
'Website', 'Filename', 'OriginalFileName', 'PEDescription', 'Product',
Expand Down Expand Up @@ -56,7 +56,7 @@ def write_rmm_tools_csv(rmm_tools, output_dir, VERBOSE):
writer.writerow(row)

def write_rmm_tools_table_csv(rmm_tools, output_dir, VERBOSE):
output_file = os.path.join(output_dir, 'content', 'rmm_tools_table.csv')
output_file = os.path.join(output_dir, 'public', 'rmm_tools_table.csv')

header = ['Name', 'Category', 'Description', 'Author']

Expand Down Expand Up @@ -112,37 +112,38 @@ def clean_multiline(text):
return text

j2_env.filters['clean_multiline'] = clean_multiline
j2_env.globals.update(dump=json.dumps)

d = datetime.datetime.now()
template = j2_env.get_template('rmm.md.j2')
for rmm_tool in rmm_tools:
# Replace parentheses with underscores in the file name
file_name = f"{rmm_tool['Name'].lower().replace(' ', '_').replace('(', '_').replace(')', '_')}.md"
output_path = os.path.join(OUTPUT_DIR, 'content', 'rmm_tools', file_name)
file_name = f"{rmm_tool['Name'].lower().replace(' ', '_').replace('(', '_').replace(')', '_')}.mdx"
output_path = os.path.join(OUTPUT_DIR, 'pages', 'tools', file_name)
output = template.render(rmm=rmm_tool, time=str(d.strftime("%Y-%m-%d")))
with open(output_path, 'w', encoding="utf-8") as f:
f.write(output)
messages.append(f"site_gen.py wrote {len(rmm_tools)} RMM tools markdown to: {os.path.join(OUTPUT_DIR, 'content', 'rmm_tools')}")
messages.append(f"site_gen.py wrote {len(rmm_tools)} RMM tools markdown to: {os.path.join(OUTPUT_DIR, 'pages', 'tools')}")

# Write API CSV
write_rmm_tools_csv(rmm_tools, OUTPUT_DIR, VERBOSE)
messages.append(f"site_gen.py wrote RMM tools CSV to: {os.path.join(OUTPUT_DIR, 'content', 'api', 'rmm_tools.csv')}")
messages.append(f"site_gen.py wrote RMM tools CSV to: {os.path.join(OUTPUT_DIR, 'public', 'api', 'rmm_tools.csv')}")

# Write API JSON
with open(os.path.join(OUTPUT_DIR, 'content', 'api', 'rmm_tools.json'), 'w', encoding='utf-8') as f:
with open(os.path.join(OUTPUT_DIR, 'public', 'api', 'rmm_tools.json'), 'w', encoding='utf-8') as f:
json.dump(rmm_tools, f, ensure_ascii=False, indent=4)
messages.append(f"site_gen.py wrote RMM tools JSON to: {os.path.join(OUTPUT_DIR, 'content', 'api', 'rmm_tools.json')}")
messages.append(f"site_gen.py wrote RMM tools JSON to: {os.path.join(OUTPUT_DIR, 'public', 'api', 'rmm_tools.json')}")

# Write RMM tools table CSV
write_rmm_tools_table_csv(rmm_tools, OUTPUT_DIR, VERBOSE)
messages.append(f"site_gen.py wrote RMM tools table CSV to: {os.path.join(OUTPUT_DIR, 'content', 'rmm_tools_table.csv')}")
messages.append(f"site_gen.py wrote RMM tools table CSV to: {os.path.join(OUTPUT_DIR, 'public' , 'rmm_tools_table.csv')}")

return rmm_tools, messages

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generates LOLRMM site", epilog="This tool converts all LOLRMM YAMLs and builds the site with all the supporting components.")
parser.add_argument("-p", "--path", required=False, default="yaml", help="path to LOLRMM yaml folder. Defaults to `yaml`")
parser.add_argument("-o", "--output", required=False, default="lolrmm.com", help="path to the output directory for the site, defaults to `lolrmm.io`")
parser.add_argument("-o", "--output", required=False, default="website", help="path to the output directory for the site, defaults to `lolrmm.io`")
parser.add_argument("-v", "--verbose", required=False, default=False, action='store_true', help="prints verbose output")

args = parser.parse_args()
Expand All @@ -153,11 +154,11 @@ def clean_multiline(text):
TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), 'jinja2_templates')

if VERBOSE:
print(f"Wiping the {os.path.join(OUTPUT_DIR, 'content', 'rmm_tools')} folder")
print(f"Wiping the {os.path.join(OUTPUT_DIR, 'pages', 'tools')} folder")

# Clean up old RMM tool files
try:
rmm_tools_dir = os.path.join(OUTPUT_DIR, 'content', 'rmm_tools')
rmm_tools_dir = os.path.join(OUTPUT_DIR, 'pages', 'tools')
for file in os.listdir(rmm_tools_dir):
if file.endswith(".md") and file != '_index.md':
os.remove(os.path.join(rmm_tools_dir, file))
Expand All @@ -166,8 +167,8 @@ def clean_multiline(text):
sys.exit(1)

# Clean up API artifacts
api_json = os.path.join(OUTPUT_DIR, 'content', 'api', 'rmm_tools.json')
api_csv = os.path.join(OUTPUT_DIR, 'content', 'api', 'rmm_tools.csv')
api_json = os.path.join(OUTPUT_DIR, 'public', 'api', 'rmm_tools.json')
api_csv = os.path.join(OUTPUT_DIR, 'public', 'api', 'rmm_tools.csv')
if os.path.exists(api_json):
os.remove(api_json)
if os.path.exists(api_csv):
Expand Down
3 changes: 0 additions & 3 deletions lolrmm.com/.gitignore

This file was deleted.

Empty file removed lolrmm.com/.gitmodules
Empty file.
Empty file removed lolrmm.com/.hugo_build.lock
Empty file.
Loading

0 comments on commit 99e7252

Please sign in to comment.