package output import ( "html/template" "os" "time" "github.com/ffuf/ffuf/pkg/ffuf" ) type htmlFileOutput struct { CommandLine string Time string Keys []string Results []Result } const ( htmlTemplate = ` FFUF Report -


FFUF Report

{{ .CommandLine }}
{{ .Time }}
|result_raw|StatusCode|Input|Position|ContentLength|ContentWords|ContentLines|
{{ range .Keys }} {{ end }} {{range $result := .Results}}
|result_raw|{{ $result.StatusCode }}{{ range $keyword, $value := $result.Input }}|{{ $value | printf "%s" }}{{ end }}|{{ $result.Position }}|{{ $result.ContentLength }}|{{ $result.ContentWords }}|{{ $result.ContentLines }}|
{{ range $keyword, $value := $result.Input }}{{ end }} {{end}}
Status{{ . }}Position Length Words Lines
{{ $result.StatusCode }}{{ $value | printf "%s" }}{{ $result.Position }}{{ $result.ContentLength }}{{ $result.ContentWords }}{{ $result.ContentLines }}


` ) // colorizeResults returns a new slice with HTMLColor attribute func colorizeResults(results []Result) []Result { newResults := make([]Result, 0) for _, r := range results { result := r result.HTMLColor = "black" s := result.StatusCode if s >= 200 && s <= 299 { result.HTMLColor = "#adea9e" } if s >= 300 && s <= 399 { result.HTMLColor = "#bbbbe6" } if s >= 400 && s <= 499 { result.HTMLColor = "#d2cb7e" } if s >= 500 && s <= 599 { result.HTMLColor = "#de8dc1" } newResults = append(newResults, result) } return newResults } func writeHTML(config *ffuf.Config, results []Result) error { results = colorizeResults(results) ti := time.Now() keywords := make([]string, 0) for _, inputprovider := range config.InputProviders { keywords = append(keywords, inputprovider.Keyword) } outHTML := htmlFileOutput{ CommandLine: config.CommandLine, Time: ti.Format(time.RFC3339), Results: results, Keys: keywords, } f, err := os.Create(config.OutputFile) if err != nil { return err } defer f.Close() templateName := "output.html" t := template.New(templateName).Delims("{{", "}}") t.Parse(htmlTemplate) t.Execute(f, outHTML) return nil }