Skip to content

Commit

Permalink
feat: options to remove header and toc for html/mdd
Browse files Browse the repository at this point in the history
  • Loading branch information
vdjagilev committed Apr 20, 2024
1 parent f938530 commit ee7f568
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ func init() {
rootCmd.Flags().BoolVar(&config.OutputOptions.CSVOptions.SkipDownHosts, "csv-skip-down-hosts", true, "--csv-skip-down-hosts=false, would print all hosts that are offline in CSV output")
rootCmd.Flags().BoolVar(&config.OutputOptions.ExcelOptions.SkipDownHosts, "excel-skip-down-hosts", true, "--excel-skip-down-hosts=false, would print all hosts that are offline in Excel file")

// Skip header information (overall meta information from the scan)
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.SkipHeader, "html-skip-header", false, "--html-skip-header, skips header in HTML output")
rootCmd.Flags().BoolVar(&config.OutputOptions.MarkdownOptions.SkipHeader, "md-skip-header", false, "--md-skip-header, skips header in Markdown output")

// Skip table of contents (TOC) information
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.SkipTOC, "html-skip-toc", false, "--html-skip-toc, skips table of contents in HTML output")
rootCmd.Flags().BoolVar(&config.OutputOptions.MarkdownOptions.SkipTOC, "md-skip-toc", false, "--md-skip-toc, skips table of contents in Markdown output")

// Skip summary (overall meta information from the scan)
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.SkipSummary, "html-skip-summary", false, "--html-skip-summary=true, skips summary in HTML output")
rootCmd.Flags().BoolVar(&config.OutputOptions.MarkdownOptions.SkipSummary, "md-skip-summary", false, "--md-skip-summary=true, skips summary in Markdown output")
Expand Down
8 changes: 8 additions & 0 deletions formatter/output_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type OutputOptions struct {

// HTMLOutputOptions stores options related only to HTML conversion/formatting
type HTMLOutputOptions struct {
// SkipHeader skips the header of the HTML output
SkipHeader bool
// SkipTOC skips the table of contents in the HTML output
SkipTOC bool
// SkipDownHosts skips hosts that are down (including TOC)
SkipDownHosts bool
// SkipSummary skips general summary for HTML
Expand All @@ -31,6 +35,10 @@ type HTMLOutputOptions struct {

// MarkdownOutputOptions stores options related only to Markdown conversion/formatting
type MarkdownOutputOptions struct {
// SkipHeader skips the header
SkipHeader bool
// SkipTOC skips the table of contents
SkipTOC bool
// SkipDownHosts skips hosts that are down (including TOC)
SkipDownHosts bool
// SkipSummary skips general summary for Markdown
Expand Down
16 changes: 10 additions & 6 deletions formatter/resources/templates/markdown.tmpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{{- if not .OutputOptions.MarkdownOptions.SkipHeader -}}
NMAP Scan Result: {{ .NMAPRun.StartStr }}
==========================================
{{ $skipDownHosts := .OutputOptions.MarkdownOptions.SkipDownHosts }}
{{ $skipSummary := .OutputOptions.MarkdownOptions.SkipSummary }}
{{ $skipPortScripts := .OutputOptions.MarkdownOptions.SkipPortScripts }}
{{ $skipMetrics := .OutputOptions.MarkdownOptions.SkipMetrics }}
{{ $skipTraceroute := .OutputOptions.MarkdownOptions.SkipTraceroute }}

{{ end }}
{{- $skipTOC := .OutputOptions.MarkdownOptions.SkipTOC -}}
{{- $skipDownHosts := .OutputOptions.MarkdownOptions.SkipDownHosts -}}
{{- $skipSummary := .OutputOptions.MarkdownOptions.SkipSummary -}}
{{- $skipPortScripts := .OutputOptions.MarkdownOptions.SkipPortScripts -}}
{{- $skipMetrics := .OutputOptions.MarkdownOptions.SkipMetrics -}}
{{- $skipTraceroute := .OutputOptions.MarkdownOptions.SkipTraceroute -}}
{{ if not $skipTOC -}}
## TOC

{{ if not $skipSummary }}
Expand All @@ -16,6 +19,7 @@ NMAP Scan Result: {{ .NMAPRun.StartStr }}
* [{{ md_title . }}](#{{ md_link . }})
{{- end -}}{{/* .ShouldNotSkipHost $skipDownHosts */}}
{{- end -}}{{/* range .Host */}}
{{- end -}}{{/* if not $skipTOC */}}

{{- if not $skipSummary }}
----
Expand Down
6 changes: 6 additions & 0 deletions formatter/resources/templates/simple-html.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@
</style>
</head>
<body>
{{ $skipTOC := .OutputOptions.HTMLOptions.SkipTOC }}
{{ $skipHeader := .OutputOptions.HTMLOptions.SkipHeader }}
{{ $skipDownHosts := .OutputOptions.HTMLOptions.SkipDownHosts }}
{{ $skipSummary := .OutputOptions.HTMLOptions.SkipSummary }}
{{ $skipTraceroute := .OutputOptions.HTMLOptions.SkipTraceroute }}
{{ $skipMetrics := .OutputOptions.HTMLOptions.SkipMetrics }}
{{ $skipPortScripts := .OutputOptions.HTMLOptions.SkipPortScripts }}
{{- if not $skipHeader }}
<h1>NMAP Scan Result: {{ .NMAPRun.StartStr }}</h1>
<hr>
{{- end }}{{/* if not $skipHeader */}}
{{ if not $skipTOC }}
<div id="toc">
<h2>Table of contents:</h2>
<ul>
Expand All @@ -123,6 +128,7 @@
</ul>
<hr>
</div>
{{ end }}{{/* if not $skipTOC */}}
{{ if not $skipSummary }}
<a id="scan-summary"></a>
<h2>Scan Summary:</h2>
Expand Down

0 comments on commit ee7f568

Please sign in to comment.