github.com/merlinepedra/gopphish-attack@v0.9.0/config/config.go (about) 1 package config 2 3 import ( 4 "encoding/json" 5 log "github.com/gophish/gophish/logger" 6 "io/ioutil" 7 ) 8 9 // AdminServer represents the Admin server configuration details 10 type AdminServer struct { 11 ListenURL string `json:"listen_url"` 12 UseTLS bool `json:"use_tls"` 13 CertPath string `json:"cert_path"` 14 KeyPath string `json:"key_path"` 15 } 16 17 // PhishServer represents the Phish server configuration details 18 type PhishServer struct { 19 ListenURL string `json:"listen_url"` 20 UseTLS bool `json:"use_tls"` 21 CertPath string `json:"cert_path"` 22 KeyPath string `json:"key_path"` 23 } 24 25 // Config represents the configuration information. 26 type Config struct { 27 AdminConf AdminServer `json:"admin_server"` 28 PhishConf PhishServer `json:"phish_server"` 29 DBName string `json:"db_name"` 30 DBPath string `json:"db_path"` 31 DBSSLCaPath string `json:"db_sslca_path"` 32 MigrationsPath string `json:"migrations_prefix"` 33 TestFlag bool `json:"test_flag"` 34 ContactAddress string `json:"contact_address"` 35 Logging *log.Config `json:"logging"` 36 } 37 38 // Version contains the current gophish version 39 var Version = "" 40 41 // ServerName is the server type that is returned in the transparency response. 42 const ServerName = "gophish" 43 44 // LoadConfig loads the configuration from the specified filepath 45 func LoadConfig(filepath string) (*Config, error) { 46 // Get the config file 47 configFile, err := ioutil.ReadFile(filepath) 48 if err != nil { 49 return nil, err 50 } 51 config := &Config{} 52 err = json.Unmarshal(configFile, config) 53 if err != nil { 54 return nil, err 55 } 56 // Choosing the migrations directory based on the database used. 57 config.MigrationsPath = config.MigrationsPath + config.DBName 58 // Explicitly set the TestFlag to false to prevent config.json overrides 59 config.TestFlag = false 60 return config, nil 61 }