Move version output to a function (#407)

* Version info as function (#3)

* Opportunistic coloring
This commit is contained in:
Joona Hoikkala 2021-03-04 22:04:04 +02:00 committed by GitHub
parent 2ca8b83ed0
commit fb1be906f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 7 deletions

View File

@ -123,7 +123,7 @@ func Usage() {
} }
}) })
fmt.Printf("Fuzz Faster U Fool - v%s\n\n", ffuf.VERSION) fmt.Printf("Fuzz Faster U Fool - v%s\n\n", ffuf.Version())
// Print out the sections // Print out the sections
for _, section := range sections { for _, section := range sections {

View File

@ -136,7 +136,7 @@ func main() {
opts = ParseFlags(opts) opts = ParseFlags(opts)
if opts.General.ShowVersion { if opts.General.ShowVersion {
fmt.Printf("ffuf version: %s\n", ffuf.VERSION) fmt.Printf("ffuf version: %s\n", ffuf.Version())
os.Exit(0) os.Exit(0)
} }
if len(opts.Output.DebugLog) != 0 { if len(opts.Output.DebugLog) != 0 {

View File

@ -3,4 +3,5 @@ package ffuf
const ( const (
//VERSION holds the current version number //VERSION holds the current version number
VERSION = "1.3.0-git" VERSION = "1.3.0-git"
VERSION_APPENDIX = ""
) )

View File

@ -1,6 +1,7 @@
package ffuf package ffuf
import ( import (
"fmt"
"math/rand" "math/rand"
"os" "os"
) )
@ -41,3 +42,8 @@ func FileExists(path string) bool {
return !md.IsDir() return !md.IsDir()
} }
//Version returns the ffuf version string
func Version() string {
return fmt.Sprintf("%s%s", VERSION, VERSION_APPENDIX)
}

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"path" "path"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/ffuf/ffuf/pkg/ffuf" "github.com/ffuf/ffuf/pkg/ffuf"
@ -52,7 +53,8 @@ func NewStdoutput(conf *ffuf.Config) *Stdoutput {
} }
func (s *Stdoutput) Banner() { func (s *Stdoutput) Banner() {
fmt.Fprintf(os.Stderr, "%s\n v%s\n%s\n\n", BANNER_HEADER, ffuf.VERSION, BANNER_SEP) version := strings.ReplaceAll(ffuf.Version(), "<3", fmt.Sprintf("%s<3%s", ANSI_RED, ANSI_CLEAR))
fmt.Fprintf(os.Stderr, "%s\n v%s\n%s\n\n", BANNER_HEADER, version, BANNER_SEP)
printOption([]byte("Method"), []byte(s.config.Method)) printOption([]byte("Method"), []byte(s.config.Method))
printOption([]byte("URL"), []byte(s.config.Url)) printOption([]byte("URL"), []byte(s.config.Url))
@ -211,7 +213,7 @@ func (s *Stdoutput) writeToAll(config *ffuf.Config, res []Result) error {
// Go through each type of write, adding // Go through each type of write, adding
// the suffix to each output file. // the suffix to each output file.
if(config.OutputCreateEmptyFile && (len(res) == 0)){ if config.OutputCreateEmptyFile && (len(res) == 0) {
return nil return nil
} }

View File

@ -104,7 +104,7 @@ func (r *SimpleRunner) Execute(req *ffuf.Request) (ffuf.Response, error) {
// set default User-Agent header if not present // set default User-Agent header if not present
if _, ok := req.Headers["User-Agent"]; !ok { if _, ok := req.Headers["User-Agent"]; !ok {
req.Headers["User-Agent"] = fmt.Sprintf("%s v%s", "Fuzz Faster U Fool", ffuf.VERSION) req.Headers["User-Agent"] = fmt.Sprintf("%s v%s", "Fuzz Faster U Fool", ffuf.Version())
} }
// Handle Go http.Request special cases // Handle Go http.Request special cases