forked from seekr-osint/seekr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
165 lines (148 loc) · 4.9 KB
/
main.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"embed"
"flag"
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"
"github.com/seekr-osint/seekr/api"
"github.com/seekr-osint/seekr/api/config"
"github.com/seekr-osint/seekr/api/seekrd"
seekrdhandler "github.com/seekr-osint/seekr/api/seekrdHandler"
"github.com/seekr-osint/seekr/api/version"
"github.com/seekr-osint/seekr/api/discord"
"github.com/seekr-osint/seekr/api/server"
"github.com/seekr-osint/seekr/api/webserver"
"github.com/seekr-osint/seekr/seekrplugin"
)
// Web server content
//
//go:embed web/*
var content embed.FS
var dataBase = make(api.DataBase)
var ver string
var schematicVersion version.SchematicVersion
func main() {
if ver != "" {
fmt.Printf("Welcome to seekr v%s\n", ver)
schematicVersion, err := version.ParseSchematicVersion(ver)
if err != nil {
log.Panicf("error checking version: %s\n", ver)
}
if !schematicVersion.IsLatest() {
fmt.Printf("You are running an old seekr version.\nDownload the latest seekr version at: %s\n", schematicVersion.GetLatest().DownloadURL())
}
} else {
fmt.Printf("Welcome to seekr unstable\nplease note that this version of seekr is NOT officially supported\n")
}
cfg, err := config.LoadConfig()
if err != nil && err != config.ErrNoConfigFile {
log.Printf("Failed to load config: %s\n", err)
return
}
configError := err
// dir := flag.String("dir", "./web", "dir where the html source code is located")
ip := flag.String("ip", cfg.Server.Ip, "Ip to serve api + webServer on (0.0.0.0 or localhost usually)")
data := flag.String("db", "data", "Database location")
port := flag.Uint64("port", cfg.Server.Port, "Port to serve the API on")
enableWebserver := flag.Bool("webserver", true, "Enable the webserver")
enableLiveServer := flag.Bool("live", false, "Enable the live server (dev only)")
liveServerPath := flag.String("live-path", "./web", "path to ./web folder")
browser := flag.Bool("browser", cfg.General.Browser, "open up the html interface in the default web browser")
forcePort := flag.Bool("forcePort", cfg.General.ForcePort, "forcePort")
createConfig := flag.Bool("writeDefaultConfig", false, "create toml config file containing the default config if the config is invalid or doesn't exsist")
enableRichCord := flag.Bool("discord", cfg.General.Discord, "Enable the discord rich appearance")
//enableWebserver := flag.Bool("webserver", true, "Enable the webserver")
enableApiServer := true
// webserverPort := flag.String("webserverPort", "5050", "Port to serve webserver on")
pluginList := os.Getenv("SEEKR_PLUGINS")
plugins := []string{}
if pluginList != "" {
plugins = strings.Split(pluginList, ",")
}
flag.Parse()
if configError == config.ErrNoConfigFile && *createConfig {
err = config.CreateDefaultConfig()
if err != nil {
fmt.Printf("error: %s\n", err)
}
}
if *enableRichCord {
err := discord.Rich()
if err == nil {
// No error printing due it printing an error if discord is not running / installed
//fmt.Printf("%s\n", err)
fmt.Printf("Setting discord rich presence\n")
}
}
apiConfig, err := api.ApiConfig{
Config: cfg,
Version: schematicVersion,
Server: server.Server{
Ip: *ip,
Port: uint16(*port),
ForcePort: *forcePort,
WebServer: webserver.Webserver{
Disable: !*enableWebserver,
FileSystem: content,
LiveServer: *enableLiveServer,
LiveServerPath: *liveServerPath,
},
ApiServer: server.ApiServer{
Disable: !enableApiServer,
},
},
LogFile: "seekr.log",
DataBaseFile: *data,
DataBase: dataBase,
SetCORSHeader: true,
SaveDBFunc: api.DefaultSaveDB,
LoadDBFunc: api.DefaultLoadDB,
}.ConfigParse()
if err != nil {
log.Panicf("error: %s", err)
}
apiConfig, err = seekrplugin.Open(plugins, apiConfig)
if err != nil {
log.Panicf("error: %s", err)
}
if *browser && !apiConfig.Server.WebServer.Disable {
openbrowser(fmt.Sprintf("http://%s:%d/web/index.html", apiConfig.Server.Ip, apiConfig.Server.Port))
}
//fmt.Println("Welcome to seekr a powerful OSINT tool able to scan the web for " + strconv.Itoa(len(api.DefaultServices)) + "services")
seekrdInstance := seekrd.SeekrdInstance{
Interval: 30,
ApiConfig: seekrd.ApiConfig(&apiConfig),
Services: seekrd.SeekrdServices{
seekrd.SeekrdService{
Name: "test",
Func: seekrd.SeekrdFunc(seekrdhandler.Handler(func(apiConfig *api.ApiConfig) error {
//apiConfig.DataBase["1"] = api.Person{
//ID: "1",
//Name: "hacker supa hack hack hack",
//}
return nil
})),
Repeat: true,
},
},
}
go seekrdInstance.SeekrdTicker()
//go api.Seekrd(api.DefaultSeekrdServices, 30) // run every 30 minutes
api.ServeApi(apiConfig)
}
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("cmd", "/c", "start", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
}
api.Check(err)
}