forked from gophish/gophish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
67 lines (59 loc) · 2.03 KB
/
config.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
package config
import (
"encoding/json"
"io/ioutil"
log "github.com/gophish/gophish/logger"
)
// AdminServer represents the Admin server configuration details
type AdminServer struct {
ListenURL string `json:"listen_url"`
UseTLS bool `json:"use_tls"`
CertPath string `json:"cert_path"`
KeyPath string `json:"key_path"`
CSRFKey string `json:"csrf_key"`
AllowedInternalHosts []string `json:"allowed_internal_hosts"`
}
// PhishServer represents the Phish server configuration details
type PhishServer struct {
ListenURL string `json:"listen_url"`
UseTLS bool `json:"use_tls"`
CertPath string `json:"cert_path"`
KeyPath string `json:"key_path"`
}
// Config represents the configuration information.
type Config struct {
AdminConf AdminServer `json:"admin_server"`
PhishConf PhishServer `json:"phish_server"`
DBName string `json:"db_name"`
DBPath string `json:"db_path"`
DBSSLCaPath string `json:"db_sslca_path"`
MigrationsPath string `json:"migrations_prefix"`
TestFlag bool `json:"test_flag"`
ContactAddress string `json:"contact_address"`
Logging *log.Config `json:"logging"`
}
// Version contains the current gophish version
var Version = ""
// ServerName is the server type that is returned in the transparency response.
const ServerName = "gophish"
// LoadConfig loads the configuration from the specified filepath
func LoadConfig(filepath string) (*Config, error) {
// Get the config file
configFile, err := ioutil.ReadFile(filepath)
if err != nil {
return nil, err
}
config := &Config{}
err = json.Unmarshal(configFile, config)
if err != nil {
return nil, err
}
if config.Logging == nil {
config.Logging = &log.Config{}
}
// Choosing the migrations directory based on the database used.
config.MigrationsPath = config.MigrationsPath + config.DBName
// Explicitly set the TestFlag to false to prevent config.json overrides
config.TestFlag = false
return config, nil
}