Skip to content

Commit

Permalink
Release v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
j3ssie committed Apr 6, 2022
1 parent 3ee3e48 commit 4ff33fb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 63 deletions.
88 changes: 31 additions & 57 deletions core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,63 +256,10 @@ func (r *Runner) RunStepWithSource(step libs.Step) (out string, err error) {
step.Parallel = 1
}

// skip concurrency part
if step.Parallel == 1 {
for index, line := range data {
customParams := make(map[string]string)
customParams["line"] = line
customParams["line_id"] = fmt.Sprintf("%v-%v", path.Base(line), index)
customParams["_id_"] = fmt.Sprintf("%v", index)
customParams["_line_"] = execution.StripName(line)

if len(step.Commands) > 0 {
r.RunCommands(step.Commands, step.Std)
}

if len(step.Ose) > 0 {
for _, ose := range step.Ose {
r.RunOse(ose)
}
}

if len(step.Scripts) > 0 {
r.RunScripts(step.Scripts)
}

// post scripts
if len(step.PConditions) > 0 || len(step.PScripts) > 0 {
err := r.CheckCondition(step.PConditions)
if err == nil {
if len(step.PScripts) > 0 {
r.RunScripts(step.PScripts)
}
}
}

}

if step.Label != "" {
utils.BlockF("Done-Step", color.HiCyanString(step.Label))
}
return out, nil
}

/////////////
// run multiple steps in concurrency mode

utils.DebugF("Run step in Parallel: %v", step.Parallel)
var wg sync.WaitGroup
p, _ := ants.NewPoolWithFunc(step.Parallel, func(i interface{}) {
r.startStepJob(i)
wg.Done()
}, ants.WithPreAlloc(true))
defer p.Release()

//var mu sync.Mutex
// prepare the data first
var newGeneratedSteps []libs.Step
for index, line := range data {
//mu.Lock()
customParams := make(map[string]string)
//localOptions := libs.Options{}
customParams["line"] = line
customParams["line_id"] = fmt.Sprintf("%v-%v", path.Base(line), index)
customParams["_id_"] = fmt.Sprintf("%v", index)
Expand Down Expand Up @@ -349,12 +296,39 @@ func (r *Runner) RunStepWithSource(step libs.Step) (out string, err error) {
localStep.PScripts = append(localStep.PScripts, AltResolveVariable(script, customParams))
}

newGeneratedSteps = append(newGeneratedSteps, localStep)
}

// skip concurrency part
if step.Parallel == 1 {
for _, newGeneratedStep := range newGeneratedSteps {
out, err = r.RunStep(newGeneratedStep)
if err != nil {
continue
}
}
if step.Label != "" {
utils.BlockF("Done-Step", color.HiCyanString(step.Label))
}
}

/////////////
// run multiple steps in concurrency mode

utils.DebugF("Run step in Parallel: %v", step.Parallel)
var wg sync.WaitGroup
p, _ := ants.NewPoolWithFunc(step.Parallel, func(i interface{}) {
r.startStepJob(i)
wg.Done()
}, ants.WithPreAlloc(true))
defer p.Release()

for _, newGeneratedStep := range newGeneratedSteps {
wg.Add(1)
err = p.Invoke(localStep)
err = p.Invoke(newGeneratedStep)
if err != nil {
utils.ErrorF("Error in parallel: %v", err)
}
//mu.Unlock()
}

wg.Wait()
Expand Down
2 changes: 0 additions & 2 deletions core/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func AltResolveVariable(format string, data map[string]string) string {
return buf.String()
}


// ParseFlow parse mode file
func ParseFlow(flowFile string) (libs.Flow, error) {
utils.DebugF("Parsing workflow at: %v", color.HiGreenString(flowFile))
Expand Down Expand Up @@ -183,7 +182,6 @@ func ParseInput(raw string, options libs.Options) map[string]string {
return ROptions
}


// ParseParams parse more params from cli
func ParseParams(rawParams []string) map[string]string {
params := make(map[string]string)
Expand Down
3 changes: 1 addition & 2 deletions core/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Runner struct {
RuntimeFile string

RoutineModules []string
Reports []string
Reports []string
Routines []libs.Routine

VM *otto.Otto
Expand Down Expand Up @@ -312,7 +312,6 @@ func (r *Runner) Start() {
utils.WriteToFile(r.DoneFile, "done")
}


// StartRoutines start the scan
func (r *Runner) StartRoutines() {
for _, routine := range r.Routines {
Expand Down
1 change: 0 additions & 1 deletion core/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func ResolveReports(module libs.Module, params map[string]string) libs.Module {
return module
}


// print all report
func printReports(module libs.Module) {
var files []string
Expand Down
2 changes: 1 addition & 1 deletion test-workflows/sample/parallel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: parallel1
desc: Run dirbscan scan on list of HTTP file

params:
- limit: '5000'
- limit: '5000'

steps:
- label: 'Start step 111'
Expand Down

0 comments on commit 4ff33fb

Please sign in to comment.