-
Notifications
You must be signed in to change notification settings - Fork 30
/
phocus.go
84 lines (77 loc) · 1.67 KB
/
phocus.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//go:build phocus
package main
import (
"math/rand"
"os"
"time"
"github.com/urfave/cli/v2"
)
const (
DEBUG_BUILD = false
)
func phocusLoop() {
info("Initializing engine context...")
phocusEnvironment()
if conf.Shell {
go shellSocket()
}
for {
scoreImage()
jitter := time.Duration(rand.Intn(8) + 10)
info("Scored image, sleeping for a bit...")
time.Sleep(jitter * time.Second)
}
}
// phocusEnvironment runs functions needed in order for phocus to successfully
// run on first start.
func phocusEnvironment() {
// Make sure we're running as admin.
permsCheck()
// Make sure phocus is not being traced or debugged.
checkTrace()
// Read in scoring data from the scoring data file.
if err := readScoringData(); err != nil {
fail(err)
os.Exit(1)
}
// Seed the random function for scoring at "random" intervals.
rand.Seed(time.Now().UnixNano())
}
// genPhocusApp generates a basic CLI interface that is OS-independent.
func genPhocusApp() *cli.App {
return &cli.App{
Name: "phocus",
Usage: "score vulnerabilities",
Action: func(c *cli.Context) error {
phocusLoop()
return nil
},
Before: func(c *cli.Context) error {
err := determineDirectory()
if err != nil {
return err
}
return nil
},
Commands: []*cli.Command{
{
Name: "prompt",
Aliases: []string{"p"},
Usage: "Launch TeamID GUI prompt",
Action: func(c *cli.Context) error {
launchIDPrompt()
return nil
},
},
{
Name: "version",
Aliases: []string{"v"},
Usage: "Print the current version of phocus",
Action: func(c *cli.Context) error {
println("phocus version " + version)
return nil
},
},
},
}
}