2014-01-09 06:42:05 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
2018-05-04 00:07:41 +00:00
|
|
|
|
|
|
|
log "github.com/gophish/gophish/logger"
|
2014-01-09 06:42:05 +00:00
|
|
|
)
|
|
|
|
|
2016-01-17 16:45:13 +00:00
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
2014-03-25 03:31:33 +00:00
|
|
|
// Config represents the configuration information.
|
|
|
|
type Config struct {
|
2016-01-19 03:13:32 +00:00
|
|
|
AdminConf AdminServer `json:"admin_server"`
|
|
|
|
PhishConf PhishServer `json:"phish_server"`
|
2016-11-19 16:37:22 +00:00
|
|
|
DBName string `json:"db_name"`
|
2016-01-19 03:13:32 +00:00
|
|
|
DBPath string `json:"db_path"`
|
2016-11-19 16:37:22 +00:00
|
|
|
MigrationsPath string `json:"migrations_prefix"`
|
2017-12-09 21:42:07 +00:00
|
|
|
TestFlag bool `json:"test_flag"`
|
2018-06-09 23:17:22 +00:00
|
|
|
ContactAddress string `json:"contact_address"`
|
2014-03-25 03:31:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 02:47:16 +00:00
|
|
|
// Conf contains the initialized configuration struct
|
2014-03-25 03:31:33 +00:00
|
|
|
var Conf Config
|
2014-01-09 06:42:05 +00:00
|
|
|
|
2016-08-06 23:58:34 +00:00
|
|
|
// Version contains the current gophish version
|
2017-09-06 02:54:32 +00:00
|
|
|
var Version = ""
|
2016-08-06 23:58:34 +00:00
|
|
|
|
2018-06-19 02:37:59 +00:00
|
|
|
// ServerName is the server type that is returned in the transparency response.
|
|
|
|
const ServerName = "gophish"
|
|
|
|
|
2017-09-06 02:54:32 +00:00
|
|
|
// LoadConfig loads the configuration from the specified filepath
|
2017-06-09 05:14:03 +00:00
|
|
|
func LoadConfig(filepath string) {
|
2014-01-09 06:42:05 +00:00
|
|
|
// Get the config file
|
2017-09-06 02:54:32 +00:00
|
|
|
configFile, err := ioutil.ReadFile(filepath)
|
2014-01-09 06:42:05 +00:00
|
|
|
if err != nil {
|
2018-05-04 00:07:41 +00:00
|
|
|
log.Errorf("File error: %v\n", err)
|
2014-01-09 06:42:05 +00:00
|
|
|
}
|
2017-09-06 02:54:32 +00:00
|
|
|
json.Unmarshal(configFile, &Conf)
|
|
|
|
|
2016-11-19 16:37:22 +00:00
|
|
|
// Choosing the migrations directory based on the database used.
|
|
|
|
Conf.MigrationsPath = Conf.MigrationsPath + Conf.DBName
|
2017-12-09 21:42:07 +00:00
|
|
|
// Explicitly set the TestFlag to false to prevent config.json overrides
|
|
|
|
Conf.TestFlag = false
|
2018-06-09 23:17:22 +00:00
|
|
|
|
|
|
|
// Print a warning if a contact address isn't provided
|
|
|
|
// (see: https://github.com/gophish/gophish/issues/1057)
|
|
|
|
if Conf.ContactAddress == "" {
|
|
|
|
log.Warnf("No contact address has been configured.")
|
|
|
|
log.Warnf("Please consider adding a contact_address entry in your config.json")
|
|
|
|
}
|
2014-01-09 06:42:05 +00:00
|
|
|
}
|