github.com/Ne0nd0g/gophish@v0.7.1-0.20190220040016-11493024a07d/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 MigrationsPath string `json:"migrations_prefix"` 36 TestFlag bool `json:"test_flag"` 37 ContactAddress string `json:"contact_address"` 38 Logging LoggingConfig `json:"logging"` 39 } 40 41 // Version contains the current gophish version 42 var Version = "" 43 44 // ServerName is the server type that is returned in the transparency response. 45 const ServerName = "gophish" 46 47 // LoadConfig loads the configuration from the specified filepath 48 func LoadConfig(filepath string) (*Config, error) { 49 // Get the config file 50 configFile, err := ioutil.ReadFile(filepath) 51 if err != nil { 52 return nil, err 53 } 54 config := &Config{} 55 err = json.Unmarshal(configFile, config) 56 if err != nil { 57 return nil, err 58 } 59 // Choosing the migrations directory based on the database used. 60 config.MigrationsPath = config.MigrationsPath + config.DBName 61 // Explicitly set the TestFlag to false to prevent config.json overrides 62 config.TestFlag = false 63 return config, nil 64 }