Markdown Reporting Index File (#3129)

* implemented index.md creation on markdown export

* fixes on markdown generation

added also hyperlink to markdown created

* code optimization and refactoring

* index header refactor
dev
xm1k3 2023-01-15 17:30:34 +01:00 committed by GitHub
parent 94ec553234
commit 84b0581306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -11,6 +11,8 @@ import (
stringsutil "github.com/projectdiscovery/utils/strings" stringsutil "github.com/projectdiscovery/utils/strings"
) )
const indexFileName = "index.md"
type Exporter struct { type Exporter struct {
directory string directory string
options *Options options *Options
@ -33,6 +35,17 @@ func New(options *Options) (*Exporter, error) {
directory = dir directory = dir
} }
_ = os.MkdirAll(directory, 0755) _ = os.MkdirAll(directory, 0755)
// index generation header
dataHeader := "" +
"|Hostname/IP|Finding|Severity|\n" +
"|-|-|-|\n"
err := os.WriteFile(filepath.Join(directory, indexFileName), []byte(dataHeader), 0644)
if err != nil {
return nil, err
}
return &Exporter{options: options, directory: directory}, nil return &Exporter{options: options, directory: directory}, nil
} }
@ -66,6 +79,18 @@ func (exporter *Exporter) Export(event *output.ResultEvent) error {
dataBuilder.WriteString(description) dataBuilder.WriteString(description)
data := dataBuilder.Bytes() data := dataBuilder.Bytes()
// index generation
file, err := os.OpenFile(filepath.Join(exporter.directory, indexFileName), os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer file.Close()
_, err = file.WriteString("|[" + event.Host + "](" + finalFilename + ")" + "|" + event.TemplateID + " " + event.MatcherName + "|" + event.Info.SeverityHolder.Severity.String() + "|\n")
if err != nil {
return err
}
return os.WriteFile(filepath.Join(exporter.directory, finalFilename), data, 0644) return os.WriteFile(filepath.Join(exporter.directory, finalFilename), data, 0644)
} }