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