2021-11-22 17:53:25 +05:30
|
|
|
package writer
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/projectdiscovery/gologger"
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/output"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/progress"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/reporting"
|
2021-11-22 17:53:25 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// WriteResult is a helper for writing results to the output
|
2023-02-07 09:45:49 +01:00
|
|
|
func WriteResult(data *output.InternalWrappedEvent, output output.Writer, progress progress.Progress, issuesClient reporting.Client) bool {
|
2021-11-22 17:53:25 +05:30
|
|
|
// Handle the case where no result found for the template.
|
|
|
|
|
// In this case, we just show misc information about the failed
|
|
|
|
|
// match for the template.
|
2023-03-17 14:41:16 +01:00
|
|
|
if !data.HasOperatorResult() {
|
2021-11-22 17:53:25 +05:30
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
var matched bool
|
|
|
|
|
for _, result := range data.Results {
|
2024-03-10 22:02:42 +05:30
|
|
|
if issuesClient != nil {
|
|
|
|
|
if err := issuesClient.CreateIssue(result); err != nil {
|
|
|
|
|
gologger.Warning().Msgf("Could not create issue on tracker: %s", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-22 17:53:25 +05:30
|
|
|
if err := output.Write(result); err != nil {
|
|
|
|
|
gologger.Warning().Msgf("Could not write output event: %s\n", err)
|
|
|
|
|
}
|
|
|
|
|
if !matched {
|
|
|
|
|
matched = true
|
|
|
|
|
}
|
|
|
|
|
progress.IncrementMatched()
|
|
|
|
|
}
|
|
|
|
|
return matched
|
|
|
|
|
}
|