Fix an issue where output file was created regardless of -or (#444)

* Fix an issue where output file was created regardless of -or

* Add CHANGELOG entry
This commit is contained in:
Joona Hoikkala 2021-05-13 19:07:00 +03:00 committed by GitHub
parent 958f738b7d
commit ee0705e224
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 14 additions and 33 deletions

View file

@ -2,6 +2,7 @@
- master
- New
- Changed
- Fixed an issue where output file was created regardless of `-or`
- v1.3.1
- New

View file

@ -58,7 +58,7 @@ func ParseFlags(opts *ffuf.ConfigOptions) *ffuf.ConfigOptions {
flag.BoolVar(&ignored, "compressed", true, "Dummy flag for copy as curl functionality (ignored)")
flag.BoolVar(&ignored, "i", true, "Dummy flag for copy as curl functionality (ignored)")
flag.BoolVar(&ignored, "k", false, "Dummy flag for backwards compatibility")
flag.BoolVar(&opts.Output.OutputCreateEmptyFile, "or", opts.Output.OutputCreateEmptyFile, "Don't create the output file if we don't have results")
flag.BoolVar(&opts.Output.OutputSkipEmptyFile, "or", opts.Output.OutputSkipEmptyFile, "Don't create the output file if we don't have results")
flag.BoolVar(&opts.General.AutoCalibration, "ac", opts.General.AutoCalibration, "Automatically calibrate filtering options")
flag.BoolVar(&opts.General.Colors, "c", opts.General.Colors, "Colorize output.")
flag.BoolVar(&opts.General.Noninteractive, "noninteractive", opts.General.Noninteractive, "Disable the interactive console functionality")

View file

@ -34,7 +34,7 @@ type Config struct {
OutputDirectory string `json:"outputdirectory"`
OutputFile string `json:"outputfile"`
OutputFormat string `json:"outputformat"`
OutputCreateEmptyFile bool `json:"OutputCreateEmptyFile"`
OutputSkipEmptyFile bool `json:"OutputSkipEmptyFile"`
ProgressFrequency int `json:"-"`
ProxyURL string `json:"proxyurl"`
Quiet bool `json:"quiet"`

View file

@ -74,11 +74,11 @@ type InputOptions struct {
}
type OutputOptions struct {
DebugLog string
OutputDirectory string
OutputFile string
OutputFormat string
OutputCreateEmptyFile bool
DebugLog string
OutputDirectory string
OutputFile string
OutputFormat string
OutputSkipEmptyFile bool
}
type FilterOptions struct {
@ -146,7 +146,7 @@ func NewConfigOptions() *ConfigOptions {
c.Output.OutputDirectory = ""
c.Output.OutputFile = ""
c.Output.OutputFormat = "json"
c.Output.OutputCreateEmptyFile = false
c.Output.OutputSkipEmptyFile = false
return c
}
@ -382,7 +382,7 @@ func ConfigFromOptions(parseOpts *ConfigOptions, ctx context.Context, cancel con
conf.InputShell = parseOpts.Input.InputShell
conf.OutputFile = parseOpts.Output.OutputFile
conf.OutputDirectory = parseOpts.Output.OutputDirectory
conf.OutputCreateEmptyFile = parseOpts.Output.OutputCreateEmptyFile
conf.OutputSkipEmptyFile = parseOpts.Output.OutputSkipEmptyFile
conf.IgnoreBody = parseOpts.HTTP.IgnoreBody
conf.Quiet = parseOpts.General.Quiet
conf.StopOn403 = parseOpts.General.StopOn403

View file

@ -12,11 +12,6 @@ import (
var staticheaders = []string{"url", "redirectlocation", "position", "status_code", "content_length", "content_words", "content_lines", "content_type", "resultfile"}
func writeCSV(filename string, config *ffuf.Config, res []ffuf.Result, encode bool) error {
if config.OutputCreateEmptyFile && (len(res) == 0) {
return nil
}
header := make([]string, 0)
f, err := os.Create(filename)
if err != nil {

View file

@ -177,11 +177,6 @@ func colorizeResults(results []ffuf.Result) []ffuf.Result {
}
func writeHTML(filename string, config *ffuf.Config, results []ffuf.Result) error {
if config.OutputCreateEmptyFile && (len(results) == 0) {
return nil
}
results = colorizeResults(results)
ti := time.Now()

View file

@ -37,11 +37,6 @@ type jsonFileOutput struct {
}
func writeEJSON(filename string, config *ffuf.Config, res []ffuf.Result) error {
if config.OutputCreateEmptyFile && (len(res) == 0) {
return nil
}
t := time.Now()
outJSON := ejsonFileOutput{
CommandLine: config.CommandLine,

View file

@ -21,11 +21,6 @@ const (
)
func writeMarkdown(filename string, config *ffuf.Config, res []ffuf.Result) error {
if config.OutputCreateEmptyFile && (len(res) == 0) {
return nil
}
ti := time.Now()
keywords := make([]string, 0)

View file

@ -225,10 +225,6 @@ func (s *Stdoutput) writeToAll(filename string, config *ffuf.Config, res []ffuf.
// Go through each type of write, adding
// the suffix to each output file.
if config.OutputCreateEmptyFile && (len(res) == 0) {
return nil
}
s.config.OutputFile = BaseFilename + ".json"
err = writeJSON(filename, s.config, res)
if err != nil {
@ -272,6 +268,10 @@ func (s *Stdoutput) writeToAll(filename string, config *ffuf.Config, res []ffuf.
// SaveFile saves the current results to a file of a given type
func (s *Stdoutput) SaveFile(filename, format string) error {
var err error
if s.config.OutputSkipEmptyFile && len(s.Results) == 0 {
s.Info("No results and -or defined, output file not written.")
return err
}
switch format {
case "all":
err = s.writeToAll(filename, s.config, append(s.Results, s.CurrentResults...))