Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML Export Support #1689

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/commands/convert/hdf2html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {Command, Flags} from '@oclif/core'
import fs from 'fs'
import path from 'path'
import {FromHDFToHTMLMapper as Mapper} from '@mitre/hdf-converters'

// All selectable export types for an HTML export
enum FileExportTypes {
Executive = 'Executive',
Manager = 'Manager',
Administrator = 'Administrator'
}

export default class HDF2HTML extends Command {
static usage = 'convert hdf2html -i <hdf-scan-results-json>... -o <output-html> [-h]'

static description = 'Translate an HDF file into a Heimdall Report HTML file'

static examples = ['saf convert hdf2html -i hdf_input.json -o report.html']

static flags = {
help: Flags.help({char: 'h'}),
input: Flags.string({char: 'i', required: true, multiple: true, description: 'Input HDF JSON file'}),
output: Flags.string({char: 'o', required: true, description: 'Output HTML file'}),
}

async run() {
const {flags} = await this.parse(HDF2HTML)

const files = []
for (const file of flags.input) {
// Create (somewhat) unique fileID for html reference
const idCore = path.basename(file).replace(' ', '-')
const idTail1 = Math.random() * 100
const idTail2 = Math.random() * 100

const data = fs.readFileSync(file, 'utf8')
const fileName = path.basename(file)
const fileID = `${idCore}-${idTail1}-${idTail2}`
files.push({data, fileName, fileID})
}

const converter = await new Mapper(files, FileExportTypes.Administrator).toHTML('/html/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add an input flag for report type rather than defaulting to Administrator?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

fs.writeFileSync(flags.output, converter)
}
}
31 changes: 31 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @type {import('tailwindcss').Config} */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unneeded imports

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HDF to HTML has been refactored to avoid needing tailwind on SAF CLI. Tailwind is all managed by hdf-converters's build system.


// Lookup constants
const fs = require("fs");

// Grabs template and dependencies for HTML export
const files = {
[require.resolve(
"@mitre/hdf-converters/src/converters-from-hdf/html/template.html"
)]: "src/commands/convert/html/template.html",
[require.resolve("tw-elements/dist/js/tw-elements.umd.min.js")]:
"src/commands/convert/html/tw-elements.min.js",
};
for (const file in files) {
fs.copyFile(file, files[file], (err) => {
if (err) {
throw err;
}
});
}

module.exports = {
content: [
"./src/commands/convert/html/template.html",
"./node_modules/tw-elements/dist/js/**/*.js",
],
theme: {
extend: {},
},
plugins: [require("tw-elements/dist/plugin.cjs")],
};
Loading