Refactor progress functionality to correct modules (#33)
This commit is contained in:
parent
5264d85fc6
commit
45bffbffca
@ -35,6 +35,7 @@ type Config struct {
|
||||
FollowRedirects bool
|
||||
AutoCalibration bool
|
||||
Timeout int
|
||||
ProgressFrequency int
|
||||
Delay optRange
|
||||
Filters []FilterProvider
|
||||
Matchers []FilterProvider
|
||||
@ -63,6 +64,8 @@ func NewConfig(ctx context.Context) Config {
|
||||
conf.Delay = optRange{0, 0, false, false}
|
||||
conf.Extensions = make([]string, 0)
|
||||
conf.Timeout = 10
|
||||
// Progress update frequency, in milliseconds
|
||||
conf.ProgressFrequency = 100
|
||||
conf.DirSearchCompat = false
|
||||
return conf
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ type InputProvider interface {
|
||||
type OutputProvider interface {
|
||||
Banner() error
|
||||
Finalize() error
|
||||
Progress(status string)
|
||||
Progress(status Progress)
|
||||
Error(errstring string)
|
||||
Warning(warnstring string)
|
||||
Result(resp Response)
|
||||
|
||||
@ -115,26 +115,18 @@ func (j *Job) runProgress(wg *sync.WaitGroup) {
|
||||
if j.Counter == totalProgress {
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
time.Sleep(time.Millisecond * time.Duration(j.Config.ProgressFrequency))
|
||||
}
|
||||
}
|
||||
|
||||
func (j *Job) updateProgress() {
|
||||
runningSecs := int((time.Now().Sub(j.startTime)) / time.Second)
|
||||
var reqRate int
|
||||
if runningSecs > 0 {
|
||||
reqRate = int(j.Counter / runningSecs)
|
||||
} else {
|
||||
reqRate = 0
|
||||
prog := Progress{
|
||||
StartedAt: j.startTime,
|
||||
ReqCount: j.Counter,
|
||||
ReqTotal: j.Input.Total(),
|
||||
ErrorCount: j.ErrorCounter,
|
||||
}
|
||||
dur := time.Now().Sub(j.startTime)
|
||||
hours := dur / time.Hour
|
||||
dur -= hours * time.Hour
|
||||
mins := dur / time.Minute
|
||||
dur -= mins * time.Minute
|
||||
secs := dur / time.Second
|
||||
progString := fmt.Sprintf(":: Progress: [%d/%d] :: %d req/sec :: Duration: [%d:%02d:%02d] :: Errors: %d ::", j.Counter, j.Total, int(reqRate), hours, mins, secs, j.ErrorCounter)
|
||||
j.Output.Progress(progString)
|
||||
j.Output.Progress(prog)
|
||||
}
|
||||
|
||||
//Calibrate runs a self-calibration task for filtering options, requesting random resources and acting accordingly
|
||||
|
||||
12
pkg/ffuf/progress.go
Normal file
12
pkg/ffuf/progress.go
Normal file
@ -0,0 +1,12 @@
|
||||
package ffuf
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Progress struct {
|
||||
StartedAt time.Time
|
||||
ReqCount int
|
||||
ReqTotal int
|
||||
ErrorCount int
|
||||
}
|
||||
@ -3,6 +3,7 @@ package output
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/ffuf/ffuf/pkg/ffuf"
|
||||
)
|
||||
@ -52,13 +53,28 @@ func (s *Stdoutput) Banner() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Stdoutput) Progress(status string) {
|
||||
func (s *Stdoutput) Progress(status ffuf.Progress) {
|
||||
if s.config.Quiet {
|
||||
// No progress for quiet mode
|
||||
return
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s%s", TERMINAL_CLEAR_LINE, status)
|
||||
}
|
||||
|
||||
dur := time.Now().Sub(status.StartedAt)
|
||||
runningSecs := int(dur / time.Second)
|
||||
var reqRate int
|
||||
if runningSecs > 0 {
|
||||
reqRate = int(status.ReqCount / runningSecs)
|
||||
} else {
|
||||
reqRate = 0
|
||||
}
|
||||
|
||||
hours := dur / time.Hour
|
||||
dur -= hours * time.Hour
|
||||
mins := dur / time.Minute
|
||||
dur -= mins * time.Minute
|
||||
secs := dur / time.Second
|
||||
|
||||
fmt.Fprintf(os.Stderr, "%s:: Progress: [%d/%d] :: %d req/sec :: Duration: [%d:%02d:%02d] :: Errors: %d ::", TERMINAL_CLEAR_LINE, status.ReqCount, status.ReqTotal, reqRate, hours, mins, secs, status.ErrorCount)
|
||||
}
|
||||
|
||||
func (s *Stdoutput) Error(errstring string) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user