Debian Codegraph @

pkg/output/file_md.go

raw symbols SCIP
1 package output
2
3 import (
4 "html/template"
5 "os"
6 "time"
7
8 "github.com/ffuf/ffuf/v2/pkg/ffuf"
9 )
10
11 const (
12 markdownTemplate = `# FFUF Report
13
14 Command line : ` + "`{{.CommandLine}}`" + `
15 Time: ` + "{{ .Time }}" + `
16
17 {{ range .Keys }}| {{ . }} {{ end }}| URL | Redirectlocation | Position | Status Code | Content Length | Content Words | Content Lines | Content Type | Duration | ResultFile | ScraperData | Ffufhash
18 {{ range .Keys }}| :- {{ end }}| :-- | :--------------- | :---- | :------- | :---------- | :------------- | :------------ | :--------- | :----------- | :------------ | :-------- |
19 {{range .Results}}{{ range $keyword, $value := .Input }}| {{ $value | printf "%s" }} {{ end }}| {{ .Url }} | {{ .RedirectLocation }} | {{ .Position }} | {{ .StatusCode }} | {{ .ContentLength }} | {{ .ContentWords }} | {{ .ContentLines }} | {{ .ContentType }} | {{ .Duration}} | {{ .ResultFile }} | {{ .ScraperData }} | {{ .FfufHash }}
20 {{end}}` // The template format is not pretty but follows the markdown guide
21 )
22
23 func writeMarkdown(filename string, config *ffuf.Config, results []ffuf.Result) error {
24 ti := time.Now()
25
26 keywords := make([]string, 0)
27 for _, inputprovider := range config.InputProviders {
28 keywords = append(keywords, inputprovider.Keyword)
29 }
30
31 htmlResults := make([]htmlResult, 0)
32
33 ffufhash := ""
34 for _, r := range results {
35 strinput := make(map[string]string)
36 for k, v := range r.Input {
37 if k == "FFUFHASH" {
38 ffufhash = string(v)
39 } else {
40 strinput[k] = string(v)
41 }
42 }
43 strscraper := ""
44 for k, v := range r.ScraperData {
45 if len(v) > 0 {
46 strscraper = strscraper + "<p><b>" + k + ":</b><br />"
47 firstval := true
48 for _, val := range v {
49 if !firstval {
50 strscraper += "<br />"
51 }
52 strscraper += val
53 firstval = false
54 }
55 strscraper += "</p>"
56 }
57 }
58 hres := htmlResult{
59 Input: strinput,
60 Position: r.Position,
61 StatusCode: r.StatusCode,
62 ContentLength: r.ContentLength,
63 ContentWords: r.ContentWords,
64 ContentLines: r.ContentLines,
65 ContentType: r.ContentType,
66 RedirectLocation: r.RedirectLocation,
67 ScraperData: strscraper,
68 Duration: r.Duration,
69 ResultFile: r.ResultFile,
70 Url: r.Url,
71 Host: r.Host,
72 FfufHash: ffufhash,
73 }
74 htmlResults = append(htmlResults, hres)
75 }
76
77 outMD := htmlFileOutput{
78 CommandLine: config.CommandLine,
79 Time: ti.Format(time.RFC3339),
80 Results: htmlResults,
81 Keys: keywords,
82 }
83
84 f, err := os.Create(filename)
85 if err != nil {
86 return err
87 }
88 defer f.Close()
89
90 templateName := "output.md"
91 t := template.New(templateName).Delims("{{", "}}")
92 _, err = t.Parse(markdownTemplate)
93 if err != nil {
94 return err
95 }
96 err = t.Execute(f, outMD)
97 return err
98 }