ffuff/pkg/output/file_md.go
DoI 965f282c0b
Response time logging and filtering (#433)
* Added response time reporting and filtering

* Update to use the http config context

* Added changelog and contributor info

* Round time output in stdout to nearest millisecond

* Change stdout duration rounding to use Milliseconds()

* Go back to Round() for timing output

* Changed stdout to display millisecond durations

Co-authored-by: Joona Hoikkala <joohoi@users.noreply.github.com>
2021-05-17 00:10:56 +03:00

53 lines
1.6 KiB
Go

package output
import (
"html/template"
"os"
"time"
"github.com/ffuf/ffuf/pkg/ffuf"
)
const (
markdownTemplate = `# FFUF Report
Command line : ` + "`{{.CommandLine}}`" + `
Time: ` + "{{ .Time }}" + `
{{ range .Keys }}| {{ . }} {{ end }}| URL | Redirectlocation | Position | Status Code | Content Length | Content Words | Content Lines | Content Type | Duration | ResultFile |
{{ range .Keys }}| :- {{ end }}| :-- | :--------------- | :---- | :------- | :---------- | :------------- | :------------ | :--------- | :----------- |
{{range .Results}}{{ range $keyword, $value := .Input }}| {{ $value | printf "%s" }} {{ end }}| {{ .Url }} | {{ .RedirectLocation }} | {{ .Position }} | {{ .StatusCode }} | {{ .ContentLength }} | {{ .ContentWords }} | {{ .ContentLines }} | {{ .ContentType }} | {{ .Duration}} | {{ .ResultFile }} |
{{end}}` // The template format is not pretty but follows the markdown guide
)
func writeMarkdown(filename string, config *ffuf.Config, res []ffuf.Result) error {
ti := time.Now()
keywords := make([]string, 0)
for _, inputprovider := range config.InputProviders {
keywords = append(keywords, inputprovider.Keyword)
}
outMD := htmlFileOutput{
CommandLine: config.CommandLine,
Time: ti.Format(time.RFC3339),
Results: res,
Keys: keywords,
}
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
templateName := "output.md"
t := template.New(templateName).Delims("{{", "}}")
_, err = t.Parse(markdownTemplate)
if err != nil {
return err
}
err = t.Execute(f, outMD)
return err
}