This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcrossfeed-agent.go
88 lines (74 loc) · 2.03 KB
/
crossfeed-agent.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
85
86
87
88
package main
import (
"database/sql"
"fmt"
"io"
"log"
"os"
"path"
"github.com/docopt/docopt-go"
_ "github.com/lib/pq"
"github.com/tkanos/gonfig"
)
type Configuration struct {
DB_HOST string
DB_PORT string
DB_USER string
DB_PASSWORD string
DB_NAME string
LOG_PATH string
DEBUG bool
SONAR_API_KEY string
SLACK_WEBHOOK_URL string
SPAWNER_TIMEOUT_LENGTH int
SQS_URL string
AWS_REGION string
AWS_ACCESS_KEY_ID string
AWS_SECRET_ACCESS_KEY string
}
var config Configuration
var psqlInfo string
var db *sql.DB
func main() {
config = Configuration{}
err := gonfig.GetConf("config.json", &config)
handleError(err)
psqlInfo = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", config.DB_HOST, config.DB_PORT, config.DB_USER, config.DB_PASSWORD, config.DB_NAME)
if !config.DEBUG {
logPath := path.Join(config.LOG_PATH, getMonth()+".txt")
f, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
handleError(err)
defer f.Close()
mw := io.MultiWriter(os.Stdout, f)
log.SetOutput(mw)
}
db, err = sql.Open("postgres", psqlInfo)
handleError(err)
err = db.Ping()
handleError(err)
usage := `Crossfeed agent. Used to execute backend scans from job queue. Scans are pushed to remote crossfeed database.
Examples:
crossfeed-agent scan-ports 443
Usage:
crossfeed-agent <command> [<args>...]
crossfeed-agent -h | --help
crossfeed-agent --version
Options:
-h --help Show this screen.
--version Show version.`
arguments, _ := docopt.ParseDoc(usage)
if hasKey(arguments, "<command>") {
switch arguments["<command>"].(string) {
case "scan-ports":
scanPorts(getArgs(arguments))
case "scan-hosts":
fetchHosts(getArgs(arguments))
case "subjack":
subjack(getArgs(arguments))
case "spawner":
initSpawner(getArgs(arguments))
default:
fmt.Println("Command not found: " + arguments["<command>"].(string))
}
}
}