-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_pool_node.go
More file actions
56 lines (50 loc) · 1.48 KB
/
Copy pathfuzz_pool_node.go
File metadata and controls
56 lines (50 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"fmt"
"os"
"strings"
"hackme/internal/poolfuzz"
)
func poolDistributedCampaign(cfg map[string]any) bool {
return poolfuzz.PoolDistributed(cfg)
}
func poolSyncCoordinatorConfigured() bool {
u := strings.TrimRight(strings.TrimSpace(os.Getenv("HACKME_POOL_COORDINATOR_URL")), "/")
if u == "" {
u = strings.TrimRight(strings.TrimSpace(os.Getenv("HACKME_COORDINATOR_URL")), "/")
}
return u != ""
}
// applyPoolSyncResponse enqueues or runs coordinator registration and sets JSON fields.
func (a *app) applyPoolSyncResponse(resp map[string]any, ctx context.Context, c fuzzAutoCampaign) {
if !poolDistributedCampaign(parseMapJSON(c.ConfigJSON)) {
return
}
if !poolSyncCoordinatorConfigured() {
resp["pool_sync"] = "fail"
resp["pool_sync_warning"] = "pool_distributed: set HACKME_POOL_COORDINATOR_URL on the node"
return
}
mode, warn := a.schedulePoolFuzzSync(ctx, c)
resp["pool_sync"] = mode
if warn != "" {
resp["pool_sync_warning"] = warn
}
}
func (a *app) syncPoolFuzzCampaign(ctx context.Context, c fuzzAutoCampaign) error {
if !poolDistributedCampaign(parseMapJSON(c.ConfigJSON)) {
return nil
}
if !poolSyncCoordinatorConfigured() {
return fmt.Errorf("pool_distributed: set HACKME_POOL_COORDINATOR_URL on the node")
}
mode, warn := a.schedulePoolFuzzSync(ctx, c)
if warn != "" && mode != "queued" {
return fmt.Errorf("%s", warn)
}
if mode == "fail" {
return fmt.Errorf("pool sync failed (see /api/status pool_sync)")
}
return nil
}